blob: 66b596a7f710b5dc032a67e2ba403961a4bdb862 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright (C) 2002-2004 John Belmonte
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04005 * Copyright (C) 2008 Philip Langdale
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +02006 * Copyright (C) 2010 Pierre Ducroquet
Azael Avalos7216d702015-02-10 21:09:21 -07007 * Copyright (C) 2014-2015 Azael Avalos
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
Darren Hartc57c0fa2015-02-11 21:25:22 -080019 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 *
22 * The devolpment page for this driver is located at
23 * http://memebeam.org/toys/ToshibaAcpiDriver.
24 *
25 * Credits:
26 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
27 * engineering the Windows drivers
28 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
29 * Rob Miller - TV out and hotkeys help
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 */
31
Joe Perches7e334602011-03-29 15:21:52 -070032#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
Azael Avalos63ba3e22015-05-06 09:35:13 -060034#define TOSHIBA_ACPI_VERSION "0.22"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define PROC_INTERFACE_VERSION 1
36
37#include <linux/kernel.h>
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/types.h>
41#include <linux/proc_fs.h>
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -080042#include <linux/seq_file.h>
Holger Machtc9263552006-10-20 14:30:29 -070043#include <linux/backlight.h>
Matthew Garrett6335e4d2010-02-25 15:20:54 -050044#include <linux/input.h>
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -070045#include <linux/input/sparse-keymap.h>
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +020046#include <linux/leds.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090047#include <linux/slab.h>
Seth Forshee29cd2932012-01-18 13:44:09 -060048#include <linux/workqueue.h>
49#include <linux/i8042.h>
Lv Zheng8b484632013-12-03 08:49:16 +080050#include <linux/acpi.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020051#include <linux/dmi.h>
Azael Avalosb5163992015-02-10 23:43:56 -070052#include <linux/uaccess.h>
Azael Avalosfc5462f2015-07-22 18:09:11 -060053#include <linux/miscdevice.h>
54#include <linux/toshiba.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020055#include <acpi/video.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057MODULE_AUTHOR("John Belmonte");
58MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
59MODULE_LICENSE("GPL");
60
Seth Forsheef11f9992012-01-18 13:44:11 -060061#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
62
Seth Forshee29cd2932012-01-18 13:44:09 -060063/* Scan code for Fn key on TOS1900 models */
64#define TOS1900_FN_SCAN 0x6e
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/* Toshiba ACPI method paths */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
68
Darren Harte0769fe2015-02-11 20:50:08 -080069/*
70 * The Toshiba configuration interface is composed of the HCI and the SCI,
Azael Avalos258c5902014-09-29 20:40:07 -060071 * which are defined as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 *
73 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
74 * be uniform across all their models. Ideally we would just call
75 * dedicated ACPI methods instead of using this primitive interface.
76 * However the ACPI methods seem to be incomplete in some areas (for
77 * example they allow setting, but not reading, the LCD brightness value),
78 * so this is still useful.
Matthew Garrettea6b31f2014-04-04 14:22:34 -040079 *
Azael Avalos84a62732014-03-25 20:38:29 -060080 * SCI stands for "System Configuration Interface" which aim is to
81 * conceal differences in hardware between different models.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 */
83
Azael Avalos258c5902014-09-29 20:40:07 -060084#define TCI_WORDS 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Azael Avalos3f75bbe2015-05-06 09:35:11 -060086/* Operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define HCI_SET 0xff00
88#define HCI_GET 0xfe00
Azael Avalos84a62732014-03-25 20:38:29 -060089#define SCI_OPEN 0xf100
90#define SCI_CLOSE 0xf200
91#define SCI_GET 0xf300
92#define SCI_SET 0xf400
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Azael Avalos3f75bbe2015-05-06 09:35:11 -060094/* Return codes */
Azael Avalos1864bbc2014-09-29 20:40:08 -060095#define TOS_SUCCESS 0x0000
96#define TOS_OPEN_CLOSE_OK 0x0044
97#define TOS_FAILURE 0x1000
98#define TOS_NOT_SUPPORTED 0x8000
99#define TOS_ALREADY_OPEN 0x8100
100#define TOS_NOT_OPENED 0x8200
101#define TOS_INPUT_DATA_ERROR 0x8300
102#define TOS_WRITE_PROTECTED 0x8400
103#define TOS_NOT_PRESENT 0x8600
104#define TOS_FIFO_EMPTY 0x8c00
105#define TOS_DATA_NOT_AVAILABLE 0x8d20
106#define TOS_NOT_INITIALIZED 0x8d50
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700107#define TOS_NOT_INSTALLED 0x8e00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600109/* Registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define HCI_FAN 0x0004
Akio Idehara121b7b02012-04-06 01:46:43 +0900111#define HCI_TR_BACKLIGHT 0x0005
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#define HCI_SYSTEM_EVENT 0x0016
113#define HCI_VIDEO_OUT 0x001c
114#define HCI_HOTKEY_EVENT 0x001e
115#define HCI_LCD_BRIGHTNESS 0x002a
Azael Avalos5a2813e2014-03-25 20:38:34 -0600116#define HCI_ACCELEROMETER 0x006d
Azael Avalos360f0f32014-03-25 20:38:31 -0600117#define HCI_KBD_ILLUMINATION 0x0095
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600118#define HCI_ECO_MODE 0x0097
Azael Avalos5a2813e2014-03-25 20:38:34 -0600119#define HCI_ACCELEROMETER2 0x00a6
Azael Avalos56e6b352015-03-20 16:55:16 -0600120#define HCI_SYSTEM_INFO 0xc000
Azael Avalos35d53ce2015-02-10 21:09:19 -0700121#define SCI_PANEL_POWER_ON 0x010d
Azael Avalosfdb79082014-03-25 20:38:30 -0600122#define SCI_ILLUMINATION 0x014e
Azael Avalose26ffe52015-01-18 18:30:22 -0700123#define SCI_USB_SLEEP_CHARGE 0x0150
Azael Avalos360f0f32014-03-25 20:38:31 -0600124#define SCI_KBD_ILLUM_STATUS 0x015c
Azael Avalos172ce0a2015-01-18 18:30:25 -0700125#define SCI_USB_SLEEP_MUSIC 0x015e
Azael Avalos17fe4b32015-02-10 21:09:20 -0700126#define SCI_USB_THREE 0x0169
Azael Avalos9d8658a2014-03-25 20:38:32 -0600127#define SCI_TOUCHPAD 0x050e
Azael Avalosbae84192015-02-10 21:09:18 -0700128#define SCI_KBD_FUNCTION_KEYS 0x0522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600130/* Field definitions */
Azael Avalos5a2813e2014-03-25 20:38:34 -0600131#define HCI_ACCEL_MASK 0x7fff
Seth Forshee29cd2932012-01-18 13:44:09 -0600132#define HCI_HOTKEY_DISABLE 0x0b
133#define HCI_HOTKEY_ENABLE 0x09
Azael Avalosfb42d1f2015-03-20 16:55:18 -0600134#define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#define HCI_LCD_BRIGHTNESS_BITS 3
136#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
137#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
Azael Avalos360f0f32014-03-25 20:38:31 -0600138#define HCI_MISC_SHIFT 0x10
Azael Avalos56e6b352015-03-20 16:55:16 -0600139#define HCI_SYSTEM_TYPE1 0x10
140#define HCI_SYSTEM_TYPE2 0x11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#define HCI_VIDEO_OUT_LCD 0x1
142#define HCI_VIDEO_OUT_CRT 0x2
143#define HCI_VIDEO_OUT_TV 0x4
Azael Avalos93f8c162014-09-12 18:50:36 -0600144#define SCI_KBD_MODE_MASK 0x1f
Azael Avalos360f0f32014-03-25 20:38:31 -0600145#define SCI_KBD_MODE_FNZ 0x1
146#define SCI_KBD_MODE_AUTO 0x2
Azael Avalos93f8c162014-09-12 18:50:36 -0600147#define SCI_KBD_MODE_ON 0x8
148#define SCI_KBD_MODE_OFF 0x10
149#define SCI_KBD_TIME_MAX 0x3c001a
Azael Avalose26ffe52015-01-18 18:30:22 -0700150#define SCI_USB_CHARGE_MODE_MASK 0xff
Azael Avalosc8c91842015-04-02 19:26:20 -0600151#define SCI_USB_CHARGE_DISABLED 0x00
152#define SCI_USB_CHARGE_ALTERNATE 0x09
153#define SCI_USB_CHARGE_TYPICAL 0x11
154#define SCI_USB_CHARGE_AUTO 0x21
Azael Avalos182bcaa2015-01-18 18:30:23 -0700155#define SCI_USB_CHARGE_BAT_MASK 0x7
156#define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
157#define SCI_USB_CHARGE_BAT_LVL_ON 0x4
158#define SCI_USB_CHARGE_BAT_LVL 0x0200
Azael Avalosbb3fe012015-01-18 18:30:24 -0700159#define SCI_USB_CHARGE_RAPID_DSP 0x0300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Seth Forshee135740d2011-09-20 16:55:49 -0500161struct toshiba_acpi_dev {
162 struct acpi_device *acpi_dev;
163 const char *method_hci;
Seth Forshee135740d2011-09-20 16:55:49 -0500164 struct input_dev *hotkey_dev;
Seth Forshee29cd2932012-01-18 13:44:09 -0600165 struct work_struct hotkey_work;
Seth Forshee135740d2011-09-20 16:55:49 -0500166 struct backlight_device *backlight_dev;
167 struct led_classdev led_dev;
Azael Avalos360f0f32014-03-25 20:38:31 -0600168 struct led_classdev kbd_led;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600169 struct led_classdev eco_led;
Azael Avalosfc5462f2015-07-22 18:09:11 -0600170 struct miscdevice miscdev;
Seth Forshee36d03f92011-09-20 16:55:53 -0500171
Seth Forshee135740d2011-09-20 16:55:49 -0500172 int force_fan;
173 int last_key_event;
174 int key_event_valid;
Azael Avalos93f8c162014-09-12 18:50:36 -0600175 int kbd_type;
Azael Avalos360f0f32014-03-25 20:38:31 -0600176 int kbd_mode;
177 int kbd_time;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700178 int usbsc_bat_level;
Azael Avalosc8c91842015-04-02 19:26:20 -0600179 int usbsc_mode_base;
Azael Avalosa2b34712015-03-20 16:55:17 -0600180 int hotkey_event_type;
Seth Forshee135740d2011-09-20 16:55:49 -0500181
Dan Carpenter592b7462012-01-15 14:28:20 +0300182 unsigned int illumination_supported:1;
183 unsigned int video_supported:1;
184 unsigned int fan_supported:1;
185 unsigned int system_event_supported:1;
Seth Forshee29cd2932012-01-18 13:44:09 -0600186 unsigned int ntfy_supported:1;
187 unsigned int info_supported:1;
Akio Idehara121b7b02012-04-06 01:46:43 +0900188 unsigned int tr_backlight_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600189 unsigned int kbd_illum_supported:1;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600190 unsigned int touchpad_supported:1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600191 unsigned int eco_supported:1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600192 unsigned int accelerometer_supported:1;
Azael Avalose26ffe52015-01-18 18:30:22 -0700193 unsigned int usb_sleep_charge_supported:1;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700194 unsigned int usb_rapid_charge_supported:1;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700195 unsigned int usb_sleep_music_supported:1;
Azael Avalosbae84192015-02-10 21:09:18 -0700196 unsigned int kbd_function_keys_supported:1;
Azael Avalos35d53ce2015-02-10 21:09:19 -0700197 unsigned int panel_power_on_supported:1;
Azael Avalos17fe4b32015-02-10 21:09:20 -0700198 unsigned int usb_three_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600199 unsigned int sysfs_created:1;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600200
201 bool kbd_led_registered;
202 bool illumination_led_registered;
203 bool eco_led_registered;
Seth Forshee135740d2011-09-20 16:55:49 -0500204};
205
Seth Forshee29cd2932012-01-18 13:44:09 -0600206static struct toshiba_acpi_dev *toshiba_acpi;
207
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800208static const struct acpi_device_id toshiba_device_ids[] = {
209 {"TOS6200", 0},
Ondrej Zary63a9e012014-11-10 00:11:54 +0100210 {"TOS6207", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400211 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800212 {"TOS1900", 0},
213 {"", 0},
214};
215MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
216
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800217static const struct key_entry toshiba_acpi_keymap[] = {
Unai Uribarrifec278a2014-01-14 11:06:47 +0100218 { KE_KEY, 0x9e, { KEY_RFKILL } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700219 { KE_KEY, 0x101, { KEY_MUTE } },
220 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
221 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600222 { KE_KEY, 0x10f, { KEY_TAB } },
Azael Avalosaf502832012-01-18 13:44:10 -0600223 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
224 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700225 { KE_KEY, 0x13b, { KEY_COFFEE } },
226 { KE_KEY, 0x13c, { KEY_BATTERY } },
227 { KE_KEY, 0x13d, { KEY_SLEEP } },
228 { KE_KEY, 0x13e, { KEY_SUSPEND } },
229 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
230 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
231 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
232 { KE_KEY, 0x142, { KEY_WLAN } },
Azael Avalosaf502832012-01-18 13:44:10 -0600233 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
Jon Dowlanda49010f2010-10-27 00:24:59 +0100234 { KE_KEY, 0x17f, { KEY_FN } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700235 { KE_KEY, 0xb05, { KEY_PROG2 } },
236 { KE_KEY, 0xb06, { KEY_WWW } },
237 { KE_KEY, 0xb07, { KEY_MAIL } },
238 { KE_KEY, 0xb30, { KEY_STOP } },
239 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
240 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
241 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
242 { KE_KEY, 0xb5a, { KEY_MEDIA } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600243 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
244 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
245 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
246 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
247 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700248 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500249};
250
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200251static const struct key_entry toshiba_acpi_alt_keymap[] = {
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200252 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
253 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalose6efad72014-08-04 09:21:02 -0600254 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200255 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200256 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
257 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600258 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200259 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600260 { KE_KEY, 0x157, { KEY_MUTE } },
261 { KE_KEY, 0x158, { KEY_WLAN } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200262 { KE_END, 0 },
263};
264
Darren Harte0769fe2015-02-11 20:50:08 -0800265/*
Hans de Goede358d6a22015-04-21 12:01:32 +0200266 * List of models which have a broken acpi-video backlight interface and thus
267 * need to use the toshiba (vendor) interface instead.
268 */
269static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
270 {}
271};
272
273/*
Darren Harte0769fe2015-02-11 20:50:08 -0800274 * Utility
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 */
276
Azael Avalosb5163992015-02-10 23:43:56 -0700277static inline void _set_bit(u32 *word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 *word = (*word & ~mask) | (mask * value);
280}
281
Darren Harte0769fe2015-02-11 20:50:08 -0800282/*
283 * ACPI interface wrappers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 */
285
Len Brown4be44fc2005-08-05 00:44:28 -0400286static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 acpi_status status;
289
Zhang Rui619400d2013-09-03 08:31:56 +0800290 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500291 return (status == AE_OK) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
Darren Harte0769fe2015-02-11 20:50:08 -0800294/*
295 * Perform a raw configuration call. Here we don't care about input or output
Azael Avalos258c5902014-09-29 20:40:07 -0600296 * buffer format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 */
Azael Avalos258c5902014-09-29 20:40:07 -0600298static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
299 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
301 struct acpi_object_list params;
Azael Avalos258c5902014-09-29 20:40:07 -0600302 union acpi_object in_objs[TCI_WORDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 struct acpi_buffer results;
Azael Avalos258c5902014-09-29 20:40:07 -0600304 union acpi_object out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 acpi_status status;
306 int i;
307
Azael Avalos258c5902014-09-29 20:40:07 -0600308 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600310 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 in_objs[i].type = ACPI_TYPE_INTEGER;
312 in_objs[i].integer.value = in[i];
313 }
314
315 results.length = sizeof(out_objs);
316 results.pointer = out_objs;
317
Seth Forshee6e02cc72011-09-20 16:55:51 -0500318 status = acpi_evaluate_object(dev->acpi_dev->handle,
319 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400320 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600321 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Azael Avalosb5163992015-02-10 23:43:56 -0700322 for (i = 0; i < out_objs->package.count; ++i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 out[i] = out_objs->package.elements[i].integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
325
326 return status;
327}
328
Darren Harte0769fe2015-02-11 20:50:08 -0800329/*
Azael Avalosd37782b2015-05-06 09:35:10 -0600330 * Common hci tasks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 *
332 * In addition to the ACPI status, the HCI system returns a result which
333 * may be useful (such as "not supported").
334 */
335
Azael Avalosd37782b2015-05-06 09:35:10 -0600336static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Azael Avalos258c5902014-09-29 20:40:07 -0600338 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
339 u32 out[TCI_WORDS];
340 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600341
342 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
344
Azael Avalosd37782b2015-05-06 09:35:10 -0600345static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Azael Avalos258c5902014-09-29 20:40:07 -0600347 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
348 u32 out[TCI_WORDS];
349 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700350
Azael Avalos893f3f62014-09-29 20:40:09 -0600351 if (ACPI_FAILURE(status))
352 return TOS_FAILURE;
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600355
356 return out[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Darren Harte0769fe2015-02-11 20:50:08 -0800359/*
360 * Common sci tasks
Azael Avalos84a62732014-03-25 20:38:29 -0600361 */
362
363static int sci_open(struct toshiba_acpi_dev *dev)
364{
Azael Avalos258c5902014-09-29 20:40:07 -0600365 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
366 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600367 acpi_status status;
368
Azael Avalos258c5902014-09-29 20:40:07 -0600369 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600370 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600371 pr_err("ACPI call to open SCI failed\n");
372 return 0;
373 }
374
Azael Avalos1864bbc2014-09-29 20:40:08 -0600375 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600376 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600377 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600378 pr_info("Toshiba SCI already opened\n");
379 return 1;
Azael Avalosfa465732015-01-18 19:17:12 -0700380 } else if (out[0] == TOS_NOT_SUPPORTED) {
Darren Harte0769fe2015-02-11 20:50:08 -0800381 /*
382 * Some BIOSes do not have the SCI open/close functions
Azael Avalosfa465732015-01-18 19:17:12 -0700383 * implemented and return 0x8000 (Not Supported), failing to
384 * register some supported features.
385 *
386 * Simply return 1 if we hit those affected laptops to make the
387 * supported features work.
388 *
389 * In the case that some laptops really do not support the SCI,
390 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
391 * and thus, not registering support for the queried feature.
392 */
393 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600394 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600395 pr_info("Toshiba SCI is not present\n");
396 }
397
398 return 0;
399}
400
401static void sci_close(struct toshiba_acpi_dev *dev)
402{
Azael Avalos258c5902014-09-29 20:40:07 -0600403 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
404 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600405 acpi_status status;
406
Azael Avalos258c5902014-09-29 20:40:07 -0600407 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600408 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600409 pr_err("ACPI call to close SCI failed\n");
410 return;
411 }
412
Azael Avalos1864bbc2014-09-29 20:40:08 -0600413 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600414 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600415 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600416 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600417 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600418 pr_info("Toshiba SCI is not present\n");
419}
420
Azael Avalos893f3f62014-09-29 20:40:09 -0600421static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Azael Avalos84a62732014-03-25 20:38:29 -0600422{
Azael Avalos258c5902014-09-29 20:40:07 -0600423 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
424 u32 out[TCI_WORDS];
425 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700426
Azael Avalos893f3f62014-09-29 20:40:09 -0600427 if (ACPI_FAILURE(status))
428 return TOS_FAILURE;
429
Azael Avalos84a62732014-03-25 20:38:29 -0600430 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600431
432 return out[0];
Azael Avalos84a62732014-03-25 20:38:29 -0600433}
434
Azael Avalos893f3f62014-09-29 20:40:09 -0600435static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Azael Avalos84a62732014-03-25 20:38:29 -0600436{
Azael Avalos258c5902014-09-29 20:40:07 -0600437 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
438 u32 out[TCI_WORDS];
439 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600440
441 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600442}
443
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200444/* Illumination support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600445static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200446{
Azael Avalos258c5902014-09-29 20:40:07 -0600447 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
448 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200449 acpi_status status;
450
Azael Avalosea215a3f2015-07-31 21:58:12 -0600451 dev->illumination_supported = 0;
452 dev->illumination_led_registered = false;
453
Azael Avalosfdb79082014-03-25 20:38:30 -0600454 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600455 return;
Azael Avalosfdb79082014-03-25 20:38:30 -0600456
Azael Avalos258c5902014-09-29 20:40:07 -0600457 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600458 sci_close(dev);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600459 if (ACPI_FAILURE(status))
Azael Avalosfdb79082014-03-25 20:38:30 -0600460 pr_err("ACPI call to query Illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600461 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalos0409cbc2015-07-31 21:58:13 -0600462 return;
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 Avalosfdb79082014-03-25 20:38:30 -0600472 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200473
474 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600475 if (!sci_open(dev))
476 return;
477
478 /* Switch the illumination on/off */
479 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600480 result = sci_write(dev, SCI_ILLUMINATION, state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600481 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600482 if (result == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600483 pr_err("ACPI call for illumination failed\n");
484 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600485 } else if (result == TOS_NOT_SUPPORTED) {
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200486 return;
487 }
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200488}
489
490static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
491{
Seth Forshee135740d2011-09-20 16:55:49 -0500492 struct toshiba_acpi_dev *dev = container_of(cdev,
493 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600494 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200495
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600496 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600497 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200498 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200499
500 /* Check the illumination */
Azael Avalos893f3f62014-09-29 20:40:09 -0600501 result = sci_read(dev, SCI_ILLUMINATION, &state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600502 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600503 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600504 pr_err("ACPI call for illumination failed\n");
505 return LED_OFF;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600506 } else if (result == TOS_NOT_SUPPORTED) {
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200507 return LED_OFF;
508 }
509
Azael Avalosfdb79082014-03-25 20:38:30 -0600510 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200511}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400512
Azael Avalos360f0f32014-03-25 20:38:31 -0600513/* KBD Illumination */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600514static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
Azael Avalos93f8c162014-09-12 18:50:36 -0600515{
Azael Avalos258c5902014-09-29 20:40:07 -0600516 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
517 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600518 acpi_status status;
519
Azael Avalosea215a3f2015-07-31 21:58:12 -0600520 dev->kbd_illum_supported = 0;
521 dev->kbd_led_registered = false;
522
Azael Avalos93f8c162014-09-12 18:50:36 -0600523 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600524 return;
Azael Avalos93f8c162014-09-12 18:50:36 -0600525
Azael Avalos258c5902014-09-29 20:40:07 -0600526 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600527 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600528 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600529 pr_err("ACPI call to query kbd illumination support failed\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600530 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos0409cbc2015-07-31 21:58:13 -0600531 return;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600532 } else if (out[0] == TOS_SUCCESS) {
533 /*
534 * Check for keyboard backlight timeout max value,
535 * previous kbd backlight implementation set this to
536 * 0x3c0003, and now the new implementation set this
537 * to 0x3c001a, use this to distinguish between them.
538 */
539 if (out[3] == SCI_KBD_TIME_MAX)
540 dev->kbd_type = 2;
541 else
542 dev->kbd_type = 1;
543 /* Get the current keyboard backlight mode */
544 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
545 /* Get the current time (1-60 seconds) */
546 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
547 /* Flag as supported */
548 dev->kbd_illum_supported = 1;
Azael Avalos93f8c162014-09-12 18:50:36 -0600549 }
Azael Avalos93f8c162014-09-12 18:50:36 -0600550}
551
Azael Avalos360f0f32014-03-25 20:38:31 -0600552static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
553{
554 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600555
556 if (!sci_open(dev))
557 return -EIO;
558
Azael Avalos893f3f62014-09-29 20:40:09 -0600559 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600560 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600561 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600562 pr_err("ACPI call to set KBD backlight status failed\n");
563 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600564 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600565 return -ENODEV;
566 }
567
568 return 0;
569}
570
571static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
572{
573 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600574
575 if (!sci_open(dev))
576 return -EIO;
577
Azael Avalos893f3f62014-09-29 20:40:09 -0600578 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600579 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600580 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600581 pr_err("ACPI call to get KBD backlight status failed\n");
582 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600583 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600584 return -ENODEV;
585 }
586
587 return 0;
588}
589
590static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
591{
592 struct toshiba_acpi_dev *dev = container_of(cdev,
593 struct toshiba_acpi_dev, kbd_led);
594 u32 state, result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600595
596 /* Check the keyboard backlight state */
Azael Avalosd37782b2015-05-06 09:35:10 -0600597 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
Azael Avalos893f3f62014-09-29 20:40:09 -0600598 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600599 pr_err("ACPI call to get the keyboard backlight failed\n");
600 return LED_OFF;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600601 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600602 return LED_OFF;
603 }
604
605 return state ? LED_FULL : LED_OFF;
606}
607
608static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
609 enum led_brightness brightness)
610{
611 struct toshiba_acpi_dev *dev = container_of(cdev,
612 struct toshiba_acpi_dev, kbd_led);
613 u32 state, result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600614
615 /* Set the keyboard backlight state */
616 state = brightness ? 1 : 0;
Azael Avalosd37782b2015-05-06 09:35:10 -0600617 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
Azael Avalos893f3f62014-09-29 20:40:09 -0600618 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600619 pr_err("ACPI call to set KBD Illumination mode failed\n");
620 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600621 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600622 return;
623 }
624}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400625
Azael Avalos9d8658a2014-03-25 20:38:32 -0600626/* TouchPad support */
627static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
628{
629 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600630
631 if (!sci_open(dev))
632 return -EIO;
633
Azael Avalos893f3f62014-09-29 20:40:09 -0600634 result = sci_write(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600635 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600636 if (result == TOS_FAILURE) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600637 pr_err("ACPI call to set the touchpad failed\n");
638 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600639 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600640 return -ENODEV;
641 }
642
643 return 0;
644}
645
646static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
647{
648 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600649
650 if (!sci_open(dev))
651 return -EIO;
652
Azael Avalos893f3f62014-09-29 20:40:09 -0600653 result = sci_read(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600654 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600655 if (result == TOS_FAILURE) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600656 pr_err("ACPI call to query the touchpad failed\n");
657 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600658 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600659 return -ENODEV;
660 }
661
662 return 0;
663}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200664
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600665/* Eco Mode support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600666static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600667{
668 acpi_status status;
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700669 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
Azael Avalos258c5902014-09-29 20:40:07 -0600670 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600671
Azael Avalosea215a3f2015-07-31 21:58:12 -0600672 dev->eco_supported = 0;
673 dev->eco_led_registered = false;
674
Azael Avalos258c5902014-09-29 20:40:07 -0600675 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600676 if (ACPI_FAILURE(status)) {
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700677 pr_err("ACPI call to get ECO led failed\n");
678 } else if (out[0] == TOS_NOT_INSTALLED) {
679 pr_info("ECO led not installed");
680 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
Darren Harte0769fe2015-02-11 20:50:08 -0800681 /*
682 * If we receive 0x8300 (Input Data Error), it means that the
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700683 * LED device is present, but that we just screwed the input
684 * parameters.
685 *
686 * Let's query the status of the LED to see if we really have a
687 * success response, indicating the actual presense of the LED,
688 * bail out otherwise.
689 */
690 in[3] = 1;
691 status = tci_raw(dev, in, out);
692 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE)
693 pr_err("ACPI call to get ECO led failed\n");
694 else if (out[0] == TOS_SUCCESS)
Azael Avalosea215a3f2015-07-31 21:58:12 -0600695 dev->eco_supported = 1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600696 }
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600697}
698
Azael Avalosb5163992015-02-10 23:43:56 -0700699static enum led_brightness
700toshiba_eco_mode_get_status(struct led_classdev *cdev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600701{
702 struct toshiba_acpi_dev *dev = container_of(cdev,
703 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600704 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
705 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600706 acpi_status status;
707
Azael Avalos258c5902014-09-29 20:40:07 -0600708 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600709 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600710 pr_err("ACPI call to get ECO led failed\n");
711 return LED_OFF;
712 }
713
714 return out[2] ? LED_FULL : LED_OFF;
715}
716
717static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
718 enum led_brightness brightness)
719{
720 struct toshiba_acpi_dev *dev = container_of(cdev,
721 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600722 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
723 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600724 acpi_status status;
725
726 /* Switch the Eco Mode led on/off */
727 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600728 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600729 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600730 pr_err("ACPI call to set ECO led failed\n");
731 return;
732 }
733}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400734
Azael Avalos5a2813e2014-03-25 20:38:34 -0600735/* Accelerometer support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600736static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600737{
Azael Avalos258c5902014-09-29 20:40:07 -0600738 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
739 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600740 acpi_status status;
741
Azael Avalosea215a3f2015-07-31 21:58:12 -0600742 dev->accelerometer_supported = 0;
743
Darren Harte0769fe2015-02-11 20:50:08 -0800744 /*
745 * Check if the accelerometer call exists,
Azael Avalos5a2813e2014-03-25 20:38:34 -0600746 * this call also serves as initialization
747 */
Azael Avalos258c5902014-09-29 20:40:07 -0600748 status = tci_raw(dev, in, out);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600749 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600750 pr_err("ACPI call to query the accelerometer failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600751 else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
752 out[0] == TOS_NOT_INITIALIZED)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600753 pr_err("Accelerometer not initialized\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600754 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalos0409cbc2015-07-31 21:58:13 -0600755 return;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600756 else if (out[0] == TOS_SUCCESS)
757 dev->accelerometer_supported = 1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600758}
759
760static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
761 u32 *xy, u32 *z)
762{
Azael Avalos258c5902014-09-29 20:40:07 -0600763 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
764 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600765 acpi_status status;
766
767 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600768 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600769 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600770 pr_err("ACPI call to query the accelerometer failed\n");
771 return -EIO;
772 }
773
774 *xy = out[2];
775 *z = out[4];
776
777 return 0;
778}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600779
Azael Avalose26ffe52015-01-18 18:30:22 -0700780/* Sleep (Charge and Music) utilities support */
Azael Avalosc8c91842015-04-02 19:26:20 -0600781static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
782{
783 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
784 u32 out[TCI_WORDS];
785 acpi_status status;
786
Azael Avalosc8c91842015-04-02 19:26:20 -0600787 dev->usb_sleep_charge_supported = 0;
788
789 if (!sci_open(dev))
790 return;
791
792 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600793 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600794 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
795 sci_close(dev);
796 return;
797 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600798 sci_close(dev);
799 return;
800 } else if (out[0] == TOS_SUCCESS) {
801 dev->usbsc_mode_base = out[4];
802 }
803
804 in[5] = SCI_USB_CHARGE_BAT_LVL;
805 status = tci_raw(dev, in, out);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600806 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600807 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600808 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
Azael Avalosc8c91842015-04-02 19:26:20 -0600809 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos0409cbc2015-07-31 21:58:13 -0600810 return;
Azael Avalosc8c91842015-04-02 19:26:20 -0600811 } else if (out[0] == TOS_SUCCESS) {
812 dev->usbsc_bat_level = out[2];
Azael Avalosea215a3f2015-07-31 21:58:12 -0600813 /* Flag as supported */
Azael Avalosc8c91842015-04-02 19:26:20 -0600814 dev->usb_sleep_charge_supported = 1;
815 }
816
Azael Avalosc8c91842015-04-02 19:26:20 -0600817}
818
Azael Avalose26ffe52015-01-18 18:30:22 -0700819static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
820 u32 *mode)
821{
822 u32 result;
823
824 if (!sci_open(dev))
825 return -EIO;
826
827 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
828 sci_close(dev);
829 if (result == TOS_FAILURE) {
830 pr_err("ACPI call to set USB S&C mode failed\n");
831 return -EIO;
832 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalose26ffe52015-01-18 18:30:22 -0700833 return -ENODEV;
834 } else if (result == TOS_INPUT_DATA_ERROR) {
835 return -EIO;
836 }
837
838 return 0;
839}
840
841static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
842 u32 mode)
843{
844 u32 result;
845
846 if (!sci_open(dev))
847 return -EIO;
848
849 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
850 sci_close(dev);
851 if (result == TOS_FAILURE) {
852 pr_err("ACPI call to set USB S&C mode failed\n");
853 return -EIO;
854 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalose26ffe52015-01-18 18:30:22 -0700855 return -ENODEV;
856 } else if (result == TOS_INPUT_DATA_ERROR) {
857 return -EIO;
858 }
859
860 return 0;
861}
862
Azael Avalos182bcaa2015-01-18 18:30:23 -0700863static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
864 u32 *mode)
865{
866 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
867 u32 out[TCI_WORDS];
868 acpi_status status;
869
870 if (!sci_open(dev))
871 return -EIO;
872
873 in[5] = SCI_USB_CHARGE_BAT_LVL;
874 status = tci_raw(dev, in, out);
875 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600876 if (ACPI_FAILURE(status)) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700877 pr_err("ACPI call to get USB S&C battery level failed\n");
878 return -EIO;
879 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700880 return -ENODEV;
881 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
882 return -EIO;
883 }
884
885 *mode = out[2];
886
887 return 0;
888}
889
890static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
891 u32 mode)
892{
893 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
894 u32 out[TCI_WORDS];
895 acpi_status status;
896
897 if (!sci_open(dev))
898 return -EIO;
899
900 in[2] = mode;
901 in[5] = SCI_USB_CHARGE_BAT_LVL;
902 status = tci_raw(dev, in, out);
903 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600904 if (ACPI_FAILURE(status)) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700905 pr_err("ACPI call to set USB S&C battery level failed\n");
906 return -EIO;
907 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700908 return -ENODEV;
909 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
910 return -EIO;
911 }
912
913 return 0;
914}
915
Azael Avalosbb3fe012015-01-18 18:30:24 -0700916static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
917 u32 *state)
918{
919 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
920 u32 out[TCI_WORDS];
921 acpi_status status;
922
923 if (!sci_open(dev))
924 return -EIO;
925
926 in[5] = SCI_USB_CHARGE_RAPID_DSP;
927 status = tci_raw(dev, in, out);
928 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600929 if (ACPI_FAILURE(status)) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600930 pr_err("ACPI call to get USB Rapid Charge failed\n");
Azael Avalosbb3fe012015-01-18 18:30:24 -0700931 return -EIO;
932 } else if (out[0] == TOS_NOT_SUPPORTED ||
933 out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosbb3fe012015-01-18 18:30:24 -0700934 return -ENODEV;
935 }
936
937 *state = out[2];
938
939 return 0;
940}
941
942static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
943 u32 state)
944{
945 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
946 u32 out[TCI_WORDS];
947 acpi_status status;
948
949 if (!sci_open(dev))
950 return -EIO;
951
952 in[2] = state;
953 in[5] = SCI_USB_CHARGE_RAPID_DSP;
954 status = tci_raw(dev, in, out);
955 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600956 if (ACPI_FAILURE(status)) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600957 pr_err("ACPI call to set USB Rapid Charge failed\n");
Azael Avalosbb3fe012015-01-18 18:30:24 -0700958 return -EIO;
959 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosbb3fe012015-01-18 18:30:24 -0700960 return -ENODEV;
961 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
962 return -EIO;
963 }
964
965 return 0;
966}
967
Azael Avalos172ce0a2015-01-18 18:30:25 -0700968static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
969{
970 u32 result;
971
972 if (!sci_open(dev))
973 return -EIO;
974
975 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
976 sci_close(dev);
977 if (result == TOS_FAILURE) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600978 pr_err("ACPI call to get Sleep and Music failed\n");
Azael Avalos172ce0a2015-01-18 18:30:25 -0700979 return -EIO;
980 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos172ce0a2015-01-18 18:30:25 -0700981 return -ENODEV;
982 } else if (result == TOS_INPUT_DATA_ERROR) {
983 return -EIO;
984 }
985
986 return 0;
987}
988
989static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
990{
991 u32 result;
992
993 if (!sci_open(dev))
994 return -EIO;
995
996 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
997 sci_close(dev);
998 if (result == TOS_FAILURE) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600999 pr_err("ACPI call to set Sleep and Music failed\n");
Azael Avalos172ce0a2015-01-18 18:30:25 -07001000 return -EIO;
1001 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos172ce0a2015-01-18 18:30:25 -07001002 return -ENODEV;
1003 } else if (result == TOS_INPUT_DATA_ERROR) {
1004 return -EIO;
1005 }
1006
1007 return 0;
1008}
1009
Azael Avalosbae84192015-02-10 21:09:18 -07001010/* Keyboard function keys */
1011static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
1012{
1013 u32 result;
1014
1015 if (!sci_open(dev))
1016 return -EIO;
1017
1018 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
1019 sci_close(dev);
1020 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1021 pr_err("ACPI call to get KBD function keys failed\n");
1022 return -EIO;
1023 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosbae84192015-02-10 21:09:18 -07001024 return -ENODEV;
1025 }
1026
1027 return 0;
1028}
1029
1030static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1031{
1032 u32 result;
1033
1034 if (!sci_open(dev))
1035 return -EIO;
1036
1037 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1038 sci_close(dev);
1039 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1040 pr_err("ACPI call to set KBD function keys failed\n");
1041 return -EIO;
1042 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosbae84192015-02-10 21:09:18 -07001043 return -ENODEV;
1044 }
1045
1046 return 0;
1047}
1048
Azael Avalos35d53ce2015-02-10 21:09:19 -07001049/* Panel Power ON */
1050static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1051{
1052 u32 result;
1053
1054 if (!sci_open(dev))
1055 return -EIO;
1056
1057 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1058 sci_close(dev);
1059 if (result == TOS_FAILURE) {
1060 pr_err("ACPI call to get Panel Power ON failed\n");
1061 return -EIO;
1062 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos35d53ce2015-02-10 21:09:19 -07001063 return -ENODEV;
1064 } else if (result == TOS_INPUT_DATA_ERROR) {
1065 return -EIO;
1066 }
1067
1068 return 0;
1069}
1070
1071static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1072{
1073 u32 result;
1074
1075 if (!sci_open(dev))
1076 return -EIO;
1077
1078 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1079 sci_close(dev);
1080 if (result == TOS_FAILURE) {
1081 pr_err("ACPI call to set Panel Power ON failed\n");
1082 return -EIO;
1083 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos35d53ce2015-02-10 21:09:19 -07001084 return -ENODEV;
1085 } else if (result == TOS_INPUT_DATA_ERROR) {
1086 return -EIO;
1087 }
1088
1089 return 0;
1090}
1091
Azael Avalos17fe4b32015-02-10 21:09:20 -07001092/* USB Three */
1093static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1094{
1095 u32 result;
1096
1097 if (!sci_open(dev))
1098 return -EIO;
1099
1100 result = sci_read(dev, SCI_USB_THREE, state);
1101 sci_close(dev);
1102 if (result == TOS_FAILURE) {
1103 pr_err("ACPI call to get USB 3 failed\n");
1104 return -EIO;
1105 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos17fe4b32015-02-10 21:09:20 -07001106 return -ENODEV;
1107 } else if (result == TOS_INPUT_DATA_ERROR) {
1108 return -EIO;
1109 }
1110
1111 return 0;
1112}
1113
1114static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1115{
1116 u32 result;
1117
1118 if (!sci_open(dev))
1119 return -EIO;
1120
1121 result = sci_write(dev, SCI_USB_THREE, state);
1122 sci_close(dev);
1123 if (result == TOS_FAILURE) {
1124 pr_err("ACPI call to set USB 3 failed\n");
1125 return -EIO;
1126 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos17fe4b32015-02-10 21:09:20 -07001127 return -ENODEV;
1128 } else if (result == TOS_INPUT_DATA_ERROR) {
1129 return -EIO;
1130 }
1131
1132 return 0;
1133}
1134
Azael Avalos56e6b352015-03-20 16:55:16 -06001135/* Hotkey Event type */
1136static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1137 u32 *type)
1138{
Azael Avalos3b876002015-05-06 09:35:09 -06001139 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1140 u32 out[TCI_WORDS];
1141 acpi_status status;
Azael Avalos56e6b352015-03-20 16:55:16 -06001142
Azael Avalos3b876002015-05-06 09:35:09 -06001143 status = tci_raw(dev, in, out);
1144 if (ACPI_FAILURE(status)) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001145 pr_err("ACPI call to get System type failed\n");
1146 return -EIO;
Azael Avalos3b876002015-05-06 09:35:09 -06001147 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001148 return -ENODEV;
1149 }
1150
Azael Avalos3b876002015-05-06 09:35:09 -06001151 *type = out[3];
Azael Avalos56e6b352015-03-20 16:55:16 -06001152
1153 return 0;
1154}
1155
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001156/* Transflective Backlight */
Azael Avalos695f6062015-07-22 18:09:13 -06001157static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001158{
Azael Avalos695f6062015-07-22 18:09:13 -06001159 u32 hci_result = hci_read(dev, HCI_TR_BACKLIGHT, status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001160
Azael Avalos1864bbc2014-09-29 20:40:08 -06001161 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001162}
1163
Azael Avalos695f6062015-07-22 18:09:13 -06001164static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001165{
Azael Avalos695f6062015-07-22 18:09:13 -06001166 u32 hci_result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001167
Azael Avalos1864bbc2014-09-29 20:40:08 -06001168 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001169}
1170
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001171static struct proc_dir_entry *toshiba_proc_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001173/* LCD Brightness */
Seth Forshee62cce752012-04-19 11:23:50 -05001174static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175{
1176 u32 hci_result;
1177 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001178 int brightness = 0;
1179
1180 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001181 int ret = get_tr_backlight_status(dev, &value);
Azael Avalosb5163992015-02-10 23:43:56 -07001182
Akio Idehara121b7b02012-04-06 01:46:43 +09001183 if (ret)
1184 return ret;
Azael Avalos695f6062015-07-22 18:09:13 -06001185 if (value)
Akio Idehara121b7b02012-04-06 01:46:43 +09001186 return 0;
1187 brightness++;
1188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Azael Avalosd37782b2015-05-06 09:35:10 -06001190 hci_result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001191 if (hci_result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +09001192 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001193
1194 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001195}
1196
Seth Forshee62cce752012-04-19 11:23:50 -05001197static int get_lcd_brightness(struct backlight_device *bd)
1198{
1199 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001200
Seth Forshee62cce752012-04-19 11:23:50 -05001201 return __get_lcd_brightness(dev);
1202}
1203
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001204static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -07001205{
Seth Forshee135740d2011-09-20 16:55:49 -05001206 struct toshiba_acpi_dev *dev = m->private;
1207 int value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001208 int levels;
Holger Machtc9263552006-10-20 14:30:29 -07001209
Seth Forshee135740d2011-09-20 16:55:49 -05001210 if (!dev->backlight_dev)
1211 return -ENODEV;
1212
Akio Idehara121b7b02012-04-06 01:46:43 +09001213 levels = dev->backlight_dev->props.max_brightness + 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001214 value = get_lcd_brightness(dev->backlight_dev);
Holger Machtc9263552006-10-20 14:30:29 -07001215 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001216 seq_printf(m, "brightness: %d\n", value);
Akio Idehara121b7b02012-04-06 01:46:43 +09001217 seq_printf(m, "brightness_levels: %d\n", levels);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001218 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 }
1220
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001221 pr_err("Error reading LCD brightness\n");
1222 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001223}
1224
1225static int lcd_proc_open(struct inode *inode, struct file *file)
1226{
Al Virod9dda782013-03-31 18:16:14 -04001227 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
Seth Forshee62cce752012-04-19 11:23:50 -05001230static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -07001231{
Azael Avalosa39f46d2014-11-24 19:29:36 -07001232 u32 hci_result;
Holger Machtc9263552006-10-20 14:30:29 -07001233
Akio Idehara121b7b02012-04-06 01:46:43 +09001234 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001235 int ret = set_tr_backlight_status(dev, !value);
Azael Avalosb5163992015-02-10 23:43:56 -07001236
Akio Idehara121b7b02012-04-06 01:46:43 +09001237 if (ret)
1238 return ret;
1239 if (value)
1240 value--;
1241 }
1242
Azael Avalosa39f46d2014-11-24 19:29:36 -07001243 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
Azael Avalosd37782b2015-05-06 09:35:10 -06001244 hci_result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
Azael Avalosa39f46d2014-11-24 19:29:36 -07001245 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001246}
1247
1248static int set_lcd_status(struct backlight_device *bd)
1249{
Seth Forshee135740d2011-09-20 16:55:49 -05001250 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001251
Seth Forshee62cce752012-04-19 11:23:50 -05001252 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -07001253}
1254
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001255static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1256 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Al Virod9dda782013-03-31 18:16:14 -04001258 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001259 char cmd[42];
1260 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -08001262 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +09001263 int levels = dev->backlight_dev->props.max_brightness + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001265 len = min(count, sizeof(cmd) - 1);
1266 if (copy_from_user(cmd, buf, len))
1267 return -EFAULT;
1268 cmd[len] = '\0';
1269
1270 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Akio Idehara121b7b02012-04-06 01:46:43 +09001271 value >= 0 && value < levels) {
Seth Forshee62cce752012-04-19 11:23:50 -05001272 ret = set_lcd_brightness(dev, value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -08001273 if (ret == 0)
1274 ret = count;
1275 } else {
Holger Machtc9263552006-10-20 14:30:29 -07001276 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -08001277 }
Holger Machtc9263552006-10-20 14:30:29 -07001278 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279}
1280
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001281static const struct file_operations lcd_proc_fops = {
1282 .owner = THIS_MODULE,
1283 .open = lcd_proc_open,
1284 .read = seq_read,
1285 .llseek = seq_lseek,
1286 .release = single_release,
1287 .write = lcd_proc_write,
1288};
1289
Seth Forshee36d03f92011-09-20 16:55:53 -05001290static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1291{
1292 u32 hci_result;
1293
Azael Avalosd37782b2015-05-06 09:35:10 -06001294 hci_result = hci_read(dev, HCI_VIDEO_OUT, status);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001295 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001296}
1297
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001298static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
Seth Forshee135740d2011-09-20 16:55:49 -05001300 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 u32 value;
Seth Forshee36d03f92011-09-20 16:55:53 -05001302 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Seth Forshee36d03f92011-09-20 16:55:53 -05001304 ret = get_video_status(dev, &value);
1305 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1307 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001308 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001309
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001310 seq_printf(m, "lcd_out: %d\n", is_lcd);
1311 seq_printf(m, "crt_out: %d\n", is_crt);
1312 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 }
1314
Seth Forshee36d03f92011-09-20 16:55:53 -05001315 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316}
1317
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001318static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
Al Virod9dda782013-03-31 18:16:14 -04001320 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001321}
1322
1323static ssize_t video_proc_write(struct file *file, const char __user *buf,
1324 size_t count, loff_t *pos)
1325{
Al Virod9dda782013-03-31 18:16:14 -04001326 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001327 char *cmd, *buffer;
Seth Forshee36d03f92011-09-20 16:55:53 -05001328 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 int value;
1330 int remain = count;
1331 int lcd_out = -1;
1332 int crt_out = -1;
1333 int tv_out = -1;
Al Virob4482a42007-10-14 19:35:40 +01001334 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001336 cmd = kmalloc(count + 1, GFP_KERNEL);
1337 if (!cmd)
1338 return -ENOMEM;
1339 if (copy_from_user(cmd, buf, count)) {
1340 kfree(cmd);
1341 return -EFAULT;
1342 }
1343 cmd[count] = '\0';
1344
1345 buffer = cmd;
1346
Darren Harte0769fe2015-02-11 20:50:08 -08001347 /*
1348 * Scan expression. Multiple expressions may be delimited with ;
1349 * NOTE: To keep scanning simple, invalid fields are ignored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 */
1351 while (remain) {
1352 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1353 lcd_out = value & 1;
1354 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1355 crt_out = value & 1;
1356 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1357 tv_out = value & 1;
Darren Harte0769fe2015-02-11 20:50:08 -08001358 /* Advance to one character past the next ; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 do {
1360 ++buffer;
1361 --remain;
Azael Avalosb5163992015-02-10 23:43:56 -07001362 } while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 }
1364
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001365 kfree(cmd);
1366
Seth Forshee36d03f92011-09-20 16:55:53 -05001367 ret = get_video_status(dev, &video_out);
1368 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001369 unsigned int new_video_out = video_out;
Azael Avalosb5163992015-02-10 23:43:56 -07001370
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 if (lcd_out != -1)
1372 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1373 if (crt_out != -1)
1374 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1375 if (tv_out != -1)
1376 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
Darren Harte0769fe2015-02-11 20:50:08 -08001377 /*
1378 * To avoid unnecessary video disruption, only write the new
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001379 * video setting if something changed.
1380 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001382 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 }
1384
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001385 return ret ? ret : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386}
1387
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001388static const struct file_operations video_proc_fops = {
1389 .owner = THIS_MODULE,
1390 .open = video_proc_open,
1391 .read = seq_read,
1392 .llseek = seq_lseek,
1393 .release = single_release,
1394 .write = video_proc_write,
1395};
1396
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001397/* Fan status */
Seth Forshee36d03f92011-09-20 16:55:53 -05001398static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1399{
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001400 u32 result = hci_read(dev, HCI_FAN, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001401
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001402 if (result == TOS_FAILURE)
1403 pr_err("ACPI call to get Fan status failed\n");
1404 else if (result == TOS_NOT_SUPPORTED)
1405 return -ENODEV;
1406 else if (result == TOS_SUCCESS)
1407 return 0;
1408
1409 return -EIO;
1410}
1411
1412static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
1413{
1414 u32 result = hci_write(dev, HCI_FAN, status);
1415
1416 if (result == TOS_FAILURE)
1417 pr_err("ACPI call to set Fan status failed\n");
1418 else if (result == TOS_NOT_SUPPORTED)
1419 return -ENODEV;
1420 else if (result == TOS_SUCCESS)
1421 return 0;
1422
1423 return -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001424}
1425
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001426static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Seth Forshee135740d2011-09-20 16:55:49 -05001428 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 u32 value;
1430
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001431 if (get_fan_status(dev, &value))
1432 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001434 seq_printf(m, "running: %d\n", (value > 0));
1435 seq_printf(m, "force_on: %d\n", dev->force_fan);
1436
1437 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438}
1439
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001440static int fan_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, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001443}
1444
1445static ssize_t fan_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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
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 Avalos3e07e5b2015-07-27 19:22:23 -06001458 if (sscanf(cmd, " force_on : %i", &value) != 1 &&
1459 value != 0 && value != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 return -EINVAL;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001461
1462 if (set_fan_status(dev, value))
1463 return -EIO;
1464
1465 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
1467 return count;
1468}
1469
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001470static const struct file_operations fan_proc_fops = {
1471 .owner = THIS_MODULE,
1472 .open = fan_proc_open,
1473 .read = seq_read,
1474 .llseek = seq_lseek,
1475 .release = single_release,
1476 .write = fan_proc_write,
1477};
1478
1479static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480{
Seth Forshee135740d2011-09-20 16:55:49 -05001481 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Seth Forshee135740d2011-09-20 16:55:49 -05001483 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1484 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Azael Avalos7deef552015-07-22 18:09:10 -06001485
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001486 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487}
1488
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001489static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490{
Al Virod9dda782013-03-31 18:16:14 -04001491 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001492}
1493
1494static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1495 size_t count, loff_t *pos)
1496{
Al Virod9dda782013-03-31 18:16:14 -04001497 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001498 char cmd[42];
1499 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 int value;
1501
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001502 len = min(count, sizeof(cmd) - 1);
1503 if (copy_from_user(cmd, buf, len))
1504 return -EFAULT;
1505 cmd[len] = '\0';
1506
Azael Avalosb5163992015-02-10 23:43:56 -07001507 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
Seth Forshee135740d2011-09-20 16:55:49 -05001508 dev->key_event_valid = 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001509 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 return count;
1513}
1514
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001515static const struct file_operations keys_proc_fops = {
1516 .owner = THIS_MODULE,
1517 .open = keys_proc_open,
1518 .read = seq_read,
1519 .llseek = seq_lseek,
1520 .release = single_release,
1521 .write = keys_proc_write,
1522};
1523
1524static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001526 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1527 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1528 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529}
1530
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001531static int version_proc_open(struct inode *inode, struct file *file)
1532{
Al Virod9dda782013-03-31 18:16:14 -04001533 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001534}
1535
1536static const struct file_operations version_proc_fops = {
1537 .owner = THIS_MODULE,
1538 .open = version_proc_open,
1539 .read = seq_read,
1540 .llseek = seq_lseek,
1541 .release = single_release,
1542};
1543
Darren Harte0769fe2015-02-11 20:50:08 -08001544/*
1545 * Proc and module init
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 */
1547
1548#define PROC_TOSHIBA "toshiba"
1549
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001550static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Seth Forshee36d03f92011-09-20 16:55:53 -05001552 if (dev->backlight_dev)
1553 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1554 &lcd_proc_fops, dev);
1555 if (dev->video_supported)
1556 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1557 &video_proc_fops, dev);
1558 if (dev->fan_supported)
1559 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1560 &fan_proc_fops, dev);
1561 if (dev->hotkey_dev)
1562 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1563 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001564 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1565 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566}
1567
Seth Forshee36d03f92011-09-20 16:55:53 -05001568static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569{
Seth Forshee36d03f92011-09-20 16:55:53 -05001570 if (dev->backlight_dev)
1571 remove_proc_entry("lcd", toshiba_proc_dir);
1572 if (dev->video_supported)
1573 remove_proc_entry("video", toshiba_proc_dir);
1574 if (dev->fan_supported)
1575 remove_proc_entry("fan", toshiba_proc_dir);
1576 if (dev->hotkey_dev)
1577 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001578 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579}
1580
Lionel Debrouxacc24722010-11-16 14:14:02 +01001581static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001582 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001583 .get_brightness = get_lcd_brightness,
1584 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001585};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001586
Azael Avalos360f0f32014-03-25 20:38:31 -06001587/*
1588 * Sysfs files
1589 */
Azael Avalos9d309842015-02-10 23:43:59 -07001590static ssize_t version_show(struct device *dev,
1591 struct device_attribute *attr, char *buf)
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001592{
1593 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1594}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001595static DEVICE_ATTR_RO(version);
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001596
Azael Avalos9d309842015-02-10 23:43:59 -07001597static ssize_t fan_store(struct device *dev,
1598 struct device_attribute *attr,
1599 const char *buf, size_t count)
Azael Avalos94477d42015-02-10 21:09:17 -07001600{
1601 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avalos94477d42015-02-10 21:09:17 -07001602 int state;
1603 int ret;
1604
1605 ret = kstrtoint(buf, 0, &state);
1606 if (ret)
1607 return ret;
1608
1609 if (state != 0 && state != 1)
1610 return -EINVAL;
1611
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001612 ret = set_fan_status(toshiba, state);
1613 if (ret)
1614 return ret;
Azael Avalos94477d42015-02-10 21:09:17 -07001615
1616 return count;
1617}
1618
Azael Avalos9d309842015-02-10 23:43:59 -07001619static ssize_t fan_show(struct device *dev,
1620 struct device_attribute *attr, char *buf)
Azael Avalos94477d42015-02-10 21:09:17 -07001621{
1622 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1623 u32 value;
1624 int ret;
1625
1626 ret = get_fan_status(toshiba, &value);
1627 if (ret)
1628 return ret;
1629
1630 return sprintf(buf, "%d\n", value);
1631}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001632static DEVICE_ATTR_RW(fan);
Azael Avalos94477d42015-02-10 21:09:17 -07001633
Azael Avalos9d309842015-02-10 23:43:59 -07001634static ssize_t kbd_backlight_mode_store(struct device *dev,
1635 struct device_attribute *attr,
1636 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001637{
1638 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001639 int mode;
Dan Carpenteraeaac092014-09-03 14:44:37 +03001640 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001641
Dan Carpenteraeaac092014-09-03 14:44:37 +03001642
1643 ret = kstrtoint(buf, 0, &mode);
1644 if (ret)
1645 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001646
1647 /* Check for supported modes depending on keyboard backlight type */
1648 if (toshiba->kbd_type == 1) {
1649 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1650 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1651 return -EINVAL;
1652 } else if (toshiba->kbd_type == 2) {
1653 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1654 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1655 mode != SCI_KBD_MODE_OFF)
1656 return -EINVAL;
1657 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001658
Darren Harte0769fe2015-02-11 20:50:08 -08001659 /*
1660 * Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001661 * Auto - KBD backlight turns off automatically in given time
1662 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001663 * ON - KBD backlight is always on
1664 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001665 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001666
1667 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001668 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001669 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos1e574db2015-07-22 19:37:49 -06001670 int time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001671
1672 /* OR the "base time" to the actual method format */
1673 if (toshiba->kbd_type == 1) {
1674 /* Type 1 requires the current mode */
1675 time |= toshiba->kbd_mode;
1676 } else if (toshiba->kbd_type == 2) {
1677 /* Type 2 requires the desired mode */
1678 time |= mode;
1679 }
1680
Dan Carpenteraeaac092014-09-03 14:44:37 +03001681 ret = toshiba_kbd_illum_status_set(toshiba, time);
1682 if (ret)
1683 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001684
Azael Avalos360f0f32014-03-25 20:38:31 -06001685 toshiba->kbd_mode = mode;
1686 }
1687
1688 return count;
1689}
1690
Azael Avalos9d309842015-02-10 23:43:59 -07001691static ssize_t kbd_backlight_mode_show(struct device *dev,
1692 struct device_attribute *attr,
1693 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001694{
1695 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1696 u32 time;
1697
1698 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1699 return -EIO;
1700
Azael Avalos93f8c162014-09-12 18:50:36 -06001701 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1702}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001703static DEVICE_ATTR_RW(kbd_backlight_mode);
Azael Avalos93f8c162014-09-12 18:50:36 -06001704
Azael Avalos9d309842015-02-10 23:43:59 -07001705static ssize_t kbd_type_show(struct device *dev,
1706 struct device_attribute *attr, char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001707{
1708 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1709
1710 return sprintf(buf, "%d\n", toshiba->kbd_type);
1711}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001712static DEVICE_ATTR_RO(kbd_type);
Azael Avalos93f8c162014-09-12 18:50:36 -06001713
Azael Avalos9d309842015-02-10 23:43:59 -07001714static ssize_t available_kbd_modes_show(struct device *dev,
1715 struct device_attribute *attr,
1716 char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001717{
1718 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1719
1720 if (toshiba->kbd_type == 1)
1721 return sprintf(buf, "%x %x\n",
1722 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1723
1724 return sprintf(buf, "%x %x %x\n",
1725 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001726}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001727static DEVICE_ATTR_RO(available_kbd_modes);
Azael Avalos360f0f32014-03-25 20:38:31 -06001728
Azael Avalos9d309842015-02-10 23:43:59 -07001729static ssize_t kbd_backlight_timeout_store(struct device *dev,
1730 struct device_attribute *attr,
1731 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001732{
1733 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001734 int time;
1735 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001736
Azael Avaloseabde0f2014-10-04 12:02:21 -06001737 ret = kstrtoint(buf, 0, &time);
1738 if (ret)
1739 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001740
Azael Avaloseabde0f2014-10-04 12:02:21 -06001741 /* Check for supported values depending on kbd_type */
1742 if (toshiba->kbd_type == 1) {
1743 if (time < 0 || time > 60)
1744 return -EINVAL;
1745 } else if (toshiba->kbd_type == 2) {
1746 if (time < 1 || time > 60)
1747 return -EINVAL;
1748 }
1749
1750 /* Set the Keyboard Backlight Timeout */
1751
1752 /* Only make a change if the actual timeout has changed */
1753 if (toshiba->kbd_time != time) {
1754 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001755 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001756 /* OR the "base time" to the actual method format */
1757 if (toshiba->kbd_type == 1)
1758 time |= SCI_KBD_MODE_FNZ;
1759 else if (toshiba->kbd_type == 2)
1760 time |= SCI_KBD_MODE_AUTO;
1761
1762 ret = toshiba_kbd_illum_status_set(toshiba, time);
1763 if (ret)
1764 return ret;
1765
Azael Avalos360f0f32014-03-25 20:38:31 -06001766 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1767 }
1768
1769 return count;
1770}
1771
Azael Avalos9d309842015-02-10 23:43:59 -07001772static ssize_t kbd_backlight_timeout_show(struct device *dev,
1773 struct device_attribute *attr,
1774 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001775{
1776 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1777 u32 time;
1778
1779 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1780 return -EIO;
1781
1782 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1783}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001784static DEVICE_ATTR_RW(kbd_backlight_timeout);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001785
Azael Avalos9d309842015-02-10 23:43:59 -07001786static ssize_t touchpad_store(struct device *dev,
1787 struct device_attribute *attr,
1788 const char *buf, size_t count)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001789{
1790 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1791 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001792 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001793
1794 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001795 ret = kstrtoint(buf, 0, &state);
1796 if (ret)
1797 return ret;
1798 if (state != 0 && state != 1)
1799 return -EINVAL;
1800
1801 ret = toshiba_touchpad_set(toshiba, state);
1802 if (ret)
1803 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001804
1805 return count;
1806}
1807
Azael Avalos9d309842015-02-10 23:43:59 -07001808static ssize_t touchpad_show(struct device *dev,
1809 struct device_attribute *attr, char *buf)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001810{
1811 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1812 u32 state;
1813 int ret;
1814
1815 ret = toshiba_touchpad_get(toshiba, &state);
1816 if (ret < 0)
1817 return ret;
1818
1819 return sprintf(buf, "%i\n", state);
1820}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001821static DEVICE_ATTR_RW(touchpad);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001822
Azael Avalos9d309842015-02-10 23:43:59 -07001823static ssize_t position_show(struct device *dev,
1824 struct device_attribute *attr, char *buf)
Azael Avalos5a2813e2014-03-25 20:38:34 -06001825{
1826 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1827 u32 xyval, zval, tmp;
1828 u16 x, y, z;
1829 int ret;
1830
1831 xyval = zval = 0;
1832 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1833 if (ret < 0)
1834 return ret;
1835
1836 x = xyval & HCI_ACCEL_MASK;
1837 tmp = xyval >> HCI_MISC_SHIFT;
1838 y = tmp & HCI_ACCEL_MASK;
1839 z = zval & HCI_ACCEL_MASK;
1840
1841 return sprintf(buf, "%d %d %d\n", x, y, z);
1842}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001843static DEVICE_ATTR_RO(position);
Azael Avalos360f0f32014-03-25 20:38:31 -06001844
Azael Avalos9d309842015-02-10 23:43:59 -07001845static ssize_t usb_sleep_charge_show(struct device *dev,
1846 struct device_attribute *attr, char *buf)
Azael Avalose26ffe52015-01-18 18:30:22 -07001847{
1848 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1849 u32 mode;
1850 int ret;
1851
1852 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1853 if (ret < 0)
1854 return ret;
1855
1856 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1857}
1858
Azael Avalos9d309842015-02-10 23:43:59 -07001859static ssize_t usb_sleep_charge_store(struct device *dev,
1860 struct device_attribute *attr,
1861 const char *buf, size_t count)
Azael Avalose26ffe52015-01-18 18:30:22 -07001862{
1863 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1864 u32 mode;
1865 int state;
1866 int ret;
1867
1868 ret = kstrtoint(buf, 0, &state);
1869 if (ret)
1870 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08001871 /*
1872 * Check for supported values, where:
Azael Avalose26ffe52015-01-18 18:30:22 -07001873 * 0 - Disabled
1874 * 1 - Alternate (Non USB conformant devices that require more power)
1875 * 2 - Auto (USB conformant devices)
Azael Avalosc8c91842015-04-02 19:26:20 -06001876 * 3 - Typical
Azael Avalose26ffe52015-01-18 18:30:22 -07001877 */
Azael Avalosc8c91842015-04-02 19:26:20 -06001878 if (state != 0 && state != 1 && state != 2 && state != 3)
Azael Avalose26ffe52015-01-18 18:30:22 -07001879 return -EINVAL;
1880
1881 /* Set the USB charging mode to internal value */
Azael Avalosc8c91842015-04-02 19:26:20 -06001882 mode = toshiba->usbsc_mode_base;
Azael Avalose26ffe52015-01-18 18:30:22 -07001883 if (state == 0)
Azael Avalosc8c91842015-04-02 19:26:20 -06001884 mode |= SCI_USB_CHARGE_DISABLED;
Azael Avalose26ffe52015-01-18 18:30:22 -07001885 else if (state == 1)
Azael Avalosc8c91842015-04-02 19:26:20 -06001886 mode |= SCI_USB_CHARGE_ALTERNATE;
Azael Avalose26ffe52015-01-18 18:30:22 -07001887 else if (state == 2)
Azael Avalosc8c91842015-04-02 19:26:20 -06001888 mode |= SCI_USB_CHARGE_AUTO;
1889 else if (state == 3)
1890 mode |= SCI_USB_CHARGE_TYPICAL;
Azael Avalose26ffe52015-01-18 18:30:22 -07001891
1892 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
1893 if (ret)
1894 return ret;
1895
1896 return count;
1897}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001898static DEVICE_ATTR_RW(usb_sleep_charge);
Azael Avalose26ffe52015-01-18 18:30:22 -07001899
Azael Avalos182bcaa2015-01-18 18:30:23 -07001900static ssize_t sleep_functions_on_battery_show(struct device *dev,
1901 struct device_attribute *attr,
1902 char *buf)
1903{
1904 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1905 u32 state;
1906 int bat_lvl;
1907 int status;
1908 int ret;
1909 int tmp;
1910
1911 ret = toshiba_sleep_functions_status_get(toshiba, &state);
1912 if (ret < 0)
1913 return ret;
1914
1915 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1916 tmp = state & SCI_USB_CHARGE_BAT_MASK;
1917 status = (tmp == 0x4) ? 1 : 0;
1918 /* Determine the battery level set */
1919 bat_lvl = state >> HCI_MISC_SHIFT;
1920
1921 return sprintf(buf, "%d %d\n", status, bat_lvl);
1922}
1923
1924static ssize_t sleep_functions_on_battery_store(struct device *dev,
1925 struct device_attribute *attr,
1926 const char *buf, size_t count)
1927{
1928 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1929 u32 status;
1930 int value;
1931 int ret;
1932 int tmp;
1933
1934 ret = kstrtoint(buf, 0, &value);
1935 if (ret)
1936 return ret;
1937
Darren Harte0769fe2015-02-11 20:50:08 -08001938 /*
1939 * Set the status of the function:
Azael Avalos182bcaa2015-01-18 18:30:23 -07001940 * 0 - Disabled
1941 * 1-100 - Enabled
1942 */
1943 if (value < 0 || value > 100)
1944 return -EINVAL;
1945
1946 if (value == 0) {
1947 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
1948 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
1949 } else {
1950 tmp = value << HCI_MISC_SHIFT;
1951 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
1952 }
1953 ret = toshiba_sleep_functions_status_set(toshiba, status);
1954 if (ret < 0)
1955 return ret;
1956
1957 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
1958
1959 return count;
1960}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001961static DEVICE_ATTR_RW(sleep_functions_on_battery);
Azael Avalos182bcaa2015-01-18 18:30:23 -07001962
Azael Avalos9d309842015-02-10 23:43:59 -07001963static ssize_t usb_rapid_charge_show(struct device *dev,
1964 struct device_attribute *attr, char *buf)
Azael Avalosbb3fe012015-01-18 18:30:24 -07001965{
1966 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1967 u32 state;
1968 int ret;
1969
1970 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
1971 if (ret < 0)
1972 return ret;
1973
1974 return sprintf(buf, "%d\n", state);
1975}
1976
Azael Avalos9d309842015-02-10 23:43:59 -07001977static ssize_t usb_rapid_charge_store(struct device *dev,
1978 struct device_attribute *attr,
1979 const char *buf, size_t count)
Azael Avalosbb3fe012015-01-18 18:30:24 -07001980{
1981 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1982 int state;
1983 int ret;
1984
1985 ret = kstrtoint(buf, 0, &state);
1986 if (ret)
1987 return ret;
1988 if (state != 0 && state != 1)
1989 return -EINVAL;
1990
1991 ret = toshiba_usb_rapid_charge_set(toshiba, state);
1992 if (ret)
1993 return ret;
1994
1995 return count;
1996}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001997static DEVICE_ATTR_RW(usb_rapid_charge);
Azael Avalosbb3fe012015-01-18 18:30:24 -07001998
Azael Avalos9d309842015-02-10 23:43:59 -07001999static ssize_t usb_sleep_music_show(struct device *dev,
2000 struct device_attribute *attr, char *buf)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002001{
2002 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2003 u32 state;
2004 int ret;
2005
2006 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2007 if (ret < 0)
2008 return ret;
2009
2010 return sprintf(buf, "%d\n", state);
2011}
2012
Azael Avalos9d309842015-02-10 23:43:59 -07002013static ssize_t usb_sleep_music_store(struct device *dev,
2014 struct device_attribute *attr,
2015 const char *buf, size_t count)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002016{
2017 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2018 int state;
2019 int ret;
2020
2021 ret = kstrtoint(buf, 0, &state);
2022 if (ret)
2023 return ret;
2024 if (state != 0 && state != 1)
2025 return -EINVAL;
2026
2027 ret = toshiba_usb_sleep_music_set(toshiba, state);
2028 if (ret)
2029 return ret;
2030
2031 return count;
2032}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002033static DEVICE_ATTR_RW(usb_sleep_music);
Azael Avalos172ce0a2015-01-18 18:30:25 -07002034
Azael Avalos9d309842015-02-10 23:43:59 -07002035static ssize_t kbd_function_keys_show(struct device *dev,
2036 struct device_attribute *attr, char *buf)
Azael Avalosbae84192015-02-10 21:09:18 -07002037{
2038 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2039 int mode;
2040 int ret;
2041
2042 ret = toshiba_function_keys_get(toshiba, &mode);
2043 if (ret < 0)
2044 return ret;
2045
2046 return sprintf(buf, "%d\n", mode);
2047}
2048
Azael Avalos9d309842015-02-10 23:43:59 -07002049static ssize_t kbd_function_keys_store(struct device *dev,
2050 struct device_attribute *attr,
2051 const char *buf, size_t count)
Azael Avalosbae84192015-02-10 21:09:18 -07002052{
2053 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2054 int mode;
2055 int ret;
2056
2057 ret = kstrtoint(buf, 0, &mode);
2058 if (ret)
2059 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002060 /*
2061 * Check for the function keys mode where:
Azael Avalosbae84192015-02-10 21:09:18 -07002062 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2063 * 1 - Special functions (Opposite of the above setting)
2064 */
2065 if (mode != 0 && mode != 1)
2066 return -EINVAL;
2067
2068 ret = toshiba_function_keys_set(toshiba, mode);
2069 if (ret)
2070 return ret;
2071
2072 pr_info("Reboot for changes to KBD Function Keys to take effect");
2073
2074 return count;
2075}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002076static DEVICE_ATTR_RW(kbd_function_keys);
Azael Avalosbae84192015-02-10 21:09:18 -07002077
Azael Avalos9d309842015-02-10 23:43:59 -07002078static ssize_t panel_power_on_show(struct device *dev,
2079 struct device_attribute *attr, char *buf)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002080{
2081 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2082 u32 state;
2083 int ret;
2084
2085 ret = toshiba_panel_power_on_get(toshiba, &state);
2086 if (ret < 0)
2087 return ret;
2088
2089 return sprintf(buf, "%d\n", state);
2090}
2091
Azael Avalos9d309842015-02-10 23:43:59 -07002092static ssize_t panel_power_on_store(struct device *dev,
2093 struct device_attribute *attr,
2094 const char *buf, size_t count)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002095{
2096 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2097 int state;
2098 int ret;
2099
2100 ret = kstrtoint(buf, 0, &state);
2101 if (ret)
2102 return ret;
2103 if (state != 0 && state != 1)
2104 return -EINVAL;
2105
2106 ret = toshiba_panel_power_on_set(toshiba, state);
2107 if (ret)
2108 return ret;
2109
2110 pr_info("Reboot for changes to Panel Power ON to take effect");
2111
2112 return count;
2113}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002114static DEVICE_ATTR_RW(panel_power_on);
Azael Avalos35d53ce2015-02-10 21:09:19 -07002115
Azael Avalos9d309842015-02-10 23:43:59 -07002116static ssize_t usb_three_show(struct device *dev,
2117 struct device_attribute *attr, char *buf)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002118{
2119 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2120 u32 state;
2121 int ret;
2122
2123 ret = toshiba_usb_three_get(toshiba, &state);
2124 if (ret < 0)
2125 return ret;
2126
2127 return sprintf(buf, "%d\n", state);
2128}
2129
Azael Avalos9d309842015-02-10 23:43:59 -07002130static ssize_t usb_three_store(struct device *dev,
2131 struct device_attribute *attr,
2132 const char *buf, size_t count)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002133{
2134 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2135 int state;
2136 int ret;
2137
2138 ret = kstrtoint(buf, 0, &state);
2139 if (ret)
2140 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002141 /*
2142 * Check for USB 3 mode where:
Azael Avalos17fe4b32015-02-10 21:09:20 -07002143 * 0 - Disabled (Acts like a USB 2 port, saving power)
2144 * 1 - Enabled
2145 */
2146 if (state != 0 && state != 1)
2147 return -EINVAL;
2148
2149 ret = toshiba_usb_three_set(toshiba, state);
2150 if (ret)
2151 return ret;
2152
2153 pr_info("Reboot for changes to USB 3 to take effect");
2154
2155 return count;
2156}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002157static DEVICE_ATTR_RW(usb_three);
Azael Avalos9bd12132015-02-10 23:43:58 -07002158
2159static struct attribute *toshiba_attributes[] = {
2160 &dev_attr_version.attr,
2161 &dev_attr_fan.attr,
2162 &dev_attr_kbd_backlight_mode.attr,
2163 &dev_attr_kbd_type.attr,
2164 &dev_attr_available_kbd_modes.attr,
2165 &dev_attr_kbd_backlight_timeout.attr,
2166 &dev_attr_touchpad.attr,
2167 &dev_attr_position.attr,
2168 &dev_attr_usb_sleep_charge.attr,
2169 &dev_attr_sleep_functions_on_battery.attr,
2170 &dev_attr_usb_rapid_charge.attr,
2171 &dev_attr_usb_sleep_music.attr,
2172 &dev_attr_kbd_function_keys.attr,
2173 &dev_attr_panel_power_on.attr,
2174 &dev_attr_usb_three.attr,
2175 NULL,
2176};
2177
Azael Avalos360f0f32014-03-25 20:38:31 -06002178static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2179 struct attribute *attr, int idx)
2180{
2181 struct device *dev = container_of(kobj, struct device, kobj);
2182 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2183 bool exists = true;
2184
Azael Avalos94477d42015-02-10 21:09:17 -07002185 if (attr == &dev_attr_fan.attr)
2186 exists = (drv->fan_supported) ? true : false;
2187 else if (attr == &dev_attr_kbd_backlight_mode.attr)
Azael Avalos360f0f32014-03-25 20:38:31 -06002188 exists = (drv->kbd_illum_supported) ? true : false;
2189 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2190 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06002191 else if (attr == &dev_attr_touchpad.attr)
2192 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06002193 else if (attr == &dev_attr_position.attr)
2194 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalose26ffe52015-01-18 18:30:22 -07002195 else if (attr == &dev_attr_usb_sleep_charge.attr)
2196 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002197 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2198 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalosbb3fe012015-01-18 18:30:24 -07002199 else if (attr == &dev_attr_usb_rapid_charge.attr)
2200 exists = (drv->usb_rapid_charge_supported) ? true : false;
Azael Avalos172ce0a2015-01-18 18:30:25 -07002201 else if (attr == &dev_attr_usb_sleep_music.attr)
2202 exists = (drv->usb_sleep_music_supported) ? true : false;
Azael Avalosbae84192015-02-10 21:09:18 -07002203 else if (attr == &dev_attr_kbd_function_keys.attr)
2204 exists = (drv->kbd_function_keys_supported) ? true : false;
Azael Avalos35d53ce2015-02-10 21:09:19 -07002205 else if (attr == &dev_attr_panel_power_on.attr)
2206 exists = (drv->panel_power_on_supported) ? true : false;
Azael Avalos17fe4b32015-02-10 21:09:20 -07002207 else if (attr == &dev_attr_usb_three.attr)
2208 exists = (drv->usb_three_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06002209
2210 return exists ? attr->mode : 0;
2211}
2212
Azael Avalos9bd12132015-02-10 23:43:58 -07002213static struct attribute_group toshiba_attr_group = {
2214 .is_visible = toshiba_sysfs_is_visible,
2215 .attrs = toshiba_attributes,
2216};
2217
Azael Avalos1f28f292014-12-04 20:22:45 -07002218/*
Azael Avalosfc5462f2015-07-22 18:09:11 -06002219 * Misc device
2220 */
2221static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
2222{
2223 u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
2224 regs->edx, regs->esi, regs->edi };
2225 u32 out[TCI_WORDS];
2226 acpi_status status;
2227
2228 status = tci_raw(toshiba_acpi, in, out);
2229 if (ACPI_FAILURE(status)) {
2230 pr_err("ACPI call to query SMM registers failed\n");
2231 return -EIO;
2232 }
2233
2234 /* Fillout the SMM struct with the TCI call results */
2235 regs->eax = out[0];
2236 regs->ebx = out[1];
2237 regs->ecx = out[2];
2238 regs->edx = out[3];
2239 regs->esi = out[4];
2240 regs->edi = out[5];
2241
2242 return 0;
2243}
2244
2245static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
2246 unsigned long arg)
2247{
2248 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
2249 SMMRegisters regs;
2250 int ret;
2251
2252 if (!argp)
2253 return -EINVAL;
2254
2255 switch (cmd) {
2256 case TOSH_SMM:
2257 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2258 return -EFAULT;
2259 ret = toshiba_acpi_smm_bridge(&regs);
2260 if (ret)
2261 return ret;
2262 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2263 return -EFAULT;
2264 break;
2265 case TOSHIBA_ACPI_SCI:
2266 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2267 return -EFAULT;
2268 /* Ensure we are being called with a SCI_{GET, SET} register */
2269 if (regs.eax != SCI_GET && regs.eax != SCI_SET)
2270 return -EINVAL;
2271 if (!sci_open(toshiba_acpi))
2272 return -EIO;
2273 ret = toshiba_acpi_smm_bridge(&regs);
2274 sci_close(toshiba_acpi);
2275 if (ret)
2276 return ret;
2277 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2278 return -EFAULT;
2279 break;
2280 default:
2281 return -EINVAL;
2282 }
2283
2284 return 0;
2285}
2286
2287static const struct file_operations toshiba_acpi_fops = {
2288 .owner = THIS_MODULE,
2289 .unlocked_ioctl = toshiba_acpi_ioctl,
2290 .llseek = noop_llseek,
2291};
2292
2293/*
Azael Avalos1f28f292014-12-04 20:22:45 -07002294 * Hotkeys
2295 */
2296static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2297{
2298 acpi_status status;
2299 u32 result;
2300
2301 status = acpi_evaluate_object(dev->acpi_dev->handle,
2302 "ENAB", NULL, NULL);
2303 if (ACPI_FAILURE(status))
2304 return -ENODEV;
2305
Azael Avalosd37782b2015-05-06 09:35:10 -06002306 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
Azael Avalos1f28f292014-12-04 20:22:45 -07002307 if (result == TOS_FAILURE)
2308 return -EIO;
2309 else if (result == TOS_NOT_SUPPORTED)
2310 return -ENODEV;
2311
2312 return 0;
2313}
2314
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002315static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev)
2316{
2317 u32 result;
2318
2319 /*
2320 * Re-activate the hotkeys, but this time, we are using the
2321 * "Special Functions" mode.
2322 */
Azael Avalosd37782b2015-05-06 09:35:10 -06002323 result = hci_write(dev, HCI_HOTKEY_EVENT,
2324 HCI_HOTKEY_SPECIAL_FUNCTIONS);
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002325 if (result != TOS_SUCCESS)
2326 pr_err("Could not enable the Special Function mode\n");
2327}
2328
Seth Forshee29cd2932012-01-18 13:44:09 -06002329static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2330 struct serio *port)
2331{
Giedrius Statkevičius98280372014-10-18 02:57:20 +03002332 if (str & I8042_STR_AUXDATA)
Seth Forshee29cd2932012-01-18 13:44:09 -06002333 return false;
2334
2335 if (unlikely(data == 0xe0))
2336 return false;
2337
2338 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2339 schedule_work(&toshiba_acpi->hotkey_work);
2340 return true;
2341 }
2342
2343 return false;
2344}
2345
2346static void toshiba_acpi_hotkey_work(struct work_struct *work)
2347{
2348 acpi_handle ec_handle = ec_get_handle();
2349 acpi_status status;
2350
2351 if (!ec_handle)
2352 return;
2353
2354 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2355 if (ACPI_FAILURE(status))
2356 pr_err("ACPI NTFY method execution failed\n");
2357}
2358
2359/*
2360 * Returns hotkey scancode, or < 0 on failure.
2361 */
2362static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2363{
Zhang Rui74facaf2013-09-03 08:32:15 +08002364 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002365 acpi_status status;
2366
Zhang Rui74facaf2013-09-03 08:32:15 +08002367 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2368 NULL, &value);
2369 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002370 pr_err("ACPI INFO method execution failed\n");
2371 return -EIO;
2372 }
2373
Zhang Rui74facaf2013-09-03 08:32:15 +08002374 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002375}
2376
2377static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2378 int scancode)
2379{
2380 if (scancode == 0x100)
2381 return;
2382
Darren Harte0769fe2015-02-11 20:50:08 -08002383 /* Act on key press; ignore key release */
Seth Forshee29cd2932012-01-18 13:44:09 -06002384 if (scancode & 0x80)
2385 return;
2386
2387 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2388 pr_info("Unknown key %x\n", scancode);
2389}
2390
Azael Avalos71454d72014-12-04 20:22:46 -07002391static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2392{
Azael Avalos71454d72014-12-04 20:22:46 -07002393 if (dev->info_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002394 int scancode = toshiba_acpi_query_hotkey(dev);
2395
2396 if (scancode < 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002397 pr_err("Failed to query hotkey event\n");
Azael Avalos7deef552015-07-22 18:09:10 -06002398 } else if (scancode != 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002399 toshiba_acpi_report_hotkey(dev, scancode);
Azael Avalos7deef552015-07-22 18:09:10 -06002400 dev->key_event_valid = 1;
2401 dev->last_key_event = scancode;
2402 }
Azael Avalos71454d72014-12-04 20:22:46 -07002403 } else if (dev->system_event_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002404 u32 result;
2405 u32 value;
2406 int retries = 3;
2407
Azael Avalos71454d72014-12-04 20:22:46 -07002408 do {
Azael Avalos7deef552015-07-22 18:09:10 -06002409 result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2410 switch (result) {
Azael Avalos71454d72014-12-04 20:22:46 -07002411 case TOS_SUCCESS:
2412 toshiba_acpi_report_hotkey(dev, (int)value);
Azael Avalos7deef552015-07-22 18:09:10 -06002413 dev->key_event_valid = 1;
2414 dev->last_key_event = value;
Azael Avalos71454d72014-12-04 20:22:46 -07002415 break;
2416 case TOS_NOT_SUPPORTED:
2417 /*
2418 * This is a workaround for an unresolved
2419 * issue on some machines where system events
2420 * sporadically become disabled.
2421 */
Azael Avalos7deef552015-07-22 18:09:10 -06002422 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2423 if (result == TOS_SUCCESS)
2424 pr_notice("Re-enabled hotkeys\n");
Darren Harte0769fe2015-02-11 20:50:08 -08002425 /* Fall through */
Azael Avalos71454d72014-12-04 20:22:46 -07002426 default:
2427 retries--;
2428 break;
2429 }
Azael Avalos7deef552015-07-22 18:09:10 -06002430 } while (retries && result != TOS_FIFO_EMPTY);
Azael Avalos71454d72014-12-04 20:22:46 -07002431 }
2432}
2433
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002434static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002435{
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002436 const struct key_entry *keymap = toshiba_acpi_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002437 acpi_handle ec_handle;
2438 u32 events_type;
2439 u32 hci_result;
2440 int error;
2441
Azael Avalosa88bc062015-07-22 18:09:12 -06002442 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
2443 pr_info("WMI event detected, hotkeys will not be monitored\n");
2444 return 0;
2445 }
2446
Azael Avalosa2b34712015-03-20 16:55:17 -06002447 error = toshiba_acpi_enable_hotkeys(dev);
2448 if (error)
2449 return error;
2450
2451 error = toshiba_hotkey_event_type_get(dev, &events_type);
2452 if (error) {
2453 pr_err("Unable to query Hotkey Event Type\n");
2454 return error;
2455 }
2456 dev->hotkey_event_type = events_type;
Seth Forshee135740d2011-09-20 16:55:49 -05002457
Seth Forshee135740d2011-09-20 16:55:49 -05002458 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07002459 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002460 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05002461
2462 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05002463 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05002464 dev->hotkey_dev->id.bustype = BUS_HOST;
2465
Azael Avalosa2b34712015-03-20 16:55:17 -06002466 if (events_type == HCI_SYSTEM_TYPE1 ||
2467 !dev->kbd_function_keys_supported)
2468 keymap = toshiba_acpi_keymap;
2469 else if (events_type == HCI_SYSTEM_TYPE2 ||
2470 dev->kbd_function_keys_supported)
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002471 keymap = toshiba_acpi_alt_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002472 else
2473 pr_info("Unknown event type received %x\n", events_type);
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002474 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05002475 if (error)
2476 goto err_free_dev;
2477
Seth Forshee29cd2932012-01-18 13:44:09 -06002478 /*
2479 * For some machines the SCI responsible for providing hotkey
2480 * notification doesn't fire. We can trigger the notification
2481 * whenever the Fn key is pressed using the NTFY method, if
2482 * supported, so if it's present set up an i8042 key filter
2483 * for this purpose.
2484 */
Seth Forshee29cd2932012-01-18 13:44:09 -06002485 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08002486 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002487 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2488
2489 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2490 if (error) {
2491 pr_err("Error installing key filter\n");
2492 goto err_free_keymap;
2493 }
2494
2495 dev->ntfy_supported = 1;
2496 }
2497
2498 /*
2499 * Determine hotkey query interface. Prefer using the INFO
2500 * method when it is available.
2501 */
Zhang Ruie2e19602013-09-03 08:32:06 +08002502 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06002503 dev->info_supported = 1;
Zhang Ruie2e19602013-09-03 08:32:06 +08002504 else {
Azael Avalosd37782b2015-05-06 09:35:10 -06002505 hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
Azael Avalos1864bbc2014-09-29 20:40:08 -06002506 if (hci_result == TOS_SUCCESS)
Seth Forshee29cd2932012-01-18 13:44:09 -06002507 dev->system_event_supported = 1;
2508 }
2509
2510 if (!dev->info_supported && !dev->system_event_supported) {
2511 pr_warn("No hotkey query interface found\n");
2512 goto err_remove_filter;
2513 }
2514
Seth Forshee135740d2011-09-20 16:55:49 -05002515 error = input_register_device(dev->hotkey_dev);
2516 if (error) {
2517 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06002518 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05002519 }
2520
2521 return 0;
2522
Seth Forshee29cd2932012-01-18 13:44:09 -06002523 err_remove_filter:
2524 if (dev->ntfy_supported)
2525 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05002526 err_free_keymap:
2527 sparse_keymap_free(dev->hotkey_dev);
2528 err_free_dev:
2529 input_free_device(dev->hotkey_dev);
2530 dev->hotkey_dev = NULL;
2531 return error;
2532}
2533
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002534static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05002535{
2536 struct backlight_properties props;
2537 int brightness;
2538 int ret;
2539
2540 /*
2541 * Some machines don't support the backlight methods at all, and
2542 * others support it read-only. Either of these is pretty useless,
2543 * so only register the backlight device if the backlight method
2544 * supports both reads and writes.
2545 */
2546 brightness = __get_lcd_brightness(dev);
2547 if (brightness < 0)
2548 return 0;
2549 ret = set_lcd_brightness(dev, brightness);
2550 if (ret) {
2551 pr_debug("Backlight method is read-only, disabling backlight support\n");
2552 return 0;
2553 }
2554
Hans de Goede358d6a22015-04-21 12:01:32 +02002555 /*
2556 * Tell acpi-video-detect code to prefer vendor backlight on all
2557 * systems with transflective backlight and on dmi matched systems.
2558 */
2559 if (dev->tr_backlight_supported ||
2560 dmi_check_system(toshiba_vendor_backlight_dmi))
Hans de Goede234b7cf2015-06-16 16:28:11 +02002561 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
Hans de Goede358d6a22015-04-21 12:01:32 +02002562
Hans de Goede234b7cf2015-06-16 16:28:11 +02002563 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
Hans de Goede358d6a22015-04-21 12:01:32 +02002564 return 0;
2565
Matthew Garrett53039f22012-06-01 11:02:36 -04002566 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05002567 props.type = BACKLIGHT_PLATFORM;
2568 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05002569
Darren Harte0769fe2015-02-11 20:50:08 -08002570 /* Adding an extra level and having 0 change to transflective mode */
Akio Idehara121b7b02012-04-06 01:46:43 +09002571 if (dev->tr_backlight_supported)
2572 props.max_brightness++;
2573
Seth Forshee62cce752012-04-19 11:23:50 -05002574 dev->backlight_dev = backlight_device_register("toshiba",
2575 &dev->acpi_dev->dev,
2576 dev,
2577 &toshiba_backlight_data,
2578 &props);
2579 if (IS_ERR(dev->backlight_dev)) {
2580 ret = PTR_ERR(dev->backlight_dev);
2581 pr_err("Could not register toshiba backlight device\n");
2582 dev->backlight_dev = NULL;
2583 return ret;
2584 }
2585
2586 dev->backlight_dev->props.brightness = brightness;
2587 return 0;
2588}
2589
Azael Avalos0409cbc2015-07-31 21:58:13 -06002590static void print_supported_features(struct toshiba_acpi_dev *dev)
2591{
2592 pr_info("Supported laptop features:");
2593
2594 if (dev->hotkey_dev)
2595 pr_cont(" hotkeys");
2596 if (dev->backlight_dev)
2597 pr_cont(" backlight");
2598 if (dev->video_supported)
2599 pr_cont(" video-out");
2600 if (dev->fan_supported)
2601 pr_cont(" fan");
2602 if (dev->tr_backlight_supported)
2603 pr_cont(" transflective-backlight");
2604 if (dev->illumination_supported)
2605 pr_cont(" illumination");
2606 if (dev->kbd_illum_supported)
2607 pr_cont(" keyboard-backlight");
2608 if (dev->touchpad_supported)
2609 pr_cont(" touchpad");
2610 if (dev->eco_supported)
2611 pr_cont(" eco-led");
2612 if (dev->accelerometer_supported)
2613 pr_cont(" accelerometer-axes");
2614 if (dev->usb_sleep_charge_supported)
2615 pr_cont(" usb-sleep-charge");
2616 if (dev->usb_rapid_charge_supported)
2617 pr_cont(" usb-rapid-charge");
2618 if (dev->usb_sleep_music_supported)
2619 pr_cont(" usb-sleep-music");
2620 if (dev->kbd_function_keys_supported)
2621 pr_cont(" special-function-keys");
2622 if (dev->panel_power_on_supported)
2623 pr_cont(" panel-power-on");
2624 if (dev->usb_three_supported)
2625 pr_cont(" usb3");
2626
2627 pr_cont("\n");
2628}
2629
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002630static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002631{
2632 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2633
Azael Avalosfc5462f2015-07-22 18:09:11 -06002634 misc_deregister(&dev->miscdev);
2635
Seth Forshee36d03f92011-09-20 16:55:53 -05002636 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002637
Azael Avalos360f0f32014-03-25 20:38:31 -06002638 if (dev->sysfs_created)
2639 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2640 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05002641
Seth Forshee29cd2932012-01-18 13:44:09 -06002642 if (dev->ntfy_supported) {
2643 i8042_remove_filter(toshiba_acpi_i8042_filter);
2644 cancel_work_sync(&dev->hotkey_work);
2645 }
2646
Seth Forshee135740d2011-09-20 16:55:49 -05002647 if (dev->hotkey_dev) {
2648 input_unregister_device(dev->hotkey_dev);
2649 sparse_keymap_free(dev->hotkey_dev);
2650 }
2651
Markus Elfring00981812014-11-24 20:30:29 +01002652 backlight_device_unregister(dev->backlight_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002653
Azael Avalosea215a3f2015-07-31 21:58:12 -06002654 if (dev->illumination_led_registered)
Seth Forshee135740d2011-09-20 16:55:49 -05002655 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002656
Azael Avalos360f0f32014-03-25 20:38:31 -06002657 if (dev->kbd_led_registered)
2658 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002659
Azael Avalosea215a3f2015-07-31 21:58:12 -06002660 if (dev->eco_led_registered)
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002661 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05002662
Seth Forshee29cd2932012-01-18 13:44:09 -06002663 if (toshiba_acpi)
2664 toshiba_acpi = NULL;
2665
Seth Forshee135740d2011-09-20 16:55:49 -05002666 kfree(dev);
2667
2668 return 0;
2669}
2670
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002671static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05002672{
Zhang Ruie2e19602013-09-03 08:32:06 +08002673 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002674 return "GHCI";
2675
Zhang Ruie2e19602013-09-03 08:32:06 +08002676 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002677 return "SPFC";
2678
2679 return NULL;
2680}
2681
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002682static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002683{
2684 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002685 const char *hci_method;
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002686 u32 special_functions;
Seth Forshee36d03f92011-09-20 16:55:53 -05002687 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05002688 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05002689
Seth Forshee29cd2932012-01-18 13:44:09 -06002690 if (toshiba_acpi)
2691 return -EBUSY;
2692
Seth Forshee135740d2011-09-20 16:55:49 -05002693 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2694 TOSHIBA_ACPI_VERSION);
2695
Seth Forsheea540d6b2011-09-20 16:55:52 -05002696 hci_method = find_hci_method(acpi_dev->handle);
2697 if (!hci_method) {
2698 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05002699 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002700 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05002701
Seth Forshee135740d2011-09-20 16:55:49 -05002702 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2703 if (!dev)
2704 return -ENOMEM;
2705 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002706 dev->method_hci = hci_method;
Azael Avalosfc5462f2015-07-22 18:09:11 -06002707 dev->miscdev.minor = MISC_DYNAMIC_MINOR;
2708 dev->miscdev.name = "toshiba_acpi";
2709 dev->miscdev.fops = &toshiba_acpi_fops;
2710
2711 ret = misc_register(&dev->miscdev);
2712 if (ret) {
2713 pr_err("Failed to register miscdevice\n");
2714 kfree(dev);
2715 return ret;
2716 }
2717
Seth Forshee135740d2011-09-20 16:55:49 -05002718 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06002719 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002720
Azael Avalosa2b34712015-03-20 16:55:17 -06002721 /* Query the BIOS for supported features */
2722
2723 /*
2724 * The "Special Functions" are always supported by the laptops
2725 * with the new keyboard layout, query for its presence to help
2726 * determine the keymap layout to use.
2727 */
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002728 ret = toshiba_function_keys_get(dev, &special_functions);
Azael Avalosa2b34712015-03-20 16:55:17 -06002729 dev->kbd_function_keys_supported = !ret;
2730
Seth Forshee6e02cc72011-09-20 16:55:51 -05002731 if (toshiba_acpi_setup_keyboard(dev))
2732 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05002733
Azael Avalos695f6062015-07-22 18:09:13 -06002734 /* Determine whether or not BIOS supports transflective backlight */
2735 ret = get_tr_backlight_status(dev, &dummy);
2736 dev->tr_backlight_supported = !ret;
2737
Seth Forshee62cce752012-04-19 11:23:50 -05002738 ret = toshiba_acpi_setup_backlight(dev);
2739 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05002740 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05002741
Azael Avalosea215a3f2015-07-31 21:58:12 -06002742 toshiba_illumination_available(dev);
2743 if (dev->illumination_supported) {
Seth Forshee135740d2011-09-20 16:55:49 -05002744 dev->led_dev.name = "toshiba::illumination";
2745 dev->led_dev.max_brightness = 1;
2746 dev->led_dev.brightness_set = toshiba_illumination_set;
2747 dev->led_dev.brightness_get = toshiba_illumination_get;
2748 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002749 dev->illumination_led_registered = true;
Seth Forshee135740d2011-09-20 16:55:49 -05002750 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002751
Azael Avalosea215a3f2015-07-31 21:58:12 -06002752 toshiba_eco_mode_available(dev);
2753 if (dev->eco_supported) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002754 dev->eco_led.name = "toshiba::eco_mode";
2755 dev->eco_led.max_brightness = 1;
2756 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2757 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2758 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002759 dev->eco_led_registered = true;
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002760 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002761
Azael Avalosea215a3f2015-07-31 21:58:12 -06002762 toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06002763 /*
2764 * Only register the LED if KBD illumination is supported
2765 * and the keyboard backlight operation mode is set to FN-Z
2766 */
2767 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2768 dev->kbd_led.name = "toshiba::kbd_backlight";
2769 dev->kbd_led.max_brightness = 1;
2770 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2771 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2772 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002773 dev->kbd_led_registered = true;
Azael Avalos360f0f32014-03-25 20:38:31 -06002774 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002775
Azael Avalos9d8658a2014-03-25 20:38:32 -06002776 ret = toshiba_touchpad_get(dev, &dummy);
2777 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002778
Azael Avalosea215a3f2015-07-31 21:58:12 -06002779 toshiba_accelerometer_available(dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002780
Azael Avalosc8c91842015-04-02 19:26:20 -06002781 toshiba_usb_sleep_charge_available(dev);
Azael Avalose26ffe52015-01-18 18:30:22 -07002782
Azael Avalosbb3fe012015-01-18 18:30:24 -07002783 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2784 dev->usb_rapid_charge_supported = !ret;
2785
Azael Avalos172ce0a2015-01-18 18:30:25 -07002786 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2787 dev->usb_sleep_music_supported = !ret;
2788
Azael Avalos35d53ce2015-02-10 21:09:19 -07002789 ret = toshiba_panel_power_on_get(dev, &dummy);
2790 dev->panel_power_on_supported = !ret;
2791
Azael Avalos17fe4b32015-02-10 21:09:20 -07002792 ret = toshiba_usb_three_get(dev, &dummy);
2793 dev->usb_three_supported = !ret;
2794
Seth Forshee36d03f92011-09-20 16:55:53 -05002795 ret = get_video_status(dev, &dummy);
2796 dev->video_supported = !ret;
2797
2798 ret = get_fan_status(dev, &dummy);
2799 dev->fan_supported = !ret;
2800
Azael Avalos0409cbc2015-07-31 21:58:13 -06002801 print_supported_features(dev);
2802
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002803 /*
2804 * Enable the "Special Functions" mode only if they are
2805 * supported and if they are activated.
2806 */
2807 if (dev->kbd_function_keys_supported && special_functions)
2808 toshiba_acpi_enable_special_functions(dev);
2809
Azael Avalos360f0f32014-03-25 20:38:31 -06002810 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2811 &toshiba_attr_group);
2812 if (ret) {
2813 dev->sysfs_created = 0;
2814 goto error;
2815 }
2816 dev->sysfs_created = !ret;
2817
Seth Forshee36d03f92011-09-20 16:55:53 -05002818 create_toshiba_proc_entries(dev);
2819
Seth Forshee29cd2932012-01-18 13:44:09 -06002820 toshiba_acpi = dev;
2821
Seth Forshee135740d2011-09-20 16:55:49 -05002822 return 0;
2823
2824error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002825 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002826 return ret;
2827}
2828
2829static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2830{
2831 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Azael Avalos80546902014-12-04 20:22:47 -07002832 int ret;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002833
Azael Avalos71454d72014-12-04 20:22:46 -07002834 switch (event) {
2835 case 0x80: /* Hotkeys and some system events */
Azael Avalosa88bc062015-07-22 18:09:12 -06002836 /*
2837 * Machines with this WMI GUID aren't supported due to bugs in
2838 * their AML.
2839 *
2840 * Return silently to avoid triggering a netlink event.
2841 */
2842 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2843 return;
Azael Avalos71454d72014-12-04 20:22:46 -07002844 toshiba_acpi_process_hotkeys(dev);
2845 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002846 case 0x81: /* Dock events */
2847 case 0x82:
2848 case 0x83:
2849 pr_info("Dock event received %x\n", event);
2850 break;
2851 case 0x88: /* Thermal events */
2852 pr_info("Thermal event received\n");
2853 break;
2854 case 0x8f: /* LID closed */
2855 case 0x90: /* LID is closed and Dock has been ejected */
2856 break;
2857 case 0x8c: /* SATA power events */
2858 case 0x8b:
2859 pr_info("SATA power event received %x\n", event);
2860 break;
Azael Avalos80546902014-12-04 20:22:47 -07002861 case 0x92: /* Keyboard backlight mode changed */
2862 /* Update sysfs entries */
2863 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2864 &toshiba_attr_group);
2865 if (ret)
2866 pr_err("Unable to update sysfs entries\n");
2867 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002868 case 0x85: /* Unknown */
2869 case 0x8d: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002870 case 0x8e: /* Unknown */
Azael Avalosbab09e22015-03-06 18:14:41 -07002871 case 0x94: /* Unknown */
2872 case 0x95: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002873 default:
2874 pr_info("Unknown event received %x\n", event);
2875 break;
Seth Forshee29cd2932012-01-18 13:44:09 -06002876 }
Azael Avalosbab09e22015-03-06 18:14:41 -07002877
2878 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2879 dev_name(&acpi_dev->dev),
2880 event, 0);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002881}
2882
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +02002883#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002884static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002885{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002886 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002887
Azael Avalos1e574db2015-07-22 19:37:49 -06002888 if (dev->hotkey_dev) {
2889 u32 result;
2890
Azael Avalosd37782b2015-05-06 09:35:10 -06002891 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Azael Avalos1e574db2015-07-22 19:37:49 -06002892 if (result != TOS_SUCCESS)
2893 pr_info("Unable to disable hotkeys\n");
2894 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002895
2896 return 0;
2897}
2898
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002899static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002900{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002901 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002902
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002903 if (dev->hotkey_dev) {
Azael Avalos1e574db2015-07-22 19:37:49 -06002904 int error = toshiba_acpi_enable_hotkeys(dev);
2905
Azael Avalos1f28f292014-12-04 20:22:45 -07002906 if (error)
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002907 pr_info("Unable to re-enable hotkeys\n");
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002908 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002909
2910 return 0;
2911}
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +02002912#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002913
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002914static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2915 toshiba_acpi_suspend, toshiba_acpi_resume);
2916
Seth Forshee135740d2011-09-20 16:55:49 -05002917static struct acpi_driver toshiba_acpi_driver = {
2918 .name = "Toshiba ACPI driver",
2919 .owner = THIS_MODULE,
2920 .ids = toshiba_device_ids,
2921 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2922 .ops = {
2923 .add = toshiba_acpi_add,
2924 .remove = toshiba_acpi_remove,
2925 .notify = toshiba_acpi_notify,
2926 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002927 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05002928};
Holger Machtc9263552006-10-20 14:30:29 -07002929
Len Brown4be44fc2005-08-05 00:44:28 -04002930static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931{
Seth Forshee135740d2011-09-20 16:55:49 -05002932 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933
2934 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2935 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05002936 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002937 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 }
2939
Seth Forshee135740d2011-09-20 16:55:49 -05002940 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2941 if (ret) {
2942 pr_err("Failed to register ACPI driver: %d\n", ret);
2943 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07002944 }
2945
Seth Forshee135740d2011-09-20 16:55:49 -05002946 return ret;
2947}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002948
Seth Forshee135740d2011-09-20 16:55:49 -05002949static void __exit toshiba_acpi_exit(void)
2950{
2951 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2952 if (toshiba_proc_dir)
2953 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954}
2955
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956module_init(toshiba_acpi_init);
2957module_exit(toshiba_acpi_exit);