blob: 9956b9902bb40aaeb59e724b60579e56a495795e [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 Avalos7216d702015-02-10 21:09:21 -070034#define TOSHIBA_ACPI_VERSION "0.21"
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>
philipl@overt.orgc41a40c2008-08-30 11:57:39 -040044#include <linux/rfkill.h>
Matthew Garrett6335e4d2010-02-25 15:20:54 -050045#include <linux/input.h>
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -070046#include <linux/input/sparse-keymap.h>
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +020047#include <linux/leds.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090048#include <linux/slab.h>
Seth Forshee29cd2932012-01-18 13:44:09 -060049#include <linux/workqueue.h>
50#include <linux/i8042.h>
Lv Zheng8b484632013-12-03 08:49:16 +080051#include <linux/acpi.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020052#include <linux/dmi.h>
Azael Avalosb5163992015-02-10 23:43:56 -070053#include <linux/uaccess.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020054#include <acpi/video.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Linus Torvalds1da177e2005-04-16 15:20:36 -070056MODULE_AUTHOR("John Belmonte");
57MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
58MODULE_LICENSE("GPL");
59
Seth Forsheef11f9992012-01-18 13:44:11 -060060#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
61
Seth Forshee29cd2932012-01-18 13:44:09 -060062/* Scan code for Fn key on TOS1900 models */
63#define TOS1900_FN_SCAN 0x6e
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065/* Toshiba ACPI method paths */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
67
Darren Harte0769fe2015-02-11 20:50:08 -080068/*
69 * The Toshiba configuration interface is composed of the HCI and the SCI,
Azael Avalos258c5902014-09-29 20:40:07 -060070 * which are defined as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 *
72 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
73 * be uniform across all their models. Ideally we would just call
74 * dedicated ACPI methods instead of using this primitive interface.
75 * However the ACPI methods seem to be incomplete in some areas (for
76 * example they allow setting, but not reading, the LCD brightness value),
77 * so this is still useful.
Matthew Garrettea6b31f2014-04-04 14:22:34 -040078 *
Azael Avalos84a62732014-03-25 20:38:29 -060079 * SCI stands for "System Configuration Interface" which aim is to
80 * conceal differences in hardware between different models.
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 */
82
Azael Avalos258c5902014-09-29 20:40:07 -060083#define TCI_WORDS 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85/* operations */
86#define HCI_SET 0xff00
87#define HCI_GET 0xfe00
Azael Avalos84a62732014-03-25 20:38:29 -060088#define SCI_OPEN 0xf100
89#define SCI_CLOSE 0xf200
90#define SCI_GET 0xf300
91#define SCI_SET 0xf400
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93/* return codes */
Azael Avalos1864bbc2014-09-29 20:40:08 -060094#define TOS_SUCCESS 0x0000
95#define TOS_OPEN_CLOSE_OK 0x0044
96#define TOS_FAILURE 0x1000
97#define TOS_NOT_SUPPORTED 0x8000
98#define TOS_ALREADY_OPEN 0x8100
99#define TOS_NOT_OPENED 0x8200
100#define TOS_INPUT_DATA_ERROR 0x8300
101#define TOS_WRITE_PROTECTED 0x8400
102#define TOS_NOT_PRESENT 0x8600
103#define TOS_FIFO_EMPTY 0x8c00
104#define TOS_DATA_NOT_AVAILABLE 0x8d20
105#define TOS_NOT_INITIALIZED 0x8d50
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700106#define TOS_NOT_INSTALLED 0x8e00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108/* registers */
109#define HCI_FAN 0x0004
Akio Idehara121b7b02012-04-06 01:46:43 +0900110#define HCI_TR_BACKLIGHT 0x0005
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define HCI_SYSTEM_EVENT 0x0016
112#define HCI_VIDEO_OUT 0x001c
113#define HCI_HOTKEY_EVENT 0x001e
114#define HCI_LCD_BRIGHTNESS 0x002a
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400115#define HCI_WIRELESS 0x0056
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
130/* 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
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400144#define HCI_WIRELESS_KILL_SWITCH 0x01
145#define HCI_WIRELESS_BT_PRESENT 0x0f
146#define HCI_WIRELESS_BT_ATTACH 0x40
147#define HCI_WIRELESS_BT_POWER 0x80
Azael Avalos93f8c162014-09-12 18:50:36 -0600148#define SCI_KBD_MODE_MASK 0x1f
Azael Avalos360f0f32014-03-25 20:38:31 -0600149#define SCI_KBD_MODE_FNZ 0x1
150#define SCI_KBD_MODE_AUTO 0x2
Azael Avalos93f8c162014-09-12 18:50:36 -0600151#define SCI_KBD_MODE_ON 0x8
152#define SCI_KBD_MODE_OFF 0x10
153#define SCI_KBD_TIME_MAX 0x3c001a
Azael Avalose26ffe52015-01-18 18:30:22 -0700154#define SCI_USB_CHARGE_MODE_MASK 0xff
Azael Avalosc8c91842015-04-02 19:26:20 -0600155#define SCI_USB_CHARGE_DISABLED 0x00
156#define SCI_USB_CHARGE_ALTERNATE 0x09
157#define SCI_USB_CHARGE_TYPICAL 0x11
158#define SCI_USB_CHARGE_AUTO 0x21
Azael Avalos182bcaa2015-01-18 18:30:23 -0700159#define SCI_USB_CHARGE_BAT_MASK 0x7
160#define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
161#define SCI_USB_CHARGE_BAT_LVL_ON 0x4
162#define SCI_USB_CHARGE_BAT_LVL 0x0200
Azael Avalosbb3fe012015-01-18 18:30:24 -0700163#define SCI_USB_CHARGE_RAPID_DSP 0x0300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Seth Forshee135740d2011-09-20 16:55:49 -0500165struct toshiba_acpi_dev {
166 struct acpi_device *acpi_dev;
167 const char *method_hci;
168 struct rfkill *bt_rfk;
169 struct input_dev *hotkey_dev;
Seth Forshee29cd2932012-01-18 13:44:09 -0600170 struct work_struct hotkey_work;
Seth Forshee135740d2011-09-20 16:55:49 -0500171 struct backlight_device *backlight_dev;
172 struct led_classdev led_dev;
Azael Avalos360f0f32014-03-25 20:38:31 -0600173 struct led_classdev kbd_led;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600174 struct led_classdev eco_led;
Seth Forshee36d03f92011-09-20 16:55:53 -0500175
Seth Forshee135740d2011-09-20 16:55:49 -0500176 int force_fan;
177 int last_key_event;
178 int key_event_valid;
Azael Avalos93f8c162014-09-12 18:50:36 -0600179 int kbd_type;
Azael Avalos360f0f32014-03-25 20:38:31 -0600180 int kbd_mode;
181 int kbd_time;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700182 int usbsc_bat_level;
Azael Avalosc8c91842015-04-02 19:26:20 -0600183 int usbsc_mode_base;
Azael Avalosa2b34712015-03-20 16:55:17 -0600184 int hotkey_event_type;
Seth Forshee135740d2011-09-20 16:55:49 -0500185
Dan Carpenter592b7462012-01-15 14:28:20 +0300186 unsigned int illumination_supported:1;
187 unsigned int video_supported:1;
188 unsigned int fan_supported:1;
189 unsigned int system_event_supported:1;
Seth Forshee29cd2932012-01-18 13:44:09 -0600190 unsigned int ntfy_supported:1;
191 unsigned int info_supported:1;
Akio Idehara121b7b02012-04-06 01:46:43 +0900192 unsigned int tr_backlight_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600193 unsigned int kbd_illum_supported:1;
194 unsigned int kbd_led_registered:1;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600195 unsigned int touchpad_supported:1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600196 unsigned int eco_supported:1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600197 unsigned int accelerometer_supported:1;
Azael Avalose26ffe52015-01-18 18:30:22 -0700198 unsigned int usb_sleep_charge_supported:1;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700199 unsigned int usb_rapid_charge_supported:1;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700200 unsigned int usb_sleep_music_supported:1;
Azael Avalosbae84192015-02-10 21:09:18 -0700201 unsigned int kbd_function_keys_supported:1;
Azael Avalos35d53ce2015-02-10 21:09:19 -0700202 unsigned int panel_power_on_supported:1;
Azael Avalos17fe4b32015-02-10 21:09:20 -0700203 unsigned int usb_three_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600204 unsigned int sysfs_created:1;
Seth Forshee36d03f92011-09-20 16:55:53 -0500205
Seth Forshee135740d2011-09-20 16:55:49 -0500206 struct mutex mutex;
207};
208
Seth Forshee29cd2932012-01-18 13:44:09 -0600209static struct toshiba_acpi_dev *toshiba_acpi;
210
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800211static const struct acpi_device_id toshiba_device_ids[] = {
212 {"TOS6200", 0},
Ondrej Zary63a9e012014-11-10 00:11:54 +0100213 {"TOS6207", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400214 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800215 {"TOS1900", 0},
216 {"", 0},
217};
218MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
219
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800220static const struct key_entry toshiba_acpi_keymap[] = {
Unai Uribarrifec278a2014-01-14 11:06:47 +0100221 { KE_KEY, 0x9e, { KEY_RFKILL } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700222 { KE_KEY, 0x101, { KEY_MUTE } },
223 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
224 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600225 { KE_KEY, 0x10f, { KEY_TAB } },
Azael Avalosaf502832012-01-18 13:44:10 -0600226 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
227 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700228 { KE_KEY, 0x13b, { KEY_COFFEE } },
229 { KE_KEY, 0x13c, { KEY_BATTERY } },
230 { KE_KEY, 0x13d, { KEY_SLEEP } },
231 { KE_KEY, 0x13e, { KEY_SUSPEND } },
232 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
233 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
234 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
235 { KE_KEY, 0x142, { KEY_WLAN } },
Azael Avalosaf502832012-01-18 13:44:10 -0600236 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
Jon Dowlanda49010f2010-10-27 00:24:59 +0100237 { KE_KEY, 0x17f, { KEY_FN } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700238 { KE_KEY, 0xb05, { KEY_PROG2 } },
239 { KE_KEY, 0xb06, { KEY_WWW } },
240 { KE_KEY, 0xb07, { KEY_MAIL } },
241 { KE_KEY, 0xb30, { KEY_STOP } },
242 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
243 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
244 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
245 { KE_KEY, 0xb5a, { KEY_MEDIA } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600246 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
247 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
248 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
249 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
250 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700251 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500252};
253
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200254static const struct key_entry toshiba_acpi_alt_keymap[] = {
255 { KE_KEY, 0x157, { KEY_MUTE } },
256 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
257 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalose6efad72014-08-04 09:21:02 -0600258 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200259 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
260 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
261 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
262 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
263 { KE_KEY, 0x158, { KEY_WLAN } },
264 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
265 { KE_END, 0 },
266};
267
Darren Harte0769fe2015-02-11 20:50:08 -0800268/*
Hans de Goede358d6a22015-04-21 12:01:32 +0200269 * List of models which have a broken acpi-video backlight interface and thus
270 * need to use the toshiba (vendor) interface instead.
271 */
272static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
273 {}
274};
275
276/*
Darren Harte0769fe2015-02-11 20:50:08 -0800277 * Utility
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 */
279
Azael Avalosb5163992015-02-10 23:43:56 -0700280static inline void _set_bit(u32 *word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
282 *word = (*word & ~mask) | (mask * value);
283}
284
Darren Harte0769fe2015-02-11 20:50:08 -0800285/*
286 * ACPI interface wrappers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 */
288
Len Brown4be44fc2005-08-05 00:44:28 -0400289static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 acpi_status status;
292
Zhang Rui619400d2013-09-03 08:31:56 +0800293 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500294 return (status == AE_OK) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
Darren Harte0769fe2015-02-11 20:50:08 -0800297/*
298 * Perform a raw configuration call. Here we don't care about input or output
Azael Avalos258c5902014-09-29 20:40:07 -0600299 * buffer format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 */
Azael Avalos258c5902014-09-29 20:40:07 -0600301static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
302 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
304 struct acpi_object_list params;
Azael Avalos258c5902014-09-29 20:40:07 -0600305 union acpi_object in_objs[TCI_WORDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 struct acpi_buffer results;
Azael Avalos258c5902014-09-29 20:40:07 -0600307 union acpi_object out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 acpi_status status;
309 int i;
310
Azael Avalos258c5902014-09-29 20:40:07 -0600311 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600313 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 in_objs[i].type = ACPI_TYPE_INTEGER;
315 in_objs[i].integer.value = in[i];
316 }
317
318 results.length = sizeof(out_objs);
319 results.pointer = out_objs;
320
Seth Forshee6e02cc72011-09-20 16:55:51 -0500321 status = acpi_evaluate_object(dev->acpi_dev->handle,
322 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400323 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600324 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Azael Avalosb5163992015-02-10 23:43:56 -0700325 for (i = 0; i < out_objs->package.count; ++i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 out[i] = out_objs->package.elements[i].integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
328
329 return status;
330}
331
Darren Harte0769fe2015-02-11 20:50:08 -0800332/*
333 * Common hci tasks (get or set one or two value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 *
335 * In addition to the ACPI status, the HCI system returns a result which
336 * may be useful (such as "not supported").
337 */
338
Azael Avalos893f3f62014-09-29 20:40:09 -0600339static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Azael Avalos258c5902014-09-29 20:40:07 -0600341 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
342 u32 out[TCI_WORDS];
343 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600344
345 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
Azael Avalos893f3f62014-09-29 20:40:09 -0600348static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
Azael Avalos258c5902014-09-29 20:40:07 -0600350 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
351 u32 out[TCI_WORDS];
352 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700353
Azael Avalos893f3f62014-09-29 20:40:09 -0600354 if (ACPI_FAILURE(status))
355 return TOS_FAILURE;
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600358
359 return out[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
361
Azael Avalos893f3f62014-09-29 20:40:09 -0600362static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400363{
Azael Avalos258c5902014-09-29 20:40:07 -0600364 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
365 u32 out[TCI_WORDS];
366 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600367
368 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400369}
370
Azael Avalosb5163992015-02-10 23:43:56 -0700371static u32 hci_read2(struct toshiba_acpi_dev *dev,
372 u32 reg, u32 *out1, u32 *out2)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400373{
Azael Avalos258c5902014-09-29 20:40:07 -0600374 u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
375 u32 out[TCI_WORDS];
376 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700377
Azael Avalos893f3f62014-09-29 20:40:09 -0600378 if (ACPI_FAILURE(status))
379 return TOS_FAILURE;
380
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400381 *out1 = out[2];
382 *out2 = out[3];
Azael Avalos893f3f62014-09-29 20:40:09 -0600383
384 return out[0];
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400385}
386
Darren Harte0769fe2015-02-11 20:50:08 -0800387/*
388 * Common sci tasks
Azael Avalos84a62732014-03-25 20:38:29 -0600389 */
390
391static int sci_open(struct toshiba_acpi_dev *dev)
392{
Azael Avalos258c5902014-09-29 20:40:07 -0600393 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
394 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600395 acpi_status status;
396
Azael Avalos258c5902014-09-29 20:40:07 -0600397 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600398 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalos84a62732014-03-25 20:38:29 -0600399 pr_err("ACPI call to open SCI failed\n");
400 return 0;
401 }
402
Azael Avalos1864bbc2014-09-29 20:40:08 -0600403 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600404 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600405 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600406 pr_info("Toshiba SCI already opened\n");
407 return 1;
Azael Avalosfa465732015-01-18 19:17:12 -0700408 } else if (out[0] == TOS_NOT_SUPPORTED) {
Darren Harte0769fe2015-02-11 20:50:08 -0800409 /*
410 * Some BIOSes do not have the SCI open/close functions
Azael Avalosfa465732015-01-18 19:17:12 -0700411 * implemented and return 0x8000 (Not Supported), failing to
412 * register some supported features.
413 *
414 * Simply return 1 if we hit those affected laptops to make the
415 * supported features work.
416 *
417 * In the case that some laptops really do not support the SCI,
418 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
419 * and thus, not registering support for the queried feature.
420 */
421 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600422 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600423 pr_info("Toshiba SCI is not present\n");
424 }
425
426 return 0;
427}
428
429static void sci_close(struct toshiba_acpi_dev *dev)
430{
Azael Avalos258c5902014-09-29 20:40:07 -0600431 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
432 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600433 acpi_status status;
434
Azael Avalos258c5902014-09-29 20:40:07 -0600435 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600436 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalos84a62732014-03-25 20:38:29 -0600437 pr_err("ACPI call to close SCI failed\n");
438 return;
439 }
440
Azael Avalos1864bbc2014-09-29 20:40:08 -0600441 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600442 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600443 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600444 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600445 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600446 pr_info("Toshiba SCI is not present\n");
447}
448
Azael Avalos893f3f62014-09-29 20:40:09 -0600449static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Azael Avalos84a62732014-03-25 20:38:29 -0600450{
Azael Avalos258c5902014-09-29 20:40:07 -0600451 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
452 u32 out[TCI_WORDS];
453 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700454
Azael Avalos893f3f62014-09-29 20:40:09 -0600455 if (ACPI_FAILURE(status))
456 return TOS_FAILURE;
457
Azael Avalos84a62732014-03-25 20:38:29 -0600458 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600459
460 return out[0];
Azael Avalos84a62732014-03-25 20:38:29 -0600461}
462
Azael Avalos893f3f62014-09-29 20:40:09 -0600463static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Azael Avalos84a62732014-03-25 20:38:29 -0600464{
Azael Avalos258c5902014-09-29 20:40:07 -0600465 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
466 u32 out[TCI_WORDS];
467 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600468
469 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600470}
471
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200472/* Illumination support */
Seth Forshee135740d2011-09-20 16:55:49 -0500473static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200474{
Azael Avalos258c5902014-09-29 20:40:07 -0600475 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
476 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200477 acpi_status status;
478
Azael Avalosfdb79082014-03-25 20:38:30 -0600479 if (!sci_open(dev))
480 return 0;
481
Azael Avalos258c5902014-09-29 20:40:07 -0600482 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600483 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600484 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600485 pr_err("ACPI call to query Illumination support failed\n");
486 return 0;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600487 } else if (out[0] == TOS_NOT_SUPPORTED) {
Joe Perches7e334602011-03-29 15:21:52 -0700488 pr_info("Illumination device not available\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200489 return 0;
490 }
Azael Avalosfdb79082014-03-25 20:38:30 -0600491
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200492 return 1;
493}
494
495static void toshiba_illumination_set(struct led_classdev *cdev,
496 enum led_brightness brightness)
497{
Seth Forshee135740d2011-09-20 16:55:49 -0500498 struct toshiba_acpi_dev *dev = container_of(cdev,
499 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600500 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200501
502 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600503 if (!sci_open(dev))
504 return;
505
506 /* Switch the illumination on/off */
507 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600508 result = sci_write(dev, SCI_ILLUMINATION, state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600509 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600510 if (result == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600511 pr_err("ACPI call for illumination failed\n");
512 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600513 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600514 pr_info("Illumination not supported\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200515 return;
516 }
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200517}
518
519static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
520{
Seth Forshee135740d2011-09-20 16:55:49 -0500521 struct toshiba_acpi_dev *dev = container_of(cdev,
522 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600523 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200524
525 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600526 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200527 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200528
529 /* Check the illumination */
Azael Avalos893f3f62014-09-29 20:40:09 -0600530 result = sci_read(dev, SCI_ILLUMINATION, &state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600531 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600532 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600533 pr_err("ACPI call for illumination failed\n");
534 return LED_OFF;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600535 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600536 pr_info("Illumination not supported\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200537 return LED_OFF;
538 }
539
Azael Avalosfdb79082014-03-25 20:38:30 -0600540 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200541}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400542
Azael Avalos360f0f32014-03-25 20:38:31 -0600543/* KBD Illumination */
Azael Avalos93f8c162014-09-12 18:50:36 -0600544static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
545{
Azael Avalos258c5902014-09-29 20:40:07 -0600546 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
547 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600548 acpi_status status;
549
550 if (!sci_open(dev))
551 return 0;
552
Azael Avalos258c5902014-09-29 20:40:07 -0600553 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600554 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600555 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600556 pr_err("ACPI call to query kbd illumination support failed\n");
557 return 0;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600558 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600559 pr_info("Keyboard illumination not available\n");
560 return 0;
561 }
562
Darren Harte0769fe2015-02-11 20:50:08 -0800563 /*
564 * Check for keyboard backlight timeout max value,
Azael Avalos93f8c162014-09-12 18:50:36 -0600565 * previous kbd backlight implementation set this to
566 * 0x3c0003, and now the new implementation set this
Darren Harte0769fe2015-02-11 20:50:08 -0800567 * to 0x3c001a, use this to distinguish between them.
Azael Avalos93f8c162014-09-12 18:50:36 -0600568 */
569 if (out[3] == SCI_KBD_TIME_MAX)
570 dev->kbd_type = 2;
571 else
572 dev->kbd_type = 1;
573 /* Get the current keyboard backlight mode */
574 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
575 /* Get the current time (1-60 seconds) */
576 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
577
578 return 1;
579}
580
Azael Avalos360f0f32014-03-25 20:38:31 -0600581static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
582{
583 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600584
585 if (!sci_open(dev))
586 return -EIO;
587
Azael Avalos893f3f62014-09-29 20:40:09 -0600588 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600589 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600590 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600591 pr_err("ACPI call to set KBD backlight status failed\n");
592 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600593 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600594 pr_info("Keyboard backlight status not supported\n");
595 return -ENODEV;
596 }
597
598 return 0;
599}
600
601static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
602{
603 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600604
605 if (!sci_open(dev))
606 return -EIO;
607
Azael Avalos893f3f62014-09-29 20:40:09 -0600608 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600609 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600610 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600611 pr_err("ACPI call to get KBD backlight status failed\n");
612 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600613 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600614 pr_info("Keyboard backlight status not supported\n");
615 return -ENODEV;
616 }
617
618 return 0;
619}
620
621static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
622{
623 struct toshiba_acpi_dev *dev = container_of(cdev,
624 struct toshiba_acpi_dev, kbd_led);
625 u32 state, result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600626
627 /* Check the keyboard backlight state */
Azael Avalos893f3f62014-09-29 20:40:09 -0600628 result = hci_read1(dev, HCI_KBD_ILLUMINATION, &state);
629 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600630 pr_err("ACPI call to get the keyboard backlight failed\n");
631 return LED_OFF;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600632 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600633 pr_info("Keyboard backlight not supported\n");
634 return LED_OFF;
635 }
636
637 return state ? LED_FULL : LED_OFF;
638}
639
640static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
641 enum led_brightness brightness)
642{
643 struct toshiba_acpi_dev *dev = container_of(cdev,
644 struct toshiba_acpi_dev, kbd_led);
645 u32 state, result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600646
647 /* Set the keyboard backlight state */
648 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600649 result = hci_write1(dev, HCI_KBD_ILLUMINATION, state);
650 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600651 pr_err("ACPI call to set KBD Illumination mode failed\n");
652 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600653 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600654 pr_info("Keyboard backlight not supported\n");
655 return;
656 }
657}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400658
Azael Avalos9d8658a2014-03-25 20:38:32 -0600659/* TouchPad support */
660static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
661{
662 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600663
664 if (!sci_open(dev))
665 return -EIO;
666
Azael Avalos893f3f62014-09-29 20:40:09 -0600667 result = sci_write(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600668 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600669 if (result == TOS_FAILURE) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600670 pr_err("ACPI call to set the touchpad failed\n");
671 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600672 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600673 return -ENODEV;
674 }
675
676 return 0;
677}
678
679static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
680{
681 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600682
683 if (!sci_open(dev))
684 return -EIO;
685
Azael Avalos893f3f62014-09-29 20:40:09 -0600686 result = sci_read(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600687 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600688 if (result == TOS_FAILURE) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600689 pr_err("ACPI call to query the touchpad failed\n");
690 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600691 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600692 return -ENODEV;
693 }
694
695 return 0;
696}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200697
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600698/* Eco Mode support */
699static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
700{
701 acpi_status status;
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700702 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
Azael Avalos258c5902014-09-29 20:40:07 -0600703 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600704
Azael Avalos258c5902014-09-29 20:40:07 -0600705 status = tci_raw(dev, in, out);
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700706 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
707 pr_err("ACPI call to get ECO led failed\n");
708 } else if (out[0] == TOS_NOT_INSTALLED) {
709 pr_info("ECO led not installed");
710 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
Darren Harte0769fe2015-02-11 20:50:08 -0800711 /*
712 * If we receive 0x8300 (Input Data Error), it means that the
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700713 * LED device is present, but that we just screwed the input
714 * parameters.
715 *
716 * Let's query the status of the LED to see if we really have a
717 * success response, indicating the actual presense of the LED,
718 * bail out otherwise.
719 */
720 in[3] = 1;
721 status = tci_raw(dev, in, out);
722 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE)
723 pr_err("ACPI call to get ECO led failed\n");
724 else if (out[0] == TOS_SUCCESS)
725 return 1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600726 }
727
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700728 return 0;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600729}
730
Azael Avalosb5163992015-02-10 23:43:56 -0700731static enum led_brightness
732toshiba_eco_mode_get_status(struct led_classdev *cdev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600733{
734 struct toshiba_acpi_dev *dev = container_of(cdev,
735 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600736 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
737 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600738 acpi_status status;
739
Azael Avalos258c5902014-09-29 20:40:07 -0600740 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600741 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600742 pr_err("ACPI call to get ECO led failed\n");
743 return LED_OFF;
744 }
745
746 return out[2] ? LED_FULL : LED_OFF;
747}
748
749static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
750 enum led_brightness brightness)
751{
752 struct toshiba_acpi_dev *dev = container_of(cdev,
753 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600754 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
755 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600756 acpi_status status;
757
758 /* Switch the Eco Mode led on/off */
759 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600760 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600761 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600762 pr_err("ACPI call to set ECO led failed\n");
763 return;
764 }
765}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400766
Azael Avalos5a2813e2014-03-25 20:38:34 -0600767/* Accelerometer support */
768static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
769{
Azael Avalos258c5902014-09-29 20:40:07 -0600770 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
771 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600772 acpi_status status;
773
Darren Harte0769fe2015-02-11 20:50:08 -0800774 /*
775 * Check if the accelerometer call exists,
Azael Avalos5a2813e2014-03-25 20:38:34 -0600776 * this call also serves as initialization
777 */
Azael Avalos258c5902014-09-29 20:40:07 -0600778 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600779 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600780 pr_err("ACPI call to query the accelerometer failed\n");
781 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600782 } else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
783 out[0] == TOS_NOT_INITIALIZED) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600784 pr_err("Accelerometer not initialized\n");
785 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600786 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600787 pr_info("Accelerometer not supported\n");
788 return -ENODEV;
789 }
790
791 return 0;
792}
793
794static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
795 u32 *xy, u32 *z)
796{
Azael Avalos258c5902014-09-29 20:40:07 -0600797 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
798 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600799 acpi_status status;
800
801 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600802 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600803 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600804 pr_err("ACPI call to query the accelerometer failed\n");
805 return -EIO;
806 }
807
808 *xy = out[2];
809 *z = out[4];
810
811 return 0;
812}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600813
Azael Avalose26ffe52015-01-18 18:30:22 -0700814/* Sleep (Charge and Music) utilities support */
Azael Avalosc8c91842015-04-02 19:26:20 -0600815static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
816{
817 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
818 u32 out[TCI_WORDS];
819 acpi_status status;
820
821 /* Set the feature to "not supported" in case of error */
822 dev->usb_sleep_charge_supported = 0;
823
824 if (!sci_open(dev))
825 return;
826
827 status = tci_raw(dev, in, out);
828 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
829 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
830 sci_close(dev);
831 return;
832 } else if (out[0] == TOS_NOT_SUPPORTED) {
833 pr_info("USB Sleep and Charge not supported\n");
834 sci_close(dev);
835 return;
836 } else if (out[0] == TOS_SUCCESS) {
837 dev->usbsc_mode_base = out[4];
838 }
839
840 in[5] = SCI_USB_CHARGE_BAT_LVL;
841 status = tci_raw(dev, in, out);
842 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
843 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
844 sci_close(dev);
845 return;
846 } else if (out[0] == TOS_NOT_SUPPORTED) {
847 pr_info("USB Sleep and Charge not supported\n");
848 sci_close(dev);
849 return;
850 } else if (out[0] == TOS_SUCCESS) {
851 dev->usbsc_bat_level = out[2];
852 /*
853 * If we reach this point, it means that the laptop has support
854 * for this feature and all values are initialized.
855 * Set it as supported.
856 */
857 dev->usb_sleep_charge_supported = 1;
858 }
859
860 sci_close(dev);
861}
862
Azael Avalose26ffe52015-01-18 18:30:22 -0700863static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
864 u32 *mode)
865{
866 u32 result;
867
868 if (!sci_open(dev))
869 return -EIO;
870
871 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
872 sci_close(dev);
873 if (result == TOS_FAILURE) {
874 pr_err("ACPI call to set USB S&C mode failed\n");
875 return -EIO;
876 } else if (result == TOS_NOT_SUPPORTED) {
877 pr_info("USB Sleep and Charge not supported\n");
878 return -ENODEV;
879 } else if (result == TOS_INPUT_DATA_ERROR) {
880 return -EIO;
881 }
882
883 return 0;
884}
885
886static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
887 u32 mode)
888{
889 u32 result;
890
891 if (!sci_open(dev))
892 return -EIO;
893
894 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
895 sci_close(dev);
896 if (result == TOS_FAILURE) {
897 pr_err("ACPI call to set USB S&C mode failed\n");
898 return -EIO;
899 } else if (result == TOS_NOT_SUPPORTED) {
900 pr_info("USB Sleep and Charge not supported\n");
901 return -ENODEV;
902 } else if (result == TOS_INPUT_DATA_ERROR) {
903 return -EIO;
904 }
905
906 return 0;
907}
908
Azael Avalos182bcaa2015-01-18 18:30:23 -0700909static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
910 u32 *mode)
911{
912 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
913 u32 out[TCI_WORDS];
914 acpi_status status;
915
916 if (!sci_open(dev))
917 return -EIO;
918
919 in[5] = SCI_USB_CHARGE_BAT_LVL;
920 status = tci_raw(dev, in, out);
921 sci_close(dev);
922 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
923 pr_err("ACPI call to get USB S&C battery level failed\n");
924 return -EIO;
925 } else if (out[0] == TOS_NOT_SUPPORTED) {
926 pr_info("USB Sleep and Charge not supported\n");
927 return -ENODEV;
928 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
929 return -EIO;
930 }
931
932 *mode = out[2];
933
934 return 0;
935}
936
937static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
938 u32 mode)
939{
940 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
941 u32 out[TCI_WORDS];
942 acpi_status status;
943
944 if (!sci_open(dev))
945 return -EIO;
946
947 in[2] = mode;
948 in[5] = SCI_USB_CHARGE_BAT_LVL;
949 status = tci_raw(dev, in, out);
950 sci_close(dev);
951 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
952 pr_err("ACPI call to set USB S&C battery level failed\n");
953 return -EIO;
954 } else if (out[0] == TOS_NOT_SUPPORTED) {
955 pr_info("USB Sleep and Charge not supported\n");
956 return -ENODEV;
957 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
958 return -EIO;
959 }
960
961 return 0;
962}
963
Azael Avalosbb3fe012015-01-18 18:30:24 -0700964static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
965 u32 *state)
966{
967 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
968 u32 out[TCI_WORDS];
969 acpi_status status;
970
971 if (!sci_open(dev))
972 return -EIO;
973
974 in[5] = SCI_USB_CHARGE_RAPID_DSP;
975 status = tci_raw(dev, in, out);
976 sci_close(dev);
977 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600978 pr_err("ACPI call to get USB Rapid Charge failed\n");
Azael Avalosbb3fe012015-01-18 18:30:24 -0700979 return -EIO;
980 } else if (out[0] == TOS_NOT_SUPPORTED ||
981 out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600982 pr_info("USB Rapid Charge not supported\n");
Azael Avalosbb3fe012015-01-18 18:30:24 -0700983 return -ENODEV;
984 }
985
986 *state = out[2];
987
988 return 0;
989}
990
991static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
992 u32 state)
993{
994 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
995 u32 out[TCI_WORDS];
996 acpi_status status;
997
998 if (!sci_open(dev))
999 return -EIO;
1000
1001 in[2] = state;
1002 in[5] = SCI_USB_CHARGE_RAPID_DSP;
1003 status = tci_raw(dev, in, out);
1004 sci_close(dev);
1005 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalosbb26f182015-04-02 19:26:21 -06001006 pr_err("ACPI call to set USB Rapid Charge failed\n");
Azael Avalosbb3fe012015-01-18 18:30:24 -07001007 return -EIO;
1008 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosbb26f182015-04-02 19:26:21 -06001009 pr_info("USB Rapid Charge not supported\n");
Azael Avalosbb3fe012015-01-18 18:30:24 -07001010 return -ENODEV;
1011 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
1012 return -EIO;
1013 }
1014
1015 return 0;
1016}
1017
Azael Avalos172ce0a2015-01-18 18:30:25 -07001018static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
1019{
1020 u32 result;
1021
1022 if (!sci_open(dev))
1023 return -EIO;
1024
1025 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
1026 sci_close(dev);
1027 if (result == TOS_FAILURE) {
Azael Avalosbb26f182015-04-02 19:26:21 -06001028 pr_err("ACPI call to get Sleep and Music failed\n");
Azael Avalos172ce0a2015-01-18 18:30:25 -07001029 return -EIO;
1030 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosbb26f182015-04-02 19:26:21 -06001031 pr_info("Sleep and Music not supported\n");
Azael Avalos172ce0a2015-01-18 18:30:25 -07001032 return -ENODEV;
1033 } else if (result == TOS_INPUT_DATA_ERROR) {
1034 return -EIO;
1035 }
1036
1037 return 0;
1038}
1039
1040static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
1041{
1042 u32 result;
1043
1044 if (!sci_open(dev))
1045 return -EIO;
1046
1047 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
1048 sci_close(dev);
1049 if (result == TOS_FAILURE) {
Azael Avalosbb26f182015-04-02 19:26:21 -06001050 pr_err("ACPI call to set Sleep and Music failed\n");
Azael Avalos172ce0a2015-01-18 18:30:25 -07001051 return -EIO;
1052 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosbb26f182015-04-02 19:26:21 -06001053 pr_info("Sleep and Music not supported\n");
Azael Avalos172ce0a2015-01-18 18:30:25 -07001054 return -ENODEV;
1055 } else if (result == TOS_INPUT_DATA_ERROR) {
1056 return -EIO;
1057 }
1058
1059 return 0;
1060}
1061
Azael Avalosbae84192015-02-10 21:09:18 -07001062/* Keyboard function keys */
1063static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
1064{
1065 u32 result;
1066
1067 if (!sci_open(dev))
1068 return -EIO;
1069
1070 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
1071 sci_close(dev);
1072 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1073 pr_err("ACPI call to get KBD function keys failed\n");
1074 return -EIO;
1075 } else if (result == TOS_NOT_SUPPORTED) {
1076 pr_info("KBD function keys not supported\n");
1077 return -ENODEV;
1078 }
1079
1080 return 0;
1081}
1082
1083static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1084{
1085 u32 result;
1086
1087 if (!sci_open(dev))
1088 return -EIO;
1089
1090 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1091 sci_close(dev);
1092 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1093 pr_err("ACPI call to set KBD function keys failed\n");
1094 return -EIO;
1095 } else if (result == TOS_NOT_SUPPORTED) {
1096 pr_info("KBD function keys not supported\n");
1097 return -ENODEV;
1098 }
1099
1100 return 0;
1101}
1102
Azael Avalos35d53ce2015-02-10 21:09:19 -07001103/* Panel Power ON */
1104static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1105{
1106 u32 result;
1107
1108 if (!sci_open(dev))
1109 return -EIO;
1110
1111 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1112 sci_close(dev);
1113 if (result == TOS_FAILURE) {
1114 pr_err("ACPI call to get Panel Power ON failed\n");
1115 return -EIO;
1116 } else if (result == TOS_NOT_SUPPORTED) {
1117 pr_info("Panel Power on not supported\n");
1118 return -ENODEV;
1119 } else if (result == TOS_INPUT_DATA_ERROR) {
1120 return -EIO;
1121 }
1122
1123 return 0;
1124}
1125
1126static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1127{
1128 u32 result;
1129
1130 if (!sci_open(dev))
1131 return -EIO;
1132
1133 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1134 sci_close(dev);
1135 if (result == TOS_FAILURE) {
1136 pr_err("ACPI call to set Panel Power ON failed\n");
1137 return -EIO;
1138 } else if (result == TOS_NOT_SUPPORTED) {
1139 pr_info("Panel Power ON not supported\n");
1140 return -ENODEV;
1141 } else if (result == TOS_INPUT_DATA_ERROR) {
1142 return -EIO;
1143 }
1144
1145 return 0;
1146}
1147
Azael Avalos17fe4b32015-02-10 21:09:20 -07001148/* USB Three */
1149static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1150{
1151 u32 result;
1152
1153 if (!sci_open(dev))
1154 return -EIO;
1155
1156 result = sci_read(dev, SCI_USB_THREE, state);
1157 sci_close(dev);
1158 if (result == TOS_FAILURE) {
1159 pr_err("ACPI call to get USB 3 failed\n");
1160 return -EIO;
1161 } else if (result == TOS_NOT_SUPPORTED) {
1162 pr_info("USB 3 not supported\n");
1163 return -ENODEV;
1164 } else if (result == TOS_INPUT_DATA_ERROR) {
1165 return -EIO;
1166 }
1167
1168 return 0;
1169}
1170
1171static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1172{
1173 u32 result;
1174
1175 if (!sci_open(dev))
1176 return -EIO;
1177
1178 result = sci_write(dev, SCI_USB_THREE, state);
1179 sci_close(dev);
1180 if (result == TOS_FAILURE) {
1181 pr_err("ACPI call to set USB 3 failed\n");
1182 return -EIO;
1183 } else if (result == TOS_NOT_SUPPORTED) {
1184 pr_info("USB 3 not supported\n");
1185 return -ENODEV;
1186 } else if (result == TOS_INPUT_DATA_ERROR) {
1187 return -EIO;
1188 }
1189
1190 return 0;
1191}
1192
Azael Avalos56e6b352015-03-20 16:55:16 -06001193/* Hotkey Event type */
1194static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1195 u32 *type)
1196{
1197 u32 val1 = 0x03;
1198 u32 val2 = 0;
1199 u32 result;
1200
1201 result = hci_read2(dev, HCI_SYSTEM_INFO, &val1, &val2);
1202 if (result == TOS_FAILURE) {
1203 pr_err("ACPI call to get System type failed\n");
1204 return -EIO;
1205 } else if (result == TOS_NOT_SUPPORTED) {
1206 pr_info("System type not supported\n");
1207 return -ENODEV;
1208 }
1209
1210 *type = val2;
1211
1212 return 0;
1213}
1214
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001215/* Bluetooth rfkill handlers */
1216
Seth Forshee135740d2011-09-20 16:55:49 -05001217static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001218{
1219 u32 hci_result;
1220 u32 value, value2;
1221
1222 value = 0;
1223 value2 = 0;
Azael Avalos893f3f62014-09-29 20:40:09 -06001224 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001225 if (hci_result == TOS_SUCCESS)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001226 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
1227
1228 return hci_result;
1229}
1230
Seth Forshee135740d2011-09-20 16:55:49 -05001231static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001232{
1233 u32 hci_result;
1234 u32 value, value2;
1235
1236 value = 0;
1237 value2 = 0x0001;
Azael Avalos893f3f62014-09-29 20:40:09 -06001238 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001239
1240 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
1241 return hci_result;
1242}
1243
Johannes Berg19d337d2009-06-02 13:01:37 +02001244static int bt_rfkill_set_block(void *data, bool blocked)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001245{
Johannes Berg19d337d2009-06-02 13:01:37 +02001246 struct toshiba_acpi_dev *dev = data;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001247 u32 result1, result2;
1248 u32 value;
Johannes Berg19d337d2009-06-02 13:01:37 +02001249 int err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001250 bool radio_state;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001251
Johannes Berg19d337d2009-06-02 13:01:37 +02001252 value = (blocked == false);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001253
1254 mutex_lock(&dev->mutex);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001255 if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) {
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001256 err = -EIO;
Johannes Berg19d337d2009-06-02 13:01:37 +02001257 goto out;
1258 }
1259
1260 if (!radio_state) {
1261 err = 0;
1262 goto out;
1263 }
1264
Azael Avalos893f3f62014-09-29 20:40:09 -06001265 result1 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER);
1266 result2 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001267
Azael Avalos1864bbc2014-09-29 20:40:08 -06001268 if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001269 err = -EIO;
Johannes Berg19d337d2009-06-02 13:01:37 +02001270 else
1271 err = 0;
1272 out:
1273 mutex_unlock(&dev->mutex);
1274 return err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001275}
1276
Johannes Berg19d337d2009-06-02 13:01:37 +02001277static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001278{
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001279 bool new_rfk_state;
1280 bool value;
1281 u32 hci_result;
Johannes Berg19d337d2009-06-02 13:01:37 +02001282 struct toshiba_acpi_dev *dev = data;
1283
1284 mutex_lock(&dev->mutex);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001285
Seth Forshee135740d2011-09-20 16:55:49 -05001286 hci_result = hci_get_radio_state(dev, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001287 if (hci_result != TOS_SUCCESS) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001288 /* Can't do anything useful */
1289 mutex_unlock(&dev->mutex);
Jiri Slaby82e77842009-08-06 15:57:51 -07001290 return;
Johannes Berg19d337d2009-06-02 13:01:37 +02001291 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001292
1293 new_rfk_state = value;
1294
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001295 mutex_unlock(&dev->mutex);
1296
Johannes Berg19d337d2009-06-02 13:01:37 +02001297 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
1298 bt_rfkill_set_block(data, true);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001299}
1300
Johannes Berg19d337d2009-06-02 13:01:37 +02001301static const struct rfkill_ops toshiba_rfk_ops = {
1302 .set_block = bt_rfkill_set_block,
1303 .poll = bt_rfkill_poll,
1304};
1305
Akio Idehara121b7b02012-04-06 01:46:43 +09001306static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
1307{
1308 u32 hci_result;
1309 u32 status;
1310
Azael Avalos893f3f62014-09-29 20:40:09 -06001311 hci_result = hci_read1(dev, HCI_TR_BACKLIGHT, &status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001312 *enabled = !status;
Azael Avalos1864bbc2014-09-29 20:40:08 -06001313 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001314}
1315
1316static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
1317{
1318 u32 hci_result;
1319 u32 value = !enable;
1320
Azael Avalos893f3f62014-09-29 20:40:09 -06001321 hci_result = hci_write1(dev, HCI_TR_BACKLIGHT, value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001322 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001323}
1324
Azael Avalosb5163992015-02-10 23:43:56 -07001325static struct proc_dir_entry *toshiba_proc_dir /*= 0*/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Seth Forshee62cce752012-04-19 11:23:50 -05001327static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
1329 u32 hci_result;
1330 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001331 int brightness = 0;
1332
1333 if (dev->tr_backlight_supported) {
1334 bool enabled;
1335 int ret = get_tr_backlight_status(dev, &enabled);
Azael Avalosb5163992015-02-10 23:43:56 -07001336
Akio Idehara121b7b02012-04-06 01:46:43 +09001337 if (ret)
1338 return ret;
1339 if (enabled)
1340 return 0;
1341 brightness++;
1342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Azael Avalos893f3f62014-09-29 20:40:09 -06001344 hci_result = hci_read1(dev, HCI_LCD_BRIGHTNESS, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001345 if (hci_result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +09001346 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001347
1348 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001349}
1350
Seth Forshee62cce752012-04-19 11:23:50 -05001351static int get_lcd_brightness(struct backlight_device *bd)
1352{
1353 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001354
Seth Forshee62cce752012-04-19 11:23:50 -05001355 return __get_lcd_brightness(dev);
1356}
1357
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001358static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -07001359{
Seth Forshee135740d2011-09-20 16:55:49 -05001360 struct toshiba_acpi_dev *dev = m->private;
1361 int value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001362 int levels;
Holger Machtc9263552006-10-20 14:30:29 -07001363
Seth Forshee135740d2011-09-20 16:55:49 -05001364 if (!dev->backlight_dev)
1365 return -ENODEV;
1366
Akio Idehara121b7b02012-04-06 01:46:43 +09001367 levels = dev->backlight_dev->props.max_brightness + 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001368 value = get_lcd_brightness(dev->backlight_dev);
Holger Machtc9263552006-10-20 14:30:29 -07001369 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001370 seq_printf(m, "brightness: %d\n", value);
Akio Idehara121b7b02012-04-06 01:46:43 +09001371 seq_printf(m, "brightness_levels: %d\n", levels);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001372 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 }
1374
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001375 pr_err("Error reading LCD brightness\n");
1376 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001377}
1378
1379static int lcd_proc_open(struct inode *inode, struct file *file)
1380{
Al Virod9dda782013-03-31 18:16:14 -04001381 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
Seth Forshee62cce752012-04-19 11:23:50 -05001384static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -07001385{
Azael Avalosa39f46d2014-11-24 19:29:36 -07001386 u32 hci_result;
Holger Machtc9263552006-10-20 14:30:29 -07001387
Akio Idehara121b7b02012-04-06 01:46:43 +09001388 if (dev->tr_backlight_supported) {
1389 bool enable = !value;
1390 int ret = set_tr_backlight_status(dev, enable);
Azael Avalosb5163992015-02-10 23:43:56 -07001391
Akio Idehara121b7b02012-04-06 01:46:43 +09001392 if (ret)
1393 return ret;
1394 if (value)
1395 value--;
1396 }
1397
Azael Avalosa39f46d2014-11-24 19:29:36 -07001398 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
1399 hci_result = hci_write1(dev, HCI_LCD_BRIGHTNESS, value);
1400 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001401}
1402
1403static int set_lcd_status(struct backlight_device *bd)
1404{
Seth Forshee135740d2011-09-20 16:55:49 -05001405 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001406
Seth Forshee62cce752012-04-19 11:23:50 -05001407 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -07001408}
1409
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001410static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1411 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
Al Virod9dda782013-03-31 18:16:14 -04001413 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001414 char cmd[42];
1415 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -08001417 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +09001418 int levels = dev->backlight_dev->props.max_brightness + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001420 len = min(count, sizeof(cmd) - 1);
1421 if (copy_from_user(cmd, buf, len))
1422 return -EFAULT;
1423 cmd[len] = '\0';
1424
1425 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Akio Idehara121b7b02012-04-06 01:46:43 +09001426 value >= 0 && value < levels) {
Seth Forshee62cce752012-04-19 11:23:50 -05001427 ret = set_lcd_brightness(dev, value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -08001428 if (ret == 0)
1429 ret = count;
1430 } else {
Holger Machtc9263552006-10-20 14:30:29 -07001431 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -08001432 }
Holger Machtc9263552006-10-20 14:30:29 -07001433 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434}
1435
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001436static const struct file_operations lcd_proc_fops = {
1437 .owner = THIS_MODULE,
1438 .open = lcd_proc_open,
1439 .read = seq_read,
1440 .llseek = seq_lseek,
1441 .release = single_release,
1442 .write = lcd_proc_write,
1443};
1444
Seth Forshee36d03f92011-09-20 16:55:53 -05001445static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1446{
1447 u32 hci_result;
1448
Azael Avalos893f3f62014-09-29 20:40:09 -06001449 hci_result = hci_read1(dev, HCI_VIDEO_OUT, status);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001450 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001451}
1452
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001453static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
Seth Forshee135740d2011-09-20 16:55:49 -05001455 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 u32 value;
Seth Forshee36d03f92011-09-20 16:55:53 -05001457 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Seth Forshee36d03f92011-09-20 16:55:53 -05001459 ret = get_video_status(dev, &value);
1460 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1462 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001463 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001464
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001465 seq_printf(m, "lcd_out: %d\n", is_lcd);
1466 seq_printf(m, "crt_out: %d\n", is_crt);
1467 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 }
1469
Seth Forshee36d03f92011-09-20 16:55:53 -05001470 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471}
1472
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001473static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
Al Virod9dda782013-03-31 18:16:14 -04001475 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001476}
1477
1478static ssize_t video_proc_write(struct file *file, const char __user *buf,
1479 size_t count, loff_t *pos)
1480{
Al Virod9dda782013-03-31 18:16:14 -04001481 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001482 char *cmd, *buffer;
Seth Forshee36d03f92011-09-20 16:55:53 -05001483 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 int value;
1485 int remain = count;
1486 int lcd_out = -1;
1487 int crt_out = -1;
1488 int tv_out = -1;
Al Virob4482a42007-10-14 19:35:40 +01001489 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001491 cmd = kmalloc(count + 1, GFP_KERNEL);
1492 if (!cmd)
1493 return -ENOMEM;
1494 if (copy_from_user(cmd, buf, count)) {
1495 kfree(cmd);
1496 return -EFAULT;
1497 }
1498 cmd[count] = '\0';
1499
1500 buffer = cmd;
1501
Darren Harte0769fe2015-02-11 20:50:08 -08001502 /*
1503 * Scan expression. Multiple expressions may be delimited with ;
1504 * NOTE: To keep scanning simple, invalid fields are ignored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 */
1506 while (remain) {
1507 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1508 lcd_out = value & 1;
1509 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1510 crt_out = value & 1;
1511 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1512 tv_out = value & 1;
Darren Harte0769fe2015-02-11 20:50:08 -08001513 /* Advance to one character past the next ; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 do {
1515 ++buffer;
1516 --remain;
Azael Avalosb5163992015-02-10 23:43:56 -07001517 } while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 }
1519
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001520 kfree(cmd);
1521
Seth Forshee36d03f92011-09-20 16:55:53 -05001522 ret = get_video_status(dev, &video_out);
1523 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001524 unsigned int new_video_out = video_out;
Azael Avalosb5163992015-02-10 23:43:56 -07001525
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 if (lcd_out != -1)
1527 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1528 if (crt_out != -1)
1529 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1530 if (tv_out != -1)
1531 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
Darren Harte0769fe2015-02-11 20:50:08 -08001532 /*
1533 * To avoid unnecessary video disruption, only write the new
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 * video setting if something changed. */
1535 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001536 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 }
1538
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001539 return ret ? ret : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540}
1541
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001542static const struct file_operations video_proc_fops = {
1543 .owner = THIS_MODULE,
1544 .open = video_proc_open,
1545 .read = seq_read,
1546 .llseek = seq_lseek,
1547 .release = single_release,
1548 .write = video_proc_write,
1549};
1550
Seth Forshee36d03f92011-09-20 16:55:53 -05001551static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1552{
1553 u32 hci_result;
1554
Azael Avalos893f3f62014-09-29 20:40:09 -06001555 hci_result = hci_read1(dev, HCI_FAN, status);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001556 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001557}
1558
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001559static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560{
Seth Forshee135740d2011-09-20 16:55:49 -05001561 struct toshiba_acpi_dev *dev = m->private;
Seth Forshee36d03f92011-09-20 16:55:53 -05001562 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 u32 value;
1564
Seth Forshee36d03f92011-09-20 16:55:53 -05001565 ret = get_fan_status(dev, &value);
1566 if (!ret) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001567 seq_printf(m, "running: %d\n", (value > 0));
Seth Forshee135740d2011-09-20 16:55:49 -05001568 seq_printf(m, "force_on: %d\n", dev->force_fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 }
1570
Seth Forshee36d03f92011-09-20 16:55:53 -05001571 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572}
1573
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001574static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
Al Virod9dda782013-03-31 18:16:14 -04001576 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001577}
1578
1579static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1580 size_t count, loff_t *pos)
1581{
Al Virod9dda782013-03-31 18:16:14 -04001582 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001583 char cmd[42];
1584 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 int value;
1586 u32 hci_result;
1587
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001588 len = min(count, sizeof(cmd) - 1);
1589 if (copy_from_user(cmd, buf, len))
1590 return -EFAULT;
1591 cmd[len] = '\0';
1592
1593 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
Len Brown4be44fc2005-08-05 00:44:28 -04001594 value >= 0 && value <= 1) {
Azael Avalos893f3f62014-09-29 20:40:09 -06001595 hci_result = hci_write1(dev, HCI_FAN, value);
Azael Avalosb5163992015-02-10 23:43:56 -07001596 if (hci_result == TOS_SUCCESS)
Seth Forshee135740d2011-09-20 16:55:49 -05001597 dev->force_fan = value;
Azael Avalosb5163992015-02-10 23:43:56 -07001598 else
1599 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 } else {
1601 return -EINVAL;
1602 }
1603
1604 return count;
1605}
1606
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001607static const struct file_operations fan_proc_fops = {
1608 .owner = THIS_MODULE,
1609 .open = fan_proc_open,
1610 .read = seq_read,
1611 .llseek = seq_lseek,
1612 .release = single_release,
1613 .write = fan_proc_write,
1614};
1615
1616static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
Seth Forshee135740d2011-09-20 16:55:49 -05001618 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 u32 hci_result;
1620 u32 value;
1621
Seth Forshee11948b92011-11-16 17:37:45 -06001622 if (!dev->key_event_valid && dev->system_event_supported) {
Azael Avalos893f3f62014-09-29 20:40:09 -06001623 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001624 if (hci_result == TOS_SUCCESS) {
Seth Forshee135740d2011-09-20 16:55:49 -05001625 dev->key_event_valid = 1;
1626 dev->last_key_event = value;
Azael Avalos1864bbc2014-09-29 20:40:08 -06001627 } else if (hci_result == TOS_FIFO_EMPTY) {
Darren Harte0769fe2015-02-11 20:50:08 -08001628 /* Better luck next time */
Azael Avalos1864bbc2014-09-29 20:40:08 -06001629 } else if (hci_result == TOS_NOT_SUPPORTED) {
Darren Harte0769fe2015-02-11 20:50:08 -08001630 /*
1631 * This is a workaround for an unresolved issue on
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 * some machines where system events sporadically
Darren Harte0769fe2015-02-11 20:50:08 -08001633 * become disabled.
1634 */
Azael Avalos893f3f62014-09-29 20:40:09 -06001635 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
Joe Perches7e334602011-03-29 15:21:52 -07001636 pr_notice("Re-enabled hotkeys\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 } else {
Joe Perches7e334602011-03-29 15:21:52 -07001638 pr_err("Error reading hotkey status\n");
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001639 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 }
1641 }
1642
Seth Forshee135740d2011-09-20 16:55:49 -05001643 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1644 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001645 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646}
1647
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001648static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649{
Al Virod9dda782013-03-31 18:16:14 -04001650 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001651}
1652
1653static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1654 size_t count, loff_t *pos)
1655{
Al Virod9dda782013-03-31 18:16:14 -04001656 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001657 char cmd[42];
1658 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 int value;
1660
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001661 len = min(count, sizeof(cmd) - 1);
1662 if (copy_from_user(cmd, buf, len))
1663 return -EFAULT;
1664 cmd[len] = '\0';
1665
Azael Avalosb5163992015-02-10 23:43:56 -07001666 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
Seth Forshee135740d2011-09-20 16:55:49 -05001667 dev->key_event_valid = 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001668 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671 return count;
1672}
1673
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001674static const struct file_operations keys_proc_fops = {
1675 .owner = THIS_MODULE,
1676 .open = keys_proc_open,
1677 .read = seq_read,
1678 .llseek = seq_lseek,
1679 .release = single_release,
1680 .write = keys_proc_write,
1681};
1682
1683static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001685 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1686 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1687 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688}
1689
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001690static int version_proc_open(struct inode *inode, struct file *file)
1691{
Al Virod9dda782013-03-31 18:16:14 -04001692 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001693}
1694
1695static const struct file_operations version_proc_fops = {
1696 .owner = THIS_MODULE,
1697 .open = version_proc_open,
1698 .read = seq_read,
1699 .llseek = seq_lseek,
1700 .release = single_release,
1701};
1702
Darren Harte0769fe2015-02-11 20:50:08 -08001703/*
1704 * Proc and module init
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 */
1706
1707#define PROC_TOSHIBA "toshiba"
1708
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001709static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710{
Seth Forshee36d03f92011-09-20 16:55:53 -05001711 if (dev->backlight_dev)
1712 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1713 &lcd_proc_fops, dev);
1714 if (dev->video_supported)
1715 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1716 &video_proc_fops, dev);
1717 if (dev->fan_supported)
1718 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1719 &fan_proc_fops, dev);
1720 if (dev->hotkey_dev)
1721 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1722 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001723 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1724 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725}
1726
Seth Forshee36d03f92011-09-20 16:55:53 -05001727static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728{
Seth Forshee36d03f92011-09-20 16:55:53 -05001729 if (dev->backlight_dev)
1730 remove_proc_entry("lcd", toshiba_proc_dir);
1731 if (dev->video_supported)
1732 remove_proc_entry("video", toshiba_proc_dir);
1733 if (dev->fan_supported)
1734 remove_proc_entry("fan", toshiba_proc_dir);
1735 if (dev->hotkey_dev)
1736 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001737 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738}
1739
Lionel Debrouxacc24722010-11-16 14:14:02 +01001740static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001741 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001742 .get_brightness = get_lcd_brightness,
1743 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001744};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001745
Azael Avalos360f0f32014-03-25 20:38:31 -06001746/*
1747 * Sysfs files
1748 */
Azael Avalos9d309842015-02-10 23:43:59 -07001749static ssize_t version_show(struct device *dev,
1750 struct device_attribute *attr, char *buf)
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001751{
1752 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1753}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001754static DEVICE_ATTR_RO(version);
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001755
Azael Avalos9d309842015-02-10 23:43:59 -07001756static ssize_t fan_store(struct device *dev,
1757 struct device_attribute *attr,
1758 const char *buf, size_t count)
Azael Avalos94477d42015-02-10 21:09:17 -07001759{
1760 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1761 u32 result;
1762 int state;
1763 int ret;
1764
1765 ret = kstrtoint(buf, 0, &state);
1766 if (ret)
1767 return ret;
1768
1769 if (state != 0 && state != 1)
1770 return -EINVAL;
1771
1772 result = hci_write1(toshiba, HCI_FAN, state);
1773 if (result == TOS_FAILURE)
1774 return -EIO;
1775 else if (result == TOS_NOT_SUPPORTED)
1776 return -ENODEV;
1777
1778 return count;
1779}
1780
Azael Avalos9d309842015-02-10 23:43:59 -07001781static ssize_t fan_show(struct device *dev,
1782 struct device_attribute *attr, char *buf)
Azael Avalos94477d42015-02-10 21:09:17 -07001783{
1784 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1785 u32 value;
1786 int ret;
1787
1788 ret = get_fan_status(toshiba, &value);
1789 if (ret)
1790 return ret;
1791
1792 return sprintf(buf, "%d\n", value);
1793}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001794static DEVICE_ATTR_RW(fan);
Azael Avalos94477d42015-02-10 21:09:17 -07001795
Azael Avalos9d309842015-02-10 23:43:59 -07001796static ssize_t kbd_backlight_mode_store(struct device *dev,
1797 struct device_attribute *attr,
1798 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001799{
1800 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001801 int mode;
1802 int time;
1803 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001804
Dan Carpenteraeaac092014-09-03 14:44:37 +03001805
1806 ret = kstrtoint(buf, 0, &mode);
1807 if (ret)
1808 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001809
1810 /* Check for supported modes depending on keyboard backlight type */
1811 if (toshiba->kbd_type == 1) {
1812 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1813 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1814 return -EINVAL;
1815 } else if (toshiba->kbd_type == 2) {
1816 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1817 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1818 mode != SCI_KBD_MODE_OFF)
1819 return -EINVAL;
1820 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001821
Darren Harte0769fe2015-02-11 20:50:08 -08001822 /*
1823 * Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001824 * Auto - KBD backlight turns off automatically in given time
1825 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001826 * ON - KBD backlight is always on
1827 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001828 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001829
1830 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001831 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001832 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001833 time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001834
1835 /* OR the "base time" to the actual method format */
1836 if (toshiba->kbd_type == 1) {
1837 /* Type 1 requires the current mode */
1838 time |= toshiba->kbd_mode;
1839 } else if (toshiba->kbd_type == 2) {
1840 /* Type 2 requires the desired mode */
1841 time |= mode;
1842 }
1843
Dan Carpenteraeaac092014-09-03 14:44:37 +03001844 ret = toshiba_kbd_illum_status_set(toshiba, time);
1845 if (ret)
1846 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001847
Azael Avalos360f0f32014-03-25 20:38:31 -06001848 toshiba->kbd_mode = mode;
1849 }
1850
1851 return count;
1852}
1853
Azael Avalos9d309842015-02-10 23:43:59 -07001854static ssize_t kbd_backlight_mode_show(struct device *dev,
1855 struct device_attribute *attr,
1856 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001857{
1858 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1859 u32 time;
1860
1861 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1862 return -EIO;
1863
Azael Avalos93f8c162014-09-12 18:50:36 -06001864 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1865}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001866static DEVICE_ATTR_RW(kbd_backlight_mode);
Azael Avalos93f8c162014-09-12 18:50:36 -06001867
Azael Avalos9d309842015-02-10 23:43:59 -07001868static ssize_t kbd_type_show(struct device *dev,
1869 struct device_attribute *attr, char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001870{
1871 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1872
1873 return sprintf(buf, "%d\n", toshiba->kbd_type);
1874}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001875static DEVICE_ATTR_RO(kbd_type);
Azael Avalos93f8c162014-09-12 18:50:36 -06001876
Azael Avalos9d309842015-02-10 23:43:59 -07001877static ssize_t available_kbd_modes_show(struct device *dev,
1878 struct device_attribute *attr,
1879 char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001880{
1881 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1882
1883 if (toshiba->kbd_type == 1)
1884 return sprintf(buf, "%x %x\n",
1885 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1886
1887 return sprintf(buf, "%x %x %x\n",
1888 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001889}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001890static DEVICE_ATTR_RO(available_kbd_modes);
Azael Avalos360f0f32014-03-25 20:38:31 -06001891
Azael Avalos9d309842015-02-10 23:43:59 -07001892static ssize_t kbd_backlight_timeout_store(struct device *dev,
1893 struct device_attribute *attr,
1894 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001895{
1896 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001897 int time;
1898 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001899
Azael Avaloseabde0f2014-10-04 12:02:21 -06001900 ret = kstrtoint(buf, 0, &time);
1901 if (ret)
1902 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001903
Azael Avaloseabde0f2014-10-04 12:02:21 -06001904 /* Check for supported values depending on kbd_type */
1905 if (toshiba->kbd_type == 1) {
1906 if (time < 0 || time > 60)
1907 return -EINVAL;
1908 } else if (toshiba->kbd_type == 2) {
1909 if (time < 1 || time > 60)
1910 return -EINVAL;
1911 }
1912
1913 /* Set the Keyboard Backlight Timeout */
1914
1915 /* Only make a change if the actual timeout has changed */
1916 if (toshiba->kbd_time != time) {
1917 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001918 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001919 /* OR the "base time" to the actual method format */
1920 if (toshiba->kbd_type == 1)
1921 time |= SCI_KBD_MODE_FNZ;
1922 else if (toshiba->kbd_type == 2)
1923 time |= SCI_KBD_MODE_AUTO;
1924
1925 ret = toshiba_kbd_illum_status_set(toshiba, time);
1926 if (ret)
1927 return ret;
1928
Azael Avalos360f0f32014-03-25 20:38:31 -06001929 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1930 }
1931
1932 return count;
1933}
1934
Azael Avalos9d309842015-02-10 23:43:59 -07001935static ssize_t kbd_backlight_timeout_show(struct device *dev,
1936 struct device_attribute *attr,
1937 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001938{
1939 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1940 u32 time;
1941
1942 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1943 return -EIO;
1944
1945 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1946}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001947static DEVICE_ATTR_RW(kbd_backlight_timeout);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001948
Azael Avalos9d309842015-02-10 23:43:59 -07001949static ssize_t touchpad_store(struct device *dev,
1950 struct device_attribute *attr,
1951 const char *buf, size_t count)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001952{
1953 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1954 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001955 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001956
1957 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001958 ret = kstrtoint(buf, 0, &state);
1959 if (ret)
1960 return ret;
1961 if (state != 0 && state != 1)
1962 return -EINVAL;
1963
1964 ret = toshiba_touchpad_set(toshiba, state);
1965 if (ret)
1966 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001967
1968 return count;
1969}
1970
Azael Avalos9d309842015-02-10 23:43:59 -07001971static ssize_t touchpad_show(struct device *dev,
1972 struct device_attribute *attr, char *buf)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001973{
1974 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1975 u32 state;
1976 int ret;
1977
1978 ret = toshiba_touchpad_get(toshiba, &state);
1979 if (ret < 0)
1980 return ret;
1981
1982 return sprintf(buf, "%i\n", state);
1983}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001984static DEVICE_ATTR_RW(touchpad);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001985
Azael Avalos9d309842015-02-10 23:43:59 -07001986static ssize_t position_show(struct device *dev,
1987 struct device_attribute *attr, char *buf)
Azael Avalos5a2813e2014-03-25 20:38:34 -06001988{
1989 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1990 u32 xyval, zval, tmp;
1991 u16 x, y, z;
1992 int ret;
1993
1994 xyval = zval = 0;
1995 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1996 if (ret < 0)
1997 return ret;
1998
1999 x = xyval & HCI_ACCEL_MASK;
2000 tmp = xyval >> HCI_MISC_SHIFT;
2001 y = tmp & HCI_ACCEL_MASK;
2002 z = zval & HCI_ACCEL_MASK;
2003
2004 return sprintf(buf, "%d %d %d\n", x, y, z);
2005}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002006static DEVICE_ATTR_RO(position);
Azael Avalos360f0f32014-03-25 20:38:31 -06002007
Azael Avalos9d309842015-02-10 23:43:59 -07002008static ssize_t usb_sleep_charge_show(struct device *dev,
2009 struct device_attribute *attr, char *buf)
Azael Avalose26ffe52015-01-18 18:30:22 -07002010{
2011 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2012 u32 mode;
2013 int ret;
2014
2015 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
2016 if (ret < 0)
2017 return ret;
2018
2019 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
2020}
2021
Azael Avalos9d309842015-02-10 23:43:59 -07002022static ssize_t usb_sleep_charge_store(struct device *dev,
2023 struct device_attribute *attr,
2024 const char *buf, size_t count)
Azael Avalose26ffe52015-01-18 18:30:22 -07002025{
2026 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2027 u32 mode;
2028 int state;
2029 int ret;
2030
2031 ret = kstrtoint(buf, 0, &state);
2032 if (ret)
2033 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002034 /*
2035 * Check for supported values, where:
Azael Avalose26ffe52015-01-18 18:30:22 -07002036 * 0 - Disabled
2037 * 1 - Alternate (Non USB conformant devices that require more power)
2038 * 2 - Auto (USB conformant devices)
Azael Avalosc8c91842015-04-02 19:26:20 -06002039 * 3 - Typical
Azael Avalose26ffe52015-01-18 18:30:22 -07002040 */
Azael Avalosc8c91842015-04-02 19:26:20 -06002041 if (state != 0 && state != 1 && state != 2 && state != 3)
Azael Avalose26ffe52015-01-18 18:30:22 -07002042 return -EINVAL;
2043
2044 /* Set the USB charging mode to internal value */
Azael Avalosc8c91842015-04-02 19:26:20 -06002045 mode = toshiba->usbsc_mode_base;
Azael Avalose26ffe52015-01-18 18:30:22 -07002046 if (state == 0)
Azael Avalosc8c91842015-04-02 19:26:20 -06002047 mode |= SCI_USB_CHARGE_DISABLED;
Azael Avalose26ffe52015-01-18 18:30:22 -07002048 else if (state == 1)
Azael Avalosc8c91842015-04-02 19:26:20 -06002049 mode |= SCI_USB_CHARGE_ALTERNATE;
Azael Avalose26ffe52015-01-18 18:30:22 -07002050 else if (state == 2)
Azael Avalosc8c91842015-04-02 19:26:20 -06002051 mode |= SCI_USB_CHARGE_AUTO;
2052 else if (state == 3)
2053 mode |= SCI_USB_CHARGE_TYPICAL;
Azael Avalose26ffe52015-01-18 18:30:22 -07002054
2055 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
2056 if (ret)
2057 return ret;
2058
2059 return count;
2060}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002061static DEVICE_ATTR_RW(usb_sleep_charge);
Azael Avalose26ffe52015-01-18 18:30:22 -07002062
Azael Avalos182bcaa2015-01-18 18:30:23 -07002063static ssize_t sleep_functions_on_battery_show(struct device *dev,
2064 struct device_attribute *attr,
2065 char *buf)
2066{
2067 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2068 u32 state;
2069 int bat_lvl;
2070 int status;
2071 int ret;
2072 int tmp;
2073
2074 ret = toshiba_sleep_functions_status_get(toshiba, &state);
2075 if (ret < 0)
2076 return ret;
2077
2078 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
2079 tmp = state & SCI_USB_CHARGE_BAT_MASK;
2080 status = (tmp == 0x4) ? 1 : 0;
2081 /* Determine the battery level set */
2082 bat_lvl = state >> HCI_MISC_SHIFT;
2083
2084 return sprintf(buf, "%d %d\n", status, bat_lvl);
2085}
2086
2087static ssize_t sleep_functions_on_battery_store(struct device *dev,
2088 struct device_attribute *attr,
2089 const char *buf, size_t count)
2090{
2091 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2092 u32 status;
2093 int value;
2094 int ret;
2095 int tmp;
2096
2097 ret = kstrtoint(buf, 0, &value);
2098 if (ret)
2099 return ret;
2100
Darren Harte0769fe2015-02-11 20:50:08 -08002101 /*
2102 * Set the status of the function:
Azael Avalos182bcaa2015-01-18 18:30:23 -07002103 * 0 - Disabled
2104 * 1-100 - Enabled
2105 */
2106 if (value < 0 || value > 100)
2107 return -EINVAL;
2108
2109 if (value == 0) {
2110 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
2111 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
2112 } else {
2113 tmp = value << HCI_MISC_SHIFT;
2114 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
2115 }
2116 ret = toshiba_sleep_functions_status_set(toshiba, status);
2117 if (ret < 0)
2118 return ret;
2119
2120 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
2121
2122 return count;
2123}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002124static DEVICE_ATTR_RW(sleep_functions_on_battery);
Azael Avalos182bcaa2015-01-18 18:30:23 -07002125
Azael Avalos9d309842015-02-10 23:43:59 -07002126static ssize_t usb_rapid_charge_show(struct device *dev,
2127 struct device_attribute *attr, char *buf)
Azael Avalosbb3fe012015-01-18 18:30:24 -07002128{
2129 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2130 u32 state;
2131 int ret;
2132
2133 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2134 if (ret < 0)
2135 return ret;
2136
2137 return sprintf(buf, "%d\n", state);
2138}
2139
Azael Avalos9d309842015-02-10 23:43:59 -07002140static ssize_t usb_rapid_charge_store(struct device *dev,
2141 struct device_attribute *attr,
2142 const char *buf, size_t count)
Azael Avalosbb3fe012015-01-18 18:30:24 -07002143{
2144 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2145 int state;
2146 int ret;
2147
2148 ret = kstrtoint(buf, 0, &state);
2149 if (ret)
2150 return ret;
2151 if (state != 0 && state != 1)
2152 return -EINVAL;
2153
2154 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2155 if (ret)
2156 return ret;
2157
2158 return count;
2159}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002160static DEVICE_ATTR_RW(usb_rapid_charge);
Azael Avalosbb3fe012015-01-18 18:30:24 -07002161
Azael Avalos9d309842015-02-10 23:43:59 -07002162static ssize_t usb_sleep_music_show(struct device *dev,
2163 struct device_attribute *attr, char *buf)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002164{
2165 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2166 u32 state;
2167 int ret;
2168
2169 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2170 if (ret < 0)
2171 return ret;
2172
2173 return sprintf(buf, "%d\n", state);
2174}
2175
Azael Avalos9d309842015-02-10 23:43:59 -07002176static ssize_t usb_sleep_music_store(struct device *dev,
2177 struct device_attribute *attr,
2178 const char *buf, size_t count)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002179{
2180 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2181 int state;
2182 int ret;
2183
2184 ret = kstrtoint(buf, 0, &state);
2185 if (ret)
2186 return ret;
2187 if (state != 0 && state != 1)
2188 return -EINVAL;
2189
2190 ret = toshiba_usb_sleep_music_set(toshiba, state);
2191 if (ret)
2192 return ret;
2193
2194 return count;
2195}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002196static DEVICE_ATTR_RW(usb_sleep_music);
Azael Avalos172ce0a2015-01-18 18:30:25 -07002197
Azael Avalos9d309842015-02-10 23:43:59 -07002198static ssize_t kbd_function_keys_show(struct device *dev,
2199 struct device_attribute *attr, char *buf)
Azael Avalosbae84192015-02-10 21:09:18 -07002200{
2201 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2202 int mode;
2203 int ret;
2204
2205 ret = toshiba_function_keys_get(toshiba, &mode);
2206 if (ret < 0)
2207 return ret;
2208
2209 return sprintf(buf, "%d\n", mode);
2210}
2211
Azael Avalos9d309842015-02-10 23:43:59 -07002212static ssize_t kbd_function_keys_store(struct device *dev,
2213 struct device_attribute *attr,
2214 const char *buf, size_t count)
Azael Avalosbae84192015-02-10 21:09:18 -07002215{
2216 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2217 int mode;
2218 int ret;
2219
2220 ret = kstrtoint(buf, 0, &mode);
2221 if (ret)
2222 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002223 /*
2224 * Check for the function keys mode where:
Azael Avalosbae84192015-02-10 21:09:18 -07002225 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2226 * 1 - Special functions (Opposite of the above setting)
2227 */
2228 if (mode != 0 && mode != 1)
2229 return -EINVAL;
2230
2231 ret = toshiba_function_keys_set(toshiba, mode);
2232 if (ret)
2233 return ret;
2234
2235 pr_info("Reboot for changes to KBD Function Keys to take effect");
2236
2237 return count;
2238}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002239static DEVICE_ATTR_RW(kbd_function_keys);
Azael Avalosbae84192015-02-10 21:09:18 -07002240
Azael Avalos9d309842015-02-10 23:43:59 -07002241static ssize_t panel_power_on_show(struct device *dev,
2242 struct device_attribute *attr, char *buf)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002243{
2244 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2245 u32 state;
2246 int ret;
2247
2248 ret = toshiba_panel_power_on_get(toshiba, &state);
2249 if (ret < 0)
2250 return ret;
2251
2252 return sprintf(buf, "%d\n", state);
2253}
2254
Azael Avalos9d309842015-02-10 23:43:59 -07002255static ssize_t panel_power_on_store(struct device *dev,
2256 struct device_attribute *attr,
2257 const char *buf, size_t count)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002258{
2259 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2260 int state;
2261 int ret;
2262
2263 ret = kstrtoint(buf, 0, &state);
2264 if (ret)
2265 return ret;
2266 if (state != 0 && state != 1)
2267 return -EINVAL;
2268
2269 ret = toshiba_panel_power_on_set(toshiba, state);
2270 if (ret)
2271 return ret;
2272
2273 pr_info("Reboot for changes to Panel Power ON to take effect");
2274
2275 return count;
2276}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002277static DEVICE_ATTR_RW(panel_power_on);
Azael Avalos35d53ce2015-02-10 21:09:19 -07002278
Azael Avalos9d309842015-02-10 23:43:59 -07002279static ssize_t usb_three_show(struct device *dev,
2280 struct device_attribute *attr, char *buf)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002281{
2282 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2283 u32 state;
2284 int ret;
2285
2286 ret = toshiba_usb_three_get(toshiba, &state);
2287 if (ret < 0)
2288 return ret;
2289
2290 return sprintf(buf, "%d\n", state);
2291}
2292
Azael Avalos9d309842015-02-10 23:43:59 -07002293static ssize_t usb_three_store(struct device *dev,
2294 struct device_attribute *attr,
2295 const char *buf, size_t count)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002296{
2297 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2298 int state;
2299 int ret;
2300
2301 ret = kstrtoint(buf, 0, &state);
2302 if (ret)
2303 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002304 /*
2305 * Check for USB 3 mode where:
Azael Avalos17fe4b32015-02-10 21:09:20 -07002306 * 0 - Disabled (Acts like a USB 2 port, saving power)
2307 * 1 - Enabled
2308 */
2309 if (state != 0 && state != 1)
2310 return -EINVAL;
2311
2312 ret = toshiba_usb_three_set(toshiba, state);
2313 if (ret)
2314 return ret;
2315
2316 pr_info("Reboot for changes to USB 3 to take effect");
2317
2318 return count;
2319}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002320static DEVICE_ATTR_RW(usb_three);
Azael Avalos9bd12132015-02-10 23:43:58 -07002321
2322static struct attribute *toshiba_attributes[] = {
2323 &dev_attr_version.attr,
2324 &dev_attr_fan.attr,
2325 &dev_attr_kbd_backlight_mode.attr,
2326 &dev_attr_kbd_type.attr,
2327 &dev_attr_available_kbd_modes.attr,
2328 &dev_attr_kbd_backlight_timeout.attr,
2329 &dev_attr_touchpad.attr,
2330 &dev_attr_position.attr,
2331 &dev_attr_usb_sleep_charge.attr,
2332 &dev_attr_sleep_functions_on_battery.attr,
2333 &dev_attr_usb_rapid_charge.attr,
2334 &dev_attr_usb_sleep_music.attr,
2335 &dev_attr_kbd_function_keys.attr,
2336 &dev_attr_panel_power_on.attr,
2337 &dev_attr_usb_three.attr,
2338 NULL,
2339};
2340
Azael Avalos360f0f32014-03-25 20:38:31 -06002341static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2342 struct attribute *attr, int idx)
2343{
2344 struct device *dev = container_of(kobj, struct device, kobj);
2345 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2346 bool exists = true;
2347
Azael Avalos94477d42015-02-10 21:09:17 -07002348 if (attr == &dev_attr_fan.attr)
2349 exists = (drv->fan_supported) ? true : false;
2350 else if (attr == &dev_attr_kbd_backlight_mode.attr)
Azael Avalos360f0f32014-03-25 20:38:31 -06002351 exists = (drv->kbd_illum_supported) ? true : false;
2352 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2353 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06002354 else if (attr == &dev_attr_touchpad.attr)
2355 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06002356 else if (attr == &dev_attr_position.attr)
2357 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalose26ffe52015-01-18 18:30:22 -07002358 else if (attr == &dev_attr_usb_sleep_charge.attr)
2359 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002360 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2361 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalosbb3fe012015-01-18 18:30:24 -07002362 else if (attr == &dev_attr_usb_rapid_charge.attr)
2363 exists = (drv->usb_rapid_charge_supported) ? true : false;
Azael Avalos172ce0a2015-01-18 18:30:25 -07002364 else if (attr == &dev_attr_usb_sleep_music.attr)
2365 exists = (drv->usb_sleep_music_supported) ? true : false;
Azael Avalosbae84192015-02-10 21:09:18 -07002366 else if (attr == &dev_attr_kbd_function_keys.attr)
2367 exists = (drv->kbd_function_keys_supported) ? true : false;
Azael Avalos35d53ce2015-02-10 21:09:19 -07002368 else if (attr == &dev_attr_panel_power_on.attr)
2369 exists = (drv->panel_power_on_supported) ? true : false;
Azael Avalos17fe4b32015-02-10 21:09:20 -07002370 else if (attr == &dev_attr_usb_three.attr)
2371 exists = (drv->usb_three_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06002372
2373 return exists ? attr->mode : 0;
2374}
2375
Azael Avalos9bd12132015-02-10 23:43:58 -07002376static struct attribute_group toshiba_attr_group = {
2377 .is_visible = toshiba_sysfs_is_visible,
2378 .attrs = toshiba_attributes,
2379};
2380
Azael Avalos1f28f292014-12-04 20:22:45 -07002381/*
2382 * Hotkeys
2383 */
2384static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2385{
2386 acpi_status status;
2387 u32 result;
2388
2389 status = acpi_evaluate_object(dev->acpi_dev->handle,
2390 "ENAB", NULL, NULL);
2391 if (ACPI_FAILURE(status))
2392 return -ENODEV;
2393
2394 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2395 if (result == TOS_FAILURE)
2396 return -EIO;
2397 else if (result == TOS_NOT_SUPPORTED)
2398 return -ENODEV;
2399
2400 return 0;
2401}
2402
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002403static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev)
2404{
2405 u32 result;
2406
2407 /*
2408 * Re-activate the hotkeys, but this time, we are using the
2409 * "Special Functions" mode.
2410 */
2411 result = hci_write1(dev, HCI_HOTKEY_EVENT,
2412 HCI_HOTKEY_SPECIAL_FUNCTIONS);
2413 if (result != TOS_SUCCESS)
2414 pr_err("Could not enable the Special Function mode\n");
2415}
2416
Seth Forshee29cd2932012-01-18 13:44:09 -06002417static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2418 struct serio *port)
2419{
Giedrius Statkevičius98280372014-10-18 02:57:20 +03002420 if (str & I8042_STR_AUXDATA)
Seth Forshee29cd2932012-01-18 13:44:09 -06002421 return false;
2422
2423 if (unlikely(data == 0xe0))
2424 return false;
2425
2426 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2427 schedule_work(&toshiba_acpi->hotkey_work);
2428 return true;
2429 }
2430
2431 return false;
2432}
2433
2434static void toshiba_acpi_hotkey_work(struct work_struct *work)
2435{
2436 acpi_handle ec_handle = ec_get_handle();
2437 acpi_status status;
2438
2439 if (!ec_handle)
2440 return;
2441
2442 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2443 if (ACPI_FAILURE(status))
2444 pr_err("ACPI NTFY method execution failed\n");
2445}
2446
2447/*
2448 * Returns hotkey scancode, or < 0 on failure.
2449 */
2450static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2451{
Zhang Rui74facaf2013-09-03 08:32:15 +08002452 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002453 acpi_status status;
2454
Zhang Rui74facaf2013-09-03 08:32:15 +08002455 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2456 NULL, &value);
2457 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002458 pr_err("ACPI INFO method execution failed\n");
2459 return -EIO;
2460 }
2461
Zhang Rui74facaf2013-09-03 08:32:15 +08002462 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002463}
2464
2465static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2466 int scancode)
2467{
2468 if (scancode == 0x100)
2469 return;
2470
Darren Harte0769fe2015-02-11 20:50:08 -08002471 /* Act on key press; ignore key release */
Seth Forshee29cd2932012-01-18 13:44:09 -06002472 if (scancode & 0x80)
2473 return;
2474
2475 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2476 pr_info("Unknown key %x\n", scancode);
2477}
2478
Azael Avalos71454d72014-12-04 20:22:46 -07002479static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2480{
2481 u32 hci_result, value;
2482 int retries = 3;
2483 int scancode;
2484
2485 if (dev->info_supported) {
2486 scancode = toshiba_acpi_query_hotkey(dev);
2487 if (scancode < 0)
2488 pr_err("Failed to query hotkey event\n");
2489 else if (scancode != 0)
2490 toshiba_acpi_report_hotkey(dev, scancode);
2491 } else if (dev->system_event_supported) {
2492 do {
2493 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
2494 switch (hci_result) {
2495 case TOS_SUCCESS:
2496 toshiba_acpi_report_hotkey(dev, (int)value);
2497 break;
2498 case TOS_NOT_SUPPORTED:
2499 /*
2500 * This is a workaround for an unresolved
2501 * issue on some machines where system events
2502 * sporadically become disabled.
2503 */
2504 hci_result =
2505 hci_write1(dev, HCI_SYSTEM_EVENT, 1);
2506 pr_notice("Re-enabled hotkeys\n");
Darren Harte0769fe2015-02-11 20:50:08 -08002507 /* Fall through */
Azael Avalos71454d72014-12-04 20:22:46 -07002508 default:
2509 retries--;
2510 break;
2511 }
2512 } while (retries && hci_result != TOS_FIFO_EMPTY);
2513 }
2514}
2515
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002516static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002517{
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002518 const struct key_entry *keymap = toshiba_acpi_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002519 acpi_handle ec_handle;
2520 u32 events_type;
2521 u32 hci_result;
2522 int error;
2523
2524 error = toshiba_acpi_enable_hotkeys(dev);
2525 if (error)
2526 return error;
2527
2528 error = toshiba_hotkey_event_type_get(dev, &events_type);
2529 if (error) {
2530 pr_err("Unable to query Hotkey Event Type\n");
2531 return error;
2532 }
2533 dev->hotkey_event_type = events_type;
Seth Forshee135740d2011-09-20 16:55:49 -05002534
Seth Forshee135740d2011-09-20 16:55:49 -05002535 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07002536 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002537 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05002538
2539 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05002540 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05002541 dev->hotkey_dev->id.bustype = BUS_HOST;
2542
Azael Avalosa2b34712015-03-20 16:55:17 -06002543 if (events_type == HCI_SYSTEM_TYPE1 ||
2544 !dev->kbd_function_keys_supported)
2545 keymap = toshiba_acpi_keymap;
2546 else if (events_type == HCI_SYSTEM_TYPE2 ||
2547 dev->kbd_function_keys_supported)
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002548 keymap = toshiba_acpi_alt_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002549 else
2550 pr_info("Unknown event type received %x\n", events_type);
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002551 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05002552 if (error)
2553 goto err_free_dev;
2554
Seth Forshee29cd2932012-01-18 13:44:09 -06002555 /*
2556 * For some machines the SCI responsible for providing hotkey
2557 * notification doesn't fire. We can trigger the notification
2558 * whenever the Fn key is pressed using the NTFY method, if
2559 * supported, so if it's present set up an i8042 key filter
2560 * for this purpose.
2561 */
Seth Forshee29cd2932012-01-18 13:44:09 -06002562 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08002563 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002564 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2565
2566 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2567 if (error) {
2568 pr_err("Error installing key filter\n");
2569 goto err_free_keymap;
2570 }
2571
2572 dev->ntfy_supported = 1;
2573 }
2574
2575 /*
2576 * Determine hotkey query interface. Prefer using the INFO
2577 * method when it is available.
2578 */
Zhang Ruie2e19602013-09-03 08:32:06 +08002579 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06002580 dev->info_supported = 1;
Zhang Ruie2e19602013-09-03 08:32:06 +08002581 else {
Azael Avalos893f3f62014-09-29 20:40:09 -06002582 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
Azael Avalos1864bbc2014-09-29 20:40:08 -06002583 if (hci_result == TOS_SUCCESS)
Seth Forshee29cd2932012-01-18 13:44:09 -06002584 dev->system_event_supported = 1;
2585 }
2586
2587 if (!dev->info_supported && !dev->system_event_supported) {
2588 pr_warn("No hotkey query interface found\n");
2589 goto err_remove_filter;
2590 }
2591
Seth Forshee135740d2011-09-20 16:55:49 -05002592 error = input_register_device(dev->hotkey_dev);
2593 if (error) {
2594 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06002595 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05002596 }
2597
2598 return 0;
2599
Seth Forshee29cd2932012-01-18 13:44:09 -06002600 err_remove_filter:
2601 if (dev->ntfy_supported)
2602 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05002603 err_free_keymap:
2604 sparse_keymap_free(dev->hotkey_dev);
2605 err_free_dev:
2606 input_free_device(dev->hotkey_dev);
2607 dev->hotkey_dev = NULL;
2608 return error;
2609}
2610
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002611static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05002612{
2613 struct backlight_properties props;
2614 int brightness;
2615 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +09002616 bool enabled;
Seth Forshee62cce752012-04-19 11:23:50 -05002617
2618 /*
2619 * Some machines don't support the backlight methods at all, and
2620 * others support it read-only. Either of these is pretty useless,
2621 * so only register the backlight device if the backlight method
2622 * supports both reads and writes.
2623 */
2624 brightness = __get_lcd_brightness(dev);
2625 if (brightness < 0)
2626 return 0;
2627 ret = set_lcd_brightness(dev, brightness);
2628 if (ret) {
2629 pr_debug("Backlight method is read-only, disabling backlight support\n");
2630 return 0;
2631 }
2632
Akio Idehara121b7b02012-04-06 01:46:43 +09002633 /* Determine whether or not BIOS supports transflective backlight */
2634 ret = get_tr_backlight_status(dev, &enabled);
2635 dev->tr_backlight_supported = !ret;
2636
Hans de Goede358d6a22015-04-21 12:01:32 +02002637 /*
2638 * Tell acpi-video-detect code to prefer vendor backlight on all
2639 * systems with transflective backlight and on dmi matched systems.
2640 */
2641 if (dev->tr_backlight_supported ||
2642 dmi_check_system(toshiba_vendor_backlight_dmi))
2643 acpi_video_dmi_promote_vendor();
2644
2645 if (acpi_video_backlight_support())
2646 return 0;
2647
2648 /* acpi-video may have loaded before we called dmi_promote_vendor() */
2649 acpi_video_unregister_backlight();
2650
Matthew Garrett53039f22012-06-01 11:02:36 -04002651 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05002652 props.type = BACKLIGHT_PLATFORM;
2653 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05002654
Darren Harte0769fe2015-02-11 20:50:08 -08002655 /* Adding an extra level and having 0 change to transflective mode */
Akio Idehara121b7b02012-04-06 01:46:43 +09002656 if (dev->tr_backlight_supported)
2657 props.max_brightness++;
2658
Seth Forshee62cce752012-04-19 11:23:50 -05002659 dev->backlight_dev = backlight_device_register("toshiba",
2660 &dev->acpi_dev->dev,
2661 dev,
2662 &toshiba_backlight_data,
2663 &props);
2664 if (IS_ERR(dev->backlight_dev)) {
2665 ret = PTR_ERR(dev->backlight_dev);
2666 pr_err("Could not register toshiba backlight device\n");
2667 dev->backlight_dev = NULL;
2668 return ret;
2669 }
2670
2671 dev->backlight_dev->props.brightness = brightness;
2672 return 0;
2673}
2674
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002675static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002676{
2677 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2678
Seth Forshee36d03f92011-09-20 16:55:53 -05002679 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002680
Azael Avalos360f0f32014-03-25 20:38:31 -06002681 if (dev->sysfs_created)
2682 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2683 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05002684
Seth Forshee29cd2932012-01-18 13:44:09 -06002685 if (dev->ntfy_supported) {
2686 i8042_remove_filter(toshiba_acpi_i8042_filter);
2687 cancel_work_sync(&dev->hotkey_work);
2688 }
2689
Seth Forshee135740d2011-09-20 16:55:49 -05002690 if (dev->hotkey_dev) {
2691 input_unregister_device(dev->hotkey_dev);
2692 sparse_keymap_free(dev->hotkey_dev);
2693 }
2694
2695 if (dev->bt_rfk) {
2696 rfkill_unregister(dev->bt_rfk);
2697 rfkill_destroy(dev->bt_rfk);
2698 }
2699
Markus Elfring00981812014-11-24 20:30:29 +01002700 backlight_device_unregister(dev->backlight_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002701
Seth Forshee36d03f92011-09-20 16:55:53 -05002702 if (dev->illumination_supported)
Seth Forshee135740d2011-09-20 16:55:49 -05002703 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002704
Azael Avalos360f0f32014-03-25 20:38:31 -06002705 if (dev->kbd_led_registered)
2706 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002707
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002708 if (dev->eco_supported)
2709 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05002710
Seth Forshee29cd2932012-01-18 13:44:09 -06002711 if (toshiba_acpi)
2712 toshiba_acpi = NULL;
2713
Seth Forshee135740d2011-09-20 16:55:49 -05002714 kfree(dev);
2715
2716 return 0;
2717}
2718
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002719static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05002720{
Zhang Ruie2e19602013-09-03 08:32:06 +08002721 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002722 return "GHCI";
2723
Zhang Ruie2e19602013-09-03 08:32:06 +08002724 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002725 return "SPFC";
2726
2727 return NULL;
2728}
2729
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002730static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002731{
2732 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002733 const char *hci_method;
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002734 u32 special_functions;
Seth Forshee36d03f92011-09-20 16:55:53 -05002735 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05002736 bool bt_present;
2737 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05002738
Seth Forshee29cd2932012-01-18 13:44:09 -06002739 if (toshiba_acpi)
2740 return -EBUSY;
2741
Seth Forshee135740d2011-09-20 16:55:49 -05002742 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2743 TOSHIBA_ACPI_VERSION);
2744
Seth Forsheea540d6b2011-09-20 16:55:52 -05002745 hci_method = find_hci_method(acpi_dev->handle);
2746 if (!hci_method) {
2747 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05002748 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002749 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05002750
Seth Forshee135740d2011-09-20 16:55:49 -05002751 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2752 if (!dev)
2753 return -ENOMEM;
2754 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002755 dev->method_hci = hci_method;
Seth Forshee135740d2011-09-20 16:55:49 -05002756 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06002757 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002758
Azael Avalosa2b34712015-03-20 16:55:17 -06002759 /* Query the BIOS for supported features */
2760
2761 /*
2762 * The "Special Functions" are always supported by the laptops
2763 * with the new keyboard layout, query for its presence to help
2764 * determine the keymap layout to use.
2765 */
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002766 ret = toshiba_function_keys_get(dev, &special_functions);
Azael Avalosa2b34712015-03-20 16:55:17 -06002767 dev->kbd_function_keys_supported = !ret;
2768
Seth Forshee6e02cc72011-09-20 16:55:51 -05002769 if (toshiba_acpi_setup_keyboard(dev))
2770 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05002771
2772 mutex_init(&dev->mutex);
2773
Seth Forshee62cce752012-04-19 11:23:50 -05002774 ret = toshiba_acpi_setup_backlight(dev);
2775 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05002776 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05002777
2778 /* Register rfkill switch for Bluetooth */
Azael Avalos1864bbc2014-09-29 20:40:08 -06002779 if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) {
Seth Forshee135740d2011-09-20 16:55:49 -05002780 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
2781 &acpi_dev->dev,
2782 RFKILL_TYPE_BLUETOOTH,
2783 &toshiba_rfk_ops,
2784 dev);
2785 if (!dev->bt_rfk) {
2786 pr_err("unable to allocate rfkill device\n");
2787 ret = -ENOMEM;
2788 goto error;
2789 }
2790
2791 ret = rfkill_register(dev->bt_rfk);
2792 if (ret) {
2793 pr_err("unable to register rfkill device\n");
2794 rfkill_destroy(dev->bt_rfk);
2795 goto error;
2796 }
2797 }
2798
2799 if (toshiba_illumination_available(dev)) {
2800 dev->led_dev.name = "toshiba::illumination";
2801 dev->led_dev.max_brightness = 1;
2802 dev->led_dev.brightness_set = toshiba_illumination_set;
2803 dev->led_dev.brightness_get = toshiba_illumination_get;
2804 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Seth Forshee36d03f92011-09-20 16:55:53 -05002805 dev->illumination_supported = 1;
Seth Forshee135740d2011-09-20 16:55:49 -05002806 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002807
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002808 if (toshiba_eco_mode_available(dev)) {
2809 dev->eco_led.name = "toshiba::eco_mode";
2810 dev->eco_led.max_brightness = 1;
2811 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2812 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2813 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
2814 dev->eco_supported = 1;
2815 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002816
Azael Avalos93f8c162014-09-12 18:50:36 -06002817 dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06002818 /*
2819 * Only register the LED if KBD illumination is supported
2820 * and the keyboard backlight operation mode is set to FN-Z
2821 */
2822 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2823 dev->kbd_led.name = "toshiba::kbd_backlight";
2824 dev->kbd_led.max_brightness = 1;
2825 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2826 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2827 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
2828 dev->kbd_led_registered = 1;
2829 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002830
Azael Avalos9d8658a2014-03-25 20:38:32 -06002831 ret = toshiba_touchpad_get(dev, &dummy);
2832 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002833
Azael Avalos5a2813e2014-03-25 20:38:34 -06002834 ret = toshiba_accelerometer_supported(dev);
2835 dev->accelerometer_supported = !ret;
Seth Forshee135740d2011-09-20 16:55:49 -05002836
Azael Avalosc8c91842015-04-02 19:26:20 -06002837 toshiba_usb_sleep_charge_available(dev);
Azael Avalose26ffe52015-01-18 18:30:22 -07002838
Azael Avalosbb3fe012015-01-18 18:30:24 -07002839 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2840 dev->usb_rapid_charge_supported = !ret;
2841
Azael Avalos172ce0a2015-01-18 18:30:25 -07002842 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2843 dev->usb_sleep_music_supported = !ret;
2844
Azael Avalos35d53ce2015-02-10 21:09:19 -07002845 ret = toshiba_panel_power_on_get(dev, &dummy);
2846 dev->panel_power_on_supported = !ret;
2847
Azael Avalos17fe4b32015-02-10 21:09:20 -07002848 ret = toshiba_usb_three_get(dev, &dummy);
2849 dev->usb_three_supported = !ret;
2850
Seth Forshee36d03f92011-09-20 16:55:53 -05002851 ret = get_video_status(dev, &dummy);
2852 dev->video_supported = !ret;
2853
2854 ret = get_fan_status(dev, &dummy);
2855 dev->fan_supported = !ret;
2856
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002857 /*
2858 * Enable the "Special Functions" mode only if they are
2859 * supported and if they are activated.
2860 */
2861 if (dev->kbd_function_keys_supported && special_functions)
2862 toshiba_acpi_enable_special_functions(dev);
2863
Azael Avalos360f0f32014-03-25 20:38:31 -06002864 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2865 &toshiba_attr_group);
2866 if (ret) {
2867 dev->sysfs_created = 0;
2868 goto error;
2869 }
2870 dev->sysfs_created = !ret;
2871
Seth Forshee36d03f92011-09-20 16:55:53 -05002872 create_toshiba_proc_entries(dev);
2873
Seth Forshee29cd2932012-01-18 13:44:09 -06002874 toshiba_acpi = dev;
2875
Seth Forshee135740d2011-09-20 16:55:49 -05002876 return 0;
2877
2878error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002879 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002880 return ret;
2881}
2882
2883static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2884{
2885 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Azael Avalos80546902014-12-04 20:22:47 -07002886 int ret;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002887
Azael Avalos71454d72014-12-04 20:22:46 -07002888 switch (event) {
2889 case 0x80: /* Hotkeys and some system events */
2890 toshiba_acpi_process_hotkeys(dev);
2891 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002892 case 0x81: /* Dock events */
2893 case 0x82:
2894 case 0x83:
2895 pr_info("Dock event received %x\n", event);
2896 break;
2897 case 0x88: /* Thermal events */
2898 pr_info("Thermal event received\n");
2899 break;
2900 case 0x8f: /* LID closed */
2901 case 0x90: /* LID is closed and Dock has been ejected */
2902 break;
2903 case 0x8c: /* SATA power events */
2904 case 0x8b:
2905 pr_info("SATA power event received %x\n", event);
2906 break;
Azael Avalos80546902014-12-04 20:22:47 -07002907 case 0x92: /* Keyboard backlight mode changed */
2908 /* Update sysfs entries */
2909 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2910 &toshiba_attr_group);
2911 if (ret)
2912 pr_err("Unable to update sysfs entries\n");
2913 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002914 case 0x85: /* Unknown */
2915 case 0x8d: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002916 case 0x8e: /* Unknown */
Azael Avalosbab09e22015-03-06 18:14:41 -07002917 case 0x94: /* Unknown */
2918 case 0x95: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002919 default:
2920 pr_info("Unknown event received %x\n", event);
2921 break;
Seth Forshee29cd2932012-01-18 13:44:09 -06002922 }
Azael Avalosbab09e22015-03-06 18:14:41 -07002923
2924 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2925 dev_name(&acpi_dev->dev),
2926 event, 0);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002927}
2928
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02002929#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002930static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002931{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002932 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002933 u32 result;
2934
2935 if (dev->hotkey_dev)
Azael Avalos893f3f62014-09-29 20:40:09 -06002936 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Seth Forshee29cd2932012-01-18 13:44:09 -06002937
2938 return 0;
2939}
2940
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002941static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002942{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002943 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Azael Avalos1f28f292014-12-04 20:22:45 -07002944 int error;
Seth Forshee29cd2932012-01-18 13:44:09 -06002945
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002946 if (dev->hotkey_dev) {
Azael Avalos1f28f292014-12-04 20:22:45 -07002947 error = toshiba_acpi_enable_hotkeys(dev);
2948 if (error)
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002949 pr_info("Unable to re-enable hotkeys\n");
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002950 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002951
2952 return 0;
2953}
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02002954#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002955
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002956static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2957 toshiba_acpi_suspend, toshiba_acpi_resume);
2958
Seth Forshee135740d2011-09-20 16:55:49 -05002959static struct acpi_driver toshiba_acpi_driver = {
2960 .name = "Toshiba ACPI driver",
2961 .owner = THIS_MODULE,
2962 .ids = toshiba_device_ids,
2963 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2964 .ops = {
2965 .add = toshiba_acpi_add,
2966 .remove = toshiba_acpi_remove,
2967 .notify = toshiba_acpi_notify,
2968 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002969 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05002970};
Holger Machtc9263552006-10-20 14:30:29 -07002971
Len Brown4be44fc2005-08-05 00:44:28 -04002972static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973{
Seth Forshee135740d2011-09-20 16:55:49 -05002974 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
Seth Forsheef11f9992012-01-18 13:44:11 -06002976 /*
2977 * Machines with this WMI guid aren't supported due to bugs in
2978 * their AML. This check relies on wmi initializing before
2979 * toshiba_acpi to guarantee guids have been identified.
2980 */
2981 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2982 return -ENODEV;
2983
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2985 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05002986 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002987 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 }
2989
Seth Forshee135740d2011-09-20 16:55:49 -05002990 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2991 if (ret) {
2992 pr_err("Failed to register ACPI driver: %d\n", ret);
2993 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07002994 }
2995
Seth Forshee135740d2011-09-20 16:55:49 -05002996 return ret;
2997}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002998
Seth Forshee135740d2011-09-20 16:55:49 -05002999static void __exit toshiba_acpi_exit(void)
3000{
3001 acpi_bus_unregister_driver(&toshiba_acpi_driver);
3002 if (toshiba_proc_dir)
3003 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004}
3005
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006module_init(toshiba_acpi_init);
3007module_exit(toshiba_acpi_exit);