1b4f9fe12SLen Brown /* 2b4f9fe12SLen Brown * toshiba_acpi.c - Toshiba Laptop ACPI Extras 3b4f9fe12SLen Brown * 4b4f9fe12SLen Brown * Copyright (C) 2002-2004 John Belmonte 5b4f9fe12SLen Brown * Copyright (C) 2008 Philip Langdale 66c3f6e6cSPierre Ducroquet * Copyright (C) 2010 Pierre Ducroquet 77216d702SAzael Avalos * Copyright (C) 2014-2015 Azael Avalos 8b4f9fe12SLen Brown * 9b4f9fe12SLen Brown * This program is free software; you can redistribute it and/or modify 10b4f9fe12SLen Brown * it under the terms of the GNU General Public License as published by 11b4f9fe12SLen Brown * the Free Software Foundation; either version 2 of the License, or 12b4f9fe12SLen Brown * (at your option) any later version. 13b4f9fe12SLen Brown * 14b4f9fe12SLen Brown * This program is distributed in the hope that it will be useful, 15b4f9fe12SLen Brown * but WITHOUT ANY WARRANTY; without even the implied warranty of 16b4f9fe12SLen Brown * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17b4f9fe12SLen Brown * GNU General Public License for more details. 18b4f9fe12SLen Brown * 19c57c0fa4SDarren Hart * The full GNU General Public License is included in this distribution in 20c57c0fa4SDarren Hart * the file called "COPYING". 21b4f9fe12SLen Brown * 22b4f9fe12SLen Brown * The devolpment page for this driver is located at 23b4f9fe12SLen Brown * http://memebeam.org/toys/ToshibaAcpiDriver. 24b4f9fe12SLen Brown * 25b4f9fe12SLen Brown * Credits: 26b4f9fe12SLen Brown * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse 27b4f9fe12SLen Brown * engineering the Windows drivers 28b4f9fe12SLen Brown * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5 29b4f9fe12SLen Brown * Rob Miller - TV out and hotkeys help 30b4f9fe12SLen Brown */ 31b4f9fe12SLen Brown 327e33460dSJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 337e33460dSJoe Perches 3463ba3e28SAzael Avalos #define TOSHIBA_ACPI_VERSION "0.22" 35b4f9fe12SLen Brown #define PROC_INTERFACE_VERSION 1 36b4f9fe12SLen Brown 37b4f9fe12SLen Brown #include <linux/kernel.h> 38b4f9fe12SLen Brown #include <linux/module.h> 39b4f9fe12SLen Brown #include <linux/init.h> 40b4f9fe12SLen Brown #include <linux/types.h> 41b4f9fe12SLen Brown #include <linux/proc_fs.h> 42936c8bcdSAlexey Dobriyan #include <linux/seq_file.h> 43b4f9fe12SLen Brown #include <linux/backlight.h> 446335e4d5SMatthew Garrett #include <linux/input.h> 45384a7cd9SDmitry Torokhov #include <linux/input/sparse-keymap.h> 466c3f6e6cSPierre Ducroquet #include <linux/leds.h> 475a0e3ad6STejun Heo #include <linux/slab.h> 4829cd293fSSeth Forshee #include <linux/workqueue.h> 4929cd293fSSeth Forshee #include <linux/i8042.h> 508b48463fSLv Zheng #include <linux/acpi.h> 51358d6a2cSHans de Goede #include <linux/dmi.h> 52b5163992SAzael Avalos #include <linux/uaccess.h> 53fc5462f8SAzael Avalos #include <linux/miscdevice.h> 54fc5462f8SAzael Avalos #include <linux/toshiba.h> 55358d6a2cSHans de Goede #include <acpi/video.h> 56b4f9fe12SLen Brown 57b4f9fe12SLen Brown MODULE_AUTHOR("John Belmonte"); 58b4f9fe12SLen Brown MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver"); 59b4f9fe12SLen Brown MODULE_LICENSE("GPL"); 60b4f9fe12SLen Brown 61f11f999eSSeth Forshee #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100" 62f11f999eSSeth Forshee 6329cd293fSSeth Forshee /* Scan code for Fn key on TOS1900 models */ 6429cd293fSSeth Forshee #define TOS1900_FN_SCAN 0x6e 6529cd293fSSeth Forshee 66b4f9fe12SLen Brown /* Toshiba ACPI method paths */ 67b4f9fe12SLen Brown #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX" 68b4f9fe12SLen Brown 69e0769fe6SDarren Hart /* 70e0769fe6SDarren Hart * The Toshiba configuration interface is composed of the HCI and the SCI, 71258c5903SAzael Avalos * which are defined as follows: 72b4f9fe12SLen Brown * 73b4f9fe12SLen Brown * HCI is Toshiba's "Hardware Control Interface" which is supposed to 74b4f9fe12SLen Brown * be uniform across all their models. Ideally we would just call 75b4f9fe12SLen Brown * dedicated ACPI methods instead of using this primitive interface. 76b4f9fe12SLen Brown * However the ACPI methods seem to be incomplete in some areas (for 77b4f9fe12SLen Brown * example they allow setting, but not reading, the LCD brightness value), 78b4f9fe12SLen Brown * so this is still useful. 7984a6273fSAzael Avalos * 8084a6273fSAzael Avalos * SCI stands for "System Configuration Interface" which aim is to 8184a6273fSAzael Avalos * conceal differences in hardware between different models. 82b4f9fe12SLen Brown */ 83b4f9fe12SLen Brown 84258c5903SAzael Avalos #define TCI_WORDS 6 85b4f9fe12SLen Brown 863f75bbe9SAzael Avalos /* Operations */ 87b4f9fe12SLen Brown #define HCI_SET 0xff00 88b4f9fe12SLen Brown #define HCI_GET 0xfe00 8984a6273fSAzael Avalos #define SCI_OPEN 0xf100 9084a6273fSAzael Avalos #define SCI_CLOSE 0xf200 9184a6273fSAzael Avalos #define SCI_GET 0xf300 9284a6273fSAzael Avalos #define SCI_SET 0xf400 93b4f9fe12SLen Brown 943f75bbe9SAzael Avalos /* Return codes */ 951864bbc2SAzael Avalos #define TOS_SUCCESS 0x0000 961864bbc2SAzael Avalos #define TOS_OPEN_CLOSE_OK 0x0044 971864bbc2SAzael Avalos #define TOS_FAILURE 0x1000 981864bbc2SAzael Avalos #define TOS_NOT_SUPPORTED 0x8000 991864bbc2SAzael Avalos #define TOS_ALREADY_OPEN 0x8100 1001864bbc2SAzael Avalos #define TOS_NOT_OPENED 0x8200 1011864bbc2SAzael Avalos #define TOS_INPUT_DATA_ERROR 0x8300 1021864bbc2SAzael Avalos #define TOS_WRITE_PROTECTED 0x8400 1031864bbc2SAzael Avalos #define TOS_NOT_PRESENT 0x8600 1041864bbc2SAzael Avalos #define TOS_FIFO_EMPTY 0x8c00 1051864bbc2SAzael Avalos #define TOS_DATA_NOT_AVAILABLE 0x8d20 1061864bbc2SAzael Avalos #define TOS_NOT_INITIALIZED 0x8d50 10798fc4ec6SAzael Avalos #define TOS_NOT_INSTALLED 0x8e00 108b4f9fe12SLen Brown 1093f75bbe9SAzael Avalos /* Registers */ 110b4f9fe12SLen Brown #define HCI_FAN 0x0004 111121b7b0dSAkio Idehara #define HCI_TR_BACKLIGHT 0x0005 112b4f9fe12SLen Brown #define HCI_SYSTEM_EVENT 0x0016 113b4f9fe12SLen Brown #define HCI_VIDEO_OUT 0x001c 114b4f9fe12SLen Brown #define HCI_HOTKEY_EVENT 0x001e 115b4f9fe12SLen Brown #define HCI_LCD_BRIGHTNESS 0x002a 1165a2813e9SAzael Avalos #define HCI_ACCELEROMETER 0x006d 117360f0f39SAzael Avalos #define HCI_KBD_ILLUMINATION 0x0095 118def6c4e2SAzael Avalos #define HCI_ECO_MODE 0x0097 1195a2813e9SAzael Avalos #define HCI_ACCELEROMETER2 0x00a6 12056e6b353SAzael Avalos #define HCI_SYSTEM_INFO 0xc000 12135d53ceaSAzael Avalos #define SCI_PANEL_POWER_ON 0x010d 122fdb79081SAzael Avalos #define SCI_ILLUMINATION 0x014e 123e26ffe51SAzael Avalos #define SCI_USB_SLEEP_CHARGE 0x0150 124360f0f39SAzael Avalos #define SCI_KBD_ILLUM_STATUS 0x015c 125172ce0a9SAzael Avalos #define SCI_USB_SLEEP_MUSIC 0x015e 12617fe4b3dSAzael Avalos #define SCI_USB_THREE 0x0169 1279d8658acSAzael Avalos #define SCI_TOUCHPAD 0x050e 128bae84195SAzael Avalos #define SCI_KBD_FUNCTION_KEYS 0x0522 129b4f9fe12SLen Brown 1303f75bbe9SAzael Avalos /* Field definitions */ 1315a2813e9SAzael Avalos #define HCI_ACCEL_MASK 0x7fff 13229cd293fSSeth Forshee #define HCI_HOTKEY_DISABLE 0x0b 13329cd293fSSeth Forshee #define HCI_HOTKEY_ENABLE 0x09 134fb42d1f4SAzael Avalos #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10 135b4f9fe12SLen Brown #define HCI_LCD_BRIGHTNESS_BITS 3 136b4f9fe12SLen Brown #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS) 137b4f9fe12SLen Brown #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS) 138360f0f39SAzael Avalos #define HCI_MISC_SHIFT 0x10 13956e6b353SAzael Avalos #define HCI_SYSTEM_TYPE1 0x10 14056e6b353SAzael Avalos #define HCI_SYSTEM_TYPE2 0x11 141b4f9fe12SLen Brown #define HCI_VIDEO_OUT_LCD 0x1 142b4f9fe12SLen Brown #define HCI_VIDEO_OUT_CRT 0x2 143b4f9fe12SLen Brown #define HCI_VIDEO_OUT_TV 0x4 14493f8c16dSAzael Avalos #define SCI_KBD_MODE_MASK 0x1f 145360f0f39SAzael Avalos #define SCI_KBD_MODE_FNZ 0x1 146360f0f39SAzael Avalos #define SCI_KBD_MODE_AUTO 0x2 14793f8c16dSAzael Avalos #define SCI_KBD_MODE_ON 0x8 14893f8c16dSAzael Avalos #define SCI_KBD_MODE_OFF 0x10 14993f8c16dSAzael Avalos #define SCI_KBD_TIME_MAX 0x3c001a 150e26ffe51SAzael Avalos #define SCI_USB_CHARGE_MODE_MASK 0xff 151c8c91842SAzael Avalos #define SCI_USB_CHARGE_DISABLED 0x00 152c8c91842SAzael Avalos #define SCI_USB_CHARGE_ALTERNATE 0x09 153c8c91842SAzael Avalos #define SCI_USB_CHARGE_TYPICAL 0x11 154c8c91842SAzael Avalos #define SCI_USB_CHARGE_AUTO 0x21 155182bcaa5SAzael Avalos #define SCI_USB_CHARGE_BAT_MASK 0x7 156182bcaa5SAzael Avalos #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1 157182bcaa5SAzael Avalos #define SCI_USB_CHARGE_BAT_LVL_ON 0x4 158182bcaa5SAzael Avalos #define SCI_USB_CHARGE_BAT_LVL 0x0200 159bb3fe01fSAzael Avalos #define SCI_USB_CHARGE_RAPID_DSP 0x0300 160b4f9fe12SLen Brown 161135740deSSeth Forshee struct toshiba_acpi_dev { 162135740deSSeth Forshee struct acpi_device *acpi_dev; 163135740deSSeth Forshee const char *method_hci; 164135740deSSeth Forshee struct input_dev *hotkey_dev; 16529cd293fSSeth Forshee struct work_struct hotkey_work; 166135740deSSeth Forshee struct backlight_device *backlight_dev; 167135740deSSeth Forshee struct led_classdev led_dev; 168360f0f39SAzael Avalos struct led_classdev kbd_led; 169def6c4e2SAzael Avalos struct led_classdev eco_led; 170fc5462f8SAzael Avalos struct miscdevice miscdev; 17136d03f93SSeth Forshee 172135740deSSeth Forshee int force_fan; 173135740deSSeth Forshee int last_key_event; 174135740deSSeth Forshee int key_event_valid; 17593f8c16dSAzael Avalos int kbd_type; 176360f0f39SAzael Avalos int kbd_mode; 177360f0f39SAzael Avalos int kbd_time; 178182bcaa5SAzael Avalos int usbsc_bat_level; 179c8c91842SAzael Avalos int usbsc_mode_base; 180a2b3471bSAzael Avalos int hotkey_event_type; 181135740deSSeth Forshee 182592b746cSDan Carpenter unsigned int illumination_supported:1; 183592b746cSDan Carpenter unsigned int video_supported:1; 184592b746cSDan Carpenter unsigned int fan_supported:1; 185592b746cSDan Carpenter unsigned int system_event_supported:1; 18629cd293fSSeth Forshee unsigned int ntfy_supported:1; 18729cd293fSSeth Forshee unsigned int info_supported:1; 188121b7b0dSAkio Idehara unsigned int tr_backlight_supported:1; 189360f0f39SAzael Avalos unsigned int kbd_illum_supported:1; 1909d8658acSAzael Avalos unsigned int touchpad_supported:1; 191def6c4e2SAzael Avalos unsigned int eco_supported:1; 1925a2813e9SAzael Avalos unsigned int accelerometer_supported:1; 193e26ffe51SAzael Avalos unsigned int usb_sleep_charge_supported:1; 194bb3fe01fSAzael Avalos unsigned int usb_rapid_charge_supported:1; 195172ce0a9SAzael Avalos unsigned int usb_sleep_music_supported:1; 196bae84195SAzael Avalos unsigned int kbd_function_keys_supported:1; 19735d53ceaSAzael Avalos unsigned int panel_power_on_supported:1; 19817fe4b3dSAzael Avalos unsigned int usb_three_supported:1; 199360f0f39SAzael Avalos unsigned int sysfs_created:1; 200*ea215a3fSAzael Avalos 201*ea215a3fSAzael Avalos bool kbd_led_registered; 202*ea215a3fSAzael Avalos bool illumination_led_registered; 203*ea215a3fSAzael Avalos bool eco_led_registered; 204135740deSSeth Forshee }; 205135740deSSeth Forshee 20629cd293fSSeth Forshee static struct toshiba_acpi_dev *toshiba_acpi; 20729cd293fSSeth Forshee 208b4f9fe12SLen Brown static const struct acpi_device_id toshiba_device_ids[] = { 209b4f9fe12SLen Brown {"TOS6200", 0}, 21063a9e016SOndrej Zary {"TOS6207", 0}, 211b4f9fe12SLen Brown {"TOS6208", 0}, 212b4f9fe12SLen Brown {"TOS1900", 0}, 213b4f9fe12SLen Brown {"", 0}, 214b4f9fe12SLen Brown }; 215b4f9fe12SLen Brown MODULE_DEVICE_TABLE(acpi, toshiba_device_ids); 216b4f9fe12SLen Brown 217b859f159SGreg Kroah-Hartman static const struct key_entry toshiba_acpi_keymap[] = { 218fec278a1SUnai Uribarri { KE_KEY, 0x9e, { KEY_RFKILL } }, 219384a7cd9SDmitry Torokhov { KE_KEY, 0x101, { KEY_MUTE } }, 220384a7cd9SDmitry Torokhov { KE_KEY, 0x102, { KEY_ZOOMOUT } }, 221384a7cd9SDmitry Torokhov { KE_KEY, 0x103, { KEY_ZOOMIN } }, 222408a5d13SAzael Avalos { KE_KEY, 0x10f, { KEY_TAB } }, 223af502837SAzael Avalos { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, 224af502837SAzael Avalos { KE_KEY, 0x139, { KEY_ZOOMRESET } }, 225384a7cd9SDmitry Torokhov { KE_KEY, 0x13b, { KEY_COFFEE } }, 226384a7cd9SDmitry Torokhov { KE_KEY, 0x13c, { KEY_BATTERY } }, 227384a7cd9SDmitry Torokhov { KE_KEY, 0x13d, { KEY_SLEEP } }, 228384a7cd9SDmitry Torokhov { KE_KEY, 0x13e, { KEY_SUSPEND } }, 229384a7cd9SDmitry Torokhov { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } }, 230384a7cd9SDmitry Torokhov { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } }, 231384a7cd9SDmitry Torokhov { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } }, 232384a7cd9SDmitry Torokhov { KE_KEY, 0x142, { KEY_WLAN } }, 233af502837SAzael Avalos { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } }, 234a49010f5SJon Dowland { KE_KEY, 0x17f, { KEY_FN } }, 235384a7cd9SDmitry Torokhov { KE_KEY, 0xb05, { KEY_PROG2 } }, 236384a7cd9SDmitry Torokhov { KE_KEY, 0xb06, { KEY_WWW } }, 237384a7cd9SDmitry Torokhov { KE_KEY, 0xb07, { KEY_MAIL } }, 238384a7cd9SDmitry Torokhov { KE_KEY, 0xb30, { KEY_STOP } }, 239384a7cd9SDmitry Torokhov { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } }, 240384a7cd9SDmitry Torokhov { KE_KEY, 0xb32, { KEY_NEXTSONG } }, 241384a7cd9SDmitry Torokhov { KE_KEY, 0xb33, { KEY_PLAYPAUSE } }, 242384a7cd9SDmitry Torokhov { KE_KEY, 0xb5a, { KEY_MEDIA } }, 243408a5d13SAzael Avalos { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */ 244408a5d13SAzael Avalos { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */ 245408a5d13SAzael Avalos { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */ 246408a5d13SAzael Avalos { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */ 247408a5d13SAzael Avalos { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */ 248384a7cd9SDmitry Torokhov { KE_END, 0 }, 2496335e4d5SMatthew Garrett }; 2506335e4d5SMatthew Garrett 251fe808bfbSTakashi Iwai static const struct key_entry toshiba_acpi_alt_keymap[] = { 252fe808bfbSTakashi Iwai { KE_KEY, 0x102, { KEY_ZOOMOUT } }, 253fe808bfbSTakashi Iwai { KE_KEY, 0x103, { KEY_ZOOMIN } }, 254e6efad7fSAzael Avalos { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, 255fe808bfbSTakashi Iwai { KE_KEY, 0x139, { KEY_ZOOMRESET } }, 256fe808bfbSTakashi Iwai { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } }, 257fe808bfbSTakashi Iwai { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } }, 258d50c9005SAzael Avalos { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } }, 259fe808bfbSTakashi Iwai { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } }, 260d50c9005SAzael Avalos { KE_KEY, 0x157, { KEY_MUTE } }, 261d50c9005SAzael Avalos { KE_KEY, 0x158, { KEY_WLAN } }, 262fe808bfbSTakashi Iwai { KE_END, 0 }, 263fe808bfbSTakashi Iwai }; 264fe808bfbSTakashi Iwai 265e0769fe6SDarren Hart /* 266358d6a2cSHans de Goede * List of models which have a broken acpi-video backlight interface and thus 267358d6a2cSHans de Goede * need to use the toshiba (vendor) interface instead. 268358d6a2cSHans de Goede */ 269358d6a2cSHans de Goede static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = { 270358d6a2cSHans de Goede {} 271358d6a2cSHans de Goede }; 272358d6a2cSHans de Goede 273358d6a2cSHans de Goede /* 274e0769fe6SDarren Hart * Utility 275b4f9fe12SLen Brown */ 276b4f9fe12SLen Brown 277b5163992SAzael Avalos static inline void _set_bit(u32 *word, u32 mask, int value) 278b4f9fe12SLen Brown { 279b4f9fe12SLen Brown *word = (*word & ~mask) | (mask * value); 280b4f9fe12SLen Brown } 281b4f9fe12SLen Brown 282e0769fe6SDarren Hart /* 283e0769fe6SDarren Hart * ACPI interface wrappers 284b4f9fe12SLen Brown */ 285b4f9fe12SLen Brown 286b4f9fe12SLen Brown static int write_acpi_int(const char *methodName, int val) 287b4f9fe12SLen Brown { 288b4f9fe12SLen Brown acpi_status status; 289b4f9fe12SLen Brown 290619400daSZhang Rui status = acpi_execute_simple_method(NULL, (char *)methodName, val); 29132bcd5cbSSeth Forshee return (status == AE_OK) ? 0 : -EIO; 292b4f9fe12SLen Brown } 293b4f9fe12SLen Brown 294e0769fe6SDarren Hart /* 295e0769fe6SDarren Hart * Perform a raw configuration call. Here we don't care about input or output 296258c5903SAzael Avalos * buffer format. 297b4f9fe12SLen Brown */ 298258c5903SAzael Avalos static acpi_status tci_raw(struct toshiba_acpi_dev *dev, 299258c5903SAzael Avalos const u32 in[TCI_WORDS], u32 out[TCI_WORDS]) 300b4f9fe12SLen Brown { 301b4f9fe12SLen Brown struct acpi_object_list params; 302258c5903SAzael Avalos union acpi_object in_objs[TCI_WORDS]; 303b4f9fe12SLen Brown struct acpi_buffer results; 304258c5903SAzael Avalos union acpi_object out_objs[TCI_WORDS + 1]; 305b4f9fe12SLen Brown acpi_status status; 306b4f9fe12SLen Brown int i; 307b4f9fe12SLen Brown 308258c5903SAzael Avalos params.count = TCI_WORDS; 309b4f9fe12SLen Brown params.pointer = in_objs; 310258c5903SAzael Avalos for (i = 0; i < TCI_WORDS; ++i) { 311b4f9fe12SLen Brown in_objs[i].type = ACPI_TYPE_INTEGER; 312b4f9fe12SLen Brown in_objs[i].integer.value = in[i]; 313b4f9fe12SLen Brown } 314b4f9fe12SLen Brown 315b4f9fe12SLen Brown results.length = sizeof(out_objs); 316b4f9fe12SLen Brown results.pointer = out_objs; 317b4f9fe12SLen Brown 3186e02cc7eSSeth Forshee status = acpi_evaluate_object(dev->acpi_dev->handle, 3196e02cc7eSSeth Forshee (char *)dev->method_hci, ¶ms, 320b4f9fe12SLen Brown &results); 321258c5903SAzael Avalos if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) { 322b5163992SAzael Avalos for (i = 0; i < out_objs->package.count; ++i) 323b4f9fe12SLen Brown out[i] = out_objs->package.elements[i].integer.value; 324b4f9fe12SLen Brown } 325b4f9fe12SLen Brown 326b4f9fe12SLen Brown return status; 327b4f9fe12SLen Brown } 328b4f9fe12SLen Brown 329e0769fe6SDarren Hart /* 330d37782bdSAzael Avalos * Common hci tasks 331b4f9fe12SLen Brown * 332b4f9fe12SLen Brown * In addition to the ACPI status, the HCI system returns a result which 333b4f9fe12SLen Brown * may be useful (such as "not supported"). 334b4f9fe12SLen Brown */ 335b4f9fe12SLen Brown 336d37782bdSAzael Avalos static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1) 337b4f9fe12SLen Brown { 338258c5903SAzael Avalos u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; 339258c5903SAzael Avalos u32 out[TCI_WORDS]; 340258c5903SAzael Avalos acpi_status status = tci_raw(dev, in, out); 341893f3f62SAzael Avalos 342893f3f62SAzael Avalos return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; 343b4f9fe12SLen Brown } 344b4f9fe12SLen Brown 345d37782bdSAzael Avalos static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1) 346b4f9fe12SLen Brown { 347258c5903SAzael Avalos u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; 348258c5903SAzael Avalos u32 out[TCI_WORDS]; 349258c5903SAzael Avalos acpi_status status = tci_raw(dev, in, out); 350b5163992SAzael Avalos 351893f3f62SAzael Avalos if (ACPI_FAILURE(status)) 352893f3f62SAzael Avalos return TOS_FAILURE; 353893f3f62SAzael Avalos 354b4f9fe12SLen Brown *out1 = out[2]; 355893f3f62SAzael Avalos 356893f3f62SAzael Avalos return out[0]; 357b4f9fe12SLen Brown } 358b4f9fe12SLen Brown 359e0769fe6SDarren Hart /* 360e0769fe6SDarren Hart * Common sci tasks 36184a6273fSAzael Avalos */ 36284a6273fSAzael Avalos 36384a6273fSAzael Avalos static int sci_open(struct toshiba_acpi_dev *dev) 36484a6273fSAzael Avalos { 365258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 }; 366258c5903SAzael Avalos u32 out[TCI_WORDS]; 36784a6273fSAzael Avalos acpi_status status; 36884a6273fSAzael Avalos 369258c5903SAzael Avalos status = tci_raw(dev, in, out); 3708baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 37184a6273fSAzael Avalos pr_err("ACPI call to open SCI failed\n"); 37284a6273fSAzael Avalos return 0; 37384a6273fSAzael Avalos } 37484a6273fSAzael Avalos 3751864bbc2SAzael Avalos if (out[0] == TOS_OPEN_CLOSE_OK) { 37684a6273fSAzael Avalos return 1; 3771864bbc2SAzael Avalos } else if (out[0] == TOS_ALREADY_OPEN) { 37884a6273fSAzael Avalos pr_info("Toshiba SCI already opened\n"); 37984a6273fSAzael Avalos return 1; 380fa465739SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 381e0769fe6SDarren Hart /* 382e0769fe6SDarren Hart * Some BIOSes do not have the SCI open/close functions 383fa465739SAzael Avalos * implemented and return 0x8000 (Not Supported), failing to 384fa465739SAzael Avalos * register some supported features. 385fa465739SAzael Avalos * 386fa465739SAzael Avalos * Simply return 1 if we hit those affected laptops to make the 387fa465739SAzael Avalos * supported features work. 388fa465739SAzael Avalos * 389fa465739SAzael Avalos * In the case that some laptops really do not support the SCI, 390fa465739SAzael Avalos * all the SCI dependent functions check for TOS_NOT_SUPPORTED, 391fa465739SAzael Avalos * and thus, not registering support for the queried feature. 392fa465739SAzael Avalos */ 393fa465739SAzael Avalos return 1; 3941864bbc2SAzael Avalos } else if (out[0] == TOS_NOT_PRESENT) { 39584a6273fSAzael Avalos pr_info("Toshiba SCI is not present\n"); 39684a6273fSAzael Avalos } 39784a6273fSAzael Avalos 39884a6273fSAzael Avalos return 0; 39984a6273fSAzael Avalos } 40084a6273fSAzael Avalos 40184a6273fSAzael Avalos static void sci_close(struct toshiba_acpi_dev *dev) 40284a6273fSAzael Avalos { 403258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 }; 404258c5903SAzael Avalos u32 out[TCI_WORDS]; 40584a6273fSAzael Avalos acpi_status status; 40684a6273fSAzael Avalos 407258c5903SAzael Avalos status = tci_raw(dev, in, out); 4088baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 40984a6273fSAzael Avalos pr_err("ACPI call to close SCI failed\n"); 41084a6273fSAzael Avalos return; 41184a6273fSAzael Avalos } 41284a6273fSAzael Avalos 4131864bbc2SAzael Avalos if (out[0] == TOS_OPEN_CLOSE_OK) 41484a6273fSAzael Avalos return; 4151864bbc2SAzael Avalos else if (out[0] == TOS_NOT_OPENED) 41684a6273fSAzael Avalos pr_info("Toshiba SCI not opened\n"); 4171864bbc2SAzael Avalos else if (out[0] == TOS_NOT_PRESENT) 41884a6273fSAzael Avalos pr_info("Toshiba SCI is not present\n"); 41984a6273fSAzael Avalos } 42084a6273fSAzael Avalos 421893f3f62SAzael Avalos static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1) 42284a6273fSAzael Avalos { 423258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 }; 424258c5903SAzael Avalos u32 out[TCI_WORDS]; 425258c5903SAzael Avalos acpi_status status = tci_raw(dev, in, out); 426b5163992SAzael Avalos 427893f3f62SAzael Avalos if (ACPI_FAILURE(status)) 428893f3f62SAzael Avalos return TOS_FAILURE; 429893f3f62SAzael Avalos 43084a6273fSAzael Avalos *out1 = out[2]; 431893f3f62SAzael Avalos 432893f3f62SAzael Avalos return out[0]; 43384a6273fSAzael Avalos } 43484a6273fSAzael Avalos 435893f3f62SAzael Avalos static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1) 43684a6273fSAzael Avalos { 437258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 }; 438258c5903SAzael Avalos u32 out[TCI_WORDS]; 439258c5903SAzael Avalos acpi_status status = tci_raw(dev, in, out); 440893f3f62SAzael Avalos 441893f3f62SAzael Avalos return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; 44284a6273fSAzael Avalos } 44384a6273fSAzael Avalos 4446c3f6e6cSPierre Ducroquet /* Illumination support */ 445*ea215a3fSAzael Avalos static void toshiba_illumination_available(struct toshiba_acpi_dev *dev) 4466c3f6e6cSPierre Ducroquet { 447258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 }; 448258c5903SAzael Avalos u32 out[TCI_WORDS]; 4496c3f6e6cSPierre Ducroquet acpi_status status; 4506c3f6e6cSPierre Ducroquet 451*ea215a3fSAzael Avalos dev->illumination_supported = 0; 452*ea215a3fSAzael Avalos dev->illumination_led_registered = false; 453*ea215a3fSAzael Avalos 454fdb79081SAzael Avalos if (!sci_open(dev)) 455*ea215a3fSAzael Avalos return; 456fdb79081SAzael Avalos 457258c5903SAzael Avalos status = tci_raw(dev, in, out); 458fdb79081SAzael Avalos sci_close(dev); 459*ea215a3fSAzael Avalos if (ACPI_FAILURE(status)) 460fdb79081SAzael Avalos pr_err("ACPI call to query Illumination support failed\n"); 461*ea215a3fSAzael Avalos else if (out[0] == TOS_NOT_SUPPORTED) 4627e33460dSJoe Perches pr_info("Illumination device not available\n"); 463*ea215a3fSAzael Avalos else if (out[0] == TOS_SUCCESS) 464*ea215a3fSAzael Avalos dev->illumination_supported = 1; 4656c3f6e6cSPierre Ducroquet } 4666c3f6e6cSPierre Ducroquet 4676c3f6e6cSPierre Ducroquet static void toshiba_illumination_set(struct led_classdev *cdev, 4686c3f6e6cSPierre Ducroquet enum led_brightness brightness) 4696c3f6e6cSPierre Ducroquet { 470135740deSSeth Forshee struct toshiba_acpi_dev *dev = container_of(cdev, 471135740deSSeth Forshee struct toshiba_acpi_dev, led_dev); 472fdb79081SAzael Avalos u32 state, result; 4736c3f6e6cSPierre Ducroquet 4746c3f6e6cSPierre Ducroquet /* First request : initialize communication. */ 475fdb79081SAzael Avalos if (!sci_open(dev)) 4766c3f6e6cSPierre Ducroquet return; 4776c3f6e6cSPierre Ducroquet 478fdb79081SAzael Avalos /* Switch the illumination on/off */ 479fdb79081SAzael Avalos state = brightness ? 1 : 0; 480893f3f62SAzael Avalos result = sci_write(dev, SCI_ILLUMINATION, state); 481fdb79081SAzael Avalos sci_close(dev); 482893f3f62SAzael Avalos if (result == TOS_FAILURE) { 483fdb79081SAzael Avalos pr_err("ACPI call for illumination failed\n"); 484fdb79081SAzael Avalos return; 4851864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 486fdb79081SAzael Avalos pr_info("Illumination not supported\n"); 4876c3f6e6cSPierre Ducroquet return; 4886c3f6e6cSPierre Ducroquet } 4896c3f6e6cSPierre Ducroquet } 4906c3f6e6cSPierre Ducroquet 4916c3f6e6cSPierre Ducroquet static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) 4926c3f6e6cSPierre Ducroquet { 493135740deSSeth Forshee struct toshiba_acpi_dev *dev = container_of(cdev, 494135740deSSeth Forshee struct toshiba_acpi_dev, led_dev); 495fdb79081SAzael Avalos u32 state, result; 4966c3f6e6cSPierre Ducroquet 4973f75bbe9SAzael Avalos /* First request : initialize communication. */ 498fdb79081SAzael Avalos if (!sci_open(dev)) 4996c3f6e6cSPierre Ducroquet return LED_OFF; 5006c3f6e6cSPierre Ducroquet 5016c3f6e6cSPierre Ducroquet /* Check the illumination */ 502893f3f62SAzael Avalos result = sci_read(dev, SCI_ILLUMINATION, &state); 503fdb79081SAzael Avalos sci_close(dev); 504893f3f62SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 505fdb79081SAzael Avalos pr_err("ACPI call for illumination failed\n"); 506fdb79081SAzael Avalos return LED_OFF; 5071864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 508fdb79081SAzael Avalos pr_info("Illumination not supported\n"); 5096c3f6e6cSPierre Ducroquet return LED_OFF; 5106c3f6e6cSPierre Ducroquet } 5116c3f6e6cSPierre Ducroquet 512fdb79081SAzael Avalos return state ? LED_FULL : LED_OFF; 5136c3f6e6cSPierre Ducroquet } 5146c3f6e6cSPierre Ducroquet 515360f0f39SAzael Avalos /* KBD Illumination */ 516*ea215a3fSAzael Avalos static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev) 51793f8c16dSAzael Avalos { 518258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 }; 519258c5903SAzael Avalos u32 out[TCI_WORDS]; 52093f8c16dSAzael Avalos acpi_status status; 52193f8c16dSAzael Avalos 522*ea215a3fSAzael Avalos dev->kbd_illum_supported = 0; 523*ea215a3fSAzael Avalos dev->kbd_led_registered = false; 524*ea215a3fSAzael Avalos 52593f8c16dSAzael Avalos if (!sci_open(dev)) 526*ea215a3fSAzael Avalos return; 52793f8c16dSAzael Avalos 528258c5903SAzael Avalos status = tci_raw(dev, in, out); 52993f8c16dSAzael Avalos sci_close(dev); 5301864bbc2SAzael Avalos if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { 53193f8c16dSAzael Avalos pr_err("ACPI call to query kbd illumination support failed\n"); 5321864bbc2SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 53393f8c16dSAzael Avalos pr_info("Keyboard illumination not available\n"); 534*ea215a3fSAzael Avalos } else if (out[0] == TOS_SUCCESS) { 535e0769fe6SDarren Hart /* 536e0769fe6SDarren Hart * Check for keyboard backlight timeout max value, 53793f8c16dSAzael Avalos * previous kbd backlight implementation set this to 53893f8c16dSAzael Avalos * 0x3c0003, and now the new implementation set this 539e0769fe6SDarren Hart * to 0x3c001a, use this to distinguish between them. 54093f8c16dSAzael Avalos */ 54193f8c16dSAzael Avalos if (out[3] == SCI_KBD_TIME_MAX) 54293f8c16dSAzael Avalos dev->kbd_type = 2; 54393f8c16dSAzael Avalos else 54493f8c16dSAzael Avalos dev->kbd_type = 1; 54593f8c16dSAzael Avalos /* Get the current keyboard backlight mode */ 54693f8c16dSAzael Avalos dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK; 54793f8c16dSAzael Avalos /* Get the current time (1-60 seconds) */ 54893f8c16dSAzael Avalos dev->kbd_time = out[2] >> HCI_MISC_SHIFT; 549*ea215a3fSAzael Avalos /* Flag as supported */ 550*ea215a3fSAzael Avalos dev->kbd_illum_supported = 1; 551*ea215a3fSAzael Avalos } 55293f8c16dSAzael Avalos } 55393f8c16dSAzael Avalos 554360f0f39SAzael Avalos static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time) 555360f0f39SAzael Avalos { 556360f0f39SAzael Avalos u32 result; 557360f0f39SAzael Avalos 558360f0f39SAzael Avalos if (!sci_open(dev)) 559360f0f39SAzael Avalos return -EIO; 560360f0f39SAzael Avalos 561893f3f62SAzael Avalos result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time); 562360f0f39SAzael Avalos sci_close(dev); 563893f3f62SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 564360f0f39SAzael Avalos pr_err("ACPI call to set KBD backlight status failed\n"); 565360f0f39SAzael Avalos return -EIO; 5661864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 567360f0f39SAzael Avalos pr_info("Keyboard backlight status not supported\n"); 568360f0f39SAzael Avalos return -ENODEV; 569360f0f39SAzael Avalos } 570360f0f39SAzael Avalos 571360f0f39SAzael Avalos return 0; 572360f0f39SAzael Avalos } 573360f0f39SAzael Avalos 574360f0f39SAzael Avalos static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time) 575360f0f39SAzael Avalos { 576360f0f39SAzael Avalos u32 result; 577360f0f39SAzael Avalos 578360f0f39SAzael Avalos if (!sci_open(dev)) 579360f0f39SAzael Avalos return -EIO; 580360f0f39SAzael Avalos 581893f3f62SAzael Avalos result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time); 582360f0f39SAzael Avalos sci_close(dev); 583893f3f62SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 584360f0f39SAzael Avalos pr_err("ACPI call to get KBD backlight status failed\n"); 585360f0f39SAzael Avalos return -EIO; 5861864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 587360f0f39SAzael Avalos pr_info("Keyboard backlight status not supported\n"); 588360f0f39SAzael Avalos return -ENODEV; 589360f0f39SAzael Avalos } 590360f0f39SAzael Avalos 591360f0f39SAzael Avalos return 0; 592360f0f39SAzael Avalos } 593360f0f39SAzael Avalos 594360f0f39SAzael Avalos static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev) 595360f0f39SAzael Avalos { 596360f0f39SAzael Avalos struct toshiba_acpi_dev *dev = container_of(cdev, 597360f0f39SAzael Avalos struct toshiba_acpi_dev, kbd_led); 598360f0f39SAzael Avalos u32 state, result; 599360f0f39SAzael Avalos 600360f0f39SAzael Avalos /* Check the keyboard backlight state */ 601d37782bdSAzael Avalos result = hci_read(dev, HCI_KBD_ILLUMINATION, &state); 602893f3f62SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 603360f0f39SAzael Avalos pr_err("ACPI call to get the keyboard backlight failed\n"); 604360f0f39SAzael Avalos return LED_OFF; 6051864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 606360f0f39SAzael Avalos pr_info("Keyboard backlight not supported\n"); 607360f0f39SAzael Avalos return LED_OFF; 608360f0f39SAzael Avalos } 609360f0f39SAzael Avalos 610360f0f39SAzael Avalos return state ? LED_FULL : LED_OFF; 611360f0f39SAzael Avalos } 612360f0f39SAzael Avalos 613360f0f39SAzael Avalos static void toshiba_kbd_backlight_set(struct led_classdev *cdev, 614360f0f39SAzael Avalos enum led_brightness brightness) 615360f0f39SAzael Avalos { 616360f0f39SAzael Avalos struct toshiba_acpi_dev *dev = container_of(cdev, 617360f0f39SAzael Avalos struct toshiba_acpi_dev, kbd_led); 618360f0f39SAzael Avalos u32 state, result; 619360f0f39SAzael Avalos 620360f0f39SAzael Avalos /* Set the keyboard backlight state */ 621360f0f39SAzael Avalos state = brightness ? 1 : 0; 622d37782bdSAzael Avalos result = hci_write(dev, HCI_KBD_ILLUMINATION, state); 623893f3f62SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 624360f0f39SAzael Avalos pr_err("ACPI call to set KBD Illumination mode failed\n"); 625360f0f39SAzael Avalos return; 6261864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 627360f0f39SAzael Avalos pr_info("Keyboard backlight not supported\n"); 628360f0f39SAzael Avalos return; 629360f0f39SAzael Avalos } 630360f0f39SAzael Avalos } 631360f0f39SAzael Avalos 6329d8658acSAzael Avalos /* TouchPad support */ 6339d8658acSAzael Avalos static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state) 6349d8658acSAzael Avalos { 6359d8658acSAzael Avalos u32 result; 6369d8658acSAzael Avalos 6379d8658acSAzael Avalos if (!sci_open(dev)) 6389d8658acSAzael Avalos return -EIO; 6399d8658acSAzael Avalos 640893f3f62SAzael Avalos result = sci_write(dev, SCI_TOUCHPAD, state); 6419d8658acSAzael Avalos sci_close(dev); 642893f3f62SAzael Avalos if (result == TOS_FAILURE) { 6439d8658acSAzael Avalos pr_err("ACPI call to set the touchpad failed\n"); 6449d8658acSAzael Avalos return -EIO; 6451864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 6469d8658acSAzael Avalos return -ENODEV; 6479d8658acSAzael Avalos } 6489d8658acSAzael Avalos 6499d8658acSAzael Avalos return 0; 6509d8658acSAzael Avalos } 6519d8658acSAzael Avalos 6529d8658acSAzael Avalos static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state) 6539d8658acSAzael Avalos { 6549d8658acSAzael Avalos u32 result; 6559d8658acSAzael Avalos 6569d8658acSAzael Avalos if (!sci_open(dev)) 6579d8658acSAzael Avalos return -EIO; 6589d8658acSAzael Avalos 659893f3f62SAzael Avalos result = sci_read(dev, SCI_TOUCHPAD, state); 6609d8658acSAzael Avalos sci_close(dev); 661893f3f62SAzael Avalos if (result == TOS_FAILURE) { 6629d8658acSAzael Avalos pr_err("ACPI call to query the touchpad failed\n"); 6639d8658acSAzael Avalos return -EIO; 6641864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 6659d8658acSAzael Avalos return -ENODEV; 6669d8658acSAzael Avalos } 6679d8658acSAzael Avalos 6689d8658acSAzael Avalos return 0; 6699d8658acSAzael Avalos } 6709d8658acSAzael Avalos 671def6c4e2SAzael Avalos /* Eco Mode support */ 672*ea215a3fSAzael Avalos static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev) 673def6c4e2SAzael Avalos { 674def6c4e2SAzael Avalos acpi_status status; 67598fc4ec6SAzael Avalos u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 }; 676258c5903SAzael Avalos u32 out[TCI_WORDS]; 677def6c4e2SAzael Avalos 678*ea215a3fSAzael Avalos dev->eco_supported = 0; 679*ea215a3fSAzael Avalos dev->eco_led_registered = false; 680*ea215a3fSAzael Avalos 681258c5903SAzael Avalos status = tci_raw(dev, in, out); 6828baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 68398fc4ec6SAzael Avalos pr_err("ACPI call to get ECO led failed\n"); 68498fc4ec6SAzael Avalos } else if (out[0] == TOS_NOT_INSTALLED) { 68598fc4ec6SAzael Avalos pr_info("ECO led not installed"); 68698fc4ec6SAzael Avalos } else if (out[0] == TOS_INPUT_DATA_ERROR) { 687e0769fe6SDarren Hart /* 688e0769fe6SDarren Hart * If we receive 0x8300 (Input Data Error), it means that the 68998fc4ec6SAzael Avalos * LED device is present, but that we just screwed the input 69098fc4ec6SAzael Avalos * parameters. 69198fc4ec6SAzael Avalos * 69298fc4ec6SAzael Avalos * Let's query the status of the LED to see if we really have a 69398fc4ec6SAzael Avalos * success response, indicating the actual presense of the LED, 69498fc4ec6SAzael Avalos * bail out otherwise. 69598fc4ec6SAzael Avalos */ 69698fc4ec6SAzael Avalos in[3] = 1; 69798fc4ec6SAzael Avalos status = tci_raw(dev, in, out); 69898fc4ec6SAzael Avalos if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) 69998fc4ec6SAzael Avalos pr_err("ACPI call to get ECO led failed\n"); 70098fc4ec6SAzael Avalos else if (out[0] == TOS_SUCCESS) 701*ea215a3fSAzael Avalos dev->eco_supported = 1; 702def6c4e2SAzael Avalos } 703def6c4e2SAzael Avalos } 704def6c4e2SAzael Avalos 705b5163992SAzael Avalos static enum led_brightness 706b5163992SAzael Avalos toshiba_eco_mode_get_status(struct led_classdev *cdev) 707def6c4e2SAzael Avalos { 708def6c4e2SAzael Avalos struct toshiba_acpi_dev *dev = container_of(cdev, 709def6c4e2SAzael Avalos struct toshiba_acpi_dev, eco_led); 710258c5903SAzael Avalos u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 }; 711258c5903SAzael Avalos u32 out[TCI_WORDS]; 712def6c4e2SAzael Avalos acpi_status status; 713def6c4e2SAzael Avalos 714258c5903SAzael Avalos status = tci_raw(dev, in, out); 7151864bbc2SAzael Avalos if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { 716def6c4e2SAzael Avalos pr_err("ACPI call to get ECO led failed\n"); 717def6c4e2SAzael Avalos return LED_OFF; 718def6c4e2SAzael Avalos } 719def6c4e2SAzael Avalos 720def6c4e2SAzael Avalos return out[2] ? LED_FULL : LED_OFF; 721def6c4e2SAzael Avalos } 722def6c4e2SAzael Avalos 723def6c4e2SAzael Avalos static void toshiba_eco_mode_set_status(struct led_classdev *cdev, 724def6c4e2SAzael Avalos enum led_brightness brightness) 725def6c4e2SAzael Avalos { 726def6c4e2SAzael Avalos struct toshiba_acpi_dev *dev = container_of(cdev, 727def6c4e2SAzael Avalos struct toshiba_acpi_dev, eco_led); 728258c5903SAzael Avalos u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 }; 729258c5903SAzael Avalos u32 out[TCI_WORDS]; 730def6c4e2SAzael Avalos acpi_status status; 731def6c4e2SAzael Avalos 732def6c4e2SAzael Avalos /* Switch the Eco Mode led on/off */ 733def6c4e2SAzael Avalos in[2] = (brightness) ? 1 : 0; 734258c5903SAzael Avalos status = tci_raw(dev, in, out); 7351864bbc2SAzael Avalos if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { 736def6c4e2SAzael Avalos pr_err("ACPI call to set ECO led failed\n"); 737def6c4e2SAzael Avalos return; 738def6c4e2SAzael Avalos } 739def6c4e2SAzael Avalos } 740def6c4e2SAzael Avalos 7415a2813e9SAzael Avalos /* Accelerometer support */ 742*ea215a3fSAzael Avalos static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev) 7435a2813e9SAzael Avalos { 744258c5903SAzael Avalos u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 }; 745258c5903SAzael Avalos u32 out[TCI_WORDS]; 7465a2813e9SAzael Avalos acpi_status status; 7475a2813e9SAzael Avalos 748*ea215a3fSAzael Avalos dev->accelerometer_supported = 0; 749*ea215a3fSAzael Avalos 750e0769fe6SDarren Hart /* 751e0769fe6SDarren Hart * Check if the accelerometer call exists, 7525a2813e9SAzael Avalos * this call also serves as initialization 7535a2813e9SAzael Avalos */ 754258c5903SAzael Avalos status = tci_raw(dev, in, out); 755*ea215a3fSAzael Avalos if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) 7565a2813e9SAzael Avalos pr_err("ACPI call to query the accelerometer failed\n"); 757*ea215a3fSAzael Avalos else if (out[0] == TOS_DATA_NOT_AVAILABLE || 758*ea215a3fSAzael Avalos out[0] == TOS_NOT_INITIALIZED) 7595a2813e9SAzael Avalos pr_err("Accelerometer not initialized\n"); 760*ea215a3fSAzael Avalos else if (out[0] == TOS_NOT_SUPPORTED) 7615a2813e9SAzael Avalos pr_info("Accelerometer not supported\n"); 762*ea215a3fSAzael Avalos else if (out[0] == TOS_SUCCESS) 763*ea215a3fSAzael Avalos dev->accelerometer_supported = 1; 7645a2813e9SAzael Avalos } 7655a2813e9SAzael Avalos 7665a2813e9SAzael Avalos static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, 7675a2813e9SAzael Avalos u32 *xy, u32 *z) 7685a2813e9SAzael Avalos { 769258c5903SAzael Avalos u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 }; 770258c5903SAzael Avalos u32 out[TCI_WORDS]; 7715a2813e9SAzael Avalos acpi_status status; 7725a2813e9SAzael Avalos 7735a2813e9SAzael Avalos /* Check the Accelerometer status */ 774258c5903SAzael Avalos status = tci_raw(dev, in, out); 7751864bbc2SAzael Avalos if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { 7765a2813e9SAzael Avalos pr_err("ACPI call to query the accelerometer failed\n"); 7775a2813e9SAzael Avalos return -EIO; 7785a2813e9SAzael Avalos } 7795a2813e9SAzael Avalos 7805a2813e9SAzael Avalos *xy = out[2]; 7815a2813e9SAzael Avalos *z = out[4]; 7825a2813e9SAzael Avalos 7835a2813e9SAzael Avalos return 0; 7845a2813e9SAzael Avalos } 7855a2813e9SAzael Avalos 786e26ffe51SAzael Avalos /* Sleep (Charge and Music) utilities support */ 787c8c91842SAzael Avalos static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev) 788c8c91842SAzael Avalos { 789c8c91842SAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; 790c8c91842SAzael Avalos u32 out[TCI_WORDS]; 791c8c91842SAzael Avalos acpi_status status; 792c8c91842SAzael Avalos 793c8c91842SAzael Avalos dev->usb_sleep_charge_supported = 0; 794c8c91842SAzael Avalos 795c8c91842SAzael Avalos if (!sci_open(dev)) 796c8c91842SAzael Avalos return; 797c8c91842SAzael Avalos 798c8c91842SAzael Avalos status = tci_raw(dev, in, out); 7998baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 800c8c91842SAzael Avalos pr_err("ACPI call to get USB Sleep and Charge mode failed\n"); 801c8c91842SAzael Avalos sci_close(dev); 802c8c91842SAzael Avalos return; 803c8c91842SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 804c8c91842SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 805c8c91842SAzael Avalos sci_close(dev); 806c8c91842SAzael Avalos return; 807c8c91842SAzael Avalos } else if (out[0] == TOS_SUCCESS) { 808c8c91842SAzael Avalos dev->usbsc_mode_base = out[4]; 809c8c91842SAzael Avalos } 810c8c91842SAzael Avalos 811c8c91842SAzael Avalos in[5] = SCI_USB_CHARGE_BAT_LVL; 812c8c91842SAzael Avalos status = tci_raw(dev, in, out); 813*ea215a3fSAzael Avalos sci_close(dev); 8148baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 815c8c91842SAzael Avalos pr_err("ACPI call to get USB Sleep and Charge mode failed\n"); 816c8c91842SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 817c8c91842SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 818c8c91842SAzael Avalos } else if (out[0] == TOS_SUCCESS) { 819c8c91842SAzael Avalos dev->usbsc_bat_level = out[2]; 820*ea215a3fSAzael Avalos /* Flag as supported */ 821c8c91842SAzael Avalos dev->usb_sleep_charge_supported = 1; 822c8c91842SAzael Avalos } 823c8c91842SAzael Avalos 824c8c91842SAzael Avalos } 825c8c91842SAzael Avalos 826e26ffe51SAzael Avalos static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev, 827e26ffe51SAzael Avalos u32 *mode) 828e26ffe51SAzael Avalos { 829e26ffe51SAzael Avalos u32 result; 830e26ffe51SAzael Avalos 831e26ffe51SAzael Avalos if (!sci_open(dev)) 832e26ffe51SAzael Avalos return -EIO; 833e26ffe51SAzael Avalos 834e26ffe51SAzael Avalos result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode); 835e26ffe51SAzael Avalos sci_close(dev); 836e26ffe51SAzael Avalos if (result == TOS_FAILURE) { 837e26ffe51SAzael Avalos pr_err("ACPI call to set USB S&C mode failed\n"); 838e26ffe51SAzael Avalos return -EIO; 839e26ffe51SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 840e26ffe51SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 841e26ffe51SAzael Avalos return -ENODEV; 842e26ffe51SAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 843e26ffe51SAzael Avalos return -EIO; 844e26ffe51SAzael Avalos } 845e26ffe51SAzael Avalos 846e26ffe51SAzael Avalos return 0; 847e26ffe51SAzael Avalos } 848e26ffe51SAzael Avalos 849e26ffe51SAzael Avalos static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev, 850e26ffe51SAzael Avalos u32 mode) 851e26ffe51SAzael Avalos { 852e26ffe51SAzael Avalos u32 result; 853e26ffe51SAzael Avalos 854e26ffe51SAzael Avalos if (!sci_open(dev)) 855e26ffe51SAzael Avalos return -EIO; 856e26ffe51SAzael Avalos 857e26ffe51SAzael Avalos result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode); 858e26ffe51SAzael Avalos sci_close(dev); 859e26ffe51SAzael Avalos if (result == TOS_FAILURE) { 860e26ffe51SAzael Avalos pr_err("ACPI call to set USB S&C mode failed\n"); 861e26ffe51SAzael Avalos return -EIO; 862e26ffe51SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 863e26ffe51SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 864e26ffe51SAzael Avalos return -ENODEV; 865e26ffe51SAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 866e26ffe51SAzael Avalos return -EIO; 867e26ffe51SAzael Avalos } 868e26ffe51SAzael Avalos 869e26ffe51SAzael Avalos return 0; 870e26ffe51SAzael Avalos } 871e26ffe51SAzael Avalos 872182bcaa5SAzael Avalos static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev, 873182bcaa5SAzael Avalos u32 *mode) 874182bcaa5SAzael Avalos { 875182bcaa5SAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; 876182bcaa5SAzael Avalos u32 out[TCI_WORDS]; 877182bcaa5SAzael Avalos acpi_status status; 878182bcaa5SAzael Avalos 879182bcaa5SAzael Avalos if (!sci_open(dev)) 880182bcaa5SAzael Avalos return -EIO; 881182bcaa5SAzael Avalos 882182bcaa5SAzael Avalos in[5] = SCI_USB_CHARGE_BAT_LVL; 883182bcaa5SAzael Avalos status = tci_raw(dev, in, out); 884182bcaa5SAzael Avalos sci_close(dev); 8858baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 886182bcaa5SAzael Avalos pr_err("ACPI call to get USB S&C battery level failed\n"); 887182bcaa5SAzael Avalos return -EIO; 888182bcaa5SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 889182bcaa5SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 890182bcaa5SAzael Avalos return -ENODEV; 891182bcaa5SAzael Avalos } else if (out[0] == TOS_INPUT_DATA_ERROR) { 892182bcaa5SAzael Avalos return -EIO; 893182bcaa5SAzael Avalos } 894182bcaa5SAzael Avalos 895182bcaa5SAzael Avalos *mode = out[2]; 896182bcaa5SAzael Avalos 897182bcaa5SAzael Avalos return 0; 898182bcaa5SAzael Avalos } 899182bcaa5SAzael Avalos 900182bcaa5SAzael Avalos static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev, 901182bcaa5SAzael Avalos u32 mode) 902182bcaa5SAzael Avalos { 903182bcaa5SAzael Avalos u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; 904182bcaa5SAzael Avalos u32 out[TCI_WORDS]; 905182bcaa5SAzael Avalos acpi_status status; 906182bcaa5SAzael Avalos 907182bcaa5SAzael Avalos if (!sci_open(dev)) 908182bcaa5SAzael Avalos return -EIO; 909182bcaa5SAzael Avalos 910182bcaa5SAzael Avalos in[2] = mode; 911182bcaa5SAzael Avalos in[5] = SCI_USB_CHARGE_BAT_LVL; 912182bcaa5SAzael Avalos status = tci_raw(dev, in, out); 913182bcaa5SAzael Avalos sci_close(dev); 9148baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 915182bcaa5SAzael Avalos pr_err("ACPI call to set USB S&C battery level failed\n"); 916182bcaa5SAzael Avalos return -EIO; 917182bcaa5SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 918182bcaa5SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 919182bcaa5SAzael Avalos return -ENODEV; 920182bcaa5SAzael Avalos } else if (out[0] == TOS_INPUT_DATA_ERROR) { 921182bcaa5SAzael Avalos return -EIO; 922182bcaa5SAzael Avalos } 923182bcaa5SAzael Avalos 924182bcaa5SAzael Avalos return 0; 925182bcaa5SAzael Avalos } 926182bcaa5SAzael Avalos 927bb3fe01fSAzael Avalos static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev, 928bb3fe01fSAzael Avalos u32 *state) 929bb3fe01fSAzael Avalos { 930bb3fe01fSAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; 931bb3fe01fSAzael Avalos u32 out[TCI_WORDS]; 932bb3fe01fSAzael Avalos acpi_status status; 933bb3fe01fSAzael Avalos 934bb3fe01fSAzael Avalos if (!sci_open(dev)) 935bb3fe01fSAzael Avalos return -EIO; 936bb3fe01fSAzael Avalos 937bb3fe01fSAzael Avalos in[5] = SCI_USB_CHARGE_RAPID_DSP; 938bb3fe01fSAzael Avalos status = tci_raw(dev, in, out); 939bb3fe01fSAzael Avalos sci_close(dev); 9408baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 941bb26f189SAzael Avalos pr_err("ACPI call to get USB Rapid Charge failed\n"); 942bb3fe01fSAzael Avalos return -EIO; 943bb3fe01fSAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED || 944bb3fe01fSAzael Avalos out[0] == TOS_INPUT_DATA_ERROR) { 945bb26f189SAzael Avalos pr_info("USB Rapid Charge not supported\n"); 946bb3fe01fSAzael Avalos return -ENODEV; 947bb3fe01fSAzael Avalos } 948bb3fe01fSAzael Avalos 949bb3fe01fSAzael Avalos *state = out[2]; 950bb3fe01fSAzael Avalos 951bb3fe01fSAzael Avalos return 0; 952bb3fe01fSAzael Avalos } 953bb3fe01fSAzael Avalos 954bb3fe01fSAzael Avalos static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev, 955bb3fe01fSAzael Avalos u32 state) 956bb3fe01fSAzael Avalos { 957bb3fe01fSAzael Avalos u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; 958bb3fe01fSAzael Avalos u32 out[TCI_WORDS]; 959bb3fe01fSAzael Avalos acpi_status status; 960bb3fe01fSAzael Avalos 961bb3fe01fSAzael Avalos if (!sci_open(dev)) 962bb3fe01fSAzael Avalos return -EIO; 963bb3fe01fSAzael Avalos 964bb3fe01fSAzael Avalos in[2] = state; 965bb3fe01fSAzael Avalos in[5] = SCI_USB_CHARGE_RAPID_DSP; 966bb3fe01fSAzael Avalos status = tci_raw(dev, in, out); 967bb3fe01fSAzael Avalos sci_close(dev); 9688baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 969bb26f189SAzael Avalos pr_err("ACPI call to set USB Rapid Charge failed\n"); 970bb3fe01fSAzael Avalos return -EIO; 971bb3fe01fSAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 972bb26f189SAzael Avalos pr_info("USB Rapid Charge not supported\n"); 973bb3fe01fSAzael Avalos return -ENODEV; 974bb3fe01fSAzael Avalos } else if (out[0] == TOS_INPUT_DATA_ERROR) { 975bb3fe01fSAzael Avalos return -EIO; 976bb3fe01fSAzael Avalos } 977bb3fe01fSAzael Avalos 978bb3fe01fSAzael Avalos return 0; 979bb3fe01fSAzael Avalos } 980bb3fe01fSAzael Avalos 981172ce0a9SAzael Avalos static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state) 982172ce0a9SAzael Avalos { 983172ce0a9SAzael Avalos u32 result; 984172ce0a9SAzael Avalos 985172ce0a9SAzael Avalos if (!sci_open(dev)) 986172ce0a9SAzael Avalos return -EIO; 987172ce0a9SAzael Avalos 988172ce0a9SAzael Avalos result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state); 989172ce0a9SAzael Avalos sci_close(dev); 990172ce0a9SAzael Avalos if (result == TOS_FAILURE) { 991bb26f189SAzael Avalos pr_err("ACPI call to get Sleep and Music failed\n"); 992172ce0a9SAzael Avalos return -EIO; 993172ce0a9SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 994bb26f189SAzael Avalos pr_info("Sleep and Music not supported\n"); 995172ce0a9SAzael Avalos return -ENODEV; 996172ce0a9SAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 997172ce0a9SAzael Avalos return -EIO; 998172ce0a9SAzael Avalos } 999172ce0a9SAzael Avalos 1000172ce0a9SAzael Avalos return 0; 1001172ce0a9SAzael Avalos } 1002172ce0a9SAzael Avalos 1003172ce0a9SAzael Avalos static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state) 1004172ce0a9SAzael Avalos { 1005172ce0a9SAzael Avalos u32 result; 1006172ce0a9SAzael Avalos 1007172ce0a9SAzael Avalos if (!sci_open(dev)) 1008172ce0a9SAzael Avalos return -EIO; 1009172ce0a9SAzael Avalos 1010172ce0a9SAzael Avalos result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state); 1011172ce0a9SAzael Avalos sci_close(dev); 1012172ce0a9SAzael Avalos if (result == TOS_FAILURE) { 1013bb26f189SAzael Avalos pr_err("ACPI call to set Sleep and Music failed\n"); 1014172ce0a9SAzael Avalos return -EIO; 1015172ce0a9SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 1016bb26f189SAzael Avalos pr_info("Sleep and Music not supported\n"); 1017172ce0a9SAzael Avalos return -ENODEV; 1018172ce0a9SAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 1019172ce0a9SAzael Avalos return -EIO; 1020172ce0a9SAzael Avalos } 1021172ce0a9SAzael Avalos 1022172ce0a9SAzael Avalos return 0; 1023172ce0a9SAzael Avalos } 1024172ce0a9SAzael Avalos 1025bae84195SAzael Avalos /* Keyboard function keys */ 1026bae84195SAzael Avalos static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode) 1027bae84195SAzael Avalos { 1028bae84195SAzael Avalos u32 result; 1029bae84195SAzael Avalos 1030bae84195SAzael Avalos if (!sci_open(dev)) 1031bae84195SAzael Avalos return -EIO; 1032bae84195SAzael Avalos 1033bae84195SAzael Avalos result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode); 1034bae84195SAzael Avalos sci_close(dev); 1035bae84195SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 1036bae84195SAzael Avalos pr_err("ACPI call to get KBD function keys failed\n"); 1037bae84195SAzael Avalos return -EIO; 1038bae84195SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 1039bae84195SAzael Avalos pr_info("KBD function keys not supported\n"); 1040bae84195SAzael Avalos return -ENODEV; 1041bae84195SAzael Avalos } 1042bae84195SAzael Avalos 1043bae84195SAzael Avalos return 0; 1044bae84195SAzael Avalos } 1045bae84195SAzael Avalos 1046bae84195SAzael Avalos static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode) 1047bae84195SAzael Avalos { 1048bae84195SAzael Avalos u32 result; 1049bae84195SAzael Avalos 1050bae84195SAzael Avalos if (!sci_open(dev)) 1051bae84195SAzael Avalos return -EIO; 1052bae84195SAzael Avalos 1053bae84195SAzael Avalos result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode); 1054bae84195SAzael Avalos sci_close(dev); 1055bae84195SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 1056bae84195SAzael Avalos pr_err("ACPI call to set KBD function keys failed\n"); 1057bae84195SAzael Avalos return -EIO; 1058bae84195SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 1059bae84195SAzael Avalos pr_info("KBD function keys not supported\n"); 1060bae84195SAzael Avalos return -ENODEV; 1061bae84195SAzael Avalos } 1062bae84195SAzael Avalos 1063bae84195SAzael Avalos return 0; 1064bae84195SAzael Avalos } 1065bae84195SAzael Avalos 106635d53ceaSAzael Avalos /* Panel Power ON */ 106735d53ceaSAzael Avalos static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state) 106835d53ceaSAzael Avalos { 106935d53ceaSAzael Avalos u32 result; 107035d53ceaSAzael Avalos 107135d53ceaSAzael Avalos if (!sci_open(dev)) 107235d53ceaSAzael Avalos return -EIO; 107335d53ceaSAzael Avalos 107435d53ceaSAzael Avalos result = sci_read(dev, SCI_PANEL_POWER_ON, state); 107535d53ceaSAzael Avalos sci_close(dev); 107635d53ceaSAzael Avalos if (result == TOS_FAILURE) { 107735d53ceaSAzael Avalos pr_err("ACPI call to get Panel Power ON failed\n"); 107835d53ceaSAzael Avalos return -EIO; 107935d53ceaSAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 108035d53ceaSAzael Avalos pr_info("Panel Power on not supported\n"); 108135d53ceaSAzael Avalos return -ENODEV; 108235d53ceaSAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 108335d53ceaSAzael Avalos return -EIO; 108435d53ceaSAzael Avalos } 108535d53ceaSAzael Avalos 108635d53ceaSAzael Avalos return 0; 108735d53ceaSAzael Avalos } 108835d53ceaSAzael Avalos 108935d53ceaSAzael Avalos static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state) 109035d53ceaSAzael Avalos { 109135d53ceaSAzael Avalos u32 result; 109235d53ceaSAzael Avalos 109335d53ceaSAzael Avalos if (!sci_open(dev)) 109435d53ceaSAzael Avalos return -EIO; 109535d53ceaSAzael Avalos 109635d53ceaSAzael Avalos result = sci_write(dev, SCI_PANEL_POWER_ON, state); 109735d53ceaSAzael Avalos sci_close(dev); 109835d53ceaSAzael Avalos if (result == TOS_FAILURE) { 109935d53ceaSAzael Avalos pr_err("ACPI call to set Panel Power ON failed\n"); 110035d53ceaSAzael Avalos return -EIO; 110135d53ceaSAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 110235d53ceaSAzael Avalos pr_info("Panel Power ON not supported\n"); 110335d53ceaSAzael Avalos return -ENODEV; 110435d53ceaSAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 110535d53ceaSAzael Avalos return -EIO; 110635d53ceaSAzael Avalos } 110735d53ceaSAzael Avalos 110835d53ceaSAzael Avalos return 0; 110935d53ceaSAzael Avalos } 111035d53ceaSAzael Avalos 111117fe4b3dSAzael Avalos /* USB Three */ 111217fe4b3dSAzael Avalos static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state) 111317fe4b3dSAzael Avalos { 111417fe4b3dSAzael Avalos u32 result; 111517fe4b3dSAzael Avalos 111617fe4b3dSAzael Avalos if (!sci_open(dev)) 111717fe4b3dSAzael Avalos return -EIO; 111817fe4b3dSAzael Avalos 111917fe4b3dSAzael Avalos result = sci_read(dev, SCI_USB_THREE, state); 112017fe4b3dSAzael Avalos sci_close(dev); 112117fe4b3dSAzael Avalos if (result == TOS_FAILURE) { 112217fe4b3dSAzael Avalos pr_err("ACPI call to get USB 3 failed\n"); 112317fe4b3dSAzael Avalos return -EIO; 112417fe4b3dSAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 112517fe4b3dSAzael Avalos pr_info("USB 3 not supported\n"); 112617fe4b3dSAzael Avalos return -ENODEV; 112717fe4b3dSAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 112817fe4b3dSAzael Avalos return -EIO; 112917fe4b3dSAzael Avalos } 113017fe4b3dSAzael Avalos 113117fe4b3dSAzael Avalos return 0; 113217fe4b3dSAzael Avalos } 113317fe4b3dSAzael Avalos 113417fe4b3dSAzael Avalos static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state) 113517fe4b3dSAzael Avalos { 113617fe4b3dSAzael Avalos u32 result; 113717fe4b3dSAzael Avalos 113817fe4b3dSAzael Avalos if (!sci_open(dev)) 113917fe4b3dSAzael Avalos return -EIO; 114017fe4b3dSAzael Avalos 114117fe4b3dSAzael Avalos result = sci_write(dev, SCI_USB_THREE, state); 114217fe4b3dSAzael Avalos sci_close(dev); 114317fe4b3dSAzael Avalos if (result == TOS_FAILURE) { 114417fe4b3dSAzael Avalos pr_err("ACPI call to set USB 3 failed\n"); 114517fe4b3dSAzael Avalos return -EIO; 114617fe4b3dSAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 114717fe4b3dSAzael Avalos pr_info("USB 3 not supported\n"); 114817fe4b3dSAzael Avalos return -ENODEV; 114917fe4b3dSAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 115017fe4b3dSAzael Avalos return -EIO; 115117fe4b3dSAzael Avalos } 115217fe4b3dSAzael Avalos 115317fe4b3dSAzael Avalos return 0; 115417fe4b3dSAzael Avalos } 115517fe4b3dSAzael Avalos 115656e6b353SAzael Avalos /* Hotkey Event type */ 115756e6b353SAzael Avalos static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev, 115856e6b353SAzael Avalos u32 *type) 115956e6b353SAzael Avalos { 11603b876000SAzael Avalos u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 }; 11613b876000SAzael Avalos u32 out[TCI_WORDS]; 11623b876000SAzael Avalos acpi_status status; 116356e6b353SAzael Avalos 11643b876000SAzael Avalos status = tci_raw(dev, in, out); 11653b876000SAzael Avalos if (ACPI_FAILURE(status)) { 116656e6b353SAzael Avalos pr_err("ACPI call to get System type failed\n"); 116756e6b353SAzael Avalos return -EIO; 11683b876000SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 116956e6b353SAzael Avalos pr_info("System type not supported\n"); 117056e6b353SAzael Avalos return -ENODEV; 117156e6b353SAzael Avalos } 117256e6b353SAzael Avalos 11733b876000SAzael Avalos *type = out[3]; 117456e6b353SAzael Avalos 117556e6b353SAzael Avalos return 0; 117656e6b353SAzael Avalos } 117756e6b353SAzael Avalos 11783f75bbe9SAzael Avalos /* Transflective Backlight */ 1179695f6060SAzael Avalos static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status) 1180121b7b0dSAkio Idehara { 1181695f6060SAzael Avalos u32 hci_result = hci_read(dev, HCI_TR_BACKLIGHT, status); 1182121b7b0dSAkio Idehara 11831864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 1184121b7b0dSAkio Idehara } 1185121b7b0dSAkio Idehara 1186695f6060SAzael Avalos static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status) 1187121b7b0dSAkio Idehara { 1188695f6060SAzael Avalos u32 hci_result = hci_write(dev, HCI_TR_BACKLIGHT, !status); 1189121b7b0dSAkio Idehara 11901864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 1191121b7b0dSAkio Idehara } 1192121b7b0dSAkio Idehara 11933f75bbe9SAzael Avalos static struct proc_dir_entry *toshiba_proc_dir; 1194b4f9fe12SLen Brown 11953f75bbe9SAzael Avalos /* LCD Brightness */ 119662cce752SSeth Forshee static int __get_lcd_brightness(struct toshiba_acpi_dev *dev) 1197b4f9fe12SLen Brown { 1198b4f9fe12SLen Brown u32 hci_result; 1199b4f9fe12SLen Brown u32 value; 1200121b7b0dSAkio Idehara int brightness = 0; 1201121b7b0dSAkio Idehara 1202121b7b0dSAkio Idehara if (dev->tr_backlight_supported) { 1203695f6060SAzael Avalos int ret = get_tr_backlight_status(dev, &value); 1204b5163992SAzael Avalos 1205121b7b0dSAkio Idehara if (ret) 1206121b7b0dSAkio Idehara return ret; 1207695f6060SAzael Avalos if (value) 1208121b7b0dSAkio Idehara return 0; 1209121b7b0dSAkio Idehara brightness++; 1210121b7b0dSAkio Idehara } 1211b4f9fe12SLen Brown 1212d37782bdSAzael Avalos hci_result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value); 12131864bbc2SAzael Avalos if (hci_result == TOS_SUCCESS) 1214121b7b0dSAkio Idehara return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT); 121532bcd5cbSSeth Forshee 121632bcd5cbSSeth Forshee return -EIO; 1217b4f9fe12SLen Brown } 1218b4f9fe12SLen Brown 121962cce752SSeth Forshee static int get_lcd_brightness(struct backlight_device *bd) 122062cce752SSeth Forshee { 122162cce752SSeth Forshee struct toshiba_acpi_dev *dev = bl_get_data(bd); 1222b5163992SAzael Avalos 122362cce752SSeth Forshee return __get_lcd_brightness(dev); 122462cce752SSeth Forshee } 122562cce752SSeth Forshee 1226936c8bcdSAlexey Dobriyan static int lcd_proc_show(struct seq_file *m, void *v) 1227b4f9fe12SLen Brown { 1228135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 1229135740deSSeth Forshee int value; 1230121b7b0dSAkio Idehara int levels; 1231b4f9fe12SLen Brown 1232135740deSSeth Forshee if (!dev->backlight_dev) 1233135740deSSeth Forshee return -ENODEV; 1234135740deSSeth Forshee 1235121b7b0dSAkio Idehara levels = dev->backlight_dev->props.max_brightness + 1; 123662cce752SSeth Forshee value = get_lcd_brightness(dev->backlight_dev); 1237b4f9fe12SLen Brown if (value >= 0) { 1238936c8bcdSAlexey Dobriyan seq_printf(m, "brightness: %d\n", value); 1239121b7b0dSAkio Idehara seq_printf(m, "brightness_levels: %d\n", levels); 124032bcd5cbSSeth Forshee return 0; 1241b4f9fe12SLen Brown } 1242b4f9fe12SLen Brown 124332bcd5cbSSeth Forshee pr_err("Error reading LCD brightness\n"); 124432bcd5cbSSeth Forshee return -EIO; 1245936c8bcdSAlexey Dobriyan } 1246936c8bcdSAlexey Dobriyan 1247936c8bcdSAlexey Dobriyan static int lcd_proc_open(struct inode *inode, struct file *file) 1248936c8bcdSAlexey Dobriyan { 1249d9dda78bSAl Viro return single_open(file, lcd_proc_show, PDE_DATA(inode)); 1250b4f9fe12SLen Brown } 1251b4f9fe12SLen Brown 125262cce752SSeth Forshee static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value) 1253b4f9fe12SLen Brown { 1254a39f46dfSAzael Avalos u32 hci_result; 1255b4f9fe12SLen Brown 1256121b7b0dSAkio Idehara if (dev->tr_backlight_supported) { 1257695f6060SAzael Avalos int ret = set_tr_backlight_status(dev, !value); 1258b5163992SAzael Avalos 1259121b7b0dSAkio Idehara if (ret) 1260121b7b0dSAkio Idehara return ret; 1261121b7b0dSAkio Idehara if (value) 1262121b7b0dSAkio Idehara value--; 1263121b7b0dSAkio Idehara } 1264121b7b0dSAkio Idehara 1265a39f46dfSAzael Avalos value = value << HCI_LCD_BRIGHTNESS_SHIFT; 1266d37782bdSAzael Avalos hci_result = hci_write(dev, HCI_LCD_BRIGHTNESS, value); 1267a39f46dfSAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 1268b4f9fe12SLen Brown } 1269b4f9fe12SLen Brown 1270b4f9fe12SLen Brown static int set_lcd_status(struct backlight_device *bd) 1271b4f9fe12SLen Brown { 1272135740deSSeth Forshee struct toshiba_acpi_dev *dev = bl_get_data(bd); 1273b5163992SAzael Avalos 127462cce752SSeth Forshee return set_lcd_brightness(dev, bd->props.brightness); 1275b4f9fe12SLen Brown } 1276b4f9fe12SLen Brown 1277936c8bcdSAlexey Dobriyan static ssize_t lcd_proc_write(struct file *file, const char __user *buf, 1278936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1279b4f9fe12SLen Brown { 1280d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1281936c8bcdSAlexey Dobriyan char cmd[42]; 1282936c8bcdSAlexey Dobriyan size_t len; 1283b4f9fe12SLen Brown int value; 1284b4f9fe12SLen Brown int ret; 1285121b7b0dSAkio Idehara int levels = dev->backlight_dev->props.max_brightness + 1; 1286b4f9fe12SLen Brown 1287936c8bcdSAlexey Dobriyan len = min(count, sizeof(cmd) - 1); 1288936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, len)) 1289936c8bcdSAlexey Dobriyan return -EFAULT; 1290936c8bcdSAlexey Dobriyan cmd[len] = '\0'; 1291936c8bcdSAlexey Dobriyan 1292936c8bcdSAlexey Dobriyan if (sscanf(cmd, " brightness : %i", &value) == 1 && 1293121b7b0dSAkio Idehara value >= 0 && value < levels) { 129462cce752SSeth Forshee ret = set_lcd_brightness(dev, value); 1295b4f9fe12SLen Brown if (ret == 0) 1296b4f9fe12SLen Brown ret = count; 1297b4f9fe12SLen Brown } else { 1298b4f9fe12SLen Brown ret = -EINVAL; 1299b4f9fe12SLen Brown } 1300b4f9fe12SLen Brown return ret; 1301b4f9fe12SLen Brown } 1302b4f9fe12SLen Brown 1303936c8bcdSAlexey Dobriyan static const struct file_operations lcd_proc_fops = { 1304936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1305936c8bcdSAlexey Dobriyan .open = lcd_proc_open, 1306936c8bcdSAlexey Dobriyan .read = seq_read, 1307936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1308936c8bcdSAlexey Dobriyan .release = single_release, 1309936c8bcdSAlexey Dobriyan .write = lcd_proc_write, 1310936c8bcdSAlexey Dobriyan }; 1311936c8bcdSAlexey Dobriyan 131236d03f93SSeth Forshee static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status) 131336d03f93SSeth Forshee { 131436d03f93SSeth Forshee u32 hci_result; 131536d03f93SSeth Forshee 1316d37782bdSAzael Avalos hci_result = hci_read(dev, HCI_VIDEO_OUT, status); 13171864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 131836d03f93SSeth Forshee } 131936d03f93SSeth Forshee 1320936c8bcdSAlexey Dobriyan static int video_proc_show(struct seq_file *m, void *v) 1321b4f9fe12SLen Brown { 1322135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 1323b4f9fe12SLen Brown u32 value; 132436d03f93SSeth Forshee int ret; 1325b4f9fe12SLen Brown 132636d03f93SSeth Forshee ret = get_video_status(dev, &value); 132736d03f93SSeth Forshee if (!ret) { 1328b4f9fe12SLen Brown int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; 1329b4f9fe12SLen Brown int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; 1330b4f9fe12SLen Brown int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0; 1331b5163992SAzael Avalos 1332936c8bcdSAlexey Dobriyan seq_printf(m, "lcd_out: %d\n", is_lcd); 1333936c8bcdSAlexey Dobriyan seq_printf(m, "crt_out: %d\n", is_crt); 1334936c8bcdSAlexey Dobriyan seq_printf(m, "tv_out: %d\n", is_tv); 1335b4f9fe12SLen Brown } 1336b4f9fe12SLen Brown 133736d03f93SSeth Forshee return ret; 1338b4f9fe12SLen Brown } 1339b4f9fe12SLen Brown 1340936c8bcdSAlexey Dobriyan static int video_proc_open(struct inode *inode, struct file *file) 1341b4f9fe12SLen Brown { 1342d9dda78bSAl Viro return single_open(file, video_proc_show, PDE_DATA(inode)); 1343936c8bcdSAlexey Dobriyan } 1344936c8bcdSAlexey Dobriyan 1345936c8bcdSAlexey Dobriyan static ssize_t video_proc_write(struct file *file, const char __user *buf, 1346936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1347936c8bcdSAlexey Dobriyan { 1348d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1349936c8bcdSAlexey Dobriyan char *cmd, *buffer; 135036d03f93SSeth Forshee int ret; 1351b4f9fe12SLen Brown int value; 1352b4f9fe12SLen Brown int remain = count; 1353b4f9fe12SLen Brown int lcd_out = -1; 1354b4f9fe12SLen Brown int crt_out = -1; 1355b4f9fe12SLen Brown int tv_out = -1; 1356b4f9fe12SLen Brown u32 video_out; 1357b4f9fe12SLen Brown 1358936c8bcdSAlexey Dobriyan cmd = kmalloc(count + 1, GFP_KERNEL); 1359936c8bcdSAlexey Dobriyan if (!cmd) 1360936c8bcdSAlexey Dobriyan return -ENOMEM; 1361936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, count)) { 1362936c8bcdSAlexey Dobriyan kfree(cmd); 1363936c8bcdSAlexey Dobriyan return -EFAULT; 1364936c8bcdSAlexey Dobriyan } 1365936c8bcdSAlexey Dobriyan cmd[count] = '\0'; 1366936c8bcdSAlexey Dobriyan 1367936c8bcdSAlexey Dobriyan buffer = cmd; 1368936c8bcdSAlexey Dobriyan 1369e0769fe6SDarren Hart /* 1370e0769fe6SDarren Hart * Scan expression. Multiple expressions may be delimited with ; 1371e0769fe6SDarren Hart * NOTE: To keep scanning simple, invalid fields are ignored. 1372b4f9fe12SLen Brown */ 1373b4f9fe12SLen Brown while (remain) { 1374b4f9fe12SLen Brown if (sscanf(buffer, " lcd_out : %i", &value) == 1) 1375b4f9fe12SLen Brown lcd_out = value & 1; 1376b4f9fe12SLen Brown else if (sscanf(buffer, " crt_out : %i", &value) == 1) 1377b4f9fe12SLen Brown crt_out = value & 1; 1378b4f9fe12SLen Brown else if (sscanf(buffer, " tv_out : %i", &value) == 1) 1379b4f9fe12SLen Brown tv_out = value & 1; 1380e0769fe6SDarren Hart /* Advance to one character past the next ; */ 1381b4f9fe12SLen Brown do { 1382b4f9fe12SLen Brown ++buffer; 1383b4f9fe12SLen Brown --remain; 1384b5163992SAzael Avalos } while (remain && *(buffer - 1) != ';'); 1385b4f9fe12SLen Brown } 1386b4f9fe12SLen Brown 1387936c8bcdSAlexey Dobriyan kfree(cmd); 1388936c8bcdSAlexey Dobriyan 138936d03f93SSeth Forshee ret = get_video_status(dev, &video_out); 139036d03f93SSeth Forshee if (!ret) { 1391b4f9fe12SLen Brown unsigned int new_video_out = video_out; 1392b5163992SAzael Avalos 1393b4f9fe12SLen Brown if (lcd_out != -1) 1394b4f9fe12SLen Brown _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out); 1395b4f9fe12SLen Brown if (crt_out != -1) 1396b4f9fe12SLen Brown _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out); 1397b4f9fe12SLen Brown if (tv_out != -1) 1398b4f9fe12SLen Brown _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out); 1399e0769fe6SDarren Hart /* 1400e0769fe6SDarren Hart * To avoid unnecessary video disruption, only write the new 14013f75bbe9SAzael Avalos * video setting if something changed. 14023f75bbe9SAzael Avalos */ 1403b4f9fe12SLen Brown if (new_video_out != video_out) 140432bcd5cbSSeth Forshee ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out); 1405b4f9fe12SLen Brown } 1406b4f9fe12SLen Brown 140732bcd5cbSSeth Forshee return ret ? ret : count; 1408b4f9fe12SLen Brown } 1409b4f9fe12SLen Brown 1410936c8bcdSAlexey Dobriyan static const struct file_operations video_proc_fops = { 1411936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1412936c8bcdSAlexey Dobriyan .open = video_proc_open, 1413936c8bcdSAlexey Dobriyan .read = seq_read, 1414936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1415936c8bcdSAlexey Dobriyan .release = single_release, 1416936c8bcdSAlexey Dobriyan .write = video_proc_write, 1417936c8bcdSAlexey Dobriyan }; 1418936c8bcdSAlexey Dobriyan 14193e07e5baSAzael Avalos /* Fan status */ 142036d03f93SSeth Forshee static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status) 142136d03f93SSeth Forshee { 14223e07e5baSAzael Avalos u32 result = hci_read(dev, HCI_FAN, status); 142336d03f93SSeth Forshee 14243e07e5baSAzael Avalos if (result == TOS_FAILURE) 14253e07e5baSAzael Avalos pr_err("ACPI call to get Fan status failed\n"); 14263e07e5baSAzael Avalos else if (result == TOS_NOT_SUPPORTED) 14273e07e5baSAzael Avalos return -ENODEV; 14283e07e5baSAzael Avalos else if (result == TOS_SUCCESS) 14293e07e5baSAzael Avalos return 0; 14303e07e5baSAzael Avalos 14313e07e5baSAzael Avalos return -EIO; 14323e07e5baSAzael Avalos } 14333e07e5baSAzael Avalos 14343e07e5baSAzael Avalos static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status) 14353e07e5baSAzael Avalos { 14363e07e5baSAzael Avalos u32 result = hci_write(dev, HCI_FAN, status); 14373e07e5baSAzael Avalos 14383e07e5baSAzael Avalos if (result == TOS_FAILURE) 14393e07e5baSAzael Avalos pr_err("ACPI call to set Fan status failed\n"); 14403e07e5baSAzael Avalos else if (result == TOS_NOT_SUPPORTED) 14413e07e5baSAzael Avalos return -ENODEV; 14423e07e5baSAzael Avalos else if (result == TOS_SUCCESS) 14433e07e5baSAzael Avalos return 0; 14443e07e5baSAzael Avalos 14453e07e5baSAzael Avalos return -EIO; 144636d03f93SSeth Forshee } 144736d03f93SSeth Forshee 1448936c8bcdSAlexey Dobriyan static int fan_proc_show(struct seq_file *m, void *v) 1449b4f9fe12SLen Brown { 1450135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 1451b4f9fe12SLen Brown u32 value; 1452b4f9fe12SLen Brown 14533e07e5baSAzael Avalos if (get_fan_status(dev, &value)) 14543e07e5baSAzael Avalos return -EIO; 14553e07e5baSAzael Avalos 1456936c8bcdSAlexey Dobriyan seq_printf(m, "running: %d\n", (value > 0)); 1457135740deSSeth Forshee seq_printf(m, "force_on: %d\n", dev->force_fan); 1458b4f9fe12SLen Brown 14593e07e5baSAzael Avalos return 0; 1460b4f9fe12SLen Brown } 1461b4f9fe12SLen Brown 1462936c8bcdSAlexey Dobriyan static int fan_proc_open(struct inode *inode, struct file *file) 1463b4f9fe12SLen Brown { 1464d9dda78bSAl Viro return single_open(file, fan_proc_show, PDE_DATA(inode)); 1465936c8bcdSAlexey Dobriyan } 1466936c8bcdSAlexey Dobriyan 1467936c8bcdSAlexey Dobriyan static ssize_t fan_proc_write(struct file *file, const char __user *buf, 1468936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1469936c8bcdSAlexey Dobriyan { 1470d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1471936c8bcdSAlexey Dobriyan char cmd[42]; 1472936c8bcdSAlexey Dobriyan size_t len; 1473b4f9fe12SLen Brown int value; 1474b4f9fe12SLen Brown 1475936c8bcdSAlexey Dobriyan len = min(count, sizeof(cmd) - 1); 1476936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, len)) 1477936c8bcdSAlexey Dobriyan return -EFAULT; 1478936c8bcdSAlexey Dobriyan cmd[len] = '\0'; 1479936c8bcdSAlexey Dobriyan 14803e07e5baSAzael Avalos if (sscanf(cmd, " force_on : %i", &value) != 1 && 14813e07e5baSAzael Avalos value != 0 && value != 1) 1482b4f9fe12SLen Brown return -EINVAL; 14833e07e5baSAzael Avalos 14843e07e5baSAzael Avalos if (set_fan_status(dev, value)) 14853e07e5baSAzael Avalos return -EIO; 14863e07e5baSAzael Avalos 14873e07e5baSAzael Avalos dev->force_fan = value; 1488b4f9fe12SLen Brown 1489b4f9fe12SLen Brown return count; 1490b4f9fe12SLen Brown } 1491b4f9fe12SLen Brown 1492936c8bcdSAlexey Dobriyan static const struct file_operations fan_proc_fops = { 1493936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1494936c8bcdSAlexey Dobriyan .open = fan_proc_open, 1495936c8bcdSAlexey Dobriyan .read = seq_read, 1496936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1497936c8bcdSAlexey Dobriyan .release = single_release, 1498936c8bcdSAlexey Dobriyan .write = fan_proc_write, 1499936c8bcdSAlexey Dobriyan }; 1500936c8bcdSAlexey Dobriyan 1501936c8bcdSAlexey Dobriyan static int keys_proc_show(struct seq_file *m, void *v) 1502b4f9fe12SLen Brown { 1503135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 1504b4f9fe12SLen Brown 1505135740deSSeth Forshee seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid); 1506135740deSSeth Forshee seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event); 15077deef550SAzael Avalos 1508936c8bcdSAlexey Dobriyan return 0; 1509b4f9fe12SLen Brown } 1510b4f9fe12SLen Brown 1511936c8bcdSAlexey Dobriyan static int keys_proc_open(struct inode *inode, struct file *file) 1512b4f9fe12SLen Brown { 1513d9dda78bSAl Viro return single_open(file, keys_proc_show, PDE_DATA(inode)); 1514936c8bcdSAlexey Dobriyan } 1515936c8bcdSAlexey Dobriyan 1516936c8bcdSAlexey Dobriyan static ssize_t keys_proc_write(struct file *file, const char __user *buf, 1517936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1518936c8bcdSAlexey Dobriyan { 1519d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1520936c8bcdSAlexey Dobriyan char cmd[42]; 1521936c8bcdSAlexey Dobriyan size_t len; 1522b4f9fe12SLen Brown int value; 1523b4f9fe12SLen Brown 1524936c8bcdSAlexey Dobriyan len = min(count, sizeof(cmd) - 1); 1525936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, len)) 1526936c8bcdSAlexey Dobriyan return -EFAULT; 1527936c8bcdSAlexey Dobriyan cmd[len] = '\0'; 1528936c8bcdSAlexey Dobriyan 1529b5163992SAzael Avalos if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) 1530135740deSSeth Forshee dev->key_event_valid = 0; 1531b5163992SAzael Avalos else 1532b4f9fe12SLen Brown return -EINVAL; 1533b4f9fe12SLen Brown 1534b4f9fe12SLen Brown return count; 1535b4f9fe12SLen Brown } 1536b4f9fe12SLen Brown 1537936c8bcdSAlexey Dobriyan static const struct file_operations keys_proc_fops = { 1538936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1539936c8bcdSAlexey Dobriyan .open = keys_proc_open, 1540936c8bcdSAlexey Dobriyan .read = seq_read, 1541936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1542936c8bcdSAlexey Dobriyan .release = single_release, 1543936c8bcdSAlexey Dobriyan .write = keys_proc_write, 1544936c8bcdSAlexey Dobriyan }; 1545936c8bcdSAlexey Dobriyan 1546936c8bcdSAlexey Dobriyan static int version_proc_show(struct seq_file *m, void *v) 1547b4f9fe12SLen Brown { 1548936c8bcdSAlexey Dobriyan seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION); 1549936c8bcdSAlexey Dobriyan seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION); 1550936c8bcdSAlexey Dobriyan return 0; 1551b4f9fe12SLen Brown } 1552b4f9fe12SLen Brown 1553936c8bcdSAlexey Dobriyan static int version_proc_open(struct inode *inode, struct file *file) 1554936c8bcdSAlexey Dobriyan { 1555d9dda78bSAl Viro return single_open(file, version_proc_show, PDE_DATA(inode)); 1556936c8bcdSAlexey Dobriyan } 1557936c8bcdSAlexey Dobriyan 1558936c8bcdSAlexey Dobriyan static const struct file_operations version_proc_fops = { 1559936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1560936c8bcdSAlexey Dobriyan .open = version_proc_open, 1561936c8bcdSAlexey Dobriyan .read = seq_read, 1562936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1563936c8bcdSAlexey Dobriyan .release = single_release, 1564936c8bcdSAlexey Dobriyan }; 1565936c8bcdSAlexey Dobriyan 1566e0769fe6SDarren Hart /* 1567e0769fe6SDarren Hart * Proc and module init 1568b4f9fe12SLen Brown */ 1569b4f9fe12SLen Brown 1570b4f9fe12SLen Brown #define PROC_TOSHIBA "toshiba" 1571b4f9fe12SLen Brown 1572b859f159SGreg Kroah-Hartman static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev) 1573b4f9fe12SLen Brown { 157436d03f93SSeth Forshee if (dev->backlight_dev) 1575135740deSSeth Forshee proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1576135740deSSeth Forshee &lcd_proc_fops, dev); 157736d03f93SSeth Forshee if (dev->video_supported) 1578135740deSSeth Forshee proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1579135740deSSeth Forshee &video_proc_fops, dev); 158036d03f93SSeth Forshee if (dev->fan_supported) 1581135740deSSeth Forshee proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1582135740deSSeth Forshee &fan_proc_fops, dev); 158336d03f93SSeth Forshee if (dev->hotkey_dev) 1584135740deSSeth Forshee proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1585135740deSSeth Forshee &keys_proc_fops, dev); 1586135740deSSeth Forshee proc_create_data("version", S_IRUGO, toshiba_proc_dir, 1587135740deSSeth Forshee &version_proc_fops, dev); 1588b4f9fe12SLen Brown } 1589b4f9fe12SLen Brown 159036d03f93SSeth Forshee static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev) 1591b4f9fe12SLen Brown { 159236d03f93SSeth Forshee if (dev->backlight_dev) 1593936c8bcdSAlexey Dobriyan remove_proc_entry("lcd", toshiba_proc_dir); 159436d03f93SSeth Forshee if (dev->video_supported) 1595936c8bcdSAlexey Dobriyan remove_proc_entry("video", toshiba_proc_dir); 159636d03f93SSeth Forshee if (dev->fan_supported) 1597936c8bcdSAlexey Dobriyan remove_proc_entry("fan", toshiba_proc_dir); 159836d03f93SSeth Forshee if (dev->hotkey_dev) 1599936c8bcdSAlexey Dobriyan remove_proc_entry("keys", toshiba_proc_dir); 1600936c8bcdSAlexey Dobriyan remove_proc_entry("version", toshiba_proc_dir); 1601b4f9fe12SLen Brown } 1602b4f9fe12SLen Brown 1603acc2472eSLionel Debroux static const struct backlight_ops toshiba_backlight_data = { 1604121b7b0dSAkio Idehara .options = BL_CORE_SUSPENDRESUME, 160562cce752SSeth Forshee .get_brightness = get_lcd_brightness, 1606b4f9fe12SLen Brown .update_status = set_lcd_status, 1607b4f9fe12SLen Brown }; 1608b4f9fe12SLen Brown 1609360f0f39SAzael Avalos /* 1610360f0f39SAzael Avalos * Sysfs files 1611360f0f39SAzael Avalos */ 16129d309848SAzael Avalos static ssize_t version_show(struct device *dev, 1613c6c68ff8SAzael Avalos struct device_attribute *attr, char *buf) 1614c6c68ff8SAzael Avalos { 1615c6c68ff8SAzael Avalos return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION); 1616c6c68ff8SAzael Avalos } 16170c3c0f10SAzael Avalos static DEVICE_ATTR_RO(version); 1618c6c68ff8SAzael Avalos 16199d309848SAzael Avalos static ssize_t fan_store(struct device *dev, 162094477d4cSAzael Avalos struct device_attribute *attr, 162194477d4cSAzael Avalos const char *buf, size_t count) 162294477d4cSAzael Avalos { 162394477d4cSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 162494477d4cSAzael Avalos int state; 162594477d4cSAzael Avalos int ret; 162694477d4cSAzael Avalos 162794477d4cSAzael Avalos ret = kstrtoint(buf, 0, &state); 162894477d4cSAzael Avalos if (ret) 162994477d4cSAzael Avalos return ret; 163094477d4cSAzael Avalos 163194477d4cSAzael Avalos if (state != 0 && state != 1) 163294477d4cSAzael Avalos return -EINVAL; 163394477d4cSAzael Avalos 16343e07e5baSAzael Avalos ret = set_fan_status(toshiba, state); 16353e07e5baSAzael Avalos if (ret) 16363e07e5baSAzael Avalos return ret; 163794477d4cSAzael Avalos 163894477d4cSAzael Avalos return count; 163994477d4cSAzael Avalos } 164094477d4cSAzael Avalos 16419d309848SAzael Avalos static ssize_t fan_show(struct device *dev, 164294477d4cSAzael Avalos struct device_attribute *attr, char *buf) 164394477d4cSAzael Avalos { 164494477d4cSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 164594477d4cSAzael Avalos u32 value; 164694477d4cSAzael Avalos int ret; 164794477d4cSAzael Avalos 164894477d4cSAzael Avalos ret = get_fan_status(toshiba, &value); 164994477d4cSAzael Avalos if (ret) 165094477d4cSAzael Avalos return ret; 165194477d4cSAzael Avalos 165294477d4cSAzael Avalos return sprintf(buf, "%d\n", value); 165394477d4cSAzael Avalos } 16540c3c0f10SAzael Avalos static DEVICE_ATTR_RW(fan); 165594477d4cSAzael Avalos 16569d309848SAzael Avalos static ssize_t kbd_backlight_mode_store(struct device *dev, 1657360f0f39SAzael Avalos struct device_attribute *attr, 1658360f0f39SAzael Avalos const char *buf, size_t count) 1659360f0f39SAzael Avalos { 1660360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1661aeaac098SDan Carpenter int mode; 1662aeaac098SDan Carpenter int ret; 1663360f0f39SAzael Avalos 1664aeaac098SDan Carpenter 1665aeaac098SDan Carpenter ret = kstrtoint(buf, 0, &mode); 1666aeaac098SDan Carpenter if (ret) 1667aeaac098SDan Carpenter return ret; 166893f8c16dSAzael Avalos 166993f8c16dSAzael Avalos /* Check for supported modes depending on keyboard backlight type */ 167093f8c16dSAzael Avalos if (toshiba->kbd_type == 1) { 167193f8c16dSAzael Avalos /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */ 1672aeaac098SDan Carpenter if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO) 1673360f0f39SAzael Avalos return -EINVAL; 167493f8c16dSAzael Avalos } else if (toshiba->kbd_type == 2) { 167593f8c16dSAzael Avalos /* Type 2 doesn't support SCI_KBD_MODE_FNZ */ 167693f8c16dSAzael Avalos if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON && 167793f8c16dSAzael Avalos mode != SCI_KBD_MODE_OFF) 167893f8c16dSAzael Avalos return -EINVAL; 167993f8c16dSAzael Avalos } 1680360f0f39SAzael Avalos 1681e0769fe6SDarren Hart /* 1682e0769fe6SDarren Hart * Set the Keyboard Backlight Mode where: 1683360f0f39SAzael Avalos * Auto - KBD backlight turns off automatically in given time 1684360f0f39SAzael Avalos * FN-Z - KBD backlight "toggles" when hotkey pressed 168593f8c16dSAzael Avalos * ON - KBD backlight is always on 168693f8c16dSAzael Avalos * OFF - KBD backlight is always off 1687360f0f39SAzael Avalos */ 168893f8c16dSAzael Avalos 168993f8c16dSAzael Avalos /* Only make a change if the actual mode has changed */ 1690aeaac098SDan Carpenter if (toshiba->kbd_mode != mode) { 169193f8c16dSAzael Avalos /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ 16921e574dbfSAzael Avalos int time = toshiba->kbd_time << HCI_MISC_SHIFT; 169393f8c16dSAzael Avalos 169493f8c16dSAzael Avalos /* OR the "base time" to the actual method format */ 169593f8c16dSAzael Avalos if (toshiba->kbd_type == 1) { 169693f8c16dSAzael Avalos /* Type 1 requires the current mode */ 169793f8c16dSAzael Avalos time |= toshiba->kbd_mode; 169893f8c16dSAzael Avalos } else if (toshiba->kbd_type == 2) { 169993f8c16dSAzael Avalos /* Type 2 requires the desired mode */ 170093f8c16dSAzael Avalos time |= mode; 170193f8c16dSAzael Avalos } 170293f8c16dSAzael Avalos 1703aeaac098SDan Carpenter ret = toshiba_kbd_illum_status_set(toshiba, time); 1704aeaac098SDan Carpenter if (ret) 1705aeaac098SDan Carpenter return ret; 170693f8c16dSAzael Avalos 1707360f0f39SAzael Avalos toshiba->kbd_mode = mode; 1708360f0f39SAzael Avalos } 1709360f0f39SAzael Avalos 1710360f0f39SAzael Avalos return count; 1711360f0f39SAzael Avalos } 1712360f0f39SAzael Avalos 17139d309848SAzael Avalos static ssize_t kbd_backlight_mode_show(struct device *dev, 1714360f0f39SAzael Avalos struct device_attribute *attr, 1715360f0f39SAzael Avalos char *buf) 1716360f0f39SAzael Avalos { 1717360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1718360f0f39SAzael Avalos u32 time; 1719360f0f39SAzael Avalos 1720360f0f39SAzael Avalos if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) 1721360f0f39SAzael Avalos return -EIO; 1722360f0f39SAzael Avalos 172393f8c16dSAzael Avalos return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK); 172493f8c16dSAzael Avalos } 17250c3c0f10SAzael Avalos static DEVICE_ATTR_RW(kbd_backlight_mode); 172693f8c16dSAzael Avalos 17279d309848SAzael Avalos static ssize_t kbd_type_show(struct device *dev, 17289d309848SAzael Avalos struct device_attribute *attr, char *buf) 172993f8c16dSAzael Avalos { 173093f8c16dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 173193f8c16dSAzael Avalos 173293f8c16dSAzael Avalos return sprintf(buf, "%d\n", toshiba->kbd_type); 173393f8c16dSAzael Avalos } 17340c3c0f10SAzael Avalos static DEVICE_ATTR_RO(kbd_type); 173593f8c16dSAzael Avalos 17369d309848SAzael Avalos static ssize_t available_kbd_modes_show(struct device *dev, 173793f8c16dSAzael Avalos struct device_attribute *attr, 173893f8c16dSAzael Avalos char *buf) 173993f8c16dSAzael Avalos { 174093f8c16dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 174193f8c16dSAzael Avalos 174293f8c16dSAzael Avalos if (toshiba->kbd_type == 1) 174393f8c16dSAzael Avalos return sprintf(buf, "%x %x\n", 174493f8c16dSAzael Avalos SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO); 174593f8c16dSAzael Avalos 174693f8c16dSAzael Avalos return sprintf(buf, "%x %x %x\n", 174793f8c16dSAzael Avalos SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF); 1748360f0f39SAzael Avalos } 17490c3c0f10SAzael Avalos static DEVICE_ATTR_RO(available_kbd_modes); 1750360f0f39SAzael Avalos 17519d309848SAzael Avalos static ssize_t kbd_backlight_timeout_store(struct device *dev, 1752360f0f39SAzael Avalos struct device_attribute *attr, 1753360f0f39SAzael Avalos const char *buf, size_t count) 1754360f0f39SAzael Avalos { 1755360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1756eabde0faSAzael Avalos int time; 1757eabde0faSAzael Avalos int ret; 1758360f0f39SAzael Avalos 1759eabde0faSAzael Avalos ret = kstrtoint(buf, 0, &time); 1760eabde0faSAzael Avalos if (ret) 1761eabde0faSAzael Avalos return ret; 1762eabde0faSAzael Avalos 1763eabde0faSAzael Avalos /* Check for supported values depending on kbd_type */ 1764eabde0faSAzael Avalos if (toshiba->kbd_type == 1) { 1765eabde0faSAzael Avalos if (time < 0 || time > 60) 1766360f0f39SAzael Avalos return -EINVAL; 1767eabde0faSAzael Avalos } else if (toshiba->kbd_type == 2) { 1768eabde0faSAzael Avalos if (time < 1 || time > 60) 1769eabde0faSAzael Avalos return -EINVAL; 1770eabde0faSAzael Avalos } 1771360f0f39SAzael Avalos 1772eabde0faSAzael Avalos /* Set the Keyboard Backlight Timeout */ 1773eabde0faSAzael Avalos 1774eabde0faSAzael Avalos /* Only make a change if the actual timeout has changed */ 1775eabde0faSAzael Avalos if (toshiba->kbd_time != time) { 1776eabde0faSAzael Avalos /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ 1777360f0f39SAzael Avalos time = time << HCI_MISC_SHIFT; 1778eabde0faSAzael Avalos /* OR the "base time" to the actual method format */ 1779eabde0faSAzael Avalos if (toshiba->kbd_type == 1) 1780eabde0faSAzael Avalos time |= SCI_KBD_MODE_FNZ; 1781eabde0faSAzael Avalos else if (toshiba->kbd_type == 2) 1782eabde0faSAzael Avalos time |= SCI_KBD_MODE_AUTO; 1783eabde0faSAzael Avalos 1784eabde0faSAzael Avalos ret = toshiba_kbd_illum_status_set(toshiba, time); 1785eabde0faSAzael Avalos if (ret) 1786eabde0faSAzael Avalos return ret; 1787eabde0faSAzael Avalos 1788360f0f39SAzael Avalos toshiba->kbd_time = time >> HCI_MISC_SHIFT; 1789360f0f39SAzael Avalos } 1790360f0f39SAzael Avalos 1791360f0f39SAzael Avalos return count; 1792360f0f39SAzael Avalos } 1793360f0f39SAzael Avalos 17949d309848SAzael Avalos static ssize_t kbd_backlight_timeout_show(struct device *dev, 1795360f0f39SAzael Avalos struct device_attribute *attr, 1796360f0f39SAzael Avalos char *buf) 1797360f0f39SAzael Avalos { 1798360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1799360f0f39SAzael Avalos u32 time; 1800360f0f39SAzael Avalos 1801360f0f39SAzael Avalos if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) 1802360f0f39SAzael Avalos return -EIO; 1803360f0f39SAzael Avalos 1804360f0f39SAzael Avalos return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT); 1805360f0f39SAzael Avalos } 18060c3c0f10SAzael Avalos static DEVICE_ATTR_RW(kbd_backlight_timeout); 1807360f0f39SAzael Avalos 18089d309848SAzael Avalos static ssize_t touchpad_store(struct device *dev, 18099d8658acSAzael Avalos struct device_attribute *attr, 18109d8658acSAzael Avalos const char *buf, size_t count) 18119d8658acSAzael Avalos { 18129d8658acSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 18139d8658acSAzael Avalos int state; 1814c8a41669SAzael Avalos int ret; 18159d8658acSAzael Avalos 18169d8658acSAzael Avalos /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */ 1817c8a41669SAzael Avalos ret = kstrtoint(buf, 0, &state); 1818c8a41669SAzael Avalos if (ret) 1819c8a41669SAzael Avalos return ret; 1820c8a41669SAzael Avalos if (state != 0 && state != 1) 1821c8a41669SAzael Avalos return -EINVAL; 1822c8a41669SAzael Avalos 1823c8a41669SAzael Avalos ret = toshiba_touchpad_set(toshiba, state); 1824c8a41669SAzael Avalos if (ret) 1825c8a41669SAzael Avalos return ret; 18269d8658acSAzael Avalos 18279d8658acSAzael Avalos return count; 18289d8658acSAzael Avalos } 18299d8658acSAzael Avalos 18309d309848SAzael Avalos static ssize_t touchpad_show(struct device *dev, 18319d8658acSAzael Avalos struct device_attribute *attr, char *buf) 18329d8658acSAzael Avalos { 18339d8658acSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 18349d8658acSAzael Avalos u32 state; 18359d8658acSAzael Avalos int ret; 18369d8658acSAzael Avalos 18379d8658acSAzael Avalos ret = toshiba_touchpad_get(toshiba, &state); 18389d8658acSAzael Avalos if (ret < 0) 18399d8658acSAzael Avalos return ret; 18409d8658acSAzael Avalos 18419d8658acSAzael Avalos return sprintf(buf, "%i\n", state); 18429d8658acSAzael Avalos } 18430c3c0f10SAzael Avalos static DEVICE_ATTR_RW(touchpad); 18449d8658acSAzael Avalos 18459d309848SAzael Avalos static ssize_t position_show(struct device *dev, 18465a2813e9SAzael Avalos struct device_attribute *attr, char *buf) 18475a2813e9SAzael Avalos { 18485a2813e9SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 18495a2813e9SAzael Avalos u32 xyval, zval, tmp; 18505a2813e9SAzael Avalos u16 x, y, z; 18515a2813e9SAzael Avalos int ret; 18525a2813e9SAzael Avalos 18535a2813e9SAzael Avalos xyval = zval = 0; 18545a2813e9SAzael Avalos ret = toshiba_accelerometer_get(toshiba, &xyval, &zval); 18555a2813e9SAzael Avalos if (ret < 0) 18565a2813e9SAzael Avalos return ret; 18575a2813e9SAzael Avalos 18585a2813e9SAzael Avalos x = xyval & HCI_ACCEL_MASK; 18595a2813e9SAzael Avalos tmp = xyval >> HCI_MISC_SHIFT; 18605a2813e9SAzael Avalos y = tmp & HCI_ACCEL_MASK; 18615a2813e9SAzael Avalos z = zval & HCI_ACCEL_MASK; 18625a2813e9SAzael Avalos 18635a2813e9SAzael Avalos return sprintf(buf, "%d %d %d\n", x, y, z); 18645a2813e9SAzael Avalos } 18650c3c0f10SAzael Avalos static DEVICE_ATTR_RO(position); 18665a2813e9SAzael Avalos 18679d309848SAzael Avalos static ssize_t usb_sleep_charge_show(struct device *dev, 18689d309848SAzael Avalos struct device_attribute *attr, char *buf) 1869e26ffe51SAzael Avalos { 1870e26ffe51SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1871e26ffe51SAzael Avalos u32 mode; 1872e26ffe51SAzael Avalos int ret; 1873e26ffe51SAzael Avalos 1874e26ffe51SAzael Avalos ret = toshiba_usb_sleep_charge_get(toshiba, &mode); 1875e26ffe51SAzael Avalos if (ret < 0) 1876e26ffe51SAzael Avalos return ret; 1877e26ffe51SAzael Avalos 1878e26ffe51SAzael Avalos return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK); 1879e26ffe51SAzael Avalos } 1880e26ffe51SAzael Avalos 18819d309848SAzael Avalos static ssize_t usb_sleep_charge_store(struct device *dev, 1882e26ffe51SAzael Avalos struct device_attribute *attr, 1883e26ffe51SAzael Avalos const char *buf, size_t count) 1884e26ffe51SAzael Avalos { 1885e26ffe51SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1886e26ffe51SAzael Avalos u32 mode; 1887e26ffe51SAzael Avalos int state; 1888e26ffe51SAzael Avalos int ret; 1889e26ffe51SAzael Avalos 1890e26ffe51SAzael Avalos ret = kstrtoint(buf, 0, &state); 1891e26ffe51SAzael Avalos if (ret) 1892e26ffe51SAzael Avalos return ret; 1893e0769fe6SDarren Hart /* 1894e0769fe6SDarren Hart * Check for supported values, where: 1895e26ffe51SAzael Avalos * 0 - Disabled 1896e26ffe51SAzael Avalos * 1 - Alternate (Non USB conformant devices that require more power) 1897e26ffe51SAzael Avalos * 2 - Auto (USB conformant devices) 1898c8c91842SAzael Avalos * 3 - Typical 1899e26ffe51SAzael Avalos */ 1900c8c91842SAzael Avalos if (state != 0 && state != 1 && state != 2 && state != 3) 1901e26ffe51SAzael Avalos return -EINVAL; 1902e26ffe51SAzael Avalos 1903e26ffe51SAzael Avalos /* Set the USB charging mode to internal value */ 1904c8c91842SAzael Avalos mode = toshiba->usbsc_mode_base; 1905e26ffe51SAzael Avalos if (state == 0) 1906c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_DISABLED; 1907e26ffe51SAzael Avalos else if (state == 1) 1908c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_ALTERNATE; 1909e26ffe51SAzael Avalos else if (state == 2) 1910c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_AUTO; 1911c8c91842SAzael Avalos else if (state == 3) 1912c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_TYPICAL; 1913e26ffe51SAzael Avalos 1914e26ffe51SAzael Avalos ret = toshiba_usb_sleep_charge_set(toshiba, mode); 1915e26ffe51SAzael Avalos if (ret) 1916e26ffe51SAzael Avalos return ret; 1917e26ffe51SAzael Avalos 1918e26ffe51SAzael Avalos return count; 1919e26ffe51SAzael Avalos } 19200c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_sleep_charge); 1921e26ffe51SAzael Avalos 1922182bcaa5SAzael Avalos static ssize_t sleep_functions_on_battery_show(struct device *dev, 1923182bcaa5SAzael Avalos struct device_attribute *attr, 1924182bcaa5SAzael Avalos char *buf) 1925182bcaa5SAzael Avalos { 1926182bcaa5SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1927182bcaa5SAzael Avalos u32 state; 1928182bcaa5SAzael Avalos int bat_lvl; 1929182bcaa5SAzael Avalos int status; 1930182bcaa5SAzael Avalos int ret; 1931182bcaa5SAzael Avalos int tmp; 1932182bcaa5SAzael Avalos 1933182bcaa5SAzael Avalos ret = toshiba_sleep_functions_status_get(toshiba, &state); 1934182bcaa5SAzael Avalos if (ret < 0) 1935182bcaa5SAzael Avalos return ret; 1936182bcaa5SAzael Avalos 1937182bcaa5SAzael Avalos /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */ 1938182bcaa5SAzael Avalos tmp = state & SCI_USB_CHARGE_BAT_MASK; 1939182bcaa5SAzael Avalos status = (tmp == 0x4) ? 1 : 0; 1940182bcaa5SAzael Avalos /* Determine the battery level set */ 1941182bcaa5SAzael Avalos bat_lvl = state >> HCI_MISC_SHIFT; 1942182bcaa5SAzael Avalos 1943182bcaa5SAzael Avalos return sprintf(buf, "%d %d\n", status, bat_lvl); 1944182bcaa5SAzael Avalos } 1945182bcaa5SAzael Avalos 1946182bcaa5SAzael Avalos static ssize_t sleep_functions_on_battery_store(struct device *dev, 1947182bcaa5SAzael Avalos struct device_attribute *attr, 1948182bcaa5SAzael Avalos const char *buf, size_t count) 1949182bcaa5SAzael Avalos { 1950182bcaa5SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1951182bcaa5SAzael Avalos u32 status; 1952182bcaa5SAzael Avalos int value; 1953182bcaa5SAzael Avalos int ret; 1954182bcaa5SAzael Avalos int tmp; 1955182bcaa5SAzael Avalos 1956182bcaa5SAzael Avalos ret = kstrtoint(buf, 0, &value); 1957182bcaa5SAzael Avalos if (ret) 1958182bcaa5SAzael Avalos return ret; 1959182bcaa5SAzael Avalos 1960e0769fe6SDarren Hart /* 1961e0769fe6SDarren Hart * Set the status of the function: 1962182bcaa5SAzael Avalos * 0 - Disabled 1963182bcaa5SAzael Avalos * 1-100 - Enabled 1964182bcaa5SAzael Avalos */ 1965182bcaa5SAzael Avalos if (value < 0 || value > 100) 1966182bcaa5SAzael Avalos return -EINVAL; 1967182bcaa5SAzael Avalos 1968182bcaa5SAzael Avalos if (value == 0) { 1969182bcaa5SAzael Avalos tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT; 1970182bcaa5SAzael Avalos status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF; 1971182bcaa5SAzael Avalos } else { 1972182bcaa5SAzael Avalos tmp = value << HCI_MISC_SHIFT; 1973182bcaa5SAzael Avalos status = tmp | SCI_USB_CHARGE_BAT_LVL_ON; 1974182bcaa5SAzael Avalos } 1975182bcaa5SAzael Avalos ret = toshiba_sleep_functions_status_set(toshiba, status); 1976182bcaa5SAzael Avalos if (ret < 0) 1977182bcaa5SAzael Avalos return ret; 1978182bcaa5SAzael Avalos 1979182bcaa5SAzael Avalos toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT; 1980182bcaa5SAzael Avalos 1981182bcaa5SAzael Avalos return count; 1982182bcaa5SAzael Avalos } 19830c3c0f10SAzael Avalos static DEVICE_ATTR_RW(sleep_functions_on_battery); 1984182bcaa5SAzael Avalos 19859d309848SAzael Avalos static ssize_t usb_rapid_charge_show(struct device *dev, 19869d309848SAzael Avalos struct device_attribute *attr, char *buf) 1987bb3fe01fSAzael Avalos { 1988bb3fe01fSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1989bb3fe01fSAzael Avalos u32 state; 1990bb3fe01fSAzael Avalos int ret; 1991bb3fe01fSAzael Avalos 1992bb3fe01fSAzael Avalos ret = toshiba_usb_rapid_charge_get(toshiba, &state); 1993bb3fe01fSAzael Avalos if (ret < 0) 1994bb3fe01fSAzael Avalos return ret; 1995bb3fe01fSAzael Avalos 1996bb3fe01fSAzael Avalos return sprintf(buf, "%d\n", state); 1997bb3fe01fSAzael Avalos } 1998bb3fe01fSAzael Avalos 19999d309848SAzael Avalos static ssize_t usb_rapid_charge_store(struct device *dev, 2000bb3fe01fSAzael Avalos struct device_attribute *attr, 2001bb3fe01fSAzael Avalos const char *buf, size_t count) 2002bb3fe01fSAzael Avalos { 2003bb3fe01fSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2004bb3fe01fSAzael Avalos int state; 2005bb3fe01fSAzael Avalos int ret; 2006bb3fe01fSAzael Avalos 2007bb3fe01fSAzael Avalos ret = kstrtoint(buf, 0, &state); 2008bb3fe01fSAzael Avalos if (ret) 2009bb3fe01fSAzael Avalos return ret; 2010bb3fe01fSAzael Avalos if (state != 0 && state != 1) 2011bb3fe01fSAzael Avalos return -EINVAL; 2012bb3fe01fSAzael Avalos 2013bb3fe01fSAzael Avalos ret = toshiba_usb_rapid_charge_set(toshiba, state); 2014bb3fe01fSAzael Avalos if (ret) 2015bb3fe01fSAzael Avalos return ret; 2016bb3fe01fSAzael Avalos 2017bb3fe01fSAzael Avalos return count; 2018bb3fe01fSAzael Avalos } 20190c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_rapid_charge); 2020bb3fe01fSAzael Avalos 20219d309848SAzael Avalos static ssize_t usb_sleep_music_show(struct device *dev, 20229d309848SAzael Avalos struct device_attribute *attr, char *buf) 2023172ce0a9SAzael Avalos { 2024172ce0a9SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2025172ce0a9SAzael Avalos u32 state; 2026172ce0a9SAzael Avalos int ret; 2027172ce0a9SAzael Avalos 2028172ce0a9SAzael Avalos ret = toshiba_usb_sleep_music_get(toshiba, &state); 2029172ce0a9SAzael Avalos if (ret < 0) 2030172ce0a9SAzael Avalos return ret; 2031172ce0a9SAzael Avalos 2032172ce0a9SAzael Avalos return sprintf(buf, "%d\n", state); 2033172ce0a9SAzael Avalos } 2034172ce0a9SAzael Avalos 20359d309848SAzael Avalos static ssize_t usb_sleep_music_store(struct device *dev, 2036172ce0a9SAzael Avalos struct device_attribute *attr, 2037172ce0a9SAzael Avalos const char *buf, size_t count) 2038172ce0a9SAzael Avalos { 2039172ce0a9SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2040172ce0a9SAzael Avalos int state; 2041172ce0a9SAzael Avalos int ret; 2042172ce0a9SAzael Avalos 2043172ce0a9SAzael Avalos ret = kstrtoint(buf, 0, &state); 2044172ce0a9SAzael Avalos if (ret) 2045172ce0a9SAzael Avalos return ret; 2046172ce0a9SAzael Avalos if (state != 0 && state != 1) 2047172ce0a9SAzael Avalos return -EINVAL; 2048172ce0a9SAzael Avalos 2049172ce0a9SAzael Avalos ret = toshiba_usb_sleep_music_set(toshiba, state); 2050172ce0a9SAzael Avalos if (ret) 2051172ce0a9SAzael Avalos return ret; 2052172ce0a9SAzael Avalos 2053172ce0a9SAzael Avalos return count; 2054172ce0a9SAzael Avalos } 20550c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_sleep_music); 2056172ce0a9SAzael Avalos 20579d309848SAzael Avalos static ssize_t kbd_function_keys_show(struct device *dev, 20589d309848SAzael Avalos struct device_attribute *attr, char *buf) 2059bae84195SAzael Avalos { 2060bae84195SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2061bae84195SAzael Avalos int mode; 2062bae84195SAzael Avalos int ret; 2063bae84195SAzael Avalos 2064bae84195SAzael Avalos ret = toshiba_function_keys_get(toshiba, &mode); 2065bae84195SAzael Avalos if (ret < 0) 2066bae84195SAzael Avalos return ret; 2067bae84195SAzael Avalos 2068bae84195SAzael Avalos return sprintf(buf, "%d\n", mode); 2069bae84195SAzael Avalos } 2070bae84195SAzael Avalos 20719d309848SAzael Avalos static ssize_t kbd_function_keys_store(struct device *dev, 2072bae84195SAzael Avalos struct device_attribute *attr, 2073bae84195SAzael Avalos const char *buf, size_t count) 2074bae84195SAzael Avalos { 2075bae84195SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2076bae84195SAzael Avalos int mode; 2077bae84195SAzael Avalos int ret; 2078bae84195SAzael Avalos 2079bae84195SAzael Avalos ret = kstrtoint(buf, 0, &mode); 2080bae84195SAzael Avalos if (ret) 2081bae84195SAzael Avalos return ret; 2082e0769fe6SDarren Hart /* 2083e0769fe6SDarren Hart * Check for the function keys mode where: 2084bae84195SAzael Avalos * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12}) 2085bae84195SAzael Avalos * 1 - Special functions (Opposite of the above setting) 2086bae84195SAzael Avalos */ 2087bae84195SAzael Avalos if (mode != 0 && mode != 1) 2088bae84195SAzael Avalos return -EINVAL; 2089bae84195SAzael Avalos 2090bae84195SAzael Avalos ret = toshiba_function_keys_set(toshiba, mode); 2091bae84195SAzael Avalos if (ret) 2092bae84195SAzael Avalos return ret; 2093bae84195SAzael Avalos 2094bae84195SAzael Avalos pr_info("Reboot for changes to KBD Function Keys to take effect"); 2095bae84195SAzael Avalos 2096bae84195SAzael Avalos return count; 2097bae84195SAzael Avalos } 20980c3c0f10SAzael Avalos static DEVICE_ATTR_RW(kbd_function_keys); 2099bae84195SAzael Avalos 21009d309848SAzael Avalos static ssize_t panel_power_on_show(struct device *dev, 21019d309848SAzael Avalos struct device_attribute *attr, char *buf) 210235d53ceaSAzael Avalos { 210335d53ceaSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 210435d53ceaSAzael Avalos u32 state; 210535d53ceaSAzael Avalos int ret; 210635d53ceaSAzael Avalos 210735d53ceaSAzael Avalos ret = toshiba_panel_power_on_get(toshiba, &state); 210835d53ceaSAzael Avalos if (ret < 0) 210935d53ceaSAzael Avalos return ret; 211035d53ceaSAzael Avalos 211135d53ceaSAzael Avalos return sprintf(buf, "%d\n", state); 211235d53ceaSAzael Avalos } 211335d53ceaSAzael Avalos 21149d309848SAzael Avalos static ssize_t panel_power_on_store(struct device *dev, 211535d53ceaSAzael Avalos struct device_attribute *attr, 211635d53ceaSAzael Avalos const char *buf, size_t count) 211735d53ceaSAzael Avalos { 211835d53ceaSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 211935d53ceaSAzael Avalos int state; 212035d53ceaSAzael Avalos int ret; 212135d53ceaSAzael Avalos 212235d53ceaSAzael Avalos ret = kstrtoint(buf, 0, &state); 212335d53ceaSAzael Avalos if (ret) 212435d53ceaSAzael Avalos return ret; 212535d53ceaSAzael Avalos if (state != 0 && state != 1) 212635d53ceaSAzael Avalos return -EINVAL; 212735d53ceaSAzael Avalos 212835d53ceaSAzael Avalos ret = toshiba_panel_power_on_set(toshiba, state); 212935d53ceaSAzael Avalos if (ret) 213035d53ceaSAzael Avalos return ret; 213135d53ceaSAzael Avalos 213235d53ceaSAzael Avalos pr_info("Reboot for changes to Panel Power ON to take effect"); 213335d53ceaSAzael Avalos 213435d53ceaSAzael Avalos return count; 213535d53ceaSAzael Avalos } 21360c3c0f10SAzael Avalos static DEVICE_ATTR_RW(panel_power_on); 213735d53ceaSAzael Avalos 21389d309848SAzael Avalos static ssize_t usb_three_show(struct device *dev, 21399d309848SAzael Avalos struct device_attribute *attr, char *buf) 214017fe4b3dSAzael Avalos { 214117fe4b3dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 214217fe4b3dSAzael Avalos u32 state; 214317fe4b3dSAzael Avalos int ret; 214417fe4b3dSAzael Avalos 214517fe4b3dSAzael Avalos ret = toshiba_usb_three_get(toshiba, &state); 214617fe4b3dSAzael Avalos if (ret < 0) 214717fe4b3dSAzael Avalos return ret; 214817fe4b3dSAzael Avalos 214917fe4b3dSAzael Avalos return sprintf(buf, "%d\n", state); 215017fe4b3dSAzael Avalos } 215117fe4b3dSAzael Avalos 21529d309848SAzael Avalos static ssize_t usb_three_store(struct device *dev, 215317fe4b3dSAzael Avalos struct device_attribute *attr, 215417fe4b3dSAzael Avalos const char *buf, size_t count) 215517fe4b3dSAzael Avalos { 215617fe4b3dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 215717fe4b3dSAzael Avalos int state; 215817fe4b3dSAzael Avalos int ret; 215917fe4b3dSAzael Avalos 216017fe4b3dSAzael Avalos ret = kstrtoint(buf, 0, &state); 216117fe4b3dSAzael Avalos if (ret) 216217fe4b3dSAzael Avalos return ret; 2163e0769fe6SDarren Hart /* 2164e0769fe6SDarren Hart * Check for USB 3 mode where: 216517fe4b3dSAzael Avalos * 0 - Disabled (Acts like a USB 2 port, saving power) 216617fe4b3dSAzael Avalos * 1 - Enabled 216717fe4b3dSAzael Avalos */ 216817fe4b3dSAzael Avalos if (state != 0 && state != 1) 216917fe4b3dSAzael Avalos return -EINVAL; 217017fe4b3dSAzael Avalos 217117fe4b3dSAzael Avalos ret = toshiba_usb_three_set(toshiba, state); 217217fe4b3dSAzael Avalos if (ret) 217317fe4b3dSAzael Avalos return ret; 217417fe4b3dSAzael Avalos 217517fe4b3dSAzael Avalos pr_info("Reboot for changes to USB 3 to take effect"); 217617fe4b3dSAzael Avalos 217717fe4b3dSAzael Avalos return count; 217817fe4b3dSAzael Avalos } 21790c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_three); 21809bd1213bSAzael Avalos 21819bd1213bSAzael Avalos static struct attribute *toshiba_attributes[] = { 21829bd1213bSAzael Avalos &dev_attr_version.attr, 21839bd1213bSAzael Avalos &dev_attr_fan.attr, 21849bd1213bSAzael Avalos &dev_attr_kbd_backlight_mode.attr, 21859bd1213bSAzael Avalos &dev_attr_kbd_type.attr, 21869bd1213bSAzael Avalos &dev_attr_available_kbd_modes.attr, 21879bd1213bSAzael Avalos &dev_attr_kbd_backlight_timeout.attr, 21889bd1213bSAzael Avalos &dev_attr_touchpad.attr, 21899bd1213bSAzael Avalos &dev_attr_position.attr, 21909bd1213bSAzael Avalos &dev_attr_usb_sleep_charge.attr, 21919bd1213bSAzael Avalos &dev_attr_sleep_functions_on_battery.attr, 21929bd1213bSAzael Avalos &dev_attr_usb_rapid_charge.attr, 21939bd1213bSAzael Avalos &dev_attr_usb_sleep_music.attr, 21949bd1213bSAzael Avalos &dev_attr_kbd_function_keys.attr, 21959bd1213bSAzael Avalos &dev_attr_panel_power_on.attr, 21969bd1213bSAzael Avalos &dev_attr_usb_three.attr, 21979bd1213bSAzael Avalos NULL, 21989bd1213bSAzael Avalos }; 21999bd1213bSAzael Avalos 2200360f0f39SAzael Avalos static umode_t toshiba_sysfs_is_visible(struct kobject *kobj, 2201360f0f39SAzael Avalos struct attribute *attr, int idx) 2202360f0f39SAzael Avalos { 2203360f0f39SAzael Avalos struct device *dev = container_of(kobj, struct device, kobj); 2204360f0f39SAzael Avalos struct toshiba_acpi_dev *drv = dev_get_drvdata(dev); 2205360f0f39SAzael Avalos bool exists = true; 2206360f0f39SAzael Avalos 220794477d4cSAzael Avalos if (attr == &dev_attr_fan.attr) 220894477d4cSAzael Avalos exists = (drv->fan_supported) ? true : false; 220994477d4cSAzael Avalos else if (attr == &dev_attr_kbd_backlight_mode.attr) 2210360f0f39SAzael Avalos exists = (drv->kbd_illum_supported) ? true : false; 2211360f0f39SAzael Avalos else if (attr == &dev_attr_kbd_backlight_timeout.attr) 2212360f0f39SAzael Avalos exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false; 22139d8658acSAzael Avalos else if (attr == &dev_attr_touchpad.attr) 22149d8658acSAzael Avalos exists = (drv->touchpad_supported) ? true : false; 22155a2813e9SAzael Avalos else if (attr == &dev_attr_position.attr) 22165a2813e9SAzael Avalos exists = (drv->accelerometer_supported) ? true : false; 2217e26ffe51SAzael Avalos else if (attr == &dev_attr_usb_sleep_charge.attr) 2218e26ffe51SAzael Avalos exists = (drv->usb_sleep_charge_supported) ? true : false; 2219182bcaa5SAzael Avalos else if (attr == &dev_attr_sleep_functions_on_battery.attr) 2220182bcaa5SAzael Avalos exists = (drv->usb_sleep_charge_supported) ? true : false; 2221bb3fe01fSAzael Avalos else if (attr == &dev_attr_usb_rapid_charge.attr) 2222bb3fe01fSAzael Avalos exists = (drv->usb_rapid_charge_supported) ? true : false; 2223172ce0a9SAzael Avalos else if (attr == &dev_attr_usb_sleep_music.attr) 2224172ce0a9SAzael Avalos exists = (drv->usb_sleep_music_supported) ? true : false; 2225bae84195SAzael Avalos else if (attr == &dev_attr_kbd_function_keys.attr) 2226bae84195SAzael Avalos exists = (drv->kbd_function_keys_supported) ? true : false; 222735d53ceaSAzael Avalos else if (attr == &dev_attr_panel_power_on.attr) 222835d53ceaSAzael Avalos exists = (drv->panel_power_on_supported) ? true : false; 222917fe4b3dSAzael Avalos else if (attr == &dev_attr_usb_three.attr) 223017fe4b3dSAzael Avalos exists = (drv->usb_three_supported) ? true : false; 2231360f0f39SAzael Avalos 2232360f0f39SAzael Avalos return exists ? attr->mode : 0; 2233360f0f39SAzael Avalos } 2234360f0f39SAzael Avalos 22359bd1213bSAzael Avalos static struct attribute_group toshiba_attr_group = { 22369bd1213bSAzael Avalos .is_visible = toshiba_sysfs_is_visible, 22379bd1213bSAzael Avalos .attrs = toshiba_attributes, 22389bd1213bSAzael Avalos }; 22399bd1213bSAzael Avalos 22401f28f290SAzael Avalos /* 2241fc5462f8SAzael Avalos * Misc device 2242fc5462f8SAzael Avalos */ 2243fc5462f8SAzael Avalos static int toshiba_acpi_smm_bridge(SMMRegisters *regs) 2244fc5462f8SAzael Avalos { 2245fc5462f8SAzael Avalos u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx, 2246fc5462f8SAzael Avalos regs->edx, regs->esi, regs->edi }; 2247fc5462f8SAzael Avalos u32 out[TCI_WORDS]; 2248fc5462f8SAzael Avalos acpi_status status; 2249fc5462f8SAzael Avalos 2250fc5462f8SAzael Avalos status = tci_raw(toshiba_acpi, in, out); 2251fc5462f8SAzael Avalos if (ACPI_FAILURE(status)) { 2252fc5462f8SAzael Avalos pr_err("ACPI call to query SMM registers failed\n"); 2253fc5462f8SAzael Avalos return -EIO; 2254fc5462f8SAzael Avalos } 2255fc5462f8SAzael Avalos 2256fc5462f8SAzael Avalos /* Fillout the SMM struct with the TCI call results */ 2257fc5462f8SAzael Avalos regs->eax = out[0]; 2258fc5462f8SAzael Avalos regs->ebx = out[1]; 2259fc5462f8SAzael Avalos regs->ecx = out[2]; 2260fc5462f8SAzael Avalos regs->edx = out[3]; 2261fc5462f8SAzael Avalos regs->esi = out[4]; 2262fc5462f8SAzael Avalos regs->edi = out[5]; 2263fc5462f8SAzael Avalos 2264fc5462f8SAzael Avalos return 0; 2265fc5462f8SAzael Avalos } 2266fc5462f8SAzael Avalos 2267fc5462f8SAzael Avalos static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd, 2268fc5462f8SAzael Avalos unsigned long arg) 2269fc5462f8SAzael Avalos { 2270fc5462f8SAzael Avalos SMMRegisters __user *argp = (SMMRegisters __user *)arg; 2271fc5462f8SAzael Avalos SMMRegisters regs; 2272fc5462f8SAzael Avalos int ret; 2273fc5462f8SAzael Avalos 2274fc5462f8SAzael Avalos if (!argp) 2275fc5462f8SAzael Avalos return -EINVAL; 2276fc5462f8SAzael Avalos 2277fc5462f8SAzael Avalos switch (cmd) { 2278fc5462f8SAzael Avalos case TOSH_SMM: 2279fc5462f8SAzael Avalos if (copy_from_user(®s, argp, sizeof(SMMRegisters))) 2280fc5462f8SAzael Avalos return -EFAULT; 2281fc5462f8SAzael Avalos ret = toshiba_acpi_smm_bridge(®s); 2282fc5462f8SAzael Avalos if (ret) 2283fc5462f8SAzael Avalos return ret; 2284fc5462f8SAzael Avalos if (copy_to_user(argp, ®s, sizeof(SMMRegisters))) 2285fc5462f8SAzael Avalos return -EFAULT; 2286fc5462f8SAzael Avalos break; 2287fc5462f8SAzael Avalos case TOSHIBA_ACPI_SCI: 2288fc5462f8SAzael Avalos if (copy_from_user(®s, argp, sizeof(SMMRegisters))) 2289fc5462f8SAzael Avalos return -EFAULT; 2290fc5462f8SAzael Avalos /* Ensure we are being called with a SCI_{GET, SET} register */ 2291fc5462f8SAzael Avalos if (regs.eax != SCI_GET && regs.eax != SCI_SET) 2292fc5462f8SAzael Avalos return -EINVAL; 2293fc5462f8SAzael Avalos if (!sci_open(toshiba_acpi)) 2294fc5462f8SAzael Avalos return -EIO; 2295fc5462f8SAzael Avalos ret = toshiba_acpi_smm_bridge(®s); 2296fc5462f8SAzael Avalos sci_close(toshiba_acpi); 2297fc5462f8SAzael Avalos if (ret) 2298fc5462f8SAzael Avalos return ret; 2299fc5462f8SAzael Avalos if (copy_to_user(argp, ®s, sizeof(SMMRegisters))) 2300fc5462f8SAzael Avalos return -EFAULT; 2301fc5462f8SAzael Avalos break; 2302fc5462f8SAzael Avalos default: 2303fc5462f8SAzael Avalos return -EINVAL; 2304fc5462f8SAzael Avalos } 2305fc5462f8SAzael Avalos 2306fc5462f8SAzael Avalos return 0; 2307fc5462f8SAzael Avalos } 2308fc5462f8SAzael Avalos 2309fc5462f8SAzael Avalos static const struct file_operations toshiba_acpi_fops = { 2310fc5462f8SAzael Avalos .owner = THIS_MODULE, 2311fc5462f8SAzael Avalos .unlocked_ioctl = toshiba_acpi_ioctl, 2312fc5462f8SAzael Avalos .llseek = noop_llseek, 2313fc5462f8SAzael Avalos }; 2314fc5462f8SAzael Avalos 2315fc5462f8SAzael Avalos /* 23161f28f290SAzael Avalos * Hotkeys 23171f28f290SAzael Avalos */ 23181f28f290SAzael Avalos static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev) 23191f28f290SAzael Avalos { 23201f28f290SAzael Avalos acpi_status status; 23211f28f290SAzael Avalos u32 result; 23221f28f290SAzael Avalos 23231f28f290SAzael Avalos status = acpi_evaluate_object(dev->acpi_dev->handle, 23241f28f290SAzael Avalos "ENAB", NULL, NULL); 23251f28f290SAzael Avalos if (ACPI_FAILURE(status)) 23261f28f290SAzael Avalos return -ENODEV; 23271f28f290SAzael Avalos 2328d37782bdSAzael Avalos result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE); 23291f28f290SAzael Avalos if (result == TOS_FAILURE) 23301f28f290SAzael Avalos return -EIO; 23311f28f290SAzael Avalos else if (result == TOS_NOT_SUPPORTED) 23321f28f290SAzael Avalos return -ENODEV; 23331f28f290SAzael Avalos 23341f28f290SAzael Avalos return 0; 23351f28f290SAzael Avalos } 23361f28f290SAzael Avalos 2337fb42d1f4SAzael Avalos static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev) 2338fb42d1f4SAzael Avalos { 2339fb42d1f4SAzael Avalos u32 result; 2340fb42d1f4SAzael Avalos 2341fb42d1f4SAzael Avalos /* 2342fb42d1f4SAzael Avalos * Re-activate the hotkeys, but this time, we are using the 2343fb42d1f4SAzael Avalos * "Special Functions" mode. 2344fb42d1f4SAzael Avalos */ 2345d37782bdSAzael Avalos result = hci_write(dev, HCI_HOTKEY_EVENT, 2346fb42d1f4SAzael Avalos HCI_HOTKEY_SPECIAL_FUNCTIONS); 2347fb42d1f4SAzael Avalos if (result != TOS_SUCCESS) 2348fb42d1f4SAzael Avalos pr_err("Could not enable the Special Function mode\n"); 2349fb42d1f4SAzael Avalos } 2350fb42d1f4SAzael Avalos 235129cd293fSSeth Forshee static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str, 235229cd293fSSeth Forshee struct serio *port) 235329cd293fSSeth Forshee { 235498280374SGiedrius Statkevičius if (str & I8042_STR_AUXDATA) 235529cd293fSSeth Forshee return false; 235629cd293fSSeth Forshee 235729cd293fSSeth Forshee if (unlikely(data == 0xe0)) 235829cd293fSSeth Forshee return false; 235929cd293fSSeth Forshee 236029cd293fSSeth Forshee if ((data & 0x7f) == TOS1900_FN_SCAN) { 236129cd293fSSeth Forshee schedule_work(&toshiba_acpi->hotkey_work); 236229cd293fSSeth Forshee return true; 236329cd293fSSeth Forshee } 236429cd293fSSeth Forshee 236529cd293fSSeth Forshee return false; 236629cd293fSSeth Forshee } 236729cd293fSSeth Forshee 236829cd293fSSeth Forshee static void toshiba_acpi_hotkey_work(struct work_struct *work) 236929cd293fSSeth Forshee { 237029cd293fSSeth Forshee acpi_handle ec_handle = ec_get_handle(); 237129cd293fSSeth Forshee acpi_status status; 237229cd293fSSeth Forshee 237329cd293fSSeth Forshee if (!ec_handle) 237429cd293fSSeth Forshee return; 237529cd293fSSeth Forshee 237629cd293fSSeth Forshee status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL); 237729cd293fSSeth Forshee if (ACPI_FAILURE(status)) 237829cd293fSSeth Forshee pr_err("ACPI NTFY method execution failed\n"); 237929cd293fSSeth Forshee } 238029cd293fSSeth Forshee 238129cd293fSSeth Forshee /* 238229cd293fSSeth Forshee * Returns hotkey scancode, or < 0 on failure. 238329cd293fSSeth Forshee */ 238429cd293fSSeth Forshee static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev) 238529cd293fSSeth Forshee { 238674facaf7SZhang Rui unsigned long long value; 238729cd293fSSeth Forshee acpi_status status; 238829cd293fSSeth Forshee 238974facaf7SZhang Rui status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO", 239074facaf7SZhang Rui NULL, &value); 239174facaf7SZhang Rui if (ACPI_FAILURE(status)) { 239229cd293fSSeth Forshee pr_err("ACPI INFO method execution failed\n"); 239329cd293fSSeth Forshee return -EIO; 239429cd293fSSeth Forshee } 239529cd293fSSeth Forshee 239674facaf7SZhang Rui return value; 239729cd293fSSeth Forshee } 239829cd293fSSeth Forshee 239929cd293fSSeth Forshee static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev, 240029cd293fSSeth Forshee int scancode) 240129cd293fSSeth Forshee { 240229cd293fSSeth Forshee if (scancode == 0x100) 240329cd293fSSeth Forshee return; 240429cd293fSSeth Forshee 2405e0769fe6SDarren Hart /* Act on key press; ignore key release */ 240629cd293fSSeth Forshee if (scancode & 0x80) 240729cd293fSSeth Forshee return; 240829cd293fSSeth Forshee 240929cd293fSSeth Forshee if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true)) 241029cd293fSSeth Forshee pr_info("Unknown key %x\n", scancode); 241129cd293fSSeth Forshee } 241229cd293fSSeth Forshee 241371454d78SAzael Avalos static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev) 241471454d78SAzael Avalos { 241571454d78SAzael Avalos if (dev->info_supported) { 24167deef550SAzael Avalos int scancode = toshiba_acpi_query_hotkey(dev); 24177deef550SAzael Avalos 24187deef550SAzael Avalos if (scancode < 0) { 241971454d78SAzael Avalos pr_err("Failed to query hotkey event\n"); 24207deef550SAzael Avalos } else if (scancode != 0) { 242171454d78SAzael Avalos toshiba_acpi_report_hotkey(dev, scancode); 24227deef550SAzael Avalos dev->key_event_valid = 1; 24237deef550SAzael Avalos dev->last_key_event = scancode; 24247deef550SAzael Avalos } 242571454d78SAzael Avalos } else if (dev->system_event_supported) { 24267deef550SAzael Avalos u32 result; 24277deef550SAzael Avalos u32 value; 24287deef550SAzael Avalos int retries = 3; 24297deef550SAzael Avalos 243071454d78SAzael Avalos do { 24317deef550SAzael Avalos result = hci_read(dev, HCI_SYSTEM_EVENT, &value); 24327deef550SAzael Avalos switch (result) { 243371454d78SAzael Avalos case TOS_SUCCESS: 243471454d78SAzael Avalos toshiba_acpi_report_hotkey(dev, (int)value); 24357deef550SAzael Avalos dev->key_event_valid = 1; 24367deef550SAzael Avalos dev->last_key_event = value; 243771454d78SAzael Avalos break; 243871454d78SAzael Avalos case TOS_NOT_SUPPORTED: 243971454d78SAzael Avalos /* 244071454d78SAzael Avalos * This is a workaround for an unresolved 244171454d78SAzael Avalos * issue on some machines where system events 244271454d78SAzael Avalos * sporadically become disabled. 244371454d78SAzael Avalos */ 24447deef550SAzael Avalos result = hci_write(dev, HCI_SYSTEM_EVENT, 1); 24457deef550SAzael Avalos if (result == TOS_SUCCESS) 244671454d78SAzael Avalos pr_notice("Re-enabled hotkeys\n"); 2447e0769fe6SDarren Hart /* Fall through */ 244871454d78SAzael Avalos default: 244971454d78SAzael Avalos retries--; 245071454d78SAzael Avalos break; 245171454d78SAzael Avalos } 24527deef550SAzael Avalos } while (retries && result != TOS_FIFO_EMPTY); 245371454d78SAzael Avalos } 245471454d78SAzael Avalos } 245571454d78SAzael Avalos 2456b859f159SGreg Kroah-Hartman static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) 24576335e4d5SMatthew Garrett { 2458fe808bfbSTakashi Iwai const struct key_entry *keymap = toshiba_acpi_keymap; 2459a2b3471bSAzael Avalos acpi_handle ec_handle; 2460a2b3471bSAzael Avalos u32 events_type; 2461a2b3471bSAzael Avalos u32 hci_result; 2462a2b3471bSAzael Avalos int error; 2463a2b3471bSAzael Avalos 2464a88bc06eSAzael Avalos if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) { 2465a88bc06eSAzael Avalos pr_info("WMI event detected, hotkeys will not be monitored\n"); 2466a88bc06eSAzael Avalos return 0; 2467a88bc06eSAzael Avalos } 2468a88bc06eSAzael Avalos 2469a2b3471bSAzael Avalos error = toshiba_acpi_enable_hotkeys(dev); 2470a2b3471bSAzael Avalos if (error) 2471a2b3471bSAzael Avalos return error; 2472a2b3471bSAzael Avalos 2473a2b3471bSAzael Avalos error = toshiba_hotkey_event_type_get(dev, &events_type); 2474a2b3471bSAzael Avalos if (error) { 2475a2b3471bSAzael Avalos pr_err("Unable to query Hotkey Event Type\n"); 2476a2b3471bSAzael Avalos return error; 2477a2b3471bSAzael Avalos } 2478a2b3471bSAzael Avalos dev->hotkey_event_type = events_type; 2479135740deSSeth Forshee 2480135740deSSeth Forshee dev->hotkey_dev = input_allocate_device(); 2481b222cca6SJoe Perches if (!dev->hotkey_dev) 2482135740deSSeth Forshee return -ENOMEM; 2483135740deSSeth Forshee 2484135740deSSeth Forshee dev->hotkey_dev->name = "Toshiba input device"; 24856e02cc7eSSeth Forshee dev->hotkey_dev->phys = "toshiba_acpi/input0"; 2486135740deSSeth Forshee dev->hotkey_dev->id.bustype = BUS_HOST; 2487135740deSSeth Forshee 2488a2b3471bSAzael Avalos if (events_type == HCI_SYSTEM_TYPE1 || 2489a2b3471bSAzael Avalos !dev->kbd_function_keys_supported) 2490a2b3471bSAzael Avalos keymap = toshiba_acpi_keymap; 2491a2b3471bSAzael Avalos else if (events_type == HCI_SYSTEM_TYPE2 || 2492a2b3471bSAzael Avalos dev->kbd_function_keys_supported) 2493fe808bfbSTakashi Iwai keymap = toshiba_acpi_alt_keymap; 2494a2b3471bSAzael Avalos else 2495a2b3471bSAzael Avalos pr_info("Unknown event type received %x\n", events_type); 2496fe808bfbSTakashi Iwai error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL); 2497135740deSSeth Forshee if (error) 2498135740deSSeth Forshee goto err_free_dev; 2499135740deSSeth Forshee 250029cd293fSSeth Forshee /* 250129cd293fSSeth Forshee * For some machines the SCI responsible for providing hotkey 250229cd293fSSeth Forshee * notification doesn't fire. We can trigger the notification 250329cd293fSSeth Forshee * whenever the Fn key is pressed using the NTFY method, if 250429cd293fSSeth Forshee * supported, so if it's present set up an i8042 key filter 250529cd293fSSeth Forshee * for this purpose. 250629cd293fSSeth Forshee */ 250729cd293fSSeth Forshee ec_handle = ec_get_handle(); 2508e2e19606SZhang Rui if (ec_handle && acpi_has_method(ec_handle, "NTFY")) { 250929cd293fSSeth Forshee INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work); 251029cd293fSSeth Forshee 251129cd293fSSeth Forshee error = i8042_install_filter(toshiba_acpi_i8042_filter); 251229cd293fSSeth Forshee if (error) { 251329cd293fSSeth Forshee pr_err("Error installing key filter\n"); 251429cd293fSSeth Forshee goto err_free_keymap; 251529cd293fSSeth Forshee } 251629cd293fSSeth Forshee 251729cd293fSSeth Forshee dev->ntfy_supported = 1; 251829cd293fSSeth Forshee } 251929cd293fSSeth Forshee 252029cd293fSSeth Forshee /* 252129cd293fSSeth Forshee * Determine hotkey query interface. Prefer using the INFO 252229cd293fSSeth Forshee * method when it is available. 252329cd293fSSeth Forshee */ 2524e2e19606SZhang Rui if (acpi_has_method(dev->acpi_dev->handle, "INFO")) 252529cd293fSSeth Forshee dev->info_supported = 1; 2526e2e19606SZhang Rui else { 2527d37782bdSAzael Avalos hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1); 25281864bbc2SAzael Avalos if (hci_result == TOS_SUCCESS) 252929cd293fSSeth Forshee dev->system_event_supported = 1; 253029cd293fSSeth Forshee } 253129cd293fSSeth Forshee 253229cd293fSSeth Forshee if (!dev->info_supported && !dev->system_event_supported) { 253329cd293fSSeth Forshee pr_warn("No hotkey query interface found\n"); 253429cd293fSSeth Forshee goto err_remove_filter; 253529cd293fSSeth Forshee } 253629cd293fSSeth Forshee 2537135740deSSeth Forshee error = input_register_device(dev->hotkey_dev); 2538135740deSSeth Forshee if (error) { 2539135740deSSeth Forshee pr_info("Unable to register input device\n"); 254029cd293fSSeth Forshee goto err_remove_filter; 2541135740deSSeth Forshee } 2542135740deSSeth Forshee 2543135740deSSeth Forshee return 0; 2544135740deSSeth Forshee 254529cd293fSSeth Forshee err_remove_filter: 254629cd293fSSeth Forshee if (dev->ntfy_supported) 254729cd293fSSeth Forshee i8042_remove_filter(toshiba_acpi_i8042_filter); 2548135740deSSeth Forshee err_free_keymap: 2549135740deSSeth Forshee sparse_keymap_free(dev->hotkey_dev); 2550135740deSSeth Forshee err_free_dev: 2551135740deSSeth Forshee input_free_device(dev->hotkey_dev); 2552135740deSSeth Forshee dev->hotkey_dev = NULL; 2553135740deSSeth Forshee return error; 2554135740deSSeth Forshee } 2555135740deSSeth Forshee 2556b859f159SGreg Kroah-Hartman static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev) 255762cce752SSeth Forshee { 255862cce752SSeth Forshee struct backlight_properties props; 255962cce752SSeth Forshee int brightness; 256062cce752SSeth Forshee int ret; 256162cce752SSeth Forshee 256262cce752SSeth Forshee /* 256362cce752SSeth Forshee * Some machines don't support the backlight methods at all, and 256462cce752SSeth Forshee * others support it read-only. Either of these is pretty useless, 256562cce752SSeth Forshee * so only register the backlight device if the backlight method 256662cce752SSeth Forshee * supports both reads and writes. 256762cce752SSeth Forshee */ 256862cce752SSeth Forshee brightness = __get_lcd_brightness(dev); 256962cce752SSeth Forshee if (brightness < 0) 257062cce752SSeth Forshee return 0; 257162cce752SSeth Forshee ret = set_lcd_brightness(dev, brightness); 257262cce752SSeth Forshee if (ret) { 257362cce752SSeth Forshee pr_debug("Backlight method is read-only, disabling backlight support\n"); 257462cce752SSeth Forshee return 0; 257562cce752SSeth Forshee } 257662cce752SSeth Forshee 2577358d6a2cSHans de Goede /* 2578358d6a2cSHans de Goede * Tell acpi-video-detect code to prefer vendor backlight on all 2579358d6a2cSHans de Goede * systems with transflective backlight and on dmi matched systems. 2580358d6a2cSHans de Goede */ 2581358d6a2cSHans de Goede if (dev->tr_backlight_supported || 2582358d6a2cSHans de Goede dmi_check_system(toshiba_vendor_backlight_dmi)) 2583234b7cf8SHans de Goede acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); 2584358d6a2cSHans de Goede 2585234b7cf8SHans de Goede if (acpi_video_get_backlight_type() != acpi_backlight_vendor) 2586358d6a2cSHans de Goede return 0; 2587358d6a2cSHans de Goede 258853039f22SMatthew Garrett memset(&props, 0, sizeof(props)); 258962cce752SSeth Forshee props.type = BACKLIGHT_PLATFORM; 259062cce752SSeth Forshee props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; 259162cce752SSeth Forshee 2592e0769fe6SDarren Hart /* Adding an extra level and having 0 change to transflective mode */ 2593121b7b0dSAkio Idehara if (dev->tr_backlight_supported) 2594121b7b0dSAkio Idehara props.max_brightness++; 2595121b7b0dSAkio Idehara 259662cce752SSeth Forshee dev->backlight_dev = backlight_device_register("toshiba", 259762cce752SSeth Forshee &dev->acpi_dev->dev, 259862cce752SSeth Forshee dev, 259962cce752SSeth Forshee &toshiba_backlight_data, 260062cce752SSeth Forshee &props); 260162cce752SSeth Forshee if (IS_ERR(dev->backlight_dev)) { 260262cce752SSeth Forshee ret = PTR_ERR(dev->backlight_dev); 260362cce752SSeth Forshee pr_err("Could not register toshiba backlight device\n"); 260462cce752SSeth Forshee dev->backlight_dev = NULL; 260562cce752SSeth Forshee return ret; 260662cce752SSeth Forshee } 260762cce752SSeth Forshee 260862cce752SSeth Forshee dev->backlight_dev->props.brightness = brightness; 260962cce752SSeth Forshee return 0; 261062cce752SSeth Forshee } 261162cce752SSeth Forshee 261251fac838SRafael J. Wysocki static int toshiba_acpi_remove(struct acpi_device *acpi_dev) 2613135740deSSeth Forshee { 2614135740deSSeth Forshee struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); 2615135740deSSeth Forshee 2616fc5462f8SAzael Avalos misc_deregister(&dev->miscdev); 2617fc5462f8SAzael Avalos 261836d03f93SSeth Forshee remove_toshiba_proc_entries(dev); 2619135740deSSeth Forshee 2620360f0f39SAzael Avalos if (dev->sysfs_created) 2621360f0f39SAzael Avalos sysfs_remove_group(&dev->acpi_dev->dev.kobj, 2622360f0f39SAzael Avalos &toshiba_attr_group); 2623360f0f39SAzael Avalos 262429cd293fSSeth Forshee if (dev->ntfy_supported) { 262529cd293fSSeth Forshee i8042_remove_filter(toshiba_acpi_i8042_filter); 262629cd293fSSeth Forshee cancel_work_sync(&dev->hotkey_work); 262729cd293fSSeth Forshee } 262829cd293fSSeth Forshee 2629135740deSSeth Forshee if (dev->hotkey_dev) { 2630135740deSSeth Forshee input_unregister_device(dev->hotkey_dev); 2631135740deSSeth Forshee sparse_keymap_free(dev->hotkey_dev); 2632135740deSSeth Forshee } 2633135740deSSeth Forshee 2634135740deSSeth Forshee backlight_device_unregister(dev->backlight_dev); 2635135740deSSeth Forshee 2636*ea215a3fSAzael Avalos if (dev->illumination_led_registered) 2637135740deSSeth Forshee led_classdev_unregister(&dev->led_dev); 2638135740deSSeth Forshee 2639360f0f39SAzael Avalos if (dev->kbd_led_registered) 2640360f0f39SAzael Avalos led_classdev_unregister(&dev->kbd_led); 2641360f0f39SAzael Avalos 2642*ea215a3fSAzael Avalos if (dev->eco_led_registered) 2643def6c4e2SAzael Avalos led_classdev_unregister(&dev->eco_led); 2644def6c4e2SAzael Avalos 264529cd293fSSeth Forshee if (toshiba_acpi) 264629cd293fSSeth Forshee toshiba_acpi = NULL; 264729cd293fSSeth Forshee 2648135740deSSeth Forshee kfree(dev); 2649135740deSSeth Forshee 2650135740deSSeth Forshee return 0; 2651135740deSSeth Forshee } 2652135740deSSeth Forshee 2653b859f159SGreg Kroah-Hartman static const char *find_hci_method(acpi_handle handle) 2654a540d6b5SSeth Forshee { 2655e2e19606SZhang Rui if (acpi_has_method(handle, "GHCI")) 2656a540d6b5SSeth Forshee return "GHCI"; 2657a540d6b5SSeth Forshee 2658e2e19606SZhang Rui if (acpi_has_method(handle, "SPFC")) 2659a540d6b5SSeth Forshee return "SPFC"; 2660a540d6b5SSeth Forshee 2661a540d6b5SSeth Forshee return NULL; 2662a540d6b5SSeth Forshee } 2663a540d6b5SSeth Forshee 2664b859f159SGreg Kroah-Hartman static int toshiba_acpi_add(struct acpi_device *acpi_dev) 2665135740deSSeth Forshee { 2666135740deSSeth Forshee struct toshiba_acpi_dev *dev; 2667a540d6b5SSeth Forshee const char *hci_method; 2668fb42d1f4SAzael Avalos u32 special_functions; 266936d03f93SSeth Forshee u32 dummy; 2670135740deSSeth Forshee int ret = 0; 2671135740deSSeth Forshee 267229cd293fSSeth Forshee if (toshiba_acpi) 267329cd293fSSeth Forshee return -EBUSY; 267429cd293fSSeth Forshee 2675135740deSSeth Forshee pr_info("Toshiba Laptop ACPI Extras version %s\n", 2676135740deSSeth Forshee TOSHIBA_ACPI_VERSION); 2677135740deSSeth Forshee 2678a540d6b5SSeth Forshee hci_method = find_hci_method(acpi_dev->handle); 2679a540d6b5SSeth Forshee if (!hci_method) { 2680a540d6b5SSeth Forshee pr_err("HCI interface not found\n"); 26816e02cc7eSSeth Forshee return -ENODEV; 2682a540d6b5SSeth Forshee } 26836e02cc7eSSeth Forshee 2684135740deSSeth Forshee dev = kzalloc(sizeof(*dev), GFP_KERNEL); 2685135740deSSeth Forshee if (!dev) 2686135740deSSeth Forshee return -ENOMEM; 2687135740deSSeth Forshee dev->acpi_dev = acpi_dev; 2688a540d6b5SSeth Forshee dev->method_hci = hci_method; 2689fc5462f8SAzael Avalos dev->miscdev.minor = MISC_DYNAMIC_MINOR; 2690fc5462f8SAzael Avalos dev->miscdev.name = "toshiba_acpi"; 2691fc5462f8SAzael Avalos dev->miscdev.fops = &toshiba_acpi_fops; 2692fc5462f8SAzael Avalos 2693fc5462f8SAzael Avalos ret = misc_register(&dev->miscdev); 2694fc5462f8SAzael Avalos if (ret) { 2695fc5462f8SAzael Avalos pr_err("Failed to register miscdevice\n"); 2696fc5462f8SAzael Avalos kfree(dev); 2697fc5462f8SAzael Avalos return ret; 2698fc5462f8SAzael Avalos } 2699fc5462f8SAzael Avalos 2700135740deSSeth Forshee acpi_dev->driver_data = dev; 2701360f0f39SAzael Avalos dev_set_drvdata(&acpi_dev->dev, dev); 2702135740deSSeth Forshee 2703a2b3471bSAzael Avalos /* Query the BIOS for supported features */ 2704a2b3471bSAzael Avalos 2705a2b3471bSAzael Avalos /* 2706a2b3471bSAzael Avalos * The "Special Functions" are always supported by the laptops 2707a2b3471bSAzael Avalos * with the new keyboard layout, query for its presence to help 2708a2b3471bSAzael Avalos * determine the keymap layout to use. 2709a2b3471bSAzael Avalos */ 2710fb42d1f4SAzael Avalos ret = toshiba_function_keys_get(dev, &special_functions); 2711a2b3471bSAzael Avalos dev->kbd_function_keys_supported = !ret; 2712a2b3471bSAzael Avalos 27136e02cc7eSSeth Forshee if (toshiba_acpi_setup_keyboard(dev)) 2714135740deSSeth Forshee pr_info("Unable to activate hotkeys\n"); 2715135740deSSeth Forshee 2716695f6060SAzael Avalos /* Determine whether or not BIOS supports transflective backlight */ 2717695f6060SAzael Avalos ret = get_tr_backlight_status(dev, &dummy); 2718695f6060SAzael Avalos dev->tr_backlight_supported = !ret; 2719695f6060SAzael Avalos 272062cce752SSeth Forshee ret = toshiba_acpi_setup_backlight(dev); 272162cce752SSeth Forshee if (ret) 2722135740deSSeth Forshee goto error; 2723135740deSSeth Forshee 2724*ea215a3fSAzael Avalos toshiba_illumination_available(dev); 2725*ea215a3fSAzael Avalos if (dev->illumination_supported) { 2726135740deSSeth Forshee dev->led_dev.name = "toshiba::illumination"; 2727135740deSSeth Forshee dev->led_dev.max_brightness = 1; 2728135740deSSeth Forshee dev->led_dev.brightness_set = toshiba_illumination_set; 2729135740deSSeth Forshee dev->led_dev.brightness_get = toshiba_illumination_get; 2730135740deSSeth Forshee if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev)) 2731*ea215a3fSAzael Avalos dev->illumination_led_registered = true; 2732135740deSSeth Forshee } 2733135740deSSeth Forshee 2734*ea215a3fSAzael Avalos toshiba_eco_mode_available(dev); 2735*ea215a3fSAzael Avalos if (dev->eco_supported) { 2736def6c4e2SAzael Avalos dev->eco_led.name = "toshiba::eco_mode"; 2737def6c4e2SAzael Avalos dev->eco_led.max_brightness = 1; 2738def6c4e2SAzael Avalos dev->eco_led.brightness_set = toshiba_eco_mode_set_status; 2739def6c4e2SAzael Avalos dev->eco_led.brightness_get = toshiba_eco_mode_get_status; 2740def6c4e2SAzael Avalos if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led)) 2741*ea215a3fSAzael Avalos dev->eco_led_registered = true; 2742def6c4e2SAzael Avalos } 2743def6c4e2SAzael Avalos 2744*ea215a3fSAzael Avalos toshiba_kbd_illum_available(dev); 2745360f0f39SAzael Avalos /* 2746360f0f39SAzael Avalos * Only register the LED if KBD illumination is supported 2747360f0f39SAzael Avalos * and the keyboard backlight operation mode is set to FN-Z 2748360f0f39SAzael Avalos */ 2749360f0f39SAzael Avalos if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) { 2750360f0f39SAzael Avalos dev->kbd_led.name = "toshiba::kbd_backlight"; 2751360f0f39SAzael Avalos dev->kbd_led.max_brightness = 1; 2752360f0f39SAzael Avalos dev->kbd_led.brightness_set = toshiba_kbd_backlight_set; 2753360f0f39SAzael Avalos dev->kbd_led.brightness_get = toshiba_kbd_backlight_get; 2754360f0f39SAzael Avalos if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led)) 2755*ea215a3fSAzael Avalos dev->kbd_led_registered = true; 2756360f0f39SAzael Avalos } 2757360f0f39SAzael Avalos 27589d8658acSAzael Avalos ret = toshiba_touchpad_get(dev, &dummy); 27599d8658acSAzael Avalos dev->touchpad_supported = !ret; 27609d8658acSAzael Avalos 2761*ea215a3fSAzael Avalos toshiba_accelerometer_available(dev); 27625a2813e9SAzael Avalos 2763c8c91842SAzael Avalos toshiba_usb_sleep_charge_available(dev); 2764e26ffe51SAzael Avalos 2765bb3fe01fSAzael Avalos ret = toshiba_usb_rapid_charge_get(dev, &dummy); 2766bb3fe01fSAzael Avalos dev->usb_rapid_charge_supported = !ret; 2767bb3fe01fSAzael Avalos 2768172ce0a9SAzael Avalos ret = toshiba_usb_sleep_music_get(dev, &dummy); 2769172ce0a9SAzael Avalos dev->usb_sleep_music_supported = !ret; 2770172ce0a9SAzael Avalos 277135d53ceaSAzael Avalos ret = toshiba_panel_power_on_get(dev, &dummy); 277235d53ceaSAzael Avalos dev->panel_power_on_supported = !ret; 277335d53ceaSAzael Avalos 277417fe4b3dSAzael Avalos ret = toshiba_usb_three_get(dev, &dummy); 277517fe4b3dSAzael Avalos dev->usb_three_supported = !ret; 277617fe4b3dSAzael Avalos 277736d03f93SSeth Forshee ret = get_video_status(dev, &dummy); 277836d03f93SSeth Forshee dev->video_supported = !ret; 277936d03f93SSeth Forshee 278036d03f93SSeth Forshee ret = get_fan_status(dev, &dummy); 278136d03f93SSeth Forshee dev->fan_supported = !ret; 278236d03f93SSeth Forshee 2783fb42d1f4SAzael Avalos /* 2784fb42d1f4SAzael Avalos * Enable the "Special Functions" mode only if they are 2785fb42d1f4SAzael Avalos * supported and if they are activated. 2786fb42d1f4SAzael Avalos */ 2787fb42d1f4SAzael Avalos if (dev->kbd_function_keys_supported && special_functions) 2788fb42d1f4SAzael Avalos toshiba_acpi_enable_special_functions(dev); 2789fb42d1f4SAzael Avalos 2790360f0f39SAzael Avalos ret = sysfs_create_group(&dev->acpi_dev->dev.kobj, 2791360f0f39SAzael Avalos &toshiba_attr_group); 2792360f0f39SAzael Avalos if (ret) { 2793360f0f39SAzael Avalos dev->sysfs_created = 0; 2794360f0f39SAzael Avalos goto error; 2795360f0f39SAzael Avalos } 2796360f0f39SAzael Avalos dev->sysfs_created = !ret; 2797360f0f39SAzael Avalos 279836d03f93SSeth Forshee create_toshiba_proc_entries(dev); 279936d03f93SSeth Forshee 280029cd293fSSeth Forshee toshiba_acpi = dev; 280129cd293fSSeth Forshee 2802135740deSSeth Forshee return 0; 2803135740deSSeth Forshee 2804135740deSSeth Forshee error: 280551fac838SRafael J. Wysocki toshiba_acpi_remove(acpi_dev); 2806135740deSSeth Forshee return ret; 2807135740deSSeth Forshee } 2808135740deSSeth Forshee 2809135740deSSeth Forshee static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) 2810135740deSSeth Forshee { 2811135740deSSeth Forshee struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); 281280546905SAzael Avalos int ret; 28136335e4d5SMatthew Garrett 281471454d78SAzael Avalos switch (event) { 281571454d78SAzael Avalos case 0x80: /* Hotkeys and some system events */ 2816a88bc06eSAzael Avalos /* 2817a88bc06eSAzael Avalos * Machines with this WMI GUID aren't supported due to bugs in 2818a88bc06eSAzael Avalos * their AML. 2819a88bc06eSAzael Avalos * 2820a88bc06eSAzael Avalos * Return silently to avoid triggering a netlink event. 2821a88bc06eSAzael Avalos */ 2822a88bc06eSAzael Avalos if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) 2823a88bc06eSAzael Avalos return; 282471454d78SAzael Avalos toshiba_acpi_process_hotkeys(dev); 282511948b93SSeth Forshee break; 2826bab09e23SAzael Avalos case 0x81: /* Dock events */ 2827bab09e23SAzael Avalos case 0x82: 2828bab09e23SAzael Avalos case 0x83: 2829bab09e23SAzael Avalos pr_info("Dock event received %x\n", event); 2830bab09e23SAzael Avalos break; 2831bab09e23SAzael Avalos case 0x88: /* Thermal events */ 2832bab09e23SAzael Avalos pr_info("Thermal event received\n"); 2833bab09e23SAzael Avalos break; 2834bab09e23SAzael Avalos case 0x8f: /* LID closed */ 2835bab09e23SAzael Avalos case 0x90: /* LID is closed and Dock has been ejected */ 2836bab09e23SAzael Avalos break; 2837bab09e23SAzael Avalos case 0x8c: /* SATA power events */ 2838bab09e23SAzael Avalos case 0x8b: 2839bab09e23SAzael Avalos pr_info("SATA power event received %x\n", event); 2840bab09e23SAzael Avalos break; 284180546905SAzael Avalos case 0x92: /* Keyboard backlight mode changed */ 284280546905SAzael Avalos /* Update sysfs entries */ 284380546905SAzael Avalos ret = sysfs_update_group(&acpi_dev->dev.kobj, 284480546905SAzael Avalos &toshiba_attr_group); 284580546905SAzael Avalos if (ret) 284680546905SAzael Avalos pr_err("Unable to update sysfs entries\n"); 284780546905SAzael Avalos break; 2848bab09e23SAzael Avalos case 0x85: /* Unknown */ 2849bab09e23SAzael Avalos case 0x8d: /* Unknown */ 285071454d78SAzael Avalos case 0x8e: /* Unknown */ 2851bab09e23SAzael Avalos case 0x94: /* Unknown */ 2852bab09e23SAzael Avalos case 0x95: /* Unknown */ 285311948b93SSeth Forshee default: 285471454d78SAzael Avalos pr_info("Unknown event received %x\n", event); 285511948b93SSeth Forshee break; 28566335e4d5SMatthew Garrett } 2857bab09e23SAzael Avalos 2858bab09e23SAzael Avalos acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class, 2859bab09e23SAzael Avalos dev_name(&acpi_dev->dev), 2860bab09e23SAzael Avalos event, 0); 286129cd293fSSeth Forshee } 28626335e4d5SMatthew Garrett 28633567a4e2SRafael J. Wysocki #ifdef CONFIG_PM_SLEEP 286443d2fd3bSRafael J. Wysocki static int toshiba_acpi_suspend(struct device *device) 286529cd293fSSeth Forshee { 286643d2fd3bSRafael J. Wysocki struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); 28671e574dbfSAzael Avalos 28681e574dbfSAzael Avalos if (dev->hotkey_dev) { 286929cd293fSSeth Forshee u32 result; 287029cd293fSSeth Forshee 2871d37782bdSAzael Avalos result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE); 28721e574dbfSAzael Avalos if (result != TOS_SUCCESS) 28731e574dbfSAzael Avalos pr_info("Unable to disable hotkeys\n"); 28741e574dbfSAzael Avalos } 287529cd293fSSeth Forshee 287629cd293fSSeth Forshee return 0; 287729cd293fSSeth Forshee } 287829cd293fSSeth Forshee 287943d2fd3bSRafael J. Wysocki static int toshiba_acpi_resume(struct device *device) 288029cd293fSSeth Forshee { 288143d2fd3bSRafael J. Wysocki struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); 288229cd293fSSeth Forshee 2883e7fdb762SBenjamin Tissoires if (dev->hotkey_dev) { 28841e574dbfSAzael Avalos int error = toshiba_acpi_enable_hotkeys(dev); 28851e574dbfSAzael Avalos 28861f28f290SAzael Avalos if (error) 2887e7fdb762SBenjamin Tissoires pr_info("Unable to re-enable hotkeys\n"); 2888e7fdb762SBenjamin Tissoires } 288929cd293fSSeth Forshee 289029cd293fSSeth Forshee return 0; 289129cd293fSSeth Forshee } 28923567a4e2SRafael J. Wysocki #endif 28936335e4d5SMatthew Garrett 289443d2fd3bSRafael J. Wysocki static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm, 289543d2fd3bSRafael J. Wysocki toshiba_acpi_suspend, toshiba_acpi_resume); 289643d2fd3bSRafael J. Wysocki 2897135740deSSeth Forshee static struct acpi_driver toshiba_acpi_driver = { 2898135740deSSeth Forshee .name = "Toshiba ACPI driver", 2899135740deSSeth Forshee .owner = THIS_MODULE, 2900135740deSSeth Forshee .ids = toshiba_device_ids, 2901135740deSSeth Forshee .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, 2902135740deSSeth Forshee .ops = { 2903135740deSSeth Forshee .add = toshiba_acpi_add, 2904135740deSSeth Forshee .remove = toshiba_acpi_remove, 2905135740deSSeth Forshee .notify = toshiba_acpi_notify, 2906135740deSSeth Forshee }, 290743d2fd3bSRafael J. Wysocki .drv.pm = &toshiba_acpi_pm, 2908135740deSSeth Forshee }; 2909b4f9fe12SLen Brown 2910b4f9fe12SLen Brown static int __init toshiba_acpi_init(void) 2911b4f9fe12SLen Brown { 2912135740deSSeth Forshee int ret; 2913b4f9fe12SLen Brown 2914b4f9fe12SLen Brown toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir); 2915b4f9fe12SLen Brown if (!toshiba_proc_dir) { 2916135740deSSeth Forshee pr_err("Unable to create proc dir " PROC_TOSHIBA "\n"); 2917b4f9fe12SLen Brown return -ENODEV; 2918b4f9fe12SLen Brown } 2919b4f9fe12SLen Brown 2920135740deSSeth Forshee ret = acpi_bus_register_driver(&toshiba_acpi_driver); 2921b4f9fe12SLen Brown if (ret) { 2922135740deSSeth Forshee pr_err("Failed to register ACPI driver: %d\n", ret); 2923135740deSSeth Forshee remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 2924135740deSSeth Forshee } 2925135740deSSeth Forshee 2926b4f9fe12SLen Brown return ret; 2927b4f9fe12SLen Brown } 2928b4f9fe12SLen Brown 2929135740deSSeth Forshee static void __exit toshiba_acpi_exit(void) 2930135740deSSeth Forshee { 2931135740deSSeth Forshee acpi_bus_unregister_driver(&toshiba_acpi_driver); 2932135740deSSeth Forshee if (toshiba_proc_dir) 2933135740deSSeth Forshee remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 2934b4f9fe12SLen Brown } 2935b4f9fe12SLen Brown 2936b4f9fe12SLen Brown module_init(toshiba_acpi_init); 2937b4f9fe12SLen Brown module_exit(toshiba_acpi_exit); 2938