blob: 4f722aa0c7b329ac8928a5d57f0db6e199bee628 [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>
54#include <linux/toshiba.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020055#include <acpi/video.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057MODULE_AUTHOR("John Belmonte");
58MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
59MODULE_LICENSE("GPL");
60
Seth Forsheef11f9992012-01-18 13:44:11 -060061#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
62
Seth Forshee29cd2932012-01-18 13:44:09 -060063/* Scan code for Fn key on TOS1900 models */
64#define TOS1900_FN_SCAN 0x6e
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/* Toshiba ACPI method paths */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
68
Darren Harte0769fe2015-02-11 20:50:08 -080069/*
70 * The Toshiba configuration interface is composed of the HCI and the SCI,
Azael Avalos258c5902014-09-29 20:40:07 -060071 * which are defined as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 *
73 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
74 * be uniform across all their models. Ideally we would just call
75 * dedicated ACPI methods instead of using this primitive interface.
76 * However the ACPI methods seem to be incomplete in some areas (for
77 * example they allow setting, but not reading, the LCD brightness value),
78 * so this is still useful.
Matthew Garrettea6b31f2014-04-04 14:22:34 -040079 *
Azael Avalos84a62732014-03-25 20:38:29 -060080 * SCI stands for "System Configuration Interface" which aim is to
81 * conceal differences in hardware between different models.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 */
83
Azael Avalos258c5902014-09-29 20:40:07 -060084#define TCI_WORDS 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Azael Avalos3f75bbe2015-05-06 09:35:11 -060086/* Operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define HCI_SET 0xff00
88#define HCI_GET 0xfe00
Azael Avalos84a62732014-03-25 20:38:29 -060089#define SCI_OPEN 0xf100
90#define SCI_CLOSE 0xf200
91#define SCI_GET 0xf300
92#define SCI_SET 0xf400
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Azael Avalos3f75bbe2015-05-06 09:35:11 -060094/* Return codes */
Azael Avalos1864bbc2014-09-29 20:40:08 -060095#define TOS_SUCCESS 0x0000
Azael Avalose1a949c2015-07-31 21:58:14 -060096#define TOS_SUCCESS2 0x0001
Azael Avalos1864bbc2014-09-29 20:40:08 -060097#define TOS_OPEN_CLOSE_OK 0x0044
98#define TOS_FAILURE 0x1000
99#define TOS_NOT_SUPPORTED 0x8000
100#define TOS_ALREADY_OPEN 0x8100
101#define TOS_NOT_OPENED 0x8200
102#define TOS_INPUT_DATA_ERROR 0x8300
103#define TOS_WRITE_PROTECTED 0x8400
104#define TOS_NOT_PRESENT 0x8600
105#define TOS_FIFO_EMPTY 0x8c00
106#define TOS_DATA_NOT_AVAILABLE 0x8d20
107#define TOS_NOT_INITIALIZED 0x8d50
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700108#define TOS_NOT_INSTALLED 0x8e00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600110/* Registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define HCI_FAN 0x0004
Akio Idehara121b7b02012-04-06 01:46:43 +0900112#define HCI_TR_BACKLIGHT 0x0005
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define HCI_SYSTEM_EVENT 0x0016
114#define HCI_VIDEO_OUT 0x001c
115#define HCI_HOTKEY_EVENT 0x001e
116#define HCI_LCD_BRIGHTNESS 0x002a
Azael Avalos5a2813e2014-03-25 20:38:34 -0600117#define HCI_ACCELEROMETER 0x006d
Azael Avalos360f0f32014-03-25 20:38:31 -0600118#define HCI_KBD_ILLUMINATION 0x0095
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600119#define HCI_ECO_MODE 0x0097
Azael Avalos5a2813e2014-03-25 20:38:34 -0600120#define HCI_ACCELEROMETER2 0x00a6
Azael Avalos56e6b352015-03-20 16:55:16 -0600121#define HCI_SYSTEM_INFO 0xc000
Azael Avalos35d53ce2015-02-10 21:09:19 -0700122#define SCI_PANEL_POWER_ON 0x010d
Azael Avalosfdb79082014-03-25 20:38:30 -0600123#define SCI_ILLUMINATION 0x014e
Azael Avalose26ffe52015-01-18 18:30:22 -0700124#define SCI_USB_SLEEP_CHARGE 0x0150
Azael Avalos360f0f32014-03-25 20:38:31 -0600125#define SCI_KBD_ILLUM_STATUS 0x015c
Azael Avalos172ce0a2015-01-18 18:30:25 -0700126#define SCI_USB_SLEEP_MUSIC 0x015e
Azael Avalos17fe4b32015-02-10 21:09:20 -0700127#define SCI_USB_THREE 0x0169
Azael Avalos9d8658a2014-03-25 20:38:32 -0600128#define SCI_TOUCHPAD 0x050e
Azael Avalosbae84192015-02-10 21:09:18 -0700129#define SCI_KBD_FUNCTION_KEYS 0x0522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600131/* Field definitions */
Azael Avalos5a2813e2014-03-25 20:38:34 -0600132#define HCI_ACCEL_MASK 0x7fff
Seth Forshee29cd2932012-01-18 13:44:09 -0600133#define HCI_HOTKEY_DISABLE 0x0b
Azael Avalos52cbae02015-09-09 11:28:20 -0600134#define HCI_HOTKEY_ENABLE 0x01
Azael Avalosfb42d1f2015-03-20 16:55:18 -0600135#define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#define HCI_LCD_BRIGHTNESS_BITS 3
137#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
138#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
Azael Avalos360f0f32014-03-25 20:38:31 -0600139#define HCI_MISC_SHIFT 0x10
Azael Avalos56e6b352015-03-20 16:55:16 -0600140#define HCI_SYSTEM_TYPE1 0x10
141#define HCI_SYSTEM_TYPE2 0x11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define HCI_VIDEO_OUT_LCD 0x1
143#define HCI_VIDEO_OUT_CRT 0x2
144#define HCI_VIDEO_OUT_TV 0x4
Azael Avalos93f8c162014-09-12 18:50:36 -0600145#define SCI_KBD_MODE_MASK 0x1f
Azael Avalos360f0f32014-03-25 20:38:31 -0600146#define SCI_KBD_MODE_FNZ 0x1
147#define SCI_KBD_MODE_AUTO 0x2
Azael Avalos93f8c162014-09-12 18:50:36 -0600148#define SCI_KBD_MODE_ON 0x8
149#define SCI_KBD_MODE_OFF 0x10
150#define SCI_KBD_TIME_MAX 0x3c001a
Azael Avalose26ffe52015-01-18 18:30:22 -0700151#define SCI_USB_CHARGE_MODE_MASK 0xff
Azael Avalosc8c91842015-04-02 19:26:20 -0600152#define SCI_USB_CHARGE_DISABLED 0x00
153#define SCI_USB_CHARGE_ALTERNATE 0x09
154#define SCI_USB_CHARGE_TYPICAL 0x11
155#define SCI_USB_CHARGE_AUTO 0x21
Azael Avalos182bcaa2015-01-18 18:30:23 -0700156#define SCI_USB_CHARGE_BAT_MASK 0x7
157#define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
158#define SCI_USB_CHARGE_BAT_LVL_ON 0x4
159#define SCI_USB_CHARGE_BAT_LVL 0x0200
Azael Avalosbb3fe012015-01-18 18:30:24 -0700160#define SCI_USB_CHARGE_RAPID_DSP 0x0300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Seth Forshee135740d2011-09-20 16:55:49 -0500162struct toshiba_acpi_dev {
163 struct acpi_device *acpi_dev;
164 const char *method_hci;
Seth Forshee135740d2011-09-20 16:55:49 -0500165 struct input_dev *hotkey_dev;
Seth Forshee29cd2932012-01-18 13:44:09 -0600166 struct work_struct hotkey_work;
Seth Forshee135740d2011-09-20 16:55:49 -0500167 struct backlight_device *backlight_dev;
168 struct led_classdev led_dev;
Azael Avalos360f0f32014-03-25 20:38:31 -0600169 struct led_classdev kbd_led;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600170 struct led_classdev eco_led;
Azael Avalosfc5462f2015-07-22 18:09:11 -0600171 struct miscdevice miscdev;
Seth Forshee36d03f92011-09-20 16:55:53 -0500172
Seth Forshee135740d2011-09-20 16:55:49 -0500173 int force_fan;
174 int last_key_event;
175 int key_event_valid;
Azael Avalos93f8c162014-09-12 18:50:36 -0600176 int kbd_type;
Azael Avalos360f0f32014-03-25 20:38:31 -0600177 int kbd_mode;
178 int kbd_time;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700179 int usbsc_bat_level;
Azael Avalosc8c91842015-04-02 19:26:20 -0600180 int usbsc_mode_base;
Azael Avalosa2b34712015-03-20 16:55:17 -0600181 int hotkey_event_type;
Seth Forshee135740d2011-09-20 16:55:49 -0500182
Dan Carpenter592b7462012-01-15 14:28:20 +0300183 unsigned int illumination_supported:1;
184 unsigned int video_supported:1;
185 unsigned int fan_supported:1;
186 unsigned int system_event_supported:1;
Seth Forshee29cd2932012-01-18 13:44:09 -0600187 unsigned int ntfy_supported:1;
188 unsigned int info_supported:1;
Akio Idehara121b7b02012-04-06 01:46:43 +0900189 unsigned int tr_backlight_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600190 unsigned int kbd_illum_supported:1;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600191 unsigned int touchpad_supported:1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600192 unsigned int eco_supported:1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600193 unsigned int accelerometer_supported:1;
Azael Avalose26ffe52015-01-18 18:30:22 -0700194 unsigned int usb_sleep_charge_supported:1;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700195 unsigned int usb_rapid_charge_supported:1;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700196 unsigned int usb_sleep_music_supported:1;
Azael Avalosbae84192015-02-10 21:09:18 -0700197 unsigned int kbd_function_keys_supported:1;
Azael Avalos35d53ce2015-02-10 21:09:19 -0700198 unsigned int panel_power_on_supported:1;
Azael Avalos17fe4b32015-02-10 21:09:20 -0700199 unsigned int usb_three_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600200 unsigned int sysfs_created:1;
Azael Avalosb116fd02015-09-09 11:28:19 -0600201 unsigned int special_functions;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600202
203 bool kbd_led_registered;
204 bool illumination_led_registered;
205 bool eco_led_registered;
Seth Forshee135740d2011-09-20 16:55:49 -0500206};
207
Seth Forshee29cd2932012-01-18 13:44:09 -0600208static struct toshiba_acpi_dev *toshiba_acpi;
209
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800210static const struct acpi_device_id toshiba_device_ids[] = {
211 {"TOS6200", 0},
Ondrej Zary63a9e012014-11-10 00:11:54 +0100212 {"TOS6207", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400213 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800214 {"TOS1900", 0},
215 {"", 0},
216};
217MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
218
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800219static const struct key_entry toshiba_acpi_keymap[] = {
Unai Uribarrifec278a2014-01-14 11:06:47 +0100220 { KE_KEY, 0x9e, { KEY_RFKILL } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700221 { KE_KEY, 0x101, { KEY_MUTE } },
222 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
223 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600224 { KE_KEY, 0x10f, { KEY_TAB } },
Azael Avalosaf502832012-01-18 13:44:10 -0600225 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
226 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700227 { KE_KEY, 0x13b, { KEY_COFFEE } },
228 { KE_KEY, 0x13c, { KEY_BATTERY } },
229 { KE_KEY, 0x13d, { KEY_SLEEP } },
230 { KE_KEY, 0x13e, { KEY_SUSPEND } },
231 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
232 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
233 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
234 { KE_KEY, 0x142, { KEY_WLAN } },
Azael Avalosaf502832012-01-18 13:44:10 -0600235 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
Jon Dowlanda49010f2010-10-27 00:24:59 +0100236 { KE_KEY, 0x17f, { KEY_FN } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700237 { KE_KEY, 0xb05, { KEY_PROG2 } },
238 { KE_KEY, 0xb06, { KEY_WWW } },
239 { KE_KEY, 0xb07, { KEY_MAIL } },
240 { KE_KEY, 0xb30, { KEY_STOP } },
241 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
242 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
243 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
244 { KE_KEY, 0xb5a, { KEY_MEDIA } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600245 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
246 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
247 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
248 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
249 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700250 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500251};
252
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200253static const struct key_entry toshiba_acpi_alt_keymap[] = {
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200254 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
255 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalose6efad72014-08-04 09:21:02 -0600256 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200257 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200258 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
259 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600260 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200261 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600262 { KE_KEY, 0x157, { KEY_MUTE } },
263 { KE_KEY, 0x158, { KEY_WLAN } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200264 { KE_END, 0 },
265};
266
Darren Harte0769fe2015-02-11 20:50:08 -0800267/*
Hans de Goede358d6a22015-04-21 12:01:32 +0200268 * List of models which have a broken acpi-video backlight interface and thus
269 * need to use the toshiba (vendor) interface instead.
270 */
271static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
272 {}
273};
274
275/*
Darren Harte0769fe2015-02-11 20:50:08 -0800276 * Utility
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 */
278
Azael Avalosb5163992015-02-10 23:43:56 -0700279static inline void _set_bit(u32 *word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
281 *word = (*word & ~mask) | (mask * value);
282}
283
Darren Harte0769fe2015-02-11 20:50:08 -0800284/*
285 * ACPI interface wrappers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 */
287
Len Brown4be44fc2005-08-05 00:44:28 -0400288static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 acpi_status status;
291
Zhang Rui619400d2013-09-03 08:31:56 +0800292 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500293 return (status == AE_OK) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294}
295
Darren Harte0769fe2015-02-11 20:50:08 -0800296/*
297 * Perform a raw configuration call. Here we don't care about input or output
Azael Avalos258c5902014-09-29 20:40:07 -0600298 * buffer format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 */
Azael Avalos258c5902014-09-29 20:40:07 -0600300static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
301 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
303 struct acpi_object_list params;
Azael Avalos258c5902014-09-29 20:40:07 -0600304 union acpi_object in_objs[TCI_WORDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 struct acpi_buffer results;
Azael Avalos258c5902014-09-29 20:40:07 -0600306 union acpi_object out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 acpi_status status;
308 int i;
309
Azael Avalos258c5902014-09-29 20:40:07 -0600310 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600312 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 in_objs[i].type = ACPI_TYPE_INTEGER;
314 in_objs[i].integer.value = in[i];
315 }
316
317 results.length = sizeof(out_objs);
318 results.pointer = out_objs;
319
Seth Forshee6e02cc72011-09-20 16:55:51 -0500320 status = acpi_evaluate_object(dev->acpi_dev->handle,
321 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400322 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600323 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Azael Avalosb5163992015-02-10 23:43:56 -0700324 for (i = 0; i < out_objs->package.count; ++i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 out[i] = out_objs->package.elements[i].integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
327
328 return status;
329}
330
Darren Harte0769fe2015-02-11 20:50:08 -0800331/*
Azael Avalosd37782b2015-05-06 09:35:10 -0600332 * Common hci tasks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 *
334 * In addition to the ACPI status, the HCI system returns a result which
335 * may be useful (such as "not supported").
336 */
337
Azael Avalosd37782b2015-05-06 09:35:10 -0600338static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
Azael Avalos258c5902014-09-29 20:40:07 -0600340 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
341 u32 out[TCI_WORDS];
342 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600343
344 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345}
346
Azael Avalosd37782b2015-05-06 09:35:10 -0600347static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Azael Avalos258c5902014-09-29 20:40:07 -0600349 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
350 u32 out[TCI_WORDS];
351 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700352
Azael Avalos893f3f62014-09-29 20:40:09 -0600353 if (ACPI_FAILURE(status))
354 return TOS_FAILURE;
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600357
358 return out[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
Darren Harte0769fe2015-02-11 20:50:08 -0800361/*
362 * Common sci tasks
Azael Avalos84a62732014-03-25 20:38:29 -0600363 */
364
365static int sci_open(struct toshiba_acpi_dev *dev)
366{
Azael Avalos258c5902014-09-29 20:40:07 -0600367 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
368 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600369 acpi_status status;
370
Azael Avalos258c5902014-09-29 20:40:07 -0600371 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600372 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600373 pr_err("ACPI call to open SCI failed\n");
374 return 0;
375 }
376
Azael Avalos1864bbc2014-09-29 20:40:08 -0600377 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600378 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600379 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600380 pr_info("Toshiba SCI already opened\n");
381 return 1;
Azael Avalosfa465732015-01-18 19:17:12 -0700382 } else if (out[0] == TOS_NOT_SUPPORTED) {
Darren Harte0769fe2015-02-11 20:50:08 -0800383 /*
384 * Some BIOSes do not have the SCI open/close functions
Azael Avalosfa465732015-01-18 19:17:12 -0700385 * implemented and return 0x8000 (Not Supported), failing to
386 * register some supported features.
387 *
388 * Simply return 1 if we hit those affected laptops to make the
389 * supported features work.
390 *
391 * In the case that some laptops really do not support the SCI,
392 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
393 * and thus, not registering support for the queried feature.
394 */
395 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600396 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600397 pr_info("Toshiba SCI is not present\n");
398 }
399
400 return 0;
401}
402
403static void sci_close(struct toshiba_acpi_dev *dev)
404{
Azael Avalos258c5902014-09-29 20:40:07 -0600405 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
406 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600407 acpi_status status;
408
Azael Avalos258c5902014-09-29 20:40:07 -0600409 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600410 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600411 pr_err("ACPI call to close SCI failed\n");
412 return;
413 }
414
Azael Avalos1864bbc2014-09-29 20:40:08 -0600415 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600416 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600417 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600418 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600419 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600420 pr_info("Toshiba SCI is not present\n");
421}
422
Azael Avalos893f3f62014-09-29 20:40:09 -0600423static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Azael Avalos84a62732014-03-25 20:38:29 -0600424{
Azael Avalos258c5902014-09-29 20:40:07 -0600425 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
426 u32 out[TCI_WORDS];
427 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700428
Azael Avalos893f3f62014-09-29 20:40:09 -0600429 if (ACPI_FAILURE(status))
430 return TOS_FAILURE;
431
Azael Avalos84a62732014-03-25 20:38:29 -0600432 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600433
434 return out[0];
Azael Avalos84a62732014-03-25 20:38:29 -0600435}
436
Azael Avalos893f3f62014-09-29 20:40:09 -0600437static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Azael Avalos84a62732014-03-25 20:38:29 -0600438{
Azael Avalos258c5902014-09-29 20:40:07 -0600439 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
440 u32 out[TCI_WORDS];
441 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600442
443 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600444}
445
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200446/* Illumination support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600447static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200448{
Azael Avalos258c5902014-09-29 20:40:07 -0600449 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
450 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200451 acpi_status status;
452
Azael Avalosea215a3f2015-07-31 21:58:12 -0600453 dev->illumination_supported = 0;
454 dev->illumination_led_registered = false;
455
Azael Avalosfdb79082014-03-25 20:38:30 -0600456 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600457 return;
Azael Avalosfdb79082014-03-25 20:38:30 -0600458
Azael Avalos258c5902014-09-29 20:40:07 -0600459 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600460 sci_close(dev);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600461 if (ACPI_FAILURE(status))
Azael Avalosfdb79082014-03-25 20:38:30 -0600462 pr_err("ACPI call to query Illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600463 else if (out[0] == TOS_SUCCESS)
464 dev->illumination_supported = 1;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200465}
466
467static void toshiba_illumination_set(struct led_classdev *cdev,
468 enum led_brightness brightness)
469{
Seth Forshee135740d2011-09-20 16:55:49 -0500470 struct toshiba_acpi_dev *dev = container_of(cdev,
471 struct toshiba_acpi_dev, led_dev);
Azael Avalose1a949c2015-07-31 21:58:14 -0600472 u32 result;
473 u32 state;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200474
475 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600476 if (!sci_open(dev))
477 return;
478
479 /* Switch the illumination on/off */
480 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600481 result = sci_write(dev, SCI_ILLUMINATION, state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600482 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600483 if (result == TOS_FAILURE)
Azael Avalosfdb79082014-03-25 20:38:30 -0600484 pr_err("ACPI call for illumination failed\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200485}
486
487static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
488{
Seth Forshee135740d2011-09-20 16:55:49 -0500489 struct toshiba_acpi_dev *dev = container_of(cdev,
490 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600491 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200492
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600493 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600494 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200495 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200496
497 /* Check the illumination */
Azael Avalos893f3f62014-09-29 20:40:09 -0600498 result = sci_read(dev, SCI_ILLUMINATION, &state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600499 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600500 if (result == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600501 pr_err("ACPI call for illumination failed\n");
502 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600503 } else if (result != TOS_SUCCESS) {
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200504 return LED_OFF;
505 }
506
Azael Avalosfdb79082014-03-25 20:38:30 -0600507 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200508}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400509
Azael Avalos360f0f32014-03-25 20:38:31 -0600510/* KBD Illumination */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600511static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
Azael Avalos93f8c162014-09-12 18:50:36 -0600512{
Azael Avalos258c5902014-09-29 20:40:07 -0600513 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
514 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600515 acpi_status status;
516
Azael Avalosea215a3f2015-07-31 21:58:12 -0600517 dev->kbd_illum_supported = 0;
518 dev->kbd_led_registered = false;
519
Azael Avalos93f8c162014-09-12 18:50:36 -0600520 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600521 return;
Azael Avalos93f8c162014-09-12 18:50:36 -0600522
Azael Avalos258c5902014-09-29 20:40:07 -0600523 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600524 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600525 if (ACPI_FAILURE(status)) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600526 pr_err("ACPI call to query kbd illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600527 } else if (out[0] == TOS_SUCCESS) {
528 /*
529 * Check for keyboard backlight timeout max value,
530 * previous kbd backlight implementation set this to
531 * 0x3c0003, and now the new implementation set this
532 * to 0x3c001a, use this to distinguish between them.
533 */
534 if (out[3] == SCI_KBD_TIME_MAX)
535 dev->kbd_type = 2;
536 else
537 dev->kbd_type = 1;
538 /* Get the current keyboard backlight mode */
539 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
540 /* Get the current time (1-60 seconds) */
541 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
542 /* Flag as supported */
543 dev->kbd_illum_supported = 1;
Azael Avalos93f8c162014-09-12 18:50:36 -0600544 }
Azael Avalos93f8c162014-09-12 18:50:36 -0600545}
546
Azael Avalos360f0f32014-03-25 20:38:31 -0600547static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
548{
549 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600550
551 if (!sci_open(dev))
552 return -EIO;
553
Azael Avalos893f3f62014-09-29 20:40:09 -0600554 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600555 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600556 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600557 pr_err("ACPI call to set KBD backlight status failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600558 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos360f0f32014-03-25 20:38:31 -0600559 return -ENODEV;
Azael Avalos360f0f32014-03-25 20:38:31 -0600560
Azael Avalose1a949c2015-07-31 21:58:14 -0600561 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600562}
563
564static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
565{
566 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600567
568 if (!sci_open(dev))
569 return -EIO;
570
Azael Avalos893f3f62014-09-29 20:40:09 -0600571 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600572 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600573 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600574 pr_err("ACPI call to get KBD backlight status failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600575 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos360f0f32014-03-25 20:38:31 -0600576 return -ENODEV;
Azael Avalos360f0f32014-03-25 20:38:31 -0600577
Azael Avalose1a949c2015-07-31 21:58:14 -0600578 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600579}
580
581static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
582{
583 struct toshiba_acpi_dev *dev = container_of(cdev,
584 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600585 u32 result;
586 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600587
588 /* Check the keyboard backlight state */
Azael Avalosd37782b2015-05-06 09:35:10 -0600589 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
Azael Avalosa6b53542015-07-31 21:58:15 -0600590 if (result == TOS_FAILURE) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600591 pr_err("ACPI call to get the keyboard backlight failed\n");
592 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600593 } else if (result != TOS_SUCCESS) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600594 return LED_OFF;
595 }
596
597 return state ? LED_FULL : LED_OFF;
598}
599
600static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
601 enum led_brightness brightness)
602{
603 struct toshiba_acpi_dev *dev = container_of(cdev,
604 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600605 u32 result;
606 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600607
608 /* Set the keyboard backlight state */
609 state = brightness ? 1 : 0;
Azael Avalosd37782b2015-05-06 09:35:10 -0600610 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
Azael Avalosa6b53542015-07-31 21:58:15 -0600611 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600612 pr_err("ACPI call to set KBD Illumination mode failed\n");
Azael Avalos360f0f32014-03-25 20:38:31 -0600613}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400614
Azael Avalos9d8658a2014-03-25 20:38:32 -0600615/* TouchPad support */
616static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
617{
618 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600619
620 if (!sci_open(dev))
621 return -EIO;
622
Azael Avalos893f3f62014-09-29 20:40:09 -0600623 result = sci_write(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600624 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600625 if (result == TOS_FAILURE)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600626 pr_err("ACPI call to set the touchpad failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600627 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600628 return -ENODEV;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600629
Azael Avalose1a949c2015-07-31 21:58:14 -0600630 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600631}
632
633static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
634{
635 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600636
637 if (!sci_open(dev))
638 return -EIO;
639
Azael Avalos893f3f62014-09-29 20:40:09 -0600640 result = sci_read(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600641 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600642 if (result == TOS_FAILURE)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600643 pr_err("ACPI call to query the touchpad failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600644 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600645 return -ENODEV;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600646
Azael Avalose1a949c2015-07-31 21:58:14 -0600647 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600648}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200649
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600650/* Eco Mode support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600651static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600652{
653 acpi_status status;
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700654 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
Azael Avalos258c5902014-09-29 20:40:07 -0600655 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600656
Azael Avalosea215a3f2015-07-31 21:58:12 -0600657 dev->eco_supported = 0;
658 dev->eco_led_registered = false;
659
Azael Avalos258c5902014-09-29 20:40:07 -0600660 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600661 if (ACPI_FAILURE(status)) {
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700662 pr_err("ACPI call to get ECO led failed\n");
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700663 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
Darren Harte0769fe2015-02-11 20:50:08 -0800664 /*
665 * If we receive 0x8300 (Input Data Error), it means that the
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700666 * LED device is present, but that we just screwed the input
667 * parameters.
668 *
669 * Let's query the status of the LED to see if we really have a
670 * success response, indicating the actual presense of the LED,
671 * bail out otherwise.
672 */
673 in[3] = 1;
674 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600675 if (ACPI_FAILURE(status))
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700676 pr_err("ACPI call to get ECO led failed\n");
677 else if (out[0] == TOS_SUCCESS)
Azael Avalosea215a3f2015-07-31 21:58:12 -0600678 dev->eco_supported = 1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600679 }
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600680}
681
Azael Avalosb5163992015-02-10 23:43:56 -0700682static enum led_brightness
683toshiba_eco_mode_get_status(struct led_classdev *cdev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600684{
685 struct toshiba_acpi_dev *dev = container_of(cdev,
686 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600687 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
688 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600689 acpi_status status;
690
Azael Avalos258c5902014-09-29 20:40:07 -0600691 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600692 if (ACPI_FAILURE(status)) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600693 pr_err("ACPI call to get ECO led failed\n");
694 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600695 } else if (out[0] != TOS_SUCCESS) {
696 return LED_OFF;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600697 }
698
699 return out[2] ? LED_FULL : LED_OFF;
700}
701
702static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
703 enum led_brightness brightness)
704{
705 struct toshiba_acpi_dev *dev = container_of(cdev,
706 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600707 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
708 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600709 acpi_status status;
710
711 /* Switch the Eco Mode led on/off */
712 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600713 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600714 if (ACPI_FAILURE(status))
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600715 pr_err("ACPI call to set ECO led failed\n");
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600716}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400717
Azael Avalos5a2813e2014-03-25 20:38:34 -0600718/* Accelerometer support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600719static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600720{
Azael Avalos258c5902014-09-29 20:40:07 -0600721 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
722 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600723 acpi_status status;
724
Azael Avalosea215a3f2015-07-31 21:58:12 -0600725 dev->accelerometer_supported = 0;
726
Darren Harte0769fe2015-02-11 20:50:08 -0800727 /*
728 * Check if the accelerometer call exists,
Azael Avalos5a2813e2014-03-25 20:38:34 -0600729 * this call also serves as initialization
730 */
Azael Avalos258c5902014-09-29 20:40:07 -0600731 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600732 if (ACPI_FAILURE(status))
Azael Avalos5a2813e2014-03-25 20:38:34 -0600733 pr_err("ACPI call to query the accelerometer failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600734 else if (out[0] == TOS_SUCCESS)
735 dev->accelerometer_supported = 1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600736}
737
738static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
Azael Avalosa6b53542015-07-31 21:58:15 -0600739 u32 *xy, u32 *z)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600740{
Azael Avalos258c5902014-09-29 20:40:07 -0600741 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
742 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600743 acpi_status status;
744
745 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600746 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600747 if (ACPI_FAILURE(status)) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600748 pr_err("ACPI call to query the accelerometer failed\n");
749 return -EIO;
Azael Avalose1a949c2015-07-31 21:58:14 -0600750 } else if (out[0] == TOS_NOT_SUPPORTED) {
751 return -ENODEV;
752 } else if (out[0] == TOS_SUCCESS) {
753 *xy = out[2];
754 *z = out[4];
755 return 0;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600756 }
757
Azael Avalose1a949c2015-07-31 21:58:14 -0600758 return -EIO;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600759}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600760
Azael Avalose26ffe52015-01-18 18:30:22 -0700761/* Sleep (Charge and Music) utilities support */
Azael Avalosc8c91842015-04-02 19:26:20 -0600762static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
763{
764 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
765 u32 out[TCI_WORDS];
766 acpi_status status;
767
Azael Avalosc8c91842015-04-02 19:26:20 -0600768 dev->usb_sleep_charge_supported = 0;
769
770 if (!sci_open(dev))
771 return;
772
773 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600774 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600775 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
776 sci_close(dev);
777 return;
778 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600779 sci_close(dev);
780 return;
781 } else if (out[0] == TOS_SUCCESS) {
782 dev->usbsc_mode_base = out[4];
783 }
784
785 in[5] = SCI_USB_CHARGE_BAT_LVL;
786 status = tci_raw(dev, in, out);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600787 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600788 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600789 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
Azael Avalosc8c91842015-04-02 19:26:20 -0600790 } else if (out[0] == TOS_SUCCESS) {
791 dev->usbsc_bat_level = out[2];
Azael Avalosea215a3f2015-07-31 21:58:12 -0600792 /* Flag as supported */
Azael Avalosc8c91842015-04-02 19:26:20 -0600793 dev->usb_sleep_charge_supported = 1;
794 }
795
Azael Avalosc8c91842015-04-02 19:26:20 -0600796}
797
Azael Avalose26ffe52015-01-18 18:30:22 -0700798static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
799 u32 *mode)
800{
801 u32 result;
802
803 if (!sci_open(dev))
804 return -EIO;
805
806 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
807 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600808 if (result == TOS_FAILURE)
Azael Avalose26ffe52015-01-18 18:30:22 -0700809 pr_err("ACPI call to set USB S&C mode failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600810 else if (result == TOS_NOT_SUPPORTED)
Azael Avalose26ffe52015-01-18 18:30:22 -0700811 return -ENODEV;
Azael Avalose26ffe52015-01-18 18:30:22 -0700812
Azael Avalose1a949c2015-07-31 21:58:14 -0600813 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700814}
815
816static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
817 u32 mode)
818{
819 u32 result;
820
821 if (!sci_open(dev))
822 return -EIO;
823
824 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
825 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600826 if (result == TOS_FAILURE)
Azael Avalose26ffe52015-01-18 18:30:22 -0700827 pr_err("ACPI call to set USB S&C mode failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600828 else if (result == TOS_NOT_SUPPORTED)
Azael Avalose26ffe52015-01-18 18:30:22 -0700829 return -ENODEV;
Azael Avalose26ffe52015-01-18 18:30:22 -0700830
Azael Avalose1a949c2015-07-31 21:58:14 -0600831 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700832}
833
Azael Avalos182bcaa2015-01-18 18:30:23 -0700834static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
835 u32 *mode)
836{
837 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
838 u32 out[TCI_WORDS];
839 acpi_status status;
840
841 if (!sci_open(dev))
842 return -EIO;
843
844 in[5] = SCI_USB_CHARGE_BAT_LVL;
845 status = tci_raw(dev, in, out);
846 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600847 if (ACPI_FAILURE(status)) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700848 pr_err("ACPI call to get USB S&C battery level failed\n");
Azael Avalos182bcaa2015-01-18 18:30:23 -0700849 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700850 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600851 } else if (out[0] == TOS_SUCCESS) {
852 *mode = out[2];
853 return 0;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700854 }
855
Azael Avalose1a949c2015-07-31 21:58:14 -0600856 return -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700857}
858
859static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
860 u32 mode)
861{
862 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
863 u32 out[TCI_WORDS];
864 acpi_status status;
865
866 if (!sci_open(dev))
867 return -EIO;
868
869 in[2] = mode;
870 in[5] = SCI_USB_CHARGE_BAT_LVL;
871 status = tci_raw(dev, in, out);
872 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600873 if (ACPI_FAILURE(status))
Azael Avalos182bcaa2015-01-18 18:30:23 -0700874 pr_err("ACPI call to set USB S&C battery level failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600875 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalos182bcaa2015-01-18 18:30:23 -0700876 return -ENODEV;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700877
Azael Avalose1a949c2015-07-31 21:58:14 -0600878 return out[0] == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700879}
880
Azael Avalosbb3fe012015-01-18 18:30:24 -0700881static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
882 u32 *state)
883{
884 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
885 u32 out[TCI_WORDS];
886 acpi_status status;
887
888 if (!sci_open(dev))
889 return -EIO;
890
891 in[5] = SCI_USB_CHARGE_RAPID_DSP;
892 status = tci_raw(dev, in, out);
893 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600894 if (ACPI_FAILURE(status)) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600895 pr_err("ACPI call to get USB Rapid Charge failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600896 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosbb3fe012015-01-18 18:30:24 -0700897 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600898 } else if (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) {
899 *state = out[2];
900 return 0;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700901 }
902
Azael Avalose1a949c2015-07-31 21:58:14 -0600903 return -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700904}
905
906static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
907 u32 state)
908{
909 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
910 u32 out[TCI_WORDS];
911 acpi_status status;
912
913 if (!sci_open(dev))
914 return -EIO;
915
916 in[2] = state;
917 in[5] = SCI_USB_CHARGE_RAPID_DSP;
918 status = tci_raw(dev, in, out);
919 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600920 if (ACPI_FAILURE(status))
Azael Avalosbb26f182015-04-02 19:26:21 -0600921 pr_err("ACPI call to set USB Rapid Charge failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600922 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalosbb3fe012015-01-18 18:30:24 -0700923 return -ENODEV;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700924
Azael Avalose1a949c2015-07-31 21:58:14 -0600925 return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700926}
927
Azael Avalos172ce0a2015-01-18 18:30:25 -0700928static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
929{
930 u32 result;
931
932 if (!sci_open(dev))
933 return -EIO;
934
935 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
936 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600937 if (result == TOS_FAILURE)
Azael Avalosbb26f182015-04-02 19:26:21 -0600938 pr_err("ACPI call to get Sleep and Music failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600939 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos172ce0a2015-01-18 18:30:25 -0700940 return -ENODEV;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700941
Azael Avaloscf680ea2015-09-09 11:25:44 -0600942 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700943}
944
945static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
946{
947 u32 result;
948
949 if (!sci_open(dev))
950 return -EIO;
951
952 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
953 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600954 if (result == TOS_FAILURE)
Azael Avalosbb26f182015-04-02 19:26:21 -0600955 pr_err("ACPI call to set Sleep and Music failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600956 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos172ce0a2015-01-18 18:30:25 -0700957 return -ENODEV;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700958
Azael Avalose1a949c2015-07-31 21:58:14 -0600959 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700960}
961
Azael Avalosbae84192015-02-10 21:09:18 -0700962/* Keyboard function keys */
963static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
964{
965 u32 result;
966
967 if (!sci_open(dev))
968 return -EIO;
969
970 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
971 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600972 if (result == TOS_FAILURE)
Azael Avalosbae84192015-02-10 21:09:18 -0700973 pr_err("ACPI call to get KBD function keys failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600974 else if (result == TOS_NOT_SUPPORTED)
Azael Avalosbae84192015-02-10 21:09:18 -0700975 return -ENODEV;
Azael Avalosbae84192015-02-10 21:09:18 -0700976
Azael Avalose1a949c2015-07-31 21:58:14 -0600977 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -0700978}
979
980static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
981{
982 u32 result;
983
984 if (!sci_open(dev))
985 return -EIO;
986
987 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
988 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600989 if (result == TOS_FAILURE)
Azael Avalosbae84192015-02-10 21:09:18 -0700990 pr_err("ACPI call to set KBD function keys failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600991 else if (result == TOS_NOT_SUPPORTED)
Azael Avalosbae84192015-02-10 21:09:18 -0700992 return -ENODEV;
Azael Avalosbae84192015-02-10 21:09:18 -0700993
Azael Avalose1a949c2015-07-31 21:58:14 -0600994 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -0700995}
996
Azael Avalos35d53ce2015-02-10 21:09:19 -0700997/* Panel Power ON */
998static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
999{
1000 u32 result;
1001
1002 if (!sci_open(dev))
1003 return -EIO;
1004
1005 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1006 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001007 if (result == TOS_FAILURE)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001008 pr_err("ACPI call to get Panel Power ON failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001009 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001010 return -ENODEV;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001011
Azael Avalose1a949c2015-07-31 21:58:14 -06001012 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001013}
1014
1015static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1016{
1017 u32 result;
1018
1019 if (!sci_open(dev))
1020 return -EIO;
1021
1022 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1023 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001024 if (result == TOS_FAILURE)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001025 pr_err("ACPI call to set Panel Power ON failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001026 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001027 return -ENODEV;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001028
Azael Avalose1a949c2015-07-31 21:58:14 -06001029 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001030}
1031
Azael Avalos17fe4b32015-02-10 21:09:20 -07001032/* USB Three */
1033static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1034{
1035 u32 result;
1036
1037 if (!sci_open(dev))
1038 return -EIO;
1039
1040 result = sci_read(dev, SCI_USB_THREE, state);
1041 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001042 if (result == TOS_FAILURE)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001043 pr_err("ACPI call to get USB 3 failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001044 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001045 return -ENODEV;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001046
Azael Avalose1a949c2015-07-31 21:58:14 -06001047 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001048}
1049
1050static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1051{
1052 u32 result;
1053
1054 if (!sci_open(dev))
1055 return -EIO;
1056
1057 result = sci_write(dev, SCI_USB_THREE, state);
1058 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001059 if (result == TOS_FAILURE)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001060 pr_err("ACPI call to set USB 3 failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001061 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001062 return -ENODEV;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001063
Azael Avalose1a949c2015-07-31 21:58:14 -06001064 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001065}
1066
Azael Avalos56e6b352015-03-20 16:55:16 -06001067/* Hotkey Event type */
1068static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1069 u32 *type)
1070{
Azael Avalos3b876002015-05-06 09:35:09 -06001071 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1072 u32 out[TCI_WORDS];
1073 acpi_status status;
Azael Avalos56e6b352015-03-20 16:55:16 -06001074
Azael Avalos3b876002015-05-06 09:35:09 -06001075 status = tci_raw(dev, in, out);
1076 if (ACPI_FAILURE(status)) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001077 pr_err("ACPI call to get System type failed\n");
Azael Avalos3b876002015-05-06 09:35:09 -06001078 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001079 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -06001080 } else if (out[0] == TOS_SUCCESS) {
1081 *type = out[3];
1082 return 0;
Azael Avalos56e6b352015-03-20 16:55:16 -06001083 }
1084
Azael Avalose1a949c2015-07-31 21:58:14 -06001085 return -EIO;
Azael Avalos56e6b352015-03-20 16:55:16 -06001086}
1087
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001088/* Transflective Backlight */
Azael Avalos695f6062015-07-22 18:09:13 -06001089static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001090{
Azael Avalose1a949c2015-07-31 21:58:14 -06001091 u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001092
Azael Avalose1a949c2015-07-31 21:58:14 -06001093 if (result == TOS_FAILURE)
1094 pr_err("ACPI call to get Transflective Backlight failed\n");
1095 else if (result == TOS_NOT_SUPPORTED)
1096 return -ENODEV;
1097
1098 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001099}
1100
Azael Avalos695f6062015-07-22 18:09:13 -06001101static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001102{
Azael Avalose1a949c2015-07-31 21:58:14 -06001103 u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001104
Azael Avalose1a949c2015-07-31 21:58:14 -06001105 if (result == TOS_FAILURE)
1106 pr_err("ACPI call to set Transflective Backlight failed\n");
1107 else if (result == TOS_NOT_SUPPORTED)
1108 return -ENODEV;
1109
1110 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001111}
1112
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001113static struct proc_dir_entry *toshiba_proc_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001115/* LCD Brightness */
Seth Forshee62cce752012-04-19 11:23:50 -05001116static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Azael Avalose1a949c2015-07-31 21:58:14 -06001118 u32 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001120 int brightness = 0;
1121
1122 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001123 int ret = get_tr_backlight_status(dev, &value);
Azael Avalosb5163992015-02-10 23:43:56 -07001124
Akio Idehara121b7b02012-04-06 01:46:43 +09001125 if (ret)
1126 return ret;
Azael Avalos695f6062015-07-22 18:09:13 -06001127 if (value)
Akio Idehara121b7b02012-04-06 01:46:43 +09001128 return 0;
1129 brightness++;
1130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Azael Avalose1a949c2015-07-31 21:58:14 -06001132 result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
1133 if (result == TOS_FAILURE)
1134 pr_err("ACPI call to get LCD Brightness failed\n");
1135 else if (result == TOS_NOT_SUPPORTED)
1136 return -ENODEV;
1137 if (result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +09001138 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001139
1140 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001141}
1142
Seth Forshee62cce752012-04-19 11:23:50 -05001143static int get_lcd_brightness(struct backlight_device *bd)
1144{
1145 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001146
Seth Forshee62cce752012-04-19 11:23:50 -05001147 return __get_lcd_brightness(dev);
1148}
1149
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001150static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -07001151{
Seth Forshee135740d2011-09-20 16:55:49 -05001152 struct toshiba_acpi_dev *dev = m->private;
Akio Idehara121b7b02012-04-06 01:46:43 +09001153 int levels;
Azael Avalose1a949c2015-07-31 21:58:14 -06001154 int value;
Holger Machtc9263552006-10-20 14:30:29 -07001155
Seth Forshee135740d2011-09-20 16:55:49 -05001156 if (!dev->backlight_dev)
1157 return -ENODEV;
1158
Akio Idehara121b7b02012-04-06 01:46:43 +09001159 levels = dev->backlight_dev->props.max_brightness + 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001160 value = get_lcd_brightness(dev->backlight_dev);
Holger Machtc9263552006-10-20 14:30:29 -07001161 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001162 seq_printf(m, "brightness: %d\n", value);
Akio Idehara121b7b02012-04-06 01:46:43 +09001163 seq_printf(m, "brightness_levels: %d\n", levels);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001164 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
1166
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001167 pr_err("Error reading LCD brightness\n");
Azael Avalose1a949c2015-07-31 21:58:14 -06001168
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001169 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001170}
1171
1172static int lcd_proc_open(struct inode *inode, struct file *file)
1173{
Al Virod9dda782013-03-31 18:16:14 -04001174 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175}
1176
Seth Forshee62cce752012-04-19 11:23:50 -05001177static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -07001178{
Azael Avalose1a949c2015-07-31 21:58:14 -06001179 u32 result;
Holger Machtc9263552006-10-20 14:30:29 -07001180
Akio Idehara121b7b02012-04-06 01:46:43 +09001181 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001182 int ret = set_tr_backlight_status(dev, !value);
Azael Avalosb5163992015-02-10 23:43:56 -07001183
Akio Idehara121b7b02012-04-06 01:46:43 +09001184 if (ret)
1185 return ret;
1186 if (value)
1187 value--;
1188 }
1189
Azael Avalosa39f46d2014-11-24 19:29:36 -07001190 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
Azael Avalose1a949c2015-07-31 21:58:14 -06001191 result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
1192 if (result == TOS_FAILURE)
1193 pr_err("ACPI call to set LCD Brightness failed\n");
1194 else if (result == TOS_NOT_SUPPORTED)
1195 return -ENODEV;
1196
1197 return result == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001198}
1199
1200static int set_lcd_status(struct backlight_device *bd)
1201{
Seth Forshee135740d2011-09-20 16:55:49 -05001202 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001203
Seth Forshee62cce752012-04-19 11:23:50 -05001204 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -07001205}
1206
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001207static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1208 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209{
Al Virod9dda782013-03-31 18:16:14 -04001210 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001211 char cmd[42];
1212 size_t len;
Akio Idehara121b7b02012-04-06 01:46:43 +09001213 int levels = dev->backlight_dev->props.max_brightness + 1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001214 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001216 len = min(count, sizeof(cmd) - 1);
1217 if (copy_from_user(cmd, buf, len))
1218 return -EFAULT;
1219 cmd[len] = '\0';
1220
Azael Avalose1a949c2015-07-31 21:58:14 -06001221 if (sscanf(cmd, " brightness : %i", &value) != 1 &&
1222 value < 0 && value > levels)
1223 return -EINVAL;
1224
1225 if (set_lcd_brightness(dev, value))
1226 return -EIO;
1227
1228 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229}
1230
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001231static const struct file_operations lcd_proc_fops = {
1232 .owner = THIS_MODULE,
1233 .open = lcd_proc_open,
1234 .read = seq_read,
1235 .llseek = seq_lseek,
1236 .release = single_release,
1237 .write = lcd_proc_write,
1238};
1239
Azael Avalose1a949c2015-07-31 21:58:14 -06001240/* Video-Out */
Seth Forshee36d03f92011-09-20 16:55:53 -05001241static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1242{
Azael Avalose1a949c2015-07-31 21:58:14 -06001243 u32 result = hci_read(dev, HCI_VIDEO_OUT, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001244
Azael Avalose1a949c2015-07-31 21:58:14 -06001245 if (result == TOS_FAILURE)
1246 pr_err("ACPI call to get Video-Out failed\n");
1247 else if (result == TOS_NOT_SUPPORTED)
1248 return -ENODEV;
1249
1250 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001251}
1252
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001253static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Seth Forshee135740d2011-09-20 16:55:49 -05001255 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 u32 value;
1257
Azael Avalose1a949c2015-07-31 21:58:14 -06001258 if (!get_video_status(dev, &value)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1260 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001261 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001262
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001263 seq_printf(m, "lcd_out: %d\n", is_lcd);
1264 seq_printf(m, "crt_out: %d\n", is_crt);
1265 seq_printf(m, "tv_out: %d\n", is_tv);
Azael Avalose1a949c2015-07-31 21:58:14 -06001266 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 }
1268
Azael Avalose1a949c2015-07-31 21:58:14 -06001269 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270}
1271
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001272static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273{
Al Virod9dda782013-03-31 18:16:14 -04001274 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001275}
1276
1277static ssize_t video_proc_write(struct file *file, const char __user *buf,
1278 size_t count, loff_t *pos)
1279{
Al Virod9dda782013-03-31 18:16:14 -04001280 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Azael Avalose1a949c2015-07-31 21:58:14 -06001281 char *buffer;
1282 char *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 int remain = count;
1284 int lcd_out = -1;
1285 int crt_out = -1;
1286 int tv_out = -1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001287 int value;
1288 int ret;
Al Virob4482a42007-10-14 19:35:40 +01001289 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001291 cmd = kmalloc(count + 1, GFP_KERNEL);
1292 if (!cmd)
1293 return -ENOMEM;
1294 if (copy_from_user(cmd, buf, count)) {
1295 kfree(cmd);
1296 return -EFAULT;
1297 }
1298 cmd[count] = '\0';
1299
1300 buffer = cmd;
1301
Darren Harte0769fe2015-02-11 20:50:08 -08001302 /*
1303 * Scan expression. Multiple expressions may be delimited with ;
1304 * NOTE: To keep scanning simple, invalid fields are ignored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 */
1306 while (remain) {
1307 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1308 lcd_out = value & 1;
1309 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1310 crt_out = value & 1;
1311 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1312 tv_out = value & 1;
Darren Harte0769fe2015-02-11 20:50:08 -08001313 /* Advance to one character past the next ; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 do {
1315 ++buffer;
1316 --remain;
Azael Avalosb5163992015-02-10 23:43:56 -07001317 } while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 }
1319
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001320 kfree(cmd);
1321
Seth Forshee36d03f92011-09-20 16:55:53 -05001322 ret = get_video_status(dev, &video_out);
1323 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001324 unsigned int new_video_out = video_out;
Azael Avalosb5163992015-02-10 23:43:56 -07001325
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 if (lcd_out != -1)
1327 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1328 if (crt_out != -1)
1329 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1330 if (tv_out != -1)
1331 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
Darren Harte0769fe2015-02-11 20:50:08 -08001332 /*
1333 * To avoid unnecessary video disruption, only write the new
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001334 * video setting if something changed.
1335 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001337 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 }
1339
Azael Avalose1a949c2015-07-31 21:58:14 -06001340 return ret ? -EIO : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341}
1342
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001343static const struct file_operations video_proc_fops = {
1344 .owner = THIS_MODULE,
1345 .open = video_proc_open,
1346 .read = seq_read,
1347 .llseek = seq_lseek,
1348 .release = single_release,
1349 .write = video_proc_write,
1350};
1351
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001352/* Fan status */
Seth Forshee36d03f92011-09-20 16:55:53 -05001353static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1354{
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001355 u32 result = hci_read(dev, HCI_FAN, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001356
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001357 if (result == TOS_FAILURE)
1358 pr_err("ACPI call to get Fan status failed\n");
1359 else if (result == TOS_NOT_SUPPORTED)
1360 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001361
Azael Avalose1a949c2015-07-31 21:58:14 -06001362 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001363}
1364
1365static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
1366{
1367 u32 result = hci_write(dev, HCI_FAN, status);
1368
1369 if (result == TOS_FAILURE)
1370 pr_err("ACPI call to set Fan status failed\n");
1371 else if (result == TOS_NOT_SUPPORTED)
1372 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001373
Azael Avalose1a949c2015-07-31 21:58:14 -06001374 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001375}
1376
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001377static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
Seth Forshee135740d2011-09-20 16:55:49 -05001379 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 u32 value;
1381
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001382 if (get_fan_status(dev, &value))
1383 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001385 seq_printf(m, "running: %d\n", (value > 0));
1386 seq_printf(m, "force_on: %d\n", dev->force_fan);
1387
1388 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389}
1390
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001391static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
Al Virod9dda782013-03-31 18:16:14 -04001393 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001394}
1395
1396static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1397 size_t count, loff_t *pos)
1398{
Al Virod9dda782013-03-31 18:16:14 -04001399 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001400 char cmd[42];
1401 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001404 len = min(count, sizeof(cmd) - 1);
1405 if (copy_from_user(cmd, buf, len))
1406 return -EFAULT;
1407 cmd[len] = '\0';
1408
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001409 if (sscanf(cmd, " force_on : %i", &value) != 1 &&
1410 value != 0 && value != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 return -EINVAL;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001412
1413 if (set_fan_status(dev, value))
1414 return -EIO;
1415
1416 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418 return count;
1419}
1420
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001421static const struct file_operations fan_proc_fops = {
1422 .owner = THIS_MODULE,
1423 .open = fan_proc_open,
1424 .read = seq_read,
1425 .llseek = seq_lseek,
1426 .release = single_release,
1427 .write = fan_proc_write,
1428};
1429
1430static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431{
Seth Forshee135740d2011-09-20 16:55:49 -05001432 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Seth Forshee135740d2011-09-20 16:55:49 -05001434 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1435 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Azael Avalos7deef552015-07-22 18:09:10 -06001436
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001437 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438}
1439
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001440static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441{
Al Virod9dda782013-03-31 18:16:14 -04001442 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001443}
1444
1445static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1446 size_t count, loff_t *pos)
1447{
Al Virod9dda782013-03-31 18:16:14 -04001448 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001449 char cmd[42];
1450 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 int value;
1452
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001453 len = min(count, sizeof(cmd) - 1);
1454 if (copy_from_user(cmd, buf, len))
1455 return -EFAULT;
1456 cmd[len] = '\0';
1457
Azael Avalosb5163992015-02-10 23:43:56 -07001458 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
Seth Forshee135740d2011-09-20 16:55:49 -05001459 dev->key_event_valid = 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001460 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
1463 return count;
1464}
1465
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001466static const struct file_operations keys_proc_fops = {
1467 .owner = THIS_MODULE,
1468 .open = keys_proc_open,
1469 .read = seq_read,
1470 .llseek = seq_lseek,
1471 .release = single_release,
1472 .write = keys_proc_write,
1473};
1474
1475static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001477 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1478 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1479 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480}
1481
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001482static int version_proc_open(struct inode *inode, struct file *file)
1483{
Al Virod9dda782013-03-31 18:16:14 -04001484 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001485}
1486
1487static const struct file_operations version_proc_fops = {
1488 .owner = THIS_MODULE,
1489 .open = version_proc_open,
1490 .read = seq_read,
1491 .llseek = seq_lseek,
1492 .release = single_release,
1493};
1494
Darren Harte0769fe2015-02-11 20:50:08 -08001495/*
1496 * Proc and module init
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 */
1498
1499#define PROC_TOSHIBA "toshiba"
1500
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001501static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502{
Seth Forshee36d03f92011-09-20 16:55:53 -05001503 if (dev->backlight_dev)
1504 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1505 &lcd_proc_fops, dev);
1506 if (dev->video_supported)
1507 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1508 &video_proc_fops, dev);
1509 if (dev->fan_supported)
1510 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1511 &fan_proc_fops, dev);
1512 if (dev->hotkey_dev)
1513 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1514 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001515 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1516 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517}
1518
Seth Forshee36d03f92011-09-20 16:55:53 -05001519static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520{
Seth Forshee36d03f92011-09-20 16:55:53 -05001521 if (dev->backlight_dev)
1522 remove_proc_entry("lcd", toshiba_proc_dir);
1523 if (dev->video_supported)
1524 remove_proc_entry("video", toshiba_proc_dir);
1525 if (dev->fan_supported)
1526 remove_proc_entry("fan", toshiba_proc_dir);
1527 if (dev->hotkey_dev)
1528 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001529 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Lionel Debrouxacc24722010-11-16 14:14:02 +01001532static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001533 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001534 .get_brightness = get_lcd_brightness,
1535 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001536};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001537
Azael Avalos360f0f32014-03-25 20:38:31 -06001538/*
1539 * Sysfs files
1540 */
Azael Avalos9d309842015-02-10 23:43:59 -07001541static ssize_t version_show(struct device *dev,
1542 struct device_attribute *attr, char *buf)
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001543{
1544 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1545}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001546static DEVICE_ATTR_RO(version);
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001547
Azael Avalos9d309842015-02-10 23:43:59 -07001548static ssize_t fan_store(struct device *dev,
1549 struct device_attribute *attr,
1550 const char *buf, size_t count)
Azael Avalos94477d42015-02-10 21:09:17 -07001551{
1552 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avalos94477d42015-02-10 21:09:17 -07001553 int state;
1554 int ret;
1555
1556 ret = kstrtoint(buf, 0, &state);
1557 if (ret)
1558 return ret;
1559
1560 if (state != 0 && state != 1)
1561 return -EINVAL;
1562
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001563 ret = set_fan_status(toshiba, state);
1564 if (ret)
1565 return ret;
Azael Avalos94477d42015-02-10 21:09:17 -07001566
1567 return count;
1568}
1569
Azael Avalos9d309842015-02-10 23:43:59 -07001570static ssize_t fan_show(struct device *dev,
1571 struct device_attribute *attr, char *buf)
Azael Avalos94477d42015-02-10 21:09:17 -07001572{
1573 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1574 u32 value;
1575 int ret;
1576
1577 ret = get_fan_status(toshiba, &value);
1578 if (ret)
1579 return ret;
1580
1581 return sprintf(buf, "%d\n", value);
1582}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001583static DEVICE_ATTR_RW(fan);
Azael Avalos94477d42015-02-10 21:09:17 -07001584
Azael Avalos9d309842015-02-10 23:43:59 -07001585static ssize_t kbd_backlight_mode_store(struct device *dev,
1586 struct device_attribute *attr,
1587 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001588{
1589 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001590 int mode;
Dan Carpenteraeaac092014-09-03 14:44:37 +03001591 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001592
Dan Carpenteraeaac092014-09-03 14:44:37 +03001593
1594 ret = kstrtoint(buf, 0, &mode);
1595 if (ret)
1596 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001597
1598 /* Check for supported modes depending on keyboard backlight type */
1599 if (toshiba->kbd_type == 1) {
1600 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1601 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1602 return -EINVAL;
1603 } else if (toshiba->kbd_type == 2) {
1604 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1605 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1606 mode != SCI_KBD_MODE_OFF)
1607 return -EINVAL;
1608 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001609
Darren Harte0769fe2015-02-11 20:50:08 -08001610 /*
1611 * Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001612 * Auto - KBD backlight turns off automatically in given time
1613 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001614 * ON - KBD backlight is always on
1615 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001616 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001617
1618 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001619 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001620 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos1e574db2015-07-22 19:37:49 -06001621 int time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001622
1623 /* OR the "base time" to the actual method format */
1624 if (toshiba->kbd_type == 1) {
1625 /* Type 1 requires the current mode */
1626 time |= toshiba->kbd_mode;
1627 } else if (toshiba->kbd_type == 2) {
1628 /* Type 2 requires the desired mode */
1629 time |= mode;
1630 }
1631
Dan Carpenteraeaac092014-09-03 14:44:37 +03001632 ret = toshiba_kbd_illum_status_set(toshiba, time);
1633 if (ret)
1634 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001635
Azael Avalos360f0f32014-03-25 20:38:31 -06001636 toshiba->kbd_mode = mode;
1637 }
1638
1639 return count;
1640}
1641
Azael Avalos9d309842015-02-10 23:43:59 -07001642static ssize_t kbd_backlight_mode_show(struct device *dev,
1643 struct device_attribute *attr,
1644 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001645{
1646 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1647 u32 time;
1648
1649 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1650 return -EIO;
1651
Azael Avalos93f8c162014-09-12 18:50:36 -06001652 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1653}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001654static DEVICE_ATTR_RW(kbd_backlight_mode);
Azael Avalos93f8c162014-09-12 18:50:36 -06001655
Azael Avalos9d309842015-02-10 23:43:59 -07001656static ssize_t kbd_type_show(struct device *dev,
1657 struct device_attribute *attr, char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001658{
1659 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1660
1661 return sprintf(buf, "%d\n", toshiba->kbd_type);
1662}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001663static DEVICE_ATTR_RO(kbd_type);
Azael Avalos93f8c162014-09-12 18:50:36 -06001664
Azael Avalos9d309842015-02-10 23:43:59 -07001665static ssize_t available_kbd_modes_show(struct device *dev,
1666 struct device_attribute *attr,
1667 char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001668{
1669 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1670
1671 if (toshiba->kbd_type == 1)
Azael Avalos0b498202015-09-09 11:30:09 -06001672 return sprintf(buf, "0x%x 0x%x\n",
Azael Avalos93f8c162014-09-12 18:50:36 -06001673 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1674
Azael Avalos0b498202015-09-09 11:30:09 -06001675 return sprintf(buf, "0x%x 0x%x 0x%x\n",
Azael Avalos93f8c162014-09-12 18:50:36 -06001676 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001677}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001678static DEVICE_ATTR_RO(available_kbd_modes);
Azael Avalos360f0f32014-03-25 20:38:31 -06001679
Azael Avalos9d309842015-02-10 23:43:59 -07001680static ssize_t kbd_backlight_timeout_store(struct device *dev,
1681 struct device_attribute *attr,
1682 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001683{
1684 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001685 int time;
1686 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001687
Azael Avaloseabde0f2014-10-04 12:02:21 -06001688 ret = kstrtoint(buf, 0, &time);
1689 if (ret)
1690 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001691
Azael Avaloseabde0f2014-10-04 12:02:21 -06001692 /* Check for supported values depending on kbd_type */
1693 if (toshiba->kbd_type == 1) {
1694 if (time < 0 || time > 60)
1695 return -EINVAL;
1696 } else if (toshiba->kbd_type == 2) {
1697 if (time < 1 || time > 60)
1698 return -EINVAL;
1699 }
1700
1701 /* Set the Keyboard Backlight Timeout */
1702
1703 /* Only make a change if the actual timeout has changed */
1704 if (toshiba->kbd_time != time) {
1705 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001706 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001707 /* OR the "base time" to the actual method format */
1708 if (toshiba->kbd_type == 1)
1709 time |= SCI_KBD_MODE_FNZ;
1710 else if (toshiba->kbd_type == 2)
1711 time |= SCI_KBD_MODE_AUTO;
1712
1713 ret = toshiba_kbd_illum_status_set(toshiba, time);
1714 if (ret)
1715 return ret;
1716
Azael Avalos360f0f32014-03-25 20:38:31 -06001717 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1718 }
1719
1720 return count;
1721}
1722
Azael Avalos9d309842015-02-10 23:43:59 -07001723static ssize_t kbd_backlight_timeout_show(struct device *dev,
1724 struct device_attribute *attr,
1725 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001726{
1727 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1728 u32 time;
1729
1730 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1731 return -EIO;
1732
1733 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1734}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001735static DEVICE_ATTR_RW(kbd_backlight_timeout);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001736
Azael Avalos9d309842015-02-10 23:43:59 -07001737static ssize_t touchpad_store(struct device *dev,
1738 struct device_attribute *attr,
1739 const char *buf, size_t count)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001740{
1741 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1742 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001743 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001744
1745 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001746 ret = kstrtoint(buf, 0, &state);
1747 if (ret)
1748 return ret;
1749 if (state != 0 && state != 1)
1750 return -EINVAL;
1751
1752 ret = toshiba_touchpad_set(toshiba, state);
1753 if (ret)
1754 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001755
1756 return count;
1757}
1758
Azael Avalos9d309842015-02-10 23:43:59 -07001759static ssize_t touchpad_show(struct device *dev,
1760 struct device_attribute *attr, char *buf)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001761{
1762 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1763 u32 state;
1764 int ret;
1765
1766 ret = toshiba_touchpad_get(toshiba, &state);
1767 if (ret < 0)
1768 return ret;
1769
1770 return sprintf(buf, "%i\n", state);
1771}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001772static DEVICE_ATTR_RW(touchpad);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001773
Azael Avalos9d309842015-02-10 23:43:59 -07001774static ssize_t position_show(struct device *dev,
1775 struct device_attribute *attr, char *buf)
Azael Avalos5a2813e2014-03-25 20:38:34 -06001776{
1777 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1778 u32 xyval, zval, tmp;
1779 u16 x, y, z;
1780 int ret;
1781
1782 xyval = zval = 0;
1783 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1784 if (ret < 0)
1785 return ret;
1786
1787 x = xyval & HCI_ACCEL_MASK;
1788 tmp = xyval >> HCI_MISC_SHIFT;
1789 y = tmp & HCI_ACCEL_MASK;
1790 z = zval & HCI_ACCEL_MASK;
1791
1792 return sprintf(buf, "%d %d %d\n", x, y, z);
1793}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001794static DEVICE_ATTR_RO(position);
Azael Avalos360f0f32014-03-25 20:38:31 -06001795
Azael Avalos9d309842015-02-10 23:43:59 -07001796static ssize_t usb_sleep_charge_show(struct device *dev,
1797 struct device_attribute *attr, char *buf)
Azael Avalose26ffe52015-01-18 18:30:22 -07001798{
1799 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1800 u32 mode;
1801 int ret;
1802
1803 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1804 if (ret < 0)
1805 return ret;
1806
1807 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1808}
1809
Azael Avalos9d309842015-02-10 23:43:59 -07001810static ssize_t usb_sleep_charge_store(struct device *dev,
1811 struct device_attribute *attr,
1812 const char *buf, size_t count)
Azael Avalose26ffe52015-01-18 18:30:22 -07001813{
1814 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1815 u32 mode;
1816 int state;
1817 int ret;
1818
1819 ret = kstrtoint(buf, 0, &state);
1820 if (ret)
1821 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08001822 /*
1823 * Check for supported values, where:
Azael Avalose26ffe52015-01-18 18:30:22 -07001824 * 0 - Disabled
1825 * 1 - Alternate (Non USB conformant devices that require more power)
1826 * 2 - Auto (USB conformant devices)
Azael Avalosc8c91842015-04-02 19:26:20 -06001827 * 3 - Typical
Azael Avalose26ffe52015-01-18 18:30:22 -07001828 */
Azael Avalosc8c91842015-04-02 19:26:20 -06001829 if (state != 0 && state != 1 && state != 2 && state != 3)
Azael Avalose26ffe52015-01-18 18:30:22 -07001830 return -EINVAL;
1831
1832 /* Set the USB charging mode to internal value */
Azael Avalosc8c91842015-04-02 19:26:20 -06001833 mode = toshiba->usbsc_mode_base;
Azael Avalose26ffe52015-01-18 18:30:22 -07001834 if (state == 0)
Azael Avalosc8c91842015-04-02 19:26:20 -06001835 mode |= SCI_USB_CHARGE_DISABLED;
Azael Avalose26ffe52015-01-18 18:30:22 -07001836 else if (state == 1)
Azael Avalosc8c91842015-04-02 19:26:20 -06001837 mode |= SCI_USB_CHARGE_ALTERNATE;
Azael Avalose26ffe52015-01-18 18:30:22 -07001838 else if (state == 2)
Azael Avalosc8c91842015-04-02 19:26:20 -06001839 mode |= SCI_USB_CHARGE_AUTO;
1840 else if (state == 3)
1841 mode |= SCI_USB_CHARGE_TYPICAL;
Azael Avalose26ffe52015-01-18 18:30:22 -07001842
1843 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
1844 if (ret)
1845 return ret;
1846
1847 return count;
1848}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001849static DEVICE_ATTR_RW(usb_sleep_charge);
Azael Avalose26ffe52015-01-18 18:30:22 -07001850
Azael Avalos182bcaa2015-01-18 18:30:23 -07001851static ssize_t sleep_functions_on_battery_show(struct device *dev,
1852 struct device_attribute *attr,
1853 char *buf)
1854{
1855 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1856 u32 state;
1857 int bat_lvl;
1858 int status;
1859 int ret;
1860 int tmp;
1861
1862 ret = toshiba_sleep_functions_status_get(toshiba, &state);
1863 if (ret < 0)
1864 return ret;
1865
1866 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1867 tmp = state & SCI_USB_CHARGE_BAT_MASK;
1868 status = (tmp == 0x4) ? 1 : 0;
1869 /* Determine the battery level set */
1870 bat_lvl = state >> HCI_MISC_SHIFT;
1871
1872 return sprintf(buf, "%d %d\n", status, bat_lvl);
1873}
1874
1875static ssize_t sleep_functions_on_battery_store(struct device *dev,
1876 struct device_attribute *attr,
1877 const char *buf, size_t count)
1878{
1879 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1880 u32 status;
1881 int value;
1882 int ret;
1883 int tmp;
1884
1885 ret = kstrtoint(buf, 0, &value);
1886 if (ret)
1887 return ret;
1888
Darren Harte0769fe2015-02-11 20:50:08 -08001889 /*
1890 * Set the status of the function:
Azael Avalos182bcaa2015-01-18 18:30:23 -07001891 * 0 - Disabled
1892 * 1-100 - Enabled
1893 */
1894 if (value < 0 || value > 100)
1895 return -EINVAL;
1896
1897 if (value == 0) {
1898 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
1899 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
1900 } else {
1901 tmp = value << HCI_MISC_SHIFT;
1902 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
1903 }
1904 ret = toshiba_sleep_functions_status_set(toshiba, status);
1905 if (ret < 0)
1906 return ret;
1907
1908 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
1909
1910 return count;
1911}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001912static DEVICE_ATTR_RW(sleep_functions_on_battery);
Azael Avalos182bcaa2015-01-18 18:30:23 -07001913
Azael Avalos9d309842015-02-10 23:43:59 -07001914static ssize_t usb_rapid_charge_show(struct device *dev,
1915 struct device_attribute *attr, char *buf)
Azael Avalosbb3fe012015-01-18 18:30:24 -07001916{
1917 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1918 u32 state;
1919 int ret;
1920
1921 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
1922 if (ret < 0)
1923 return ret;
1924
1925 return sprintf(buf, "%d\n", state);
1926}
1927
Azael Avalos9d309842015-02-10 23:43:59 -07001928static ssize_t usb_rapid_charge_store(struct device *dev,
1929 struct device_attribute *attr,
1930 const char *buf, size_t count)
Azael Avalosbb3fe012015-01-18 18:30:24 -07001931{
1932 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1933 int state;
1934 int ret;
1935
1936 ret = kstrtoint(buf, 0, &state);
1937 if (ret)
1938 return ret;
1939 if (state != 0 && state != 1)
1940 return -EINVAL;
1941
1942 ret = toshiba_usb_rapid_charge_set(toshiba, state);
1943 if (ret)
1944 return ret;
1945
1946 return count;
1947}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001948static DEVICE_ATTR_RW(usb_rapid_charge);
Azael Avalosbb3fe012015-01-18 18:30:24 -07001949
Azael Avalos9d309842015-02-10 23:43:59 -07001950static ssize_t usb_sleep_music_show(struct device *dev,
1951 struct device_attribute *attr, char *buf)
Azael Avalos172ce0a2015-01-18 18:30:25 -07001952{
1953 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1954 u32 state;
1955 int ret;
1956
1957 ret = toshiba_usb_sleep_music_get(toshiba, &state);
1958 if (ret < 0)
1959 return ret;
1960
1961 return sprintf(buf, "%d\n", state);
1962}
1963
Azael Avalos9d309842015-02-10 23:43:59 -07001964static ssize_t usb_sleep_music_store(struct device *dev,
1965 struct device_attribute *attr,
1966 const char *buf, size_t count)
Azael Avalos172ce0a2015-01-18 18:30:25 -07001967{
1968 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1969 int state;
1970 int ret;
1971
1972 ret = kstrtoint(buf, 0, &state);
1973 if (ret)
1974 return ret;
1975 if (state != 0 && state != 1)
1976 return -EINVAL;
1977
1978 ret = toshiba_usb_sleep_music_set(toshiba, state);
1979 if (ret)
1980 return ret;
1981
1982 return count;
1983}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001984static DEVICE_ATTR_RW(usb_sleep_music);
Azael Avalos172ce0a2015-01-18 18:30:25 -07001985
Azael Avalos9d309842015-02-10 23:43:59 -07001986static ssize_t kbd_function_keys_show(struct device *dev,
1987 struct device_attribute *attr, char *buf)
Azael Avalosbae84192015-02-10 21:09:18 -07001988{
1989 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1990 int mode;
1991 int ret;
1992
1993 ret = toshiba_function_keys_get(toshiba, &mode);
1994 if (ret < 0)
1995 return ret;
1996
1997 return sprintf(buf, "%d\n", mode);
1998}
1999
Azael Avalos9d309842015-02-10 23:43:59 -07002000static ssize_t kbd_function_keys_store(struct device *dev,
2001 struct device_attribute *attr,
2002 const char *buf, size_t count)
Azael Avalosbae84192015-02-10 21:09:18 -07002003{
2004 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2005 int mode;
2006 int ret;
2007
2008 ret = kstrtoint(buf, 0, &mode);
2009 if (ret)
2010 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002011 /*
2012 * Check for the function keys mode where:
Azael Avalosbae84192015-02-10 21:09:18 -07002013 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2014 * 1 - Special functions (Opposite of the above setting)
2015 */
2016 if (mode != 0 && mode != 1)
2017 return -EINVAL;
2018
2019 ret = toshiba_function_keys_set(toshiba, mode);
2020 if (ret)
2021 return ret;
2022
2023 pr_info("Reboot for changes to KBD Function Keys to take effect");
2024
2025 return count;
2026}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002027static DEVICE_ATTR_RW(kbd_function_keys);
Azael Avalosbae84192015-02-10 21:09:18 -07002028
Azael Avalos9d309842015-02-10 23:43:59 -07002029static ssize_t panel_power_on_show(struct device *dev,
2030 struct device_attribute *attr, char *buf)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002031{
2032 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2033 u32 state;
2034 int ret;
2035
2036 ret = toshiba_panel_power_on_get(toshiba, &state);
2037 if (ret < 0)
2038 return ret;
2039
2040 return sprintf(buf, "%d\n", state);
2041}
2042
Azael Avalos9d309842015-02-10 23:43:59 -07002043static ssize_t panel_power_on_store(struct device *dev,
2044 struct device_attribute *attr,
2045 const char *buf, size_t count)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002046{
2047 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2048 int state;
2049 int ret;
2050
2051 ret = kstrtoint(buf, 0, &state);
2052 if (ret)
2053 return ret;
2054 if (state != 0 && state != 1)
2055 return -EINVAL;
2056
2057 ret = toshiba_panel_power_on_set(toshiba, state);
2058 if (ret)
2059 return ret;
2060
2061 pr_info("Reboot for changes to Panel Power ON to take effect");
2062
2063 return count;
2064}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002065static DEVICE_ATTR_RW(panel_power_on);
Azael Avalos35d53ce2015-02-10 21:09:19 -07002066
Azael Avalos9d309842015-02-10 23:43:59 -07002067static ssize_t usb_three_show(struct device *dev,
2068 struct device_attribute *attr, char *buf)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002069{
2070 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2071 u32 state;
2072 int ret;
2073
2074 ret = toshiba_usb_three_get(toshiba, &state);
2075 if (ret < 0)
2076 return ret;
2077
2078 return sprintf(buf, "%d\n", state);
2079}
2080
Azael Avalos9d309842015-02-10 23:43:59 -07002081static ssize_t usb_three_store(struct device *dev,
2082 struct device_attribute *attr,
2083 const char *buf, size_t count)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002084{
2085 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2086 int state;
2087 int ret;
2088
2089 ret = kstrtoint(buf, 0, &state);
2090 if (ret)
2091 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002092 /*
2093 * Check for USB 3 mode where:
Azael Avalos17fe4b32015-02-10 21:09:20 -07002094 * 0 - Disabled (Acts like a USB 2 port, saving power)
2095 * 1 - Enabled
2096 */
2097 if (state != 0 && state != 1)
2098 return -EINVAL;
2099
2100 ret = toshiba_usb_three_set(toshiba, state);
2101 if (ret)
2102 return ret;
2103
2104 pr_info("Reboot for changes to USB 3 to take effect");
2105
2106 return count;
2107}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002108static DEVICE_ATTR_RW(usb_three);
Azael Avalos9bd12132015-02-10 23:43:58 -07002109
2110static struct attribute *toshiba_attributes[] = {
2111 &dev_attr_version.attr,
2112 &dev_attr_fan.attr,
2113 &dev_attr_kbd_backlight_mode.attr,
2114 &dev_attr_kbd_type.attr,
2115 &dev_attr_available_kbd_modes.attr,
2116 &dev_attr_kbd_backlight_timeout.attr,
2117 &dev_attr_touchpad.attr,
2118 &dev_attr_position.attr,
2119 &dev_attr_usb_sleep_charge.attr,
2120 &dev_attr_sleep_functions_on_battery.attr,
2121 &dev_attr_usb_rapid_charge.attr,
2122 &dev_attr_usb_sleep_music.attr,
2123 &dev_attr_kbd_function_keys.attr,
2124 &dev_attr_panel_power_on.attr,
2125 &dev_attr_usb_three.attr,
2126 NULL,
2127};
2128
Azael Avalos360f0f32014-03-25 20:38:31 -06002129static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2130 struct attribute *attr, int idx)
2131{
2132 struct device *dev = container_of(kobj, struct device, kobj);
2133 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2134 bool exists = true;
2135
Azael Avalos94477d42015-02-10 21:09:17 -07002136 if (attr == &dev_attr_fan.attr)
2137 exists = (drv->fan_supported) ? true : false;
2138 else if (attr == &dev_attr_kbd_backlight_mode.attr)
Azael Avalos360f0f32014-03-25 20:38:31 -06002139 exists = (drv->kbd_illum_supported) ? true : false;
2140 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2141 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06002142 else if (attr == &dev_attr_touchpad.attr)
2143 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06002144 else if (attr == &dev_attr_position.attr)
2145 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalose26ffe52015-01-18 18:30:22 -07002146 else if (attr == &dev_attr_usb_sleep_charge.attr)
2147 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002148 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2149 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalosbb3fe012015-01-18 18:30:24 -07002150 else if (attr == &dev_attr_usb_rapid_charge.attr)
2151 exists = (drv->usb_rapid_charge_supported) ? true : false;
Azael Avalos172ce0a2015-01-18 18:30:25 -07002152 else if (attr == &dev_attr_usb_sleep_music.attr)
2153 exists = (drv->usb_sleep_music_supported) ? true : false;
Azael Avalosbae84192015-02-10 21:09:18 -07002154 else if (attr == &dev_attr_kbd_function_keys.attr)
2155 exists = (drv->kbd_function_keys_supported) ? true : false;
Azael Avalos35d53ce2015-02-10 21:09:19 -07002156 else if (attr == &dev_attr_panel_power_on.attr)
2157 exists = (drv->panel_power_on_supported) ? true : false;
Azael Avalos17fe4b32015-02-10 21:09:20 -07002158 else if (attr == &dev_attr_usb_three.attr)
2159 exists = (drv->usb_three_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06002160
2161 return exists ? attr->mode : 0;
2162}
2163
Azael Avalos9bd12132015-02-10 23:43:58 -07002164static struct attribute_group toshiba_attr_group = {
2165 .is_visible = toshiba_sysfs_is_visible,
2166 .attrs = toshiba_attributes,
2167};
2168
Azael Avalos1f28f292014-12-04 20:22:45 -07002169/*
Azael Avalosfc5462f2015-07-22 18:09:11 -06002170 * Misc device
2171 */
2172static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
2173{
2174 u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
2175 regs->edx, regs->esi, regs->edi };
2176 u32 out[TCI_WORDS];
2177 acpi_status status;
2178
2179 status = tci_raw(toshiba_acpi, in, out);
2180 if (ACPI_FAILURE(status)) {
2181 pr_err("ACPI call to query SMM registers failed\n");
2182 return -EIO;
2183 }
2184
2185 /* Fillout the SMM struct with the TCI call results */
2186 regs->eax = out[0];
2187 regs->ebx = out[1];
2188 regs->ecx = out[2];
2189 regs->edx = out[3];
2190 regs->esi = out[4];
2191 regs->edi = out[5];
2192
2193 return 0;
2194}
2195
2196static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
2197 unsigned long arg)
2198{
2199 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
2200 SMMRegisters regs;
2201 int ret;
2202
2203 if (!argp)
2204 return -EINVAL;
2205
2206 switch (cmd) {
2207 case TOSH_SMM:
2208 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2209 return -EFAULT;
2210 ret = toshiba_acpi_smm_bridge(&regs);
2211 if (ret)
2212 return ret;
2213 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2214 return -EFAULT;
2215 break;
2216 case TOSHIBA_ACPI_SCI:
2217 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2218 return -EFAULT;
2219 /* Ensure we are being called with a SCI_{GET, SET} register */
2220 if (regs.eax != SCI_GET && regs.eax != SCI_SET)
2221 return -EINVAL;
2222 if (!sci_open(toshiba_acpi))
2223 return -EIO;
2224 ret = toshiba_acpi_smm_bridge(&regs);
2225 sci_close(toshiba_acpi);
2226 if (ret)
2227 return ret;
2228 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2229 return -EFAULT;
2230 break;
2231 default:
2232 return -EINVAL;
2233 }
2234
2235 return 0;
2236}
2237
2238static const struct file_operations toshiba_acpi_fops = {
2239 .owner = THIS_MODULE,
2240 .unlocked_ioctl = toshiba_acpi_ioctl,
2241 .llseek = noop_llseek,
2242};
2243
2244/*
Azael Avalos1f28f292014-12-04 20:22:45 -07002245 * Hotkeys
2246 */
2247static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2248{
2249 acpi_status status;
2250 u32 result;
2251
2252 status = acpi_evaluate_object(dev->acpi_dev->handle,
2253 "ENAB", NULL, NULL);
2254 if (ACPI_FAILURE(status))
2255 return -ENODEV;
2256
Azael Avalosb116fd02015-09-09 11:28:19 -06002257 /*
2258 * Enable the "Special Functions" mode only if they are
2259 * supported and if they are activated.
2260 */
2261 if (dev->kbd_function_keys_supported && dev->special_functions)
2262 result = hci_write(dev, HCI_HOTKEY_EVENT,
2263 HCI_HOTKEY_SPECIAL_FUNCTIONS);
2264 else
2265 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2266
Azael Avalos1f28f292014-12-04 20:22:45 -07002267 if (result == TOS_FAILURE)
2268 return -EIO;
2269 else if (result == TOS_NOT_SUPPORTED)
2270 return -ENODEV;
2271
2272 return 0;
2273}
2274
Seth Forshee29cd2932012-01-18 13:44:09 -06002275static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2276 struct serio *port)
2277{
Giedrius Statkevičius98280372014-10-18 02:57:20 +03002278 if (str & I8042_STR_AUXDATA)
Seth Forshee29cd2932012-01-18 13:44:09 -06002279 return false;
2280
2281 if (unlikely(data == 0xe0))
2282 return false;
2283
2284 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2285 schedule_work(&toshiba_acpi->hotkey_work);
2286 return true;
2287 }
2288
2289 return false;
2290}
2291
2292static void toshiba_acpi_hotkey_work(struct work_struct *work)
2293{
2294 acpi_handle ec_handle = ec_get_handle();
2295 acpi_status status;
2296
2297 if (!ec_handle)
2298 return;
2299
2300 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2301 if (ACPI_FAILURE(status))
2302 pr_err("ACPI NTFY method execution failed\n");
2303}
2304
2305/*
2306 * Returns hotkey scancode, or < 0 on failure.
2307 */
2308static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2309{
Zhang Rui74facaf2013-09-03 08:32:15 +08002310 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002311 acpi_status status;
2312
Zhang Rui74facaf2013-09-03 08:32:15 +08002313 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2314 NULL, &value);
2315 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002316 pr_err("ACPI INFO method execution failed\n");
2317 return -EIO;
2318 }
2319
Zhang Rui74facaf2013-09-03 08:32:15 +08002320 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002321}
2322
2323static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2324 int scancode)
2325{
2326 if (scancode == 0x100)
2327 return;
2328
Darren Harte0769fe2015-02-11 20:50:08 -08002329 /* Act on key press; ignore key release */
Seth Forshee29cd2932012-01-18 13:44:09 -06002330 if (scancode & 0x80)
2331 return;
2332
2333 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2334 pr_info("Unknown key %x\n", scancode);
2335}
2336
Azael Avalos71454d72014-12-04 20:22:46 -07002337static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2338{
Azael Avalos71454d72014-12-04 20:22:46 -07002339 if (dev->info_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002340 int scancode = toshiba_acpi_query_hotkey(dev);
2341
2342 if (scancode < 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002343 pr_err("Failed to query hotkey event\n");
Azael Avalos7deef552015-07-22 18:09:10 -06002344 } else if (scancode != 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002345 toshiba_acpi_report_hotkey(dev, scancode);
Azael Avalos7deef552015-07-22 18:09:10 -06002346 dev->key_event_valid = 1;
2347 dev->last_key_event = scancode;
2348 }
Azael Avalos71454d72014-12-04 20:22:46 -07002349 } else if (dev->system_event_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002350 u32 result;
2351 u32 value;
2352 int retries = 3;
2353
Azael Avalos71454d72014-12-04 20:22:46 -07002354 do {
Azael Avalos7deef552015-07-22 18:09:10 -06002355 result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2356 switch (result) {
Azael Avalos71454d72014-12-04 20:22:46 -07002357 case TOS_SUCCESS:
2358 toshiba_acpi_report_hotkey(dev, (int)value);
Azael Avalos7deef552015-07-22 18:09:10 -06002359 dev->key_event_valid = 1;
2360 dev->last_key_event = value;
Azael Avalos71454d72014-12-04 20:22:46 -07002361 break;
2362 case TOS_NOT_SUPPORTED:
2363 /*
2364 * This is a workaround for an unresolved
2365 * issue on some machines where system events
2366 * sporadically become disabled.
2367 */
Azael Avalos7deef552015-07-22 18:09:10 -06002368 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2369 if (result == TOS_SUCCESS)
2370 pr_notice("Re-enabled hotkeys\n");
Darren Harte0769fe2015-02-11 20:50:08 -08002371 /* Fall through */
Azael Avalos71454d72014-12-04 20:22:46 -07002372 default:
2373 retries--;
2374 break;
2375 }
Azael Avalos7deef552015-07-22 18:09:10 -06002376 } while (retries && result != TOS_FIFO_EMPTY);
Azael Avalos71454d72014-12-04 20:22:46 -07002377 }
2378}
2379
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002380static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002381{
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002382 const struct key_entry *keymap = toshiba_acpi_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002383 acpi_handle ec_handle;
Azael Avalosa2b34712015-03-20 16:55:17 -06002384 int error;
2385
Azael Avalosa88bc062015-07-22 18:09:12 -06002386 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
2387 pr_info("WMI event detected, hotkeys will not be monitored\n");
2388 return 0;
2389 }
2390
Azael Avalosa2b34712015-03-20 16:55:17 -06002391 error = toshiba_acpi_enable_hotkeys(dev);
2392 if (error)
2393 return error;
2394
Azael Avalos10e6aaab2015-09-18 22:45:34 -06002395 if (toshiba_hotkey_event_type_get(dev, &dev->hotkey_event_type))
Azael Avalos53147b62015-09-09 11:25:45 -06002396 pr_notice("Unable to query Hotkey Event Type\n");
2397
Seth Forshee135740d2011-09-20 16:55:49 -05002398 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07002399 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002400 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05002401
2402 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05002403 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05002404 dev->hotkey_dev->id.bustype = BUS_HOST;
2405
Azael Avalos10e6aaab2015-09-18 22:45:34 -06002406 if (dev->hotkey_event_type == HCI_SYSTEM_TYPE1 ||
Azael Avalosa2b34712015-03-20 16:55:17 -06002407 !dev->kbd_function_keys_supported)
2408 keymap = toshiba_acpi_keymap;
Azael Avalos10e6aaab2015-09-18 22:45:34 -06002409 else if (dev->hotkey_event_type == HCI_SYSTEM_TYPE2 ||
Azael Avalosa2b34712015-03-20 16:55:17 -06002410 dev->kbd_function_keys_supported)
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002411 keymap = toshiba_acpi_alt_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002412 else
Azael Avalos10e6aaab2015-09-18 22:45:34 -06002413 pr_info("Unknown event type received %x\n",
2414 dev->hotkey_event_type);
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002415 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05002416 if (error)
2417 goto err_free_dev;
2418
Seth Forshee29cd2932012-01-18 13:44:09 -06002419 /*
2420 * For some machines the SCI responsible for providing hotkey
2421 * notification doesn't fire. We can trigger the notification
2422 * whenever the Fn key is pressed using the NTFY method, if
2423 * supported, so if it's present set up an i8042 key filter
2424 * for this purpose.
2425 */
Seth Forshee29cd2932012-01-18 13:44:09 -06002426 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08002427 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002428 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2429
2430 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2431 if (error) {
2432 pr_err("Error installing key filter\n");
2433 goto err_free_keymap;
2434 }
2435
2436 dev->ntfy_supported = 1;
2437 }
2438
2439 /*
2440 * Determine hotkey query interface. Prefer using the INFO
2441 * method when it is available.
2442 */
Zhang Ruie2e19602013-09-03 08:32:06 +08002443 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06002444 dev->info_supported = 1;
Azael Avalos10e6aaab2015-09-18 22:45:34 -06002445 else if (hci_write(dev, HCI_SYSTEM_EVENT, 1) == TOS_SUCCESS)
2446 dev->system_event_supported = 1;
Seth Forshee29cd2932012-01-18 13:44:09 -06002447
2448 if (!dev->info_supported && !dev->system_event_supported) {
2449 pr_warn("No hotkey query interface found\n");
2450 goto err_remove_filter;
2451 }
2452
Seth Forshee135740d2011-09-20 16:55:49 -05002453 error = input_register_device(dev->hotkey_dev);
2454 if (error) {
2455 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06002456 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05002457 }
2458
2459 return 0;
2460
Seth Forshee29cd2932012-01-18 13:44:09 -06002461 err_remove_filter:
2462 if (dev->ntfy_supported)
2463 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05002464 err_free_keymap:
2465 sparse_keymap_free(dev->hotkey_dev);
2466 err_free_dev:
2467 input_free_device(dev->hotkey_dev);
2468 dev->hotkey_dev = NULL;
2469 return error;
2470}
2471
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002472static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05002473{
2474 struct backlight_properties props;
2475 int brightness;
2476 int ret;
2477
2478 /*
2479 * Some machines don't support the backlight methods at all, and
2480 * others support it read-only. Either of these is pretty useless,
2481 * so only register the backlight device if the backlight method
2482 * supports both reads and writes.
2483 */
2484 brightness = __get_lcd_brightness(dev);
2485 if (brightness < 0)
2486 return 0;
Azael Avalosbae53362015-11-15 20:32:47 -07002487 /*
2488 * If transflective backlight is supported and the brightness is zero
2489 * (lowest brightness level), the set_lcd_brightness function will
2490 * activate the transflective backlight, making the LCD appear to be
2491 * turned off, simply increment the brightness level to avoid that.
2492 */
2493 if (dev->tr_backlight_supported && brightness == 0)
2494 brightness++;
Seth Forshee62cce752012-04-19 11:23:50 -05002495 ret = set_lcd_brightness(dev, brightness);
2496 if (ret) {
2497 pr_debug("Backlight method is read-only, disabling backlight support\n");
2498 return 0;
2499 }
2500
Hans de Goede358d6a22015-04-21 12:01:32 +02002501 /*
2502 * Tell acpi-video-detect code to prefer vendor backlight on all
2503 * systems with transflective backlight and on dmi matched systems.
2504 */
2505 if (dev->tr_backlight_supported ||
2506 dmi_check_system(toshiba_vendor_backlight_dmi))
Hans de Goede234b7cf2015-06-16 16:28:11 +02002507 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
Hans de Goede358d6a22015-04-21 12:01:32 +02002508
Hans de Goede234b7cf2015-06-16 16:28:11 +02002509 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
Hans de Goede358d6a22015-04-21 12:01:32 +02002510 return 0;
2511
Matthew Garrett53039f22012-06-01 11:02:36 -04002512 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05002513 props.type = BACKLIGHT_PLATFORM;
2514 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05002515
Darren Harte0769fe2015-02-11 20:50:08 -08002516 /* Adding an extra level and having 0 change to transflective mode */
Akio Idehara121b7b02012-04-06 01:46:43 +09002517 if (dev->tr_backlight_supported)
2518 props.max_brightness++;
2519
Seth Forshee62cce752012-04-19 11:23:50 -05002520 dev->backlight_dev = backlight_device_register("toshiba",
2521 &dev->acpi_dev->dev,
2522 dev,
2523 &toshiba_backlight_data,
2524 &props);
2525 if (IS_ERR(dev->backlight_dev)) {
2526 ret = PTR_ERR(dev->backlight_dev);
2527 pr_err("Could not register toshiba backlight device\n");
2528 dev->backlight_dev = NULL;
2529 return ret;
2530 }
2531
2532 dev->backlight_dev->props.brightness = brightness;
2533 return 0;
2534}
2535
Azael Avalos0409cbc2015-07-31 21:58:13 -06002536static void print_supported_features(struct toshiba_acpi_dev *dev)
2537{
2538 pr_info("Supported laptop features:");
2539
2540 if (dev->hotkey_dev)
2541 pr_cont(" hotkeys");
2542 if (dev->backlight_dev)
2543 pr_cont(" backlight");
2544 if (dev->video_supported)
2545 pr_cont(" video-out");
2546 if (dev->fan_supported)
2547 pr_cont(" fan");
2548 if (dev->tr_backlight_supported)
2549 pr_cont(" transflective-backlight");
2550 if (dev->illumination_supported)
2551 pr_cont(" illumination");
2552 if (dev->kbd_illum_supported)
2553 pr_cont(" keyboard-backlight");
2554 if (dev->touchpad_supported)
2555 pr_cont(" touchpad");
2556 if (dev->eco_supported)
2557 pr_cont(" eco-led");
2558 if (dev->accelerometer_supported)
2559 pr_cont(" accelerometer-axes");
2560 if (dev->usb_sleep_charge_supported)
2561 pr_cont(" usb-sleep-charge");
2562 if (dev->usb_rapid_charge_supported)
2563 pr_cont(" usb-rapid-charge");
2564 if (dev->usb_sleep_music_supported)
2565 pr_cont(" usb-sleep-music");
2566 if (dev->kbd_function_keys_supported)
2567 pr_cont(" special-function-keys");
2568 if (dev->panel_power_on_supported)
2569 pr_cont(" panel-power-on");
2570 if (dev->usb_three_supported)
2571 pr_cont(" usb3");
2572
2573 pr_cont("\n");
2574}
2575
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002576static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002577{
2578 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2579
Azael Avalosfc5462f2015-07-22 18:09:11 -06002580 misc_deregister(&dev->miscdev);
2581
Seth Forshee36d03f92011-09-20 16:55:53 -05002582 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002583
Azael Avalos360f0f32014-03-25 20:38:31 -06002584 if (dev->sysfs_created)
2585 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2586 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05002587
Seth Forshee29cd2932012-01-18 13:44:09 -06002588 if (dev->ntfy_supported) {
2589 i8042_remove_filter(toshiba_acpi_i8042_filter);
2590 cancel_work_sync(&dev->hotkey_work);
2591 }
2592
Seth Forshee135740d2011-09-20 16:55:49 -05002593 if (dev->hotkey_dev) {
2594 input_unregister_device(dev->hotkey_dev);
2595 sparse_keymap_free(dev->hotkey_dev);
2596 }
2597
Markus Elfring00981812014-11-24 20:30:29 +01002598 backlight_device_unregister(dev->backlight_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002599
Azael Avalosea215a3f2015-07-31 21:58:12 -06002600 if (dev->illumination_led_registered)
Seth Forshee135740d2011-09-20 16:55:49 -05002601 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002602
Azael Avalos360f0f32014-03-25 20:38:31 -06002603 if (dev->kbd_led_registered)
2604 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002605
Azael Avalosea215a3f2015-07-31 21:58:12 -06002606 if (dev->eco_led_registered)
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002607 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05002608
Seth Forshee29cd2932012-01-18 13:44:09 -06002609 if (toshiba_acpi)
2610 toshiba_acpi = NULL;
2611
Seth Forshee135740d2011-09-20 16:55:49 -05002612 kfree(dev);
2613
2614 return 0;
2615}
2616
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002617static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05002618{
Zhang Ruie2e19602013-09-03 08:32:06 +08002619 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002620 return "GHCI";
2621
Zhang Ruie2e19602013-09-03 08:32:06 +08002622 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002623 return "SPFC";
2624
2625 return NULL;
2626}
2627
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002628static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002629{
2630 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002631 const char *hci_method;
Seth Forshee36d03f92011-09-20 16:55:53 -05002632 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05002633 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05002634
Seth Forshee29cd2932012-01-18 13:44:09 -06002635 if (toshiba_acpi)
2636 return -EBUSY;
2637
Seth Forshee135740d2011-09-20 16:55:49 -05002638 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2639 TOSHIBA_ACPI_VERSION);
2640
Seth Forsheea540d6b2011-09-20 16:55:52 -05002641 hci_method = find_hci_method(acpi_dev->handle);
2642 if (!hci_method) {
2643 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05002644 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002645 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05002646
Seth Forshee135740d2011-09-20 16:55:49 -05002647 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2648 if (!dev)
2649 return -ENOMEM;
2650 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002651 dev->method_hci = hci_method;
Azael Avalosfc5462f2015-07-22 18:09:11 -06002652 dev->miscdev.minor = MISC_DYNAMIC_MINOR;
2653 dev->miscdev.name = "toshiba_acpi";
2654 dev->miscdev.fops = &toshiba_acpi_fops;
2655
2656 ret = misc_register(&dev->miscdev);
2657 if (ret) {
2658 pr_err("Failed to register miscdevice\n");
2659 kfree(dev);
2660 return ret;
2661 }
2662
Seth Forshee135740d2011-09-20 16:55:49 -05002663 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06002664 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002665
Azael Avalosa2b34712015-03-20 16:55:17 -06002666 /* Query the BIOS for supported features */
2667
2668 /*
2669 * The "Special Functions" are always supported by the laptops
2670 * with the new keyboard layout, query for its presence to help
2671 * determine the keymap layout to use.
2672 */
Azael Avalosb116fd02015-09-09 11:28:19 -06002673 ret = toshiba_function_keys_get(dev, &dev->special_functions);
Azael Avalosa2b34712015-03-20 16:55:17 -06002674 dev->kbd_function_keys_supported = !ret;
2675
Azael Avalosd2f20612015-11-04 09:28:26 -07002676 dev->hotkey_event_type = 0;
Seth Forshee6e02cc72011-09-20 16:55:51 -05002677 if (toshiba_acpi_setup_keyboard(dev))
2678 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05002679
Azael Avalos695f6062015-07-22 18:09:13 -06002680 /* Determine whether or not BIOS supports transflective backlight */
2681 ret = get_tr_backlight_status(dev, &dummy);
2682 dev->tr_backlight_supported = !ret;
2683
Seth Forshee62cce752012-04-19 11:23:50 -05002684 ret = toshiba_acpi_setup_backlight(dev);
2685 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05002686 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05002687
Azael Avalosea215a3f2015-07-31 21:58:12 -06002688 toshiba_illumination_available(dev);
2689 if (dev->illumination_supported) {
Seth Forshee135740d2011-09-20 16:55:49 -05002690 dev->led_dev.name = "toshiba::illumination";
2691 dev->led_dev.max_brightness = 1;
2692 dev->led_dev.brightness_set = toshiba_illumination_set;
2693 dev->led_dev.brightness_get = toshiba_illumination_get;
2694 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002695 dev->illumination_led_registered = true;
Seth Forshee135740d2011-09-20 16:55:49 -05002696 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002697
Azael Avalosea215a3f2015-07-31 21:58:12 -06002698 toshiba_eco_mode_available(dev);
2699 if (dev->eco_supported) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002700 dev->eco_led.name = "toshiba::eco_mode";
2701 dev->eco_led.max_brightness = 1;
2702 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2703 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2704 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002705 dev->eco_led_registered = true;
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002706 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002707
Azael Avalosea215a3f2015-07-31 21:58:12 -06002708 toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06002709 /*
2710 * Only register the LED if KBD illumination is supported
2711 * and the keyboard backlight operation mode is set to FN-Z
2712 */
2713 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2714 dev->kbd_led.name = "toshiba::kbd_backlight";
2715 dev->kbd_led.max_brightness = 1;
2716 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2717 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2718 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002719 dev->kbd_led_registered = true;
Azael Avalos360f0f32014-03-25 20:38:31 -06002720 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002721
Azael Avalos9d8658a2014-03-25 20:38:32 -06002722 ret = toshiba_touchpad_get(dev, &dummy);
2723 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002724
Azael Avalosea215a3f2015-07-31 21:58:12 -06002725 toshiba_accelerometer_available(dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002726
Azael Avalosc8c91842015-04-02 19:26:20 -06002727 toshiba_usb_sleep_charge_available(dev);
Azael Avalose26ffe52015-01-18 18:30:22 -07002728
Azael Avalosbb3fe012015-01-18 18:30:24 -07002729 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2730 dev->usb_rapid_charge_supported = !ret;
2731
Azael Avalos172ce0a2015-01-18 18:30:25 -07002732 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2733 dev->usb_sleep_music_supported = !ret;
2734
Azael Avalos35d53ce2015-02-10 21:09:19 -07002735 ret = toshiba_panel_power_on_get(dev, &dummy);
2736 dev->panel_power_on_supported = !ret;
2737
Azael Avalos17fe4b32015-02-10 21:09:20 -07002738 ret = toshiba_usb_three_get(dev, &dummy);
2739 dev->usb_three_supported = !ret;
2740
Seth Forshee36d03f92011-09-20 16:55:53 -05002741 ret = get_video_status(dev, &dummy);
2742 dev->video_supported = !ret;
2743
2744 ret = get_fan_status(dev, &dummy);
2745 dev->fan_supported = !ret;
2746
Azael Avalos0409cbc2015-07-31 21:58:13 -06002747 print_supported_features(dev);
2748
Azael Avalos360f0f32014-03-25 20:38:31 -06002749 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2750 &toshiba_attr_group);
2751 if (ret) {
2752 dev->sysfs_created = 0;
2753 goto error;
2754 }
2755 dev->sysfs_created = !ret;
2756
Seth Forshee36d03f92011-09-20 16:55:53 -05002757 create_toshiba_proc_entries(dev);
2758
Seth Forshee29cd2932012-01-18 13:44:09 -06002759 toshiba_acpi = dev;
2760
Seth Forshee135740d2011-09-20 16:55:49 -05002761 return 0;
2762
2763error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002764 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002765 return ret;
2766}
2767
2768static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2769{
2770 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Azael Avalos80546902014-12-04 20:22:47 -07002771 int ret;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002772
Azael Avalos71454d72014-12-04 20:22:46 -07002773 switch (event) {
2774 case 0x80: /* Hotkeys and some system events */
Azael Avalosa88bc062015-07-22 18:09:12 -06002775 /*
2776 * Machines with this WMI GUID aren't supported due to bugs in
2777 * their AML.
2778 *
2779 * Return silently to avoid triggering a netlink event.
2780 */
2781 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2782 return;
Azael Avalos71454d72014-12-04 20:22:46 -07002783 toshiba_acpi_process_hotkeys(dev);
2784 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002785 case 0x81: /* Dock events */
2786 case 0x82:
2787 case 0x83:
2788 pr_info("Dock event received %x\n", event);
2789 break;
2790 case 0x88: /* Thermal events */
2791 pr_info("Thermal event received\n");
2792 break;
2793 case 0x8f: /* LID closed */
2794 case 0x90: /* LID is closed and Dock has been ejected */
2795 break;
2796 case 0x8c: /* SATA power events */
2797 case 0x8b:
2798 pr_info("SATA power event received %x\n", event);
2799 break;
Azael Avalos80546902014-12-04 20:22:47 -07002800 case 0x92: /* Keyboard backlight mode changed */
2801 /* Update sysfs entries */
2802 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2803 &toshiba_attr_group);
2804 if (ret)
2805 pr_err("Unable to update sysfs entries\n");
2806 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002807 case 0x85: /* Unknown */
2808 case 0x8d: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002809 case 0x8e: /* Unknown */
Azael Avalosbab09e22015-03-06 18:14:41 -07002810 case 0x94: /* Unknown */
2811 case 0x95: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002812 default:
2813 pr_info("Unknown event received %x\n", event);
2814 break;
Seth Forshee29cd2932012-01-18 13:44:09 -06002815 }
Azael Avalosbab09e22015-03-06 18:14:41 -07002816
2817 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2818 dev_name(&acpi_dev->dev),
Azael Avalos13ae84f2015-11-15 20:33:46 -07002819 event, (event == 0x80) ?
2820 dev->last_key_event : 0);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002821}
2822
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +02002823#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002824static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002825{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002826 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002827
Azael Avalos1e574db2015-07-22 19:37:49 -06002828 if (dev->hotkey_dev) {
2829 u32 result;
2830
Azael Avalosd37782b2015-05-06 09:35:10 -06002831 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Azael Avalos1e574db2015-07-22 19:37:49 -06002832 if (result != TOS_SUCCESS)
2833 pr_info("Unable to disable hotkeys\n");
2834 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002835
2836 return 0;
2837}
2838
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002839static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002840{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002841 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002842
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002843 if (dev->hotkey_dev) {
Azael Avalos1e574db2015-07-22 19:37:49 -06002844 int error = toshiba_acpi_enable_hotkeys(dev);
2845
Azael Avalos1f28f292014-12-04 20:22:45 -07002846 if (error)
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002847 pr_info("Unable to re-enable hotkeys\n");
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002848 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002849
2850 return 0;
2851}
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +02002852#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002853
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002854static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2855 toshiba_acpi_suspend, toshiba_acpi_resume);
2856
Seth Forshee135740d2011-09-20 16:55:49 -05002857static struct acpi_driver toshiba_acpi_driver = {
2858 .name = "Toshiba ACPI driver",
2859 .owner = THIS_MODULE,
2860 .ids = toshiba_device_ids,
2861 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2862 .ops = {
2863 .add = toshiba_acpi_add,
2864 .remove = toshiba_acpi_remove,
2865 .notify = toshiba_acpi_notify,
2866 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002867 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05002868};
Holger Machtc9263552006-10-20 14:30:29 -07002869
Len Brown4be44fc2005-08-05 00:44:28 -04002870static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871{
Seth Forshee135740d2011-09-20 16:55:49 -05002872 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
2874 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2875 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05002876 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002877 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 }
2879
Seth Forshee135740d2011-09-20 16:55:49 -05002880 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2881 if (ret) {
2882 pr_err("Failed to register ACPI driver: %d\n", ret);
2883 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07002884 }
2885
Seth Forshee135740d2011-09-20 16:55:49 -05002886 return ret;
2887}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002888
Seth Forshee135740d2011-09-20 16:55:49 -05002889static void __exit toshiba_acpi_exit(void)
2890{
2891 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2892 if (toshiba_proc_dir)
2893 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894}
2895
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896module_init(toshiba_acpi_init);
2897module_exit(toshiba_acpi_exit);