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 116b4f9fe12SLen Brown #define HCI_WIRELESS 0x0056 1175a2813e9SAzael Avalos #define HCI_ACCELEROMETER 0x006d 118360f0f39SAzael Avalos #define HCI_KBD_ILLUMINATION 0x0095 119def6c4e2SAzael Avalos #define HCI_ECO_MODE 0x0097 1205a2813e9SAzael Avalos #define HCI_ACCELEROMETER2 0x00a6 12156e6b353SAzael Avalos #define HCI_SYSTEM_INFO 0xc000 12235d53ceaSAzael Avalos #define SCI_PANEL_POWER_ON 0x010d 123fdb79081SAzael Avalos #define SCI_ILLUMINATION 0x014e 124e26ffe51SAzael Avalos #define SCI_USB_SLEEP_CHARGE 0x0150 125360f0f39SAzael Avalos #define SCI_KBD_ILLUM_STATUS 0x015c 126172ce0a9SAzael Avalos #define SCI_USB_SLEEP_MUSIC 0x015e 12717fe4b3dSAzael Avalos #define SCI_USB_THREE 0x0169 1289d8658acSAzael Avalos #define SCI_TOUCHPAD 0x050e 129bae84195SAzael Avalos #define SCI_KBD_FUNCTION_KEYS 0x0522 130b4f9fe12SLen Brown 1313f75bbe9SAzael Avalos /* Field definitions */ 1325a2813e9SAzael Avalos #define HCI_ACCEL_MASK 0x7fff 13329cd293fSSeth Forshee #define HCI_HOTKEY_DISABLE 0x0b 13429cd293fSSeth Forshee #define HCI_HOTKEY_ENABLE 0x09 135fb42d1f4SAzael Avalos #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10 136b4f9fe12SLen Brown #define HCI_LCD_BRIGHTNESS_BITS 3 137b4f9fe12SLen Brown #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS) 138b4f9fe12SLen Brown #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS) 139360f0f39SAzael Avalos #define HCI_MISC_SHIFT 0x10 14056e6b353SAzael Avalos #define HCI_SYSTEM_TYPE1 0x10 14156e6b353SAzael Avalos #define HCI_SYSTEM_TYPE2 0x11 142b4f9fe12SLen Brown #define HCI_VIDEO_OUT_LCD 0x1 143b4f9fe12SLen Brown #define HCI_VIDEO_OUT_CRT 0x2 144b4f9fe12SLen Brown #define HCI_VIDEO_OUT_TV 0x4 145b4f9fe12SLen Brown #define HCI_WIRELESS_KILL_SWITCH 0x01 146b4f9fe12SLen Brown #define HCI_WIRELESS_BT_PRESENT 0x0f 147b4f9fe12SLen Brown #define HCI_WIRELESS_BT_ATTACH 0x40 148b4f9fe12SLen Brown #define HCI_WIRELESS_BT_POWER 0x80 14993f8c16dSAzael Avalos #define SCI_KBD_MODE_MASK 0x1f 150360f0f39SAzael Avalos #define SCI_KBD_MODE_FNZ 0x1 151360f0f39SAzael Avalos #define SCI_KBD_MODE_AUTO 0x2 15293f8c16dSAzael Avalos #define SCI_KBD_MODE_ON 0x8 15393f8c16dSAzael Avalos #define SCI_KBD_MODE_OFF 0x10 15493f8c16dSAzael Avalos #define SCI_KBD_TIME_MAX 0x3c001a 155e26ffe51SAzael Avalos #define SCI_USB_CHARGE_MODE_MASK 0xff 156c8c91842SAzael Avalos #define SCI_USB_CHARGE_DISABLED 0x00 157c8c91842SAzael Avalos #define SCI_USB_CHARGE_ALTERNATE 0x09 158c8c91842SAzael Avalos #define SCI_USB_CHARGE_TYPICAL 0x11 159c8c91842SAzael Avalos #define SCI_USB_CHARGE_AUTO 0x21 160182bcaa5SAzael Avalos #define SCI_USB_CHARGE_BAT_MASK 0x7 161182bcaa5SAzael Avalos #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1 162182bcaa5SAzael Avalos #define SCI_USB_CHARGE_BAT_LVL_ON 0x4 163182bcaa5SAzael Avalos #define SCI_USB_CHARGE_BAT_LVL 0x0200 164bb3fe01fSAzael Avalos #define SCI_USB_CHARGE_RAPID_DSP 0x0300 165b4f9fe12SLen Brown 166135740deSSeth Forshee struct toshiba_acpi_dev { 167135740deSSeth Forshee struct acpi_device *acpi_dev; 168135740deSSeth Forshee const char *method_hci; 169135740deSSeth Forshee struct input_dev *hotkey_dev; 17029cd293fSSeth Forshee struct work_struct hotkey_work; 171135740deSSeth Forshee struct backlight_device *backlight_dev; 172135740deSSeth Forshee struct led_classdev led_dev; 173360f0f39SAzael Avalos struct led_classdev kbd_led; 174def6c4e2SAzael Avalos struct led_classdev eco_led; 175fc5462f8SAzael Avalos struct miscdevice miscdev; 17636d03f93SSeth Forshee 177135740deSSeth Forshee int force_fan; 178135740deSSeth Forshee int last_key_event; 179135740deSSeth Forshee int key_event_valid; 18093f8c16dSAzael Avalos int kbd_type; 181360f0f39SAzael Avalos int kbd_mode; 182360f0f39SAzael Avalos int kbd_time; 183182bcaa5SAzael Avalos int usbsc_bat_level; 184c8c91842SAzael Avalos int usbsc_mode_base; 185a2b3471bSAzael Avalos int hotkey_event_type; 186135740deSSeth Forshee 187592b746cSDan Carpenter unsigned int illumination_supported:1; 188592b746cSDan Carpenter unsigned int video_supported:1; 189592b746cSDan Carpenter unsigned int fan_supported:1; 190592b746cSDan Carpenter unsigned int system_event_supported:1; 19129cd293fSSeth Forshee unsigned int ntfy_supported:1; 19229cd293fSSeth Forshee unsigned int info_supported:1; 193121b7b0dSAkio Idehara unsigned int tr_backlight_supported:1; 194360f0f39SAzael Avalos unsigned int kbd_illum_supported:1; 195360f0f39SAzael Avalos unsigned int kbd_led_registered:1; 1969d8658acSAzael Avalos unsigned int touchpad_supported:1; 197def6c4e2SAzael Avalos unsigned int eco_supported:1; 1985a2813e9SAzael Avalos unsigned int accelerometer_supported:1; 199e26ffe51SAzael Avalos unsigned int usb_sleep_charge_supported:1; 200bb3fe01fSAzael Avalos unsigned int usb_rapid_charge_supported:1; 201172ce0a9SAzael Avalos unsigned int usb_sleep_music_supported:1; 202bae84195SAzael Avalos unsigned int kbd_function_keys_supported:1; 20335d53ceaSAzael Avalos unsigned int panel_power_on_supported:1; 20417fe4b3dSAzael Avalos unsigned int usb_three_supported:1; 205360f0f39SAzael Avalos unsigned int sysfs_created:1; 206135740deSSeth Forshee }; 207135740deSSeth Forshee 20829cd293fSSeth Forshee static struct toshiba_acpi_dev *toshiba_acpi; 20929cd293fSSeth Forshee 210b4f9fe12SLen Brown static const struct acpi_device_id toshiba_device_ids[] = { 211b4f9fe12SLen Brown {"TOS6200", 0}, 21263a9e016SOndrej Zary {"TOS6207", 0}, 213b4f9fe12SLen Brown {"TOS6208", 0}, 214b4f9fe12SLen Brown {"TOS1900", 0}, 215b4f9fe12SLen Brown {"", 0}, 216b4f9fe12SLen Brown }; 217b4f9fe12SLen Brown MODULE_DEVICE_TABLE(acpi, toshiba_device_ids); 218b4f9fe12SLen Brown 219b859f159SGreg Kroah-Hartman static const struct key_entry toshiba_acpi_keymap[] = { 220fec278a1SUnai Uribarri { KE_KEY, 0x9e, { KEY_RFKILL } }, 221384a7cd9SDmitry Torokhov { KE_KEY, 0x101, { KEY_MUTE } }, 222384a7cd9SDmitry Torokhov { KE_KEY, 0x102, { KEY_ZOOMOUT } }, 223384a7cd9SDmitry Torokhov { KE_KEY, 0x103, { KEY_ZOOMIN } }, 224408a5d13SAzael Avalos { KE_KEY, 0x10f, { KEY_TAB } }, 225af502837SAzael Avalos { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, 226af502837SAzael Avalos { KE_KEY, 0x139, { KEY_ZOOMRESET } }, 227384a7cd9SDmitry Torokhov { KE_KEY, 0x13b, { KEY_COFFEE } }, 228384a7cd9SDmitry Torokhov { KE_KEY, 0x13c, { KEY_BATTERY } }, 229384a7cd9SDmitry Torokhov { KE_KEY, 0x13d, { KEY_SLEEP } }, 230384a7cd9SDmitry Torokhov { KE_KEY, 0x13e, { KEY_SUSPEND } }, 231384a7cd9SDmitry Torokhov { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } }, 232384a7cd9SDmitry Torokhov { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } }, 233384a7cd9SDmitry Torokhov { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } }, 234384a7cd9SDmitry Torokhov { KE_KEY, 0x142, { KEY_WLAN } }, 235af502837SAzael Avalos { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } }, 236a49010f5SJon Dowland { KE_KEY, 0x17f, { KEY_FN } }, 237384a7cd9SDmitry Torokhov { KE_KEY, 0xb05, { KEY_PROG2 } }, 238384a7cd9SDmitry Torokhov { KE_KEY, 0xb06, { KEY_WWW } }, 239384a7cd9SDmitry Torokhov { KE_KEY, 0xb07, { KEY_MAIL } }, 240384a7cd9SDmitry Torokhov { KE_KEY, 0xb30, { KEY_STOP } }, 241384a7cd9SDmitry Torokhov { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } }, 242384a7cd9SDmitry Torokhov { KE_KEY, 0xb32, { KEY_NEXTSONG } }, 243384a7cd9SDmitry Torokhov { KE_KEY, 0xb33, { KEY_PLAYPAUSE } }, 244384a7cd9SDmitry Torokhov { KE_KEY, 0xb5a, { KEY_MEDIA } }, 245408a5d13SAzael Avalos { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */ 246408a5d13SAzael Avalos { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */ 247408a5d13SAzael Avalos { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */ 248408a5d13SAzael Avalos { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */ 249408a5d13SAzael Avalos { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */ 250384a7cd9SDmitry Torokhov { KE_END, 0 }, 2516335e4d5SMatthew Garrett }; 2526335e4d5SMatthew Garrett 253fe808bfbSTakashi Iwai static const struct key_entry toshiba_acpi_alt_keymap[] = { 254fe808bfbSTakashi Iwai { KE_KEY, 0x157, { KEY_MUTE } }, 255fe808bfbSTakashi Iwai { KE_KEY, 0x102, { KEY_ZOOMOUT } }, 256fe808bfbSTakashi Iwai { KE_KEY, 0x103, { KEY_ZOOMIN } }, 257e6efad7fSAzael Avalos { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, 258fe808bfbSTakashi Iwai { KE_KEY, 0x139, { KEY_ZOOMRESET } }, 259fe808bfbSTakashi Iwai { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } }, 260fe808bfbSTakashi Iwai { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } }, 261fe808bfbSTakashi Iwai { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } }, 262fe808bfbSTakashi Iwai { KE_KEY, 0x158, { KEY_WLAN } }, 263fe808bfbSTakashi Iwai { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } }, 264fe808bfbSTakashi Iwai { KE_END, 0 }, 265fe808bfbSTakashi Iwai }; 266fe808bfbSTakashi Iwai 267e0769fe6SDarren Hart /* 268358d6a2cSHans de Goede * List of models which have a broken acpi-video backlight interface and thus 269358d6a2cSHans de Goede * need to use the toshiba (vendor) interface instead. 270358d6a2cSHans de Goede */ 271358d6a2cSHans de Goede static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = { 272358d6a2cSHans de Goede {} 273358d6a2cSHans de Goede }; 274358d6a2cSHans de Goede 275358d6a2cSHans de Goede /* 276e0769fe6SDarren Hart * Utility 277b4f9fe12SLen Brown */ 278b4f9fe12SLen Brown 279b5163992SAzael Avalos static inline void _set_bit(u32 *word, u32 mask, int value) 280b4f9fe12SLen Brown { 281b4f9fe12SLen Brown *word = (*word & ~mask) | (mask * value); 282b4f9fe12SLen Brown } 283b4f9fe12SLen Brown 284e0769fe6SDarren Hart /* 285e0769fe6SDarren Hart * ACPI interface wrappers 286b4f9fe12SLen Brown */ 287b4f9fe12SLen Brown 288b4f9fe12SLen Brown static int write_acpi_int(const char *methodName, int val) 289b4f9fe12SLen Brown { 290b4f9fe12SLen Brown acpi_status status; 291b4f9fe12SLen Brown 292619400daSZhang Rui status = acpi_execute_simple_method(NULL, (char *)methodName, val); 29332bcd5cbSSeth Forshee return (status == AE_OK) ? 0 : -EIO; 294b4f9fe12SLen Brown } 295b4f9fe12SLen Brown 296e0769fe6SDarren Hart /* 297e0769fe6SDarren Hart * Perform a raw configuration call. Here we don't care about input or output 298258c5903SAzael Avalos * buffer format. 299b4f9fe12SLen Brown */ 300258c5903SAzael Avalos static acpi_status tci_raw(struct toshiba_acpi_dev *dev, 301258c5903SAzael Avalos const u32 in[TCI_WORDS], u32 out[TCI_WORDS]) 302b4f9fe12SLen Brown { 303b4f9fe12SLen Brown struct acpi_object_list params; 304258c5903SAzael Avalos union acpi_object in_objs[TCI_WORDS]; 305b4f9fe12SLen Brown struct acpi_buffer results; 306258c5903SAzael Avalos union acpi_object out_objs[TCI_WORDS + 1]; 307b4f9fe12SLen Brown acpi_status status; 308b4f9fe12SLen Brown int i; 309b4f9fe12SLen Brown 310258c5903SAzael Avalos params.count = TCI_WORDS; 311b4f9fe12SLen Brown params.pointer = in_objs; 312258c5903SAzael Avalos for (i = 0; i < TCI_WORDS; ++i) { 313b4f9fe12SLen Brown in_objs[i].type = ACPI_TYPE_INTEGER; 314b4f9fe12SLen Brown in_objs[i].integer.value = in[i]; 315b4f9fe12SLen Brown } 316b4f9fe12SLen Brown 317b4f9fe12SLen Brown results.length = sizeof(out_objs); 318b4f9fe12SLen Brown results.pointer = out_objs; 319b4f9fe12SLen Brown 3206e02cc7eSSeth Forshee status = acpi_evaluate_object(dev->acpi_dev->handle, 3216e02cc7eSSeth Forshee (char *)dev->method_hci, ¶ms, 322b4f9fe12SLen Brown &results); 323258c5903SAzael Avalos if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) { 324b5163992SAzael Avalos for (i = 0; i < out_objs->package.count; ++i) 325b4f9fe12SLen Brown out[i] = out_objs->package.elements[i].integer.value; 326b4f9fe12SLen Brown } 327b4f9fe12SLen Brown 328b4f9fe12SLen Brown return status; 329b4f9fe12SLen Brown } 330b4f9fe12SLen Brown 331e0769fe6SDarren Hart /* 332d37782bdSAzael Avalos * Common hci tasks 333b4f9fe12SLen Brown * 334b4f9fe12SLen Brown * In addition to the ACPI status, the HCI system returns a result which 335b4f9fe12SLen Brown * may be useful (such as "not supported"). 336b4f9fe12SLen Brown */ 337b4f9fe12SLen Brown 338d37782bdSAzael Avalos static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1) 339b4f9fe12SLen Brown { 340258c5903SAzael Avalos u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; 341258c5903SAzael Avalos u32 out[TCI_WORDS]; 342258c5903SAzael Avalos acpi_status status = tci_raw(dev, in, out); 343893f3f62SAzael Avalos 344893f3f62SAzael Avalos return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; 345b4f9fe12SLen Brown } 346b4f9fe12SLen Brown 347d37782bdSAzael Avalos static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1) 348b4f9fe12SLen Brown { 349258c5903SAzael Avalos u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; 350258c5903SAzael Avalos u32 out[TCI_WORDS]; 351258c5903SAzael Avalos acpi_status status = tci_raw(dev, in, out); 352b5163992SAzael Avalos 353893f3f62SAzael Avalos if (ACPI_FAILURE(status)) 354893f3f62SAzael Avalos return TOS_FAILURE; 355893f3f62SAzael Avalos 356b4f9fe12SLen Brown *out1 = out[2]; 357893f3f62SAzael Avalos 358893f3f62SAzael Avalos return out[0]; 359b4f9fe12SLen Brown } 360b4f9fe12SLen Brown 361e0769fe6SDarren Hart /* 362e0769fe6SDarren Hart * Common sci tasks 36384a6273fSAzael Avalos */ 36484a6273fSAzael Avalos 36584a6273fSAzael Avalos static int sci_open(struct toshiba_acpi_dev *dev) 36684a6273fSAzael Avalos { 367258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 }; 368258c5903SAzael Avalos u32 out[TCI_WORDS]; 36984a6273fSAzael Avalos acpi_status status; 37084a6273fSAzael Avalos 371258c5903SAzael Avalos status = tci_raw(dev, in, out); 3728baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 37384a6273fSAzael Avalos pr_err("ACPI call to open SCI failed\n"); 37484a6273fSAzael Avalos return 0; 37584a6273fSAzael Avalos } 37684a6273fSAzael Avalos 3771864bbc2SAzael Avalos if (out[0] == TOS_OPEN_CLOSE_OK) { 37884a6273fSAzael Avalos return 1; 3791864bbc2SAzael Avalos } else if (out[0] == TOS_ALREADY_OPEN) { 38084a6273fSAzael Avalos pr_info("Toshiba SCI already opened\n"); 38184a6273fSAzael Avalos return 1; 382fa465739SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 383e0769fe6SDarren Hart /* 384e0769fe6SDarren Hart * Some BIOSes do not have the SCI open/close functions 385fa465739SAzael Avalos * implemented and return 0x8000 (Not Supported), failing to 386fa465739SAzael Avalos * register some supported features. 387fa465739SAzael Avalos * 388fa465739SAzael Avalos * Simply return 1 if we hit those affected laptops to make the 389fa465739SAzael Avalos * supported features work. 390fa465739SAzael Avalos * 391fa465739SAzael Avalos * In the case that some laptops really do not support the SCI, 392fa465739SAzael Avalos * all the SCI dependent functions check for TOS_NOT_SUPPORTED, 393fa465739SAzael Avalos * and thus, not registering support for the queried feature. 394fa465739SAzael Avalos */ 395fa465739SAzael Avalos return 1; 3961864bbc2SAzael Avalos } else if (out[0] == TOS_NOT_PRESENT) { 39784a6273fSAzael Avalos pr_info("Toshiba SCI is not present\n"); 39884a6273fSAzael Avalos } 39984a6273fSAzael Avalos 40084a6273fSAzael Avalos return 0; 40184a6273fSAzael Avalos } 40284a6273fSAzael Avalos 40384a6273fSAzael Avalos static void sci_close(struct toshiba_acpi_dev *dev) 40484a6273fSAzael Avalos { 405258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 }; 406258c5903SAzael Avalos u32 out[TCI_WORDS]; 40784a6273fSAzael Avalos acpi_status status; 40884a6273fSAzael Avalos 409258c5903SAzael Avalos status = tci_raw(dev, in, out); 4108baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 41184a6273fSAzael Avalos pr_err("ACPI call to close SCI failed\n"); 41284a6273fSAzael Avalos return; 41384a6273fSAzael Avalos } 41484a6273fSAzael Avalos 4151864bbc2SAzael Avalos if (out[0] == TOS_OPEN_CLOSE_OK) 41684a6273fSAzael Avalos return; 4171864bbc2SAzael Avalos else if (out[0] == TOS_NOT_OPENED) 41884a6273fSAzael Avalos pr_info("Toshiba SCI not opened\n"); 4191864bbc2SAzael Avalos else if (out[0] == TOS_NOT_PRESENT) 42084a6273fSAzael Avalos pr_info("Toshiba SCI is not present\n"); 42184a6273fSAzael Avalos } 42284a6273fSAzael Avalos 423893f3f62SAzael Avalos static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1) 42484a6273fSAzael Avalos { 425258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 }; 426258c5903SAzael Avalos u32 out[TCI_WORDS]; 427258c5903SAzael Avalos acpi_status status = tci_raw(dev, in, out); 428b5163992SAzael Avalos 429893f3f62SAzael Avalos if (ACPI_FAILURE(status)) 430893f3f62SAzael Avalos return TOS_FAILURE; 431893f3f62SAzael Avalos 43284a6273fSAzael Avalos *out1 = out[2]; 433893f3f62SAzael Avalos 434893f3f62SAzael Avalos return out[0]; 43584a6273fSAzael Avalos } 43684a6273fSAzael Avalos 437893f3f62SAzael Avalos static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1) 43884a6273fSAzael Avalos { 439258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 }; 440258c5903SAzael Avalos u32 out[TCI_WORDS]; 441258c5903SAzael Avalos acpi_status status = tci_raw(dev, in, out); 442893f3f62SAzael Avalos 443893f3f62SAzael Avalos return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; 44484a6273fSAzael Avalos } 44584a6273fSAzael Avalos 4466c3f6e6cSPierre Ducroquet /* Illumination support */ 447135740deSSeth Forshee static int toshiba_illumination_available(struct toshiba_acpi_dev *dev) 4486c3f6e6cSPierre Ducroquet { 449258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 }; 450258c5903SAzael Avalos u32 out[TCI_WORDS]; 4516c3f6e6cSPierre Ducroquet acpi_status status; 4526c3f6e6cSPierre Ducroquet 453fdb79081SAzael Avalos if (!sci_open(dev)) 454fdb79081SAzael Avalos return 0; 455fdb79081SAzael Avalos 456258c5903SAzael Avalos status = tci_raw(dev, in, out); 457fdb79081SAzael Avalos sci_close(dev); 4588baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 459fdb79081SAzael Avalos pr_err("ACPI call to query Illumination support failed\n"); 460fdb79081SAzael Avalos return 0; 4611864bbc2SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 4627e33460dSJoe Perches pr_info("Illumination device not available\n"); 4636c3f6e6cSPierre Ducroquet return 0; 4646c3f6e6cSPierre Ducroquet } 465fdb79081SAzael Avalos 4666c3f6e6cSPierre Ducroquet return 1; 4676c3f6e6cSPierre Ducroquet } 4686c3f6e6cSPierre Ducroquet 4696c3f6e6cSPierre Ducroquet static void toshiba_illumination_set(struct led_classdev *cdev, 4706c3f6e6cSPierre Ducroquet enum led_brightness brightness) 4716c3f6e6cSPierre Ducroquet { 472135740deSSeth Forshee struct toshiba_acpi_dev *dev = container_of(cdev, 473135740deSSeth Forshee struct toshiba_acpi_dev, led_dev); 474fdb79081SAzael Avalos u32 state, result; 4756c3f6e6cSPierre Ducroquet 4766c3f6e6cSPierre Ducroquet /* First request : initialize communication. */ 477fdb79081SAzael Avalos if (!sci_open(dev)) 4786c3f6e6cSPierre Ducroquet return; 4796c3f6e6cSPierre Ducroquet 480fdb79081SAzael Avalos /* Switch the illumination on/off */ 481fdb79081SAzael Avalos state = brightness ? 1 : 0; 482893f3f62SAzael Avalos result = sci_write(dev, SCI_ILLUMINATION, state); 483fdb79081SAzael Avalos sci_close(dev); 484893f3f62SAzael Avalos if (result == TOS_FAILURE) { 485fdb79081SAzael Avalos pr_err("ACPI call for illumination failed\n"); 486fdb79081SAzael Avalos return; 4871864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 488fdb79081SAzael Avalos pr_info("Illumination not supported\n"); 4896c3f6e6cSPierre Ducroquet return; 4906c3f6e6cSPierre Ducroquet } 4916c3f6e6cSPierre Ducroquet } 4926c3f6e6cSPierre Ducroquet 4936c3f6e6cSPierre Ducroquet static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) 4946c3f6e6cSPierre Ducroquet { 495135740deSSeth Forshee struct toshiba_acpi_dev *dev = container_of(cdev, 496135740deSSeth Forshee struct toshiba_acpi_dev, led_dev); 497fdb79081SAzael Avalos u32 state, result; 4986c3f6e6cSPierre Ducroquet 4993f75bbe9SAzael Avalos /* First request : initialize communication. */ 500fdb79081SAzael Avalos if (!sci_open(dev)) 5016c3f6e6cSPierre Ducroquet return LED_OFF; 5026c3f6e6cSPierre Ducroquet 5036c3f6e6cSPierre Ducroquet /* Check the illumination */ 504893f3f62SAzael Avalos result = sci_read(dev, SCI_ILLUMINATION, &state); 505fdb79081SAzael Avalos sci_close(dev); 506893f3f62SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 507fdb79081SAzael Avalos pr_err("ACPI call for illumination failed\n"); 508fdb79081SAzael Avalos return LED_OFF; 5091864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 510fdb79081SAzael Avalos pr_info("Illumination not supported\n"); 5116c3f6e6cSPierre Ducroquet return LED_OFF; 5126c3f6e6cSPierre Ducroquet } 5136c3f6e6cSPierre Ducroquet 514fdb79081SAzael Avalos return state ? LED_FULL : LED_OFF; 5156c3f6e6cSPierre Ducroquet } 5166c3f6e6cSPierre Ducroquet 517360f0f39SAzael Avalos /* KBD Illumination */ 51893f8c16dSAzael Avalos static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev) 51993f8c16dSAzael Avalos { 520258c5903SAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 }; 521258c5903SAzael Avalos u32 out[TCI_WORDS]; 52293f8c16dSAzael Avalos acpi_status status; 52393f8c16dSAzael Avalos 52493f8c16dSAzael Avalos if (!sci_open(dev)) 52593f8c16dSAzael Avalos return 0; 52693f8c16dSAzael Avalos 527258c5903SAzael Avalos status = tci_raw(dev, in, out); 52893f8c16dSAzael Avalos sci_close(dev); 5291864bbc2SAzael Avalos if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { 53093f8c16dSAzael Avalos pr_err("ACPI call to query kbd illumination support failed\n"); 53193f8c16dSAzael Avalos return 0; 5321864bbc2SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 53393f8c16dSAzael Avalos pr_info("Keyboard illumination not available\n"); 53493f8c16dSAzael Avalos return 0; 53593f8c16dSAzael Avalos } 53693f8c16dSAzael Avalos 537e0769fe6SDarren Hart /* 538e0769fe6SDarren Hart * Check for keyboard backlight timeout max value, 53993f8c16dSAzael Avalos * previous kbd backlight implementation set this to 54093f8c16dSAzael Avalos * 0x3c0003, and now the new implementation set this 541e0769fe6SDarren Hart * to 0x3c001a, use this to distinguish between them. 54293f8c16dSAzael Avalos */ 54393f8c16dSAzael Avalos if (out[3] == SCI_KBD_TIME_MAX) 54493f8c16dSAzael Avalos dev->kbd_type = 2; 54593f8c16dSAzael Avalos else 54693f8c16dSAzael Avalos dev->kbd_type = 1; 54793f8c16dSAzael Avalos /* Get the current keyboard backlight mode */ 54893f8c16dSAzael Avalos dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK; 54993f8c16dSAzael Avalos /* Get the current time (1-60 seconds) */ 55093f8c16dSAzael Avalos dev->kbd_time = out[2] >> HCI_MISC_SHIFT; 55193f8c16dSAzael Avalos 55293f8c16dSAzael Avalos return 1; 55393f8c16dSAzael Avalos } 55493f8c16dSAzael Avalos 555360f0f39SAzael Avalos static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time) 556360f0f39SAzael Avalos { 557360f0f39SAzael Avalos u32 result; 558360f0f39SAzael Avalos 559360f0f39SAzael Avalos if (!sci_open(dev)) 560360f0f39SAzael Avalos return -EIO; 561360f0f39SAzael Avalos 562893f3f62SAzael Avalos result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time); 563360f0f39SAzael Avalos sci_close(dev); 564893f3f62SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 565360f0f39SAzael Avalos pr_err("ACPI call to set KBD backlight status failed\n"); 566360f0f39SAzael Avalos return -EIO; 5671864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 568360f0f39SAzael Avalos pr_info("Keyboard backlight status not supported\n"); 569360f0f39SAzael Avalos return -ENODEV; 570360f0f39SAzael Avalos } 571360f0f39SAzael Avalos 572360f0f39SAzael Avalos return 0; 573360f0f39SAzael Avalos } 574360f0f39SAzael Avalos 575360f0f39SAzael Avalos static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time) 576360f0f39SAzael Avalos { 577360f0f39SAzael Avalos u32 result; 578360f0f39SAzael Avalos 579360f0f39SAzael Avalos if (!sci_open(dev)) 580360f0f39SAzael Avalos return -EIO; 581360f0f39SAzael Avalos 582893f3f62SAzael Avalos result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time); 583360f0f39SAzael Avalos sci_close(dev); 584893f3f62SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 585360f0f39SAzael Avalos pr_err("ACPI call to get KBD backlight status failed\n"); 586360f0f39SAzael Avalos return -EIO; 5871864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 588360f0f39SAzael Avalos pr_info("Keyboard backlight status not supported\n"); 589360f0f39SAzael Avalos return -ENODEV; 590360f0f39SAzael Avalos } 591360f0f39SAzael Avalos 592360f0f39SAzael Avalos return 0; 593360f0f39SAzael Avalos } 594360f0f39SAzael Avalos 595360f0f39SAzael Avalos static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev) 596360f0f39SAzael Avalos { 597360f0f39SAzael Avalos struct toshiba_acpi_dev *dev = container_of(cdev, 598360f0f39SAzael Avalos struct toshiba_acpi_dev, kbd_led); 599360f0f39SAzael Avalos u32 state, result; 600360f0f39SAzael Avalos 601360f0f39SAzael Avalos /* Check the keyboard backlight state */ 602d37782bdSAzael Avalos result = hci_read(dev, HCI_KBD_ILLUMINATION, &state); 603893f3f62SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 604360f0f39SAzael Avalos pr_err("ACPI call to get the keyboard backlight failed\n"); 605360f0f39SAzael Avalos return LED_OFF; 6061864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 607360f0f39SAzael Avalos pr_info("Keyboard backlight not supported\n"); 608360f0f39SAzael Avalos return LED_OFF; 609360f0f39SAzael Avalos } 610360f0f39SAzael Avalos 611360f0f39SAzael Avalos return state ? LED_FULL : LED_OFF; 612360f0f39SAzael Avalos } 613360f0f39SAzael Avalos 614360f0f39SAzael Avalos static void toshiba_kbd_backlight_set(struct led_classdev *cdev, 615360f0f39SAzael Avalos enum led_brightness brightness) 616360f0f39SAzael Avalos { 617360f0f39SAzael Avalos struct toshiba_acpi_dev *dev = container_of(cdev, 618360f0f39SAzael Avalos struct toshiba_acpi_dev, kbd_led); 619360f0f39SAzael Avalos u32 state, result; 620360f0f39SAzael Avalos 621360f0f39SAzael Avalos /* Set the keyboard backlight state */ 622360f0f39SAzael Avalos state = brightness ? 1 : 0; 623d37782bdSAzael Avalos result = hci_write(dev, HCI_KBD_ILLUMINATION, state); 624893f3f62SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 625360f0f39SAzael Avalos pr_err("ACPI call to set KBD Illumination mode failed\n"); 626360f0f39SAzael Avalos return; 6271864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 628360f0f39SAzael Avalos pr_info("Keyboard backlight not supported\n"); 629360f0f39SAzael Avalos return; 630360f0f39SAzael Avalos } 631360f0f39SAzael Avalos } 632360f0f39SAzael Avalos 6339d8658acSAzael Avalos /* TouchPad support */ 6349d8658acSAzael Avalos static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state) 6359d8658acSAzael Avalos { 6369d8658acSAzael Avalos u32 result; 6379d8658acSAzael Avalos 6389d8658acSAzael Avalos if (!sci_open(dev)) 6399d8658acSAzael Avalos return -EIO; 6409d8658acSAzael Avalos 641893f3f62SAzael Avalos result = sci_write(dev, SCI_TOUCHPAD, state); 6429d8658acSAzael Avalos sci_close(dev); 643893f3f62SAzael Avalos if (result == TOS_FAILURE) { 6449d8658acSAzael Avalos pr_err("ACPI call to set the touchpad failed\n"); 6459d8658acSAzael Avalos return -EIO; 6461864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 6479d8658acSAzael Avalos return -ENODEV; 6489d8658acSAzael Avalos } 6499d8658acSAzael Avalos 6509d8658acSAzael Avalos return 0; 6519d8658acSAzael Avalos } 6529d8658acSAzael Avalos 6539d8658acSAzael Avalos static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state) 6549d8658acSAzael Avalos { 6559d8658acSAzael Avalos u32 result; 6569d8658acSAzael Avalos 6579d8658acSAzael Avalos if (!sci_open(dev)) 6589d8658acSAzael Avalos return -EIO; 6599d8658acSAzael Avalos 660893f3f62SAzael Avalos result = sci_read(dev, SCI_TOUCHPAD, state); 6619d8658acSAzael Avalos sci_close(dev); 662893f3f62SAzael Avalos if (result == TOS_FAILURE) { 6639d8658acSAzael Avalos pr_err("ACPI call to query the touchpad failed\n"); 6649d8658acSAzael Avalos return -EIO; 6651864bbc2SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 6669d8658acSAzael Avalos return -ENODEV; 6679d8658acSAzael Avalos } 6689d8658acSAzael Avalos 6699d8658acSAzael Avalos return 0; 6709d8658acSAzael Avalos } 6719d8658acSAzael Avalos 672def6c4e2SAzael Avalos /* Eco Mode support */ 673def6c4e2SAzael Avalos static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev) 674def6c4e2SAzael Avalos { 675def6c4e2SAzael Avalos acpi_status status; 67698fc4ec6SAzael Avalos u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 }; 677258c5903SAzael Avalos u32 out[TCI_WORDS]; 678def6c4e2SAzael Avalos 679258c5903SAzael Avalos status = tci_raw(dev, in, out); 6808baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 68198fc4ec6SAzael Avalos pr_err("ACPI call to get ECO led failed\n"); 68298fc4ec6SAzael Avalos } else if (out[0] == TOS_NOT_INSTALLED) { 68398fc4ec6SAzael Avalos pr_info("ECO led not installed"); 68498fc4ec6SAzael Avalos } else if (out[0] == TOS_INPUT_DATA_ERROR) { 685e0769fe6SDarren Hart /* 686e0769fe6SDarren Hart * If we receive 0x8300 (Input Data Error), it means that the 68798fc4ec6SAzael Avalos * LED device is present, but that we just screwed the input 68898fc4ec6SAzael Avalos * parameters. 68998fc4ec6SAzael Avalos * 69098fc4ec6SAzael Avalos * Let's query the status of the LED to see if we really have a 69198fc4ec6SAzael Avalos * success response, indicating the actual presense of the LED, 69298fc4ec6SAzael Avalos * bail out otherwise. 69398fc4ec6SAzael Avalos */ 69498fc4ec6SAzael Avalos in[3] = 1; 69598fc4ec6SAzael Avalos status = tci_raw(dev, in, out); 69698fc4ec6SAzael Avalos if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) 69798fc4ec6SAzael Avalos pr_err("ACPI call to get ECO led failed\n"); 69898fc4ec6SAzael Avalos else if (out[0] == TOS_SUCCESS) 69998fc4ec6SAzael Avalos return 1; 700def6c4e2SAzael Avalos } 701def6c4e2SAzael Avalos 70298fc4ec6SAzael Avalos return 0; 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 */ 7425a2813e9SAzael Avalos static int toshiba_accelerometer_supported(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 748e0769fe6SDarren Hart /* 749e0769fe6SDarren Hart * Check if the accelerometer call exists, 7505a2813e9SAzael Avalos * this call also serves as initialization 7515a2813e9SAzael Avalos */ 752258c5903SAzael Avalos status = tci_raw(dev, in, out); 7531864bbc2SAzael Avalos if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { 7545a2813e9SAzael Avalos pr_err("ACPI call to query the accelerometer failed\n"); 7555a2813e9SAzael Avalos return -EIO; 7561864bbc2SAzael Avalos } else if (out[0] == TOS_DATA_NOT_AVAILABLE || 7571864bbc2SAzael Avalos out[0] == TOS_NOT_INITIALIZED) { 7585a2813e9SAzael Avalos pr_err("Accelerometer not initialized\n"); 7595a2813e9SAzael Avalos return -EIO; 7601864bbc2SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 7615a2813e9SAzael Avalos pr_info("Accelerometer not supported\n"); 7625a2813e9SAzael Avalos return -ENODEV; 7635a2813e9SAzael Avalos } 7645a2813e9SAzael Avalos 7655a2813e9SAzael Avalos return 0; 7665a2813e9SAzael Avalos } 7675a2813e9SAzael Avalos 7685a2813e9SAzael Avalos static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, 7695a2813e9SAzael Avalos u32 *xy, u32 *z) 7705a2813e9SAzael Avalos { 771258c5903SAzael Avalos u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 }; 772258c5903SAzael Avalos u32 out[TCI_WORDS]; 7735a2813e9SAzael Avalos acpi_status status; 7745a2813e9SAzael Avalos 7755a2813e9SAzael Avalos /* Check the Accelerometer status */ 776258c5903SAzael Avalos status = tci_raw(dev, in, out); 7771864bbc2SAzael Avalos if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { 7785a2813e9SAzael Avalos pr_err("ACPI call to query the accelerometer failed\n"); 7795a2813e9SAzael Avalos return -EIO; 7805a2813e9SAzael Avalos } 7815a2813e9SAzael Avalos 7825a2813e9SAzael Avalos *xy = out[2]; 7835a2813e9SAzael Avalos *z = out[4]; 7845a2813e9SAzael Avalos 7855a2813e9SAzael Avalos return 0; 7865a2813e9SAzael Avalos } 7875a2813e9SAzael Avalos 788e26ffe51SAzael Avalos /* Sleep (Charge and Music) utilities support */ 789c8c91842SAzael Avalos static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev) 790c8c91842SAzael Avalos { 791c8c91842SAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; 792c8c91842SAzael Avalos u32 out[TCI_WORDS]; 793c8c91842SAzael Avalos acpi_status status; 794c8c91842SAzael Avalos 795c8c91842SAzael Avalos /* Set the feature to "not supported" in case of error */ 796c8c91842SAzael Avalos dev->usb_sleep_charge_supported = 0; 797c8c91842SAzael Avalos 798c8c91842SAzael Avalos if (!sci_open(dev)) 799c8c91842SAzael Avalos return; 800c8c91842SAzael Avalos 801c8c91842SAzael Avalos status = tci_raw(dev, in, out); 8028baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 803c8c91842SAzael Avalos pr_err("ACPI call to get USB Sleep and Charge mode failed\n"); 804c8c91842SAzael Avalos sci_close(dev); 805c8c91842SAzael Avalos return; 806c8c91842SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 807c8c91842SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 808c8c91842SAzael Avalos sci_close(dev); 809c8c91842SAzael Avalos return; 810c8c91842SAzael Avalos } else if (out[0] == TOS_SUCCESS) { 811c8c91842SAzael Avalos dev->usbsc_mode_base = out[4]; 812c8c91842SAzael Avalos } 813c8c91842SAzael Avalos 814c8c91842SAzael Avalos in[5] = SCI_USB_CHARGE_BAT_LVL; 815c8c91842SAzael Avalos status = tci_raw(dev, in, out); 8168baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 817c8c91842SAzael Avalos pr_err("ACPI call to get USB Sleep and Charge mode failed\n"); 818c8c91842SAzael Avalos sci_close(dev); 819c8c91842SAzael Avalos return; 820c8c91842SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 821c8c91842SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 822c8c91842SAzael Avalos sci_close(dev); 823c8c91842SAzael Avalos return; 824c8c91842SAzael Avalos } else if (out[0] == TOS_SUCCESS) { 825c8c91842SAzael Avalos dev->usbsc_bat_level = out[2]; 826c8c91842SAzael Avalos /* 827c8c91842SAzael Avalos * If we reach this point, it means that the laptop has support 828c8c91842SAzael Avalos * for this feature and all values are initialized. 829c8c91842SAzael Avalos * Set it as supported. 830c8c91842SAzael Avalos */ 831c8c91842SAzael Avalos dev->usb_sleep_charge_supported = 1; 832c8c91842SAzael Avalos } 833c8c91842SAzael Avalos 834c8c91842SAzael Avalos sci_close(dev); 835c8c91842SAzael Avalos } 836c8c91842SAzael Avalos 837e26ffe51SAzael Avalos static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev, 838e26ffe51SAzael Avalos u32 *mode) 839e26ffe51SAzael Avalos { 840e26ffe51SAzael Avalos u32 result; 841e26ffe51SAzael Avalos 842e26ffe51SAzael Avalos if (!sci_open(dev)) 843e26ffe51SAzael Avalos return -EIO; 844e26ffe51SAzael Avalos 845e26ffe51SAzael Avalos result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode); 846e26ffe51SAzael Avalos sci_close(dev); 847e26ffe51SAzael Avalos if (result == TOS_FAILURE) { 848e26ffe51SAzael Avalos pr_err("ACPI call to set USB S&C mode failed\n"); 849e26ffe51SAzael Avalos return -EIO; 850e26ffe51SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 851e26ffe51SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 852e26ffe51SAzael Avalos return -ENODEV; 853e26ffe51SAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 854e26ffe51SAzael Avalos return -EIO; 855e26ffe51SAzael Avalos } 856e26ffe51SAzael Avalos 857e26ffe51SAzael Avalos return 0; 858e26ffe51SAzael Avalos } 859e26ffe51SAzael Avalos 860e26ffe51SAzael Avalos static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev, 861e26ffe51SAzael Avalos u32 mode) 862e26ffe51SAzael Avalos { 863e26ffe51SAzael Avalos u32 result; 864e26ffe51SAzael Avalos 865e26ffe51SAzael Avalos if (!sci_open(dev)) 866e26ffe51SAzael Avalos return -EIO; 867e26ffe51SAzael Avalos 868e26ffe51SAzael Avalos result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode); 869e26ffe51SAzael Avalos sci_close(dev); 870e26ffe51SAzael Avalos if (result == TOS_FAILURE) { 871e26ffe51SAzael Avalos pr_err("ACPI call to set USB S&C mode failed\n"); 872e26ffe51SAzael Avalos return -EIO; 873e26ffe51SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 874e26ffe51SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 875e26ffe51SAzael Avalos return -ENODEV; 876e26ffe51SAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 877e26ffe51SAzael Avalos return -EIO; 878e26ffe51SAzael Avalos } 879e26ffe51SAzael Avalos 880e26ffe51SAzael Avalos return 0; 881e26ffe51SAzael Avalos } 882e26ffe51SAzael Avalos 883182bcaa5SAzael Avalos static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev, 884182bcaa5SAzael Avalos u32 *mode) 885182bcaa5SAzael Avalos { 886182bcaa5SAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; 887182bcaa5SAzael Avalos u32 out[TCI_WORDS]; 888182bcaa5SAzael Avalos acpi_status status; 889182bcaa5SAzael Avalos 890182bcaa5SAzael Avalos if (!sci_open(dev)) 891182bcaa5SAzael Avalos return -EIO; 892182bcaa5SAzael Avalos 893182bcaa5SAzael Avalos in[5] = SCI_USB_CHARGE_BAT_LVL; 894182bcaa5SAzael Avalos status = tci_raw(dev, in, out); 895182bcaa5SAzael Avalos sci_close(dev); 8968baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 897182bcaa5SAzael Avalos pr_err("ACPI call to get USB S&C battery level failed\n"); 898182bcaa5SAzael Avalos return -EIO; 899182bcaa5SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 900182bcaa5SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 901182bcaa5SAzael Avalos return -ENODEV; 902182bcaa5SAzael Avalos } else if (out[0] == TOS_INPUT_DATA_ERROR) { 903182bcaa5SAzael Avalos return -EIO; 904182bcaa5SAzael Avalos } 905182bcaa5SAzael Avalos 906182bcaa5SAzael Avalos *mode = out[2]; 907182bcaa5SAzael Avalos 908182bcaa5SAzael Avalos return 0; 909182bcaa5SAzael Avalos } 910182bcaa5SAzael Avalos 911182bcaa5SAzael Avalos static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev, 912182bcaa5SAzael Avalos u32 mode) 913182bcaa5SAzael Avalos { 914182bcaa5SAzael Avalos u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; 915182bcaa5SAzael Avalos u32 out[TCI_WORDS]; 916182bcaa5SAzael Avalos acpi_status status; 917182bcaa5SAzael Avalos 918182bcaa5SAzael Avalos if (!sci_open(dev)) 919182bcaa5SAzael Avalos return -EIO; 920182bcaa5SAzael Avalos 921182bcaa5SAzael Avalos in[2] = mode; 922182bcaa5SAzael Avalos in[5] = SCI_USB_CHARGE_BAT_LVL; 923182bcaa5SAzael Avalos status = tci_raw(dev, in, out); 924182bcaa5SAzael Avalos sci_close(dev); 9258baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 926182bcaa5SAzael Avalos pr_err("ACPI call to set USB S&C battery level failed\n"); 927182bcaa5SAzael Avalos return -EIO; 928182bcaa5SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 929182bcaa5SAzael Avalos pr_info("USB Sleep and Charge not supported\n"); 930182bcaa5SAzael Avalos return -ENODEV; 931182bcaa5SAzael Avalos } else if (out[0] == TOS_INPUT_DATA_ERROR) { 932182bcaa5SAzael Avalos return -EIO; 933182bcaa5SAzael Avalos } 934182bcaa5SAzael Avalos 935182bcaa5SAzael Avalos return 0; 936182bcaa5SAzael Avalos } 937182bcaa5SAzael Avalos 938bb3fe01fSAzael Avalos static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev, 939bb3fe01fSAzael Avalos u32 *state) 940bb3fe01fSAzael Avalos { 941bb3fe01fSAzael Avalos u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; 942bb3fe01fSAzael Avalos u32 out[TCI_WORDS]; 943bb3fe01fSAzael Avalos acpi_status status; 944bb3fe01fSAzael Avalos 945bb3fe01fSAzael Avalos if (!sci_open(dev)) 946bb3fe01fSAzael Avalos return -EIO; 947bb3fe01fSAzael Avalos 948bb3fe01fSAzael Avalos in[5] = SCI_USB_CHARGE_RAPID_DSP; 949bb3fe01fSAzael Avalos status = tci_raw(dev, in, out); 950bb3fe01fSAzael Avalos sci_close(dev); 9518baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 952bb26f189SAzael Avalos pr_err("ACPI call to get USB Rapid Charge failed\n"); 953bb3fe01fSAzael Avalos return -EIO; 954bb3fe01fSAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED || 955bb3fe01fSAzael Avalos out[0] == TOS_INPUT_DATA_ERROR) { 956bb26f189SAzael Avalos pr_info("USB Rapid Charge not supported\n"); 957bb3fe01fSAzael Avalos return -ENODEV; 958bb3fe01fSAzael Avalos } 959bb3fe01fSAzael Avalos 960bb3fe01fSAzael Avalos *state = out[2]; 961bb3fe01fSAzael Avalos 962bb3fe01fSAzael Avalos return 0; 963bb3fe01fSAzael Avalos } 964bb3fe01fSAzael Avalos 965bb3fe01fSAzael Avalos static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev, 966bb3fe01fSAzael Avalos u32 state) 967bb3fe01fSAzael Avalos { 968bb3fe01fSAzael Avalos u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; 969bb3fe01fSAzael Avalos u32 out[TCI_WORDS]; 970bb3fe01fSAzael Avalos acpi_status status; 971bb3fe01fSAzael Avalos 972bb3fe01fSAzael Avalos if (!sci_open(dev)) 973bb3fe01fSAzael Avalos return -EIO; 974bb3fe01fSAzael Avalos 975bb3fe01fSAzael Avalos in[2] = state; 976bb3fe01fSAzael Avalos in[5] = SCI_USB_CHARGE_RAPID_DSP; 977bb3fe01fSAzael Avalos status = tci_raw(dev, in, out); 978bb3fe01fSAzael Avalos sci_close(dev); 9798baec45dSAzael Avalos if (ACPI_FAILURE(status)) { 980bb26f189SAzael Avalos pr_err("ACPI call to set USB Rapid Charge failed\n"); 981bb3fe01fSAzael Avalos return -EIO; 982bb3fe01fSAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 983bb26f189SAzael Avalos pr_info("USB Rapid Charge not supported\n"); 984bb3fe01fSAzael Avalos return -ENODEV; 985bb3fe01fSAzael Avalos } else if (out[0] == TOS_INPUT_DATA_ERROR) { 986bb3fe01fSAzael Avalos return -EIO; 987bb3fe01fSAzael Avalos } 988bb3fe01fSAzael Avalos 989bb3fe01fSAzael Avalos return 0; 990bb3fe01fSAzael Avalos } 991bb3fe01fSAzael Avalos 992172ce0a9SAzael Avalos static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state) 993172ce0a9SAzael Avalos { 994172ce0a9SAzael Avalos u32 result; 995172ce0a9SAzael Avalos 996172ce0a9SAzael Avalos if (!sci_open(dev)) 997172ce0a9SAzael Avalos return -EIO; 998172ce0a9SAzael Avalos 999172ce0a9SAzael Avalos result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state); 1000172ce0a9SAzael Avalos sci_close(dev); 1001172ce0a9SAzael Avalos if (result == TOS_FAILURE) { 1002bb26f189SAzael Avalos pr_err("ACPI call to get Sleep and Music failed\n"); 1003172ce0a9SAzael Avalos return -EIO; 1004172ce0a9SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 1005bb26f189SAzael Avalos pr_info("Sleep and Music not supported\n"); 1006172ce0a9SAzael Avalos return -ENODEV; 1007172ce0a9SAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 1008172ce0a9SAzael Avalos return -EIO; 1009172ce0a9SAzael Avalos } 1010172ce0a9SAzael Avalos 1011172ce0a9SAzael Avalos return 0; 1012172ce0a9SAzael Avalos } 1013172ce0a9SAzael Avalos 1014172ce0a9SAzael Avalos static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state) 1015172ce0a9SAzael Avalos { 1016172ce0a9SAzael Avalos u32 result; 1017172ce0a9SAzael Avalos 1018172ce0a9SAzael Avalos if (!sci_open(dev)) 1019172ce0a9SAzael Avalos return -EIO; 1020172ce0a9SAzael Avalos 1021172ce0a9SAzael Avalos result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state); 1022172ce0a9SAzael Avalos sci_close(dev); 1023172ce0a9SAzael Avalos if (result == TOS_FAILURE) { 1024bb26f189SAzael Avalos pr_err("ACPI call to set Sleep and Music failed\n"); 1025172ce0a9SAzael Avalos return -EIO; 1026172ce0a9SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 1027bb26f189SAzael Avalos pr_info("Sleep and Music not supported\n"); 1028172ce0a9SAzael Avalos return -ENODEV; 1029172ce0a9SAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 1030172ce0a9SAzael Avalos return -EIO; 1031172ce0a9SAzael Avalos } 1032172ce0a9SAzael Avalos 1033172ce0a9SAzael Avalos return 0; 1034172ce0a9SAzael Avalos } 1035172ce0a9SAzael Avalos 1036bae84195SAzael Avalos /* Keyboard function keys */ 1037bae84195SAzael Avalos static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode) 1038bae84195SAzael Avalos { 1039bae84195SAzael Avalos u32 result; 1040bae84195SAzael Avalos 1041bae84195SAzael Avalos if (!sci_open(dev)) 1042bae84195SAzael Avalos return -EIO; 1043bae84195SAzael Avalos 1044bae84195SAzael Avalos result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode); 1045bae84195SAzael Avalos sci_close(dev); 1046bae84195SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 1047bae84195SAzael Avalos pr_err("ACPI call to get KBD function keys failed\n"); 1048bae84195SAzael Avalos return -EIO; 1049bae84195SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 1050bae84195SAzael Avalos pr_info("KBD function keys not supported\n"); 1051bae84195SAzael Avalos return -ENODEV; 1052bae84195SAzael Avalos } 1053bae84195SAzael Avalos 1054bae84195SAzael Avalos return 0; 1055bae84195SAzael Avalos } 1056bae84195SAzael Avalos 1057bae84195SAzael Avalos static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode) 1058bae84195SAzael Avalos { 1059bae84195SAzael Avalos u32 result; 1060bae84195SAzael Avalos 1061bae84195SAzael Avalos if (!sci_open(dev)) 1062bae84195SAzael Avalos return -EIO; 1063bae84195SAzael Avalos 1064bae84195SAzael Avalos result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode); 1065bae84195SAzael Avalos sci_close(dev); 1066bae84195SAzael Avalos if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { 1067bae84195SAzael Avalos pr_err("ACPI call to set KBD function keys failed\n"); 1068bae84195SAzael Avalos return -EIO; 1069bae84195SAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 1070bae84195SAzael Avalos pr_info("KBD function keys not supported\n"); 1071bae84195SAzael Avalos return -ENODEV; 1072bae84195SAzael Avalos } 1073bae84195SAzael Avalos 1074bae84195SAzael Avalos return 0; 1075bae84195SAzael Avalos } 1076bae84195SAzael Avalos 107735d53ceaSAzael Avalos /* Panel Power ON */ 107835d53ceaSAzael Avalos static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state) 107935d53ceaSAzael Avalos { 108035d53ceaSAzael Avalos u32 result; 108135d53ceaSAzael Avalos 108235d53ceaSAzael Avalos if (!sci_open(dev)) 108335d53ceaSAzael Avalos return -EIO; 108435d53ceaSAzael Avalos 108535d53ceaSAzael Avalos result = sci_read(dev, SCI_PANEL_POWER_ON, state); 108635d53ceaSAzael Avalos sci_close(dev); 108735d53ceaSAzael Avalos if (result == TOS_FAILURE) { 108835d53ceaSAzael Avalos pr_err("ACPI call to get Panel Power ON failed\n"); 108935d53ceaSAzael Avalos return -EIO; 109035d53ceaSAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 109135d53ceaSAzael Avalos pr_info("Panel Power on not supported\n"); 109235d53ceaSAzael Avalos return -ENODEV; 109335d53ceaSAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 109435d53ceaSAzael Avalos return -EIO; 109535d53ceaSAzael Avalos } 109635d53ceaSAzael Avalos 109735d53ceaSAzael Avalos return 0; 109835d53ceaSAzael Avalos } 109935d53ceaSAzael Avalos 110035d53ceaSAzael Avalos static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state) 110135d53ceaSAzael Avalos { 110235d53ceaSAzael Avalos u32 result; 110335d53ceaSAzael Avalos 110435d53ceaSAzael Avalos if (!sci_open(dev)) 110535d53ceaSAzael Avalos return -EIO; 110635d53ceaSAzael Avalos 110735d53ceaSAzael Avalos result = sci_write(dev, SCI_PANEL_POWER_ON, state); 110835d53ceaSAzael Avalos sci_close(dev); 110935d53ceaSAzael Avalos if (result == TOS_FAILURE) { 111035d53ceaSAzael Avalos pr_err("ACPI call to set Panel Power ON failed\n"); 111135d53ceaSAzael Avalos return -EIO; 111235d53ceaSAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 111335d53ceaSAzael Avalos pr_info("Panel Power ON not supported\n"); 111435d53ceaSAzael Avalos return -ENODEV; 111535d53ceaSAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 111635d53ceaSAzael Avalos return -EIO; 111735d53ceaSAzael Avalos } 111835d53ceaSAzael Avalos 111935d53ceaSAzael Avalos return 0; 112035d53ceaSAzael Avalos } 112135d53ceaSAzael Avalos 112217fe4b3dSAzael Avalos /* USB Three */ 112317fe4b3dSAzael Avalos static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state) 112417fe4b3dSAzael Avalos { 112517fe4b3dSAzael Avalos u32 result; 112617fe4b3dSAzael Avalos 112717fe4b3dSAzael Avalos if (!sci_open(dev)) 112817fe4b3dSAzael Avalos return -EIO; 112917fe4b3dSAzael Avalos 113017fe4b3dSAzael Avalos result = sci_read(dev, SCI_USB_THREE, state); 113117fe4b3dSAzael Avalos sci_close(dev); 113217fe4b3dSAzael Avalos if (result == TOS_FAILURE) { 113317fe4b3dSAzael Avalos pr_err("ACPI call to get USB 3 failed\n"); 113417fe4b3dSAzael Avalos return -EIO; 113517fe4b3dSAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 113617fe4b3dSAzael Avalos pr_info("USB 3 not supported\n"); 113717fe4b3dSAzael Avalos return -ENODEV; 113817fe4b3dSAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 113917fe4b3dSAzael Avalos return -EIO; 114017fe4b3dSAzael Avalos } 114117fe4b3dSAzael Avalos 114217fe4b3dSAzael Avalos return 0; 114317fe4b3dSAzael Avalos } 114417fe4b3dSAzael Avalos 114517fe4b3dSAzael Avalos static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state) 114617fe4b3dSAzael Avalos { 114717fe4b3dSAzael Avalos u32 result; 114817fe4b3dSAzael Avalos 114917fe4b3dSAzael Avalos if (!sci_open(dev)) 115017fe4b3dSAzael Avalos return -EIO; 115117fe4b3dSAzael Avalos 115217fe4b3dSAzael Avalos result = sci_write(dev, SCI_USB_THREE, state); 115317fe4b3dSAzael Avalos sci_close(dev); 115417fe4b3dSAzael Avalos if (result == TOS_FAILURE) { 115517fe4b3dSAzael Avalos pr_err("ACPI call to set USB 3 failed\n"); 115617fe4b3dSAzael Avalos return -EIO; 115717fe4b3dSAzael Avalos } else if (result == TOS_NOT_SUPPORTED) { 115817fe4b3dSAzael Avalos pr_info("USB 3 not supported\n"); 115917fe4b3dSAzael Avalos return -ENODEV; 116017fe4b3dSAzael Avalos } else if (result == TOS_INPUT_DATA_ERROR) { 116117fe4b3dSAzael Avalos return -EIO; 116217fe4b3dSAzael Avalos } 116317fe4b3dSAzael Avalos 116417fe4b3dSAzael Avalos return 0; 116517fe4b3dSAzael Avalos } 116617fe4b3dSAzael Avalos 116756e6b353SAzael Avalos /* Hotkey Event type */ 116856e6b353SAzael Avalos static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev, 116956e6b353SAzael Avalos u32 *type) 117056e6b353SAzael Avalos { 11713b876000SAzael Avalos u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 }; 11723b876000SAzael Avalos u32 out[TCI_WORDS]; 11733b876000SAzael Avalos acpi_status status; 117456e6b353SAzael Avalos 11753b876000SAzael Avalos status = tci_raw(dev, in, out); 11763b876000SAzael Avalos if (ACPI_FAILURE(status)) { 117756e6b353SAzael Avalos pr_err("ACPI call to get System type failed\n"); 117856e6b353SAzael Avalos return -EIO; 11793b876000SAzael Avalos } else if (out[0] == TOS_NOT_SUPPORTED) { 118056e6b353SAzael Avalos pr_info("System type not supported\n"); 118156e6b353SAzael Avalos return -ENODEV; 118256e6b353SAzael Avalos } 118356e6b353SAzael Avalos 11843b876000SAzael Avalos *type = out[3]; 118556e6b353SAzael Avalos 118656e6b353SAzael Avalos return 0; 118756e6b353SAzael Avalos } 118856e6b353SAzael Avalos 11893f75bbe9SAzael Avalos /* Transflective Backlight */ 1190*695f6060SAzael Avalos static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status) 1191121b7b0dSAkio Idehara { 1192*695f6060SAzael Avalos u32 hci_result = hci_read(dev, HCI_TR_BACKLIGHT, status); 1193121b7b0dSAkio Idehara 11941864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 1195121b7b0dSAkio Idehara } 1196121b7b0dSAkio Idehara 1197*695f6060SAzael Avalos static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status) 1198121b7b0dSAkio Idehara { 1199*695f6060SAzael Avalos u32 hci_result = hci_write(dev, HCI_TR_BACKLIGHT, !status); 1200121b7b0dSAkio Idehara 12011864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 1202121b7b0dSAkio Idehara } 1203121b7b0dSAkio Idehara 12043f75bbe9SAzael Avalos static struct proc_dir_entry *toshiba_proc_dir; 1205b4f9fe12SLen Brown 12063f75bbe9SAzael Avalos /* LCD Brightness */ 120762cce752SSeth Forshee static int __get_lcd_brightness(struct toshiba_acpi_dev *dev) 1208b4f9fe12SLen Brown { 1209b4f9fe12SLen Brown u32 hci_result; 1210b4f9fe12SLen Brown u32 value; 1211121b7b0dSAkio Idehara int brightness = 0; 1212121b7b0dSAkio Idehara 1213121b7b0dSAkio Idehara if (dev->tr_backlight_supported) { 1214*695f6060SAzael Avalos int ret = get_tr_backlight_status(dev, &value); 1215b5163992SAzael Avalos 1216121b7b0dSAkio Idehara if (ret) 1217121b7b0dSAkio Idehara return ret; 1218*695f6060SAzael Avalos if (value) 1219121b7b0dSAkio Idehara return 0; 1220121b7b0dSAkio Idehara brightness++; 1221121b7b0dSAkio Idehara } 1222b4f9fe12SLen Brown 1223d37782bdSAzael Avalos hci_result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value); 12241864bbc2SAzael Avalos if (hci_result == TOS_SUCCESS) 1225121b7b0dSAkio Idehara return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT); 122632bcd5cbSSeth Forshee 122732bcd5cbSSeth Forshee return -EIO; 1228b4f9fe12SLen Brown } 1229b4f9fe12SLen Brown 123062cce752SSeth Forshee static int get_lcd_brightness(struct backlight_device *bd) 123162cce752SSeth Forshee { 123262cce752SSeth Forshee struct toshiba_acpi_dev *dev = bl_get_data(bd); 1233b5163992SAzael Avalos 123462cce752SSeth Forshee return __get_lcd_brightness(dev); 123562cce752SSeth Forshee } 123662cce752SSeth Forshee 1237936c8bcdSAlexey Dobriyan static int lcd_proc_show(struct seq_file *m, void *v) 1238b4f9fe12SLen Brown { 1239135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 1240135740deSSeth Forshee int value; 1241121b7b0dSAkio Idehara int levels; 1242b4f9fe12SLen Brown 1243135740deSSeth Forshee if (!dev->backlight_dev) 1244135740deSSeth Forshee return -ENODEV; 1245135740deSSeth Forshee 1246121b7b0dSAkio Idehara levels = dev->backlight_dev->props.max_brightness + 1; 124762cce752SSeth Forshee value = get_lcd_brightness(dev->backlight_dev); 1248b4f9fe12SLen Brown if (value >= 0) { 1249936c8bcdSAlexey Dobriyan seq_printf(m, "brightness: %d\n", value); 1250121b7b0dSAkio Idehara seq_printf(m, "brightness_levels: %d\n", levels); 125132bcd5cbSSeth Forshee return 0; 1252b4f9fe12SLen Brown } 1253b4f9fe12SLen Brown 125432bcd5cbSSeth Forshee pr_err("Error reading LCD brightness\n"); 125532bcd5cbSSeth Forshee return -EIO; 1256936c8bcdSAlexey Dobriyan } 1257936c8bcdSAlexey Dobriyan 1258936c8bcdSAlexey Dobriyan static int lcd_proc_open(struct inode *inode, struct file *file) 1259936c8bcdSAlexey Dobriyan { 1260d9dda78bSAl Viro return single_open(file, lcd_proc_show, PDE_DATA(inode)); 1261b4f9fe12SLen Brown } 1262b4f9fe12SLen Brown 126362cce752SSeth Forshee static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value) 1264b4f9fe12SLen Brown { 1265a39f46dfSAzael Avalos u32 hci_result; 1266b4f9fe12SLen Brown 1267121b7b0dSAkio Idehara if (dev->tr_backlight_supported) { 1268*695f6060SAzael Avalos int ret = set_tr_backlight_status(dev, !value); 1269b5163992SAzael Avalos 1270121b7b0dSAkio Idehara if (ret) 1271121b7b0dSAkio Idehara return ret; 1272121b7b0dSAkio Idehara if (value) 1273121b7b0dSAkio Idehara value--; 1274121b7b0dSAkio Idehara } 1275121b7b0dSAkio Idehara 1276a39f46dfSAzael Avalos value = value << HCI_LCD_BRIGHTNESS_SHIFT; 1277d37782bdSAzael Avalos hci_result = hci_write(dev, HCI_LCD_BRIGHTNESS, value); 1278a39f46dfSAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 1279b4f9fe12SLen Brown } 1280b4f9fe12SLen Brown 1281b4f9fe12SLen Brown static int set_lcd_status(struct backlight_device *bd) 1282b4f9fe12SLen Brown { 1283135740deSSeth Forshee struct toshiba_acpi_dev *dev = bl_get_data(bd); 1284b5163992SAzael Avalos 128562cce752SSeth Forshee return set_lcd_brightness(dev, bd->props.brightness); 1286b4f9fe12SLen Brown } 1287b4f9fe12SLen Brown 1288936c8bcdSAlexey Dobriyan static ssize_t lcd_proc_write(struct file *file, const char __user *buf, 1289936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1290b4f9fe12SLen Brown { 1291d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1292936c8bcdSAlexey Dobriyan char cmd[42]; 1293936c8bcdSAlexey Dobriyan size_t len; 1294b4f9fe12SLen Brown int value; 1295b4f9fe12SLen Brown int ret; 1296121b7b0dSAkio Idehara int levels = dev->backlight_dev->props.max_brightness + 1; 1297b4f9fe12SLen Brown 1298936c8bcdSAlexey Dobriyan len = min(count, sizeof(cmd) - 1); 1299936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, len)) 1300936c8bcdSAlexey Dobriyan return -EFAULT; 1301936c8bcdSAlexey Dobriyan cmd[len] = '\0'; 1302936c8bcdSAlexey Dobriyan 1303936c8bcdSAlexey Dobriyan if (sscanf(cmd, " brightness : %i", &value) == 1 && 1304121b7b0dSAkio Idehara value >= 0 && value < levels) { 130562cce752SSeth Forshee ret = set_lcd_brightness(dev, value); 1306b4f9fe12SLen Brown if (ret == 0) 1307b4f9fe12SLen Brown ret = count; 1308b4f9fe12SLen Brown } else { 1309b4f9fe12SLen Brown ret = -EINVAL; 1310b4f9fe12SLen Brown } 1311b4f9fe12SLen Brown return ret; 1312b4f9fe12SLen Brown } 1313b4f9fe12SLen Brown 1314936c8bcdSAlexey Dobriyan static const struct file_operations lcd_proc_fops = { 1315936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1316936c8bcdSAlexey Dobriyan .open = lcd_proc_open, 1317936c8bcdSAlexey Dobriyan .read = seq_read, 1318936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1319936c8bcdSAlexey Dobriyan .release = single_release, 1320936c8bcdSAlexey Dobriyan .write = lcd_proc_write, 1321936c8bcdSAlexey Dobriyan }; 1322936c8bcdSAlexey Dobriyan 132336d03f93SSeth Forshee static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status) 132436d03f93SSeth Forshee { 132536d03f93SSeth Forshee u32 hci_result; 132636d03f93SSeth Forshee 1327d37782bdSAzael Avalos hci_result = hci_read(dev, HCI_VIDEO_OUT, status); 13281864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 132936d03f93SSeth Forshee } 133036d03f93SSeth Forshee 1331936c8bcdSAlexey Dobriyan static int video_proc_show(struct seq_file *m, void *v) 1332b4f9fe12SLen Brown { 1333135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 1334b4f9fe12SLen Brown u32 value; 133536d03f93SSeth Forshee int ret; 1336b4f9fe12SLen Brown 133736d03f93SSeth Forshee ret = get_video_status(dev, &value); 133836d03f93SSeth Forshee if (!ret) { 1339b4f9fe12SLen Brown int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; 1340b4f9fe12SLen Brown int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; 1341b4f9fe12SLen Brown int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0; 1342b5163992SAzael Avalos 1343936c8bcdSAlexey Dobriyan seq_printf(m, "lcd_out: %d\n", is_lcd); 1344936c8bcdSAlexey Dobriyan seq_printf(m, "crt_out: %d\n", is_crt); 1345936c8bcdSAlexey Dobriyan seq_printf(m, "tv_out: %d\n", is_tv); 1346b4f9fe12SLen Brown } 1347b4f9fe12SLen Brown 134836d03f93SSeth Forshee return ret; 1349b4f9fe12SLen Brown } 1350b4f9fe12SLen Brown 1351936c8bcdSAlexey Dobriyan static int video_proc_open(struct inode *inode, struct file *file) 1352b4f9fe12SLen Brown { 1353d9dda78bSAl Viro return single_open(file, video_proc_show, PDE_DATA(inode)); 1354936c8bcdSAlexey Dobriyan } 1355936c8bcdSAlexey Dobriyan 1356936c8bcdSAlexey Dobriyan static ssize_t video_proc_write(struct file *file, const char __user *buf, 1357936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1358936c8bcdSAlexey Dobriyan { 1359d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1360936c8bcdSAlexey Dobriyan char *cmd, *buffer; 136136d03f93SSeth Forshee int ret; 1362b4f9fe12SLen Brown int value; 1363b4f9fe12SLen Brown int remain = count; 1364b4f9fe12SLen Brown int lcd_out = -1; 1365b4f9fe12SLen Brown int crt_out = -1; 1366b4f9fe12SLen Brown int tv_out = -1; 1367b4f9fe12SLen Brown u32 video_out; 1368b4f9fe12SLen Brown 1369936c8bcdSAlexey Dobriyan cmd = kmalloc(count + 1, GFP_KERNEL); 1370936c8bcdSAlexey Dobriyan if (!cmd) 1371936c8bcdSAlexey Dobriyan return -ENOMEM; 1372936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, count)) { 1373936c8bcdSAlexey Dobriyan kfree(cmd); 1374936c8bcdSAlexey Dobriyan return -EFAULT; 1375936c8bcdSAlexey Dobriyan } 1376936c8bcdSAlexey Dobriyan cmd[count] = '\0'; 1377936c8bcdSAlexey Dobriyan 1378936c8bcdSAlexey Dobriyan buffer = cmd; 1379936c8bcdSAlexey Dobriyan 1380e0769fe6SDarren Hart /* 1381e0769fe6SDarren Hart * Scan expression. Multiple expressions may be delimited with ; 1382e0769fe6SDarren Hart * NOTE: To keep scanning simple, invalid fields are ignored. 1383b4f9fe12SLen Brown */ 1384b4f9fe12SLen Brown while (remain) { 1385b4f9fe12SLen Brown if (sscanf(buffer, " lcd_out : %i", &value) == 1) 1386b4f9fe12SLen Brown lcd_out = value & 1; 1387b4f9fe12SLen Brown else if (sscanf(buffer, " crt_out : %i", &value) == 1) 1388b4f9fe12SLen Brown crt_out = value & 1; 1389b4f9fe12SLen Brown else if (sscanf(buffer, " tv_out : %i", &value) == 1) 1390b4f9fe12SLen Brown tv_out = value & 1; 1391e0769fe6SDarren Hart /* Advance to one character past the next ; */ 1392b4f9fe12SLen Brown do { 1393b4f9fe12SLen Brown ++buffer; 1394b4f9fe12SLen Brown --remain; 1395b5163992SAzael Avalos } while (remain && *(buffer - 1) != ';'); 1396b4f9fe12SLen Brown } 1397b4f9fe12SLen Brown 1398936c8bcdSAlexey Dobriyan kfree(cmd); 1399936c8bcdSAlexey Dobriyan 140036d03f93SSeth Forshee ret = get_video_status(dev, &video_out); 140136d03f93SSeth Forshee if (!ret) { 1402b4f9fe12SLen Brown unsigned int new_video_out = video_out; 1403b5163992SAzael Avalos 1404b4f9fe12SLen Brown if (lcd_out != -1) 1405b4f9fe12SLen Brown _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out); 1406b4f9fe12SLen Brown if (crt_out != -1) 1407b4f9fe12SLen Brown _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out); 1408b4f9fe12SLen Brown if (tv_out != -1) 1409b4f9fe12SLen Brown _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out); 1410e0769fe6SDarren Hart /* 1411e0769fe6SDarren Hart * To avoid unnecessary video disruption, only write the new 14123f75bbe9SAzael Avalos * video setting if something changed. 14133f75bbe9SAzael Avalos */ 1414b4f9fe12SLen Brown if (new_video_out != video_out) 141532bcd5cbSSeth Forshee ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out); 1416b4f9fe12SLen Brown } 1417b4f9fe12SLen Brown 141832bcd5cbSSeth Forshee return ret ? ret : count; 1419b4f9fe12SLen Brown } 1420b4f9fe12SLen Brown 1421936c8bcdSAlexey Dobriyan static const struct file_operations video_proc_fops = { 1422936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1423936c8bcdSAlexey Dobriyan .open = video_proc_open, 1424936c8bcdSAlexey Dobriyan .read = seq_read, 1425936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1426936c8bcdSAlexey Dobriyan .release = single_release, 1427936c8bcdSAlexey Dobriyan .write = video_proc_write, 1428936c8bcdSAlexey Dobriyan }; 1429936c8bcdSAlexey Dobriyan 143036d03f93SSeth Forshee static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status) 143136d03f93SSeth Forshee { 143236d03f93SSeth Forshee u32 hci_result; 143336d03f93SSeth Forshee 1434d37782bdSAzael Avalos hci_result = hci_read(dev, HCI_FAN, status); 14351864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 143636d03f93SSeth Forshee } 143736d03f93SSeth Forshee 1438936c8bcdSAlexey Dobriyan static int fan_proc_show(struct seq_file *m, void *v) 1439b4f9fe12SLen Brown { 1440135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 144136d03f93SSeth Forshee int ret; 1442b4f9fe12SLen Brown u32 value; 1443b4f9fe12SLen Brown 144436d03f93SSeth Forshee ret = get_fan_status(dev, &value); 144536d03f93SSeth Forshee if (!ret) { 1446936c8bcdSAlexey Dobriyan seq_printf(m, "running: %d\n", (value > 0)); 1447135740deSSeth Forshee seq_printf(m, "force_on: %d\n", dev->force_fan); 1448b4f9fe12SLen Brown } 1449b4f9fe12SLen Brown 145036d03f93SSeth Forshee return ret; 1451b4f9fe12SLen Brown } 1452b4f9fe12SLen Brown 1453936c8bcdSAlexey Dobriyan static int fan_proc_open(struct inode *inode, struct file *file) 1454b4f9fe12SLen Brown { 1455d9dda78bSAl Viro return single_open(file, fan_proc_show, PDE_DATA(inode)); 1456936c8bcdSAlexey Dobriyan } 1457936c8bcdSAlexey Dobriyan 1458936c8bcdSAlexey Dobriyan static ssize_t fan_proc_write(struct file *file, const char __user *buf, 1459936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1460936c8bcdSAlexey Dobriyan { 1461d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1462936c8bcdSAlexey Dobriyan char cmd[42]; 1463936c8bcdSAlexey Dobriyan size_t len; 1464b4f9fe12SLen Brown int value; 1465b4f9fe12SLen Brown u32 hci_result; 1466b4f9fe12SLen Brown 1467936c8bcdSAlexey Dobriyan len = min(count, sizeof(cmd) - 1); 1468936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, len)) 1469936c8bcdSAlexey Dobriyan return -EFAULT; 1470936c8bcdSAlexey Dobriyan cmd[len] = '\0'; 1471936c8bcdSAlexey Dobriyan 1472936c8bcdSAlexey Dobriyan if (sscanf(cmd, " force_on : %i", &value) == 1 && 1473b4f9fe12SLen Brown value >= 0 && value <= 1) { 1474d37782bdSAzael Avalos hci_result = hci_write(dev, HCI_FAN, value); 1475b5163992SAzael Avalos if (hci_result == TOS_SUCCESS) 1476135740deSSeth Forshee dev->force_fan = value; 1477b5163992SAzael Avalos else 1478b5163992SAzael Avalos return -EIO; 1479b4f9fe12SLen Brown } else { 1480b4f9fe12SLen Brown return -EINVAL; 1481b4f9fe12SLen Brown } 1482b4f9fe12SLen Brown 1483b4f9fe12SLen Brown return count; 1484b4f9fe12SLen Brown } 1485b4f9fe12SLen Brown 1486936c8bcdSAlexey Dobriyan static const struct file_operations fan_proc_fops = { 1487936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1488936c8bcdSAlexey Dobriyan .open = fan_proc_open, 1489936c8bcdSAlexey Dobriyan .read = seq_read, 1490936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1491936c8bcdSAlexey Dobriyan .release = single_release, 1492936c8bcdSAlexey Dobriyan .write = fan_proc_write, 1493936c8bcdSAlexey Dobriyan }; 1494936c8bcdSAlexey Dobriyan 1495936c8bcdSAlexey Dobriyan static int keys_proc_show(struct seq_file *m, void *v) 1496b4f9fe12SLen Brown { 1497135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 1498b4f9fe12SLen Brown 1499135740deSSeth Forshee seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid); 1500135740deSSeth Forshee seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event); 15017deef550SAzael Avalos 1502936c8bcdSAlexey Dobriyan return 0; 1503b4f9fe12SLen Brown } 1504b4f9fe12SLen Brown 1505936c8bcdSAlexey Dobriyan static int keys_proc_open(struct inode *inode, struct file *file) 1506b4f9fe12SLen Brown { 1507d9dda78bSAl Viro return single_open(file, keys_proc_show, PDE_DATA(inode)); 1508936c8bcdSAlexey Dobriyan } 1509936c8bcdSAlexey Dobriyan 1510936c8bcdSAlexey Dobriyan static ssize_t keys_proc_write(struct file *file, const char __user *buf, 1511936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1512936c8bcdSAlexey Dobriyan { 1513d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1514936c8bcdSAlexey Dobriyan char cmd[42]; 1515936c8bcdSAlexey Dobriyan size_t len; 1516b4f9fe12SLen Brown int value; 1517b4f9fe12SLen Brown 1518936c8bcdSAlexey Dobriyan len = min(count, sizeof(cmd) - 1); 1519936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, len)) 1520936c8bcdSAlexey Dobriyan return -EFAULT; 1521936c8bcdSAlexey Dobriyan cmd[len] = '\0'; 1522936c8bcdSAlexey Dobriyan 1523b5163992SAzael Avalos if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) 1524135740deSSeth Forshee dev->key_event_valid = 0; 1525b5163992SAzael Avalos else 1526b4f9fe12SLen Brown return -EINVAL; 1527b4f9fe12SLen Brown 1528b4f9fe12SLen Brown return count; 1529b4f9fe12SLen Brown } 1530b4f9fe12SLen Brown 1531936c8bcdSAlexey Dobriyan static const struct file_operations keys_proc_fops = { 1532936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1533936c8bcdSAlexey Dobriyan .open = keys_proc_open, 1534936c8bcdSAlexey Dobriyan .read = seq_read, 1535936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1536936c8bcdSAlexey Dobriyan .release = single_release, 1537936c8bcdSAlexey Dobriyan .write = keys_proc_write, 1538936c8bcdSAlexey Dobriyan }; 1539936c8bcdSAlexey Dobriyan 1540936c8bcdSAlexey Dobriyan static int version_proc_show(struct seq_file *m, void *v) 1541b4f9fe12SLen Brown { 1542936c8bcdSAlexey Dobriyan seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION); 1543936c8bcdSAlexey Dobriyan seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION); 1544936c8bcdSAlexey Dobriyan return 0; 1545b4f9fe12SLen Brown } 1546b4f9fe12SLen Brown 1547936c8bcdSAlexey Dobriyan static int version_proc_open(struct inode *inode, struct file *file) 1548936c8bcdSAlexey Dobriyan { 1549d9dda78bSAl Viro return single_open(file, version_proc_show, PDE_DATA(inode)); 1550936c8bcdSAlexey Dobriyan } 1551936c8bcdSAlexey Dobriyan 1552936c8bcdSAlexey Dobriyan static const struct file_operations version_proc_fops = { 1553936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1554936c8bcdSAlexey Dobriyan .open = version_proc_open, 1555936c8bcdSAlexey Dobriyan .read = seq_read, 1556936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1557936c8bcdSAlexey Dobriyan .release = single_release, 1558936c8bcdSAlexey Dobriyan }; 1559936c8bcdSAlexey Dobriyan 1560e0769fe6SDarren Hart /* 1561e0769fe6SDarren Hart * Proc and module init 1562b4f9fe12SLen Brown */ 1563b4f9fe12SLen Brown 1564b4f9fe12SLen Brown #define PROC_TOSHIBA "toshiba" 1565b4f9fe12SLen Brown 1566b859f159SGreg Kroah-Hartman static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev) 1567b4f9fe12SLen Brown { 156836d03f93SSeth Forshee if (dev->backlight_dev) 1569135740deSSeth Forshee proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1570135740deSSeth Forshee &lcd_proc_fops, dev); 157136d03f93SSeth Forshee if (dev->video_supported) 1572135740deSSeth Forshee proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1573135740deSSeth Forshee &video_proc_fops, dev); 157436d03f93SSeth Forshee if (dev->fan_supported) 1575135740deSSeth Forshee proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1576135740deSSeth Forshee &fan_proc_fops, dev); 157736d03f93SSeth Forshee if (dev->hotkey_dev) 1578135740deSSeth Forshee proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1579135740deSSeth Forshee &keys_proc_fops, dev); 1580135740deSSeth Forshee proc_create_data("version", S_IRUGO, toshiba_proc_dir, 1581135740deSSeth Forshee &version_proc_fops, dev); 1582b4f9fe12SLen Brown } 1583b4f9fe12SLen Brown 158436d03f93SSeth Forshee static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev) 1585b4f9fe12SLen Brown { 158636d03f93SSeth Forshee if (dev->backlight_dev) 1587936c8bcdSAlexey Dobriyan remove_proc_entry("lcd", toshiba_proc_dir); 158836d03f93SSeth Forshee if (dev->video_supported) 1589936c8bcdSAlexey Dobriyan remove_proc_entry("video", toshiba_proc_dir); 159036d03f93SSeth Forshee if (dev->fan_supported) 1591936c8bcdSAlexey Dobriyan remove_proc_entry("fan", toshiba_proc_dir); 159236d03f93SSeth Forshee if (dev->hotkey_dev) 1593936c8bcdSAlexey Dobriyan remove_proc_entry("keys", toshiba_proc_dir); 1594936c8bcdSAlexey Dobriyan remove_proc_entry("version", toshiba_proc_dir); 1595b4f9fe12SLen Brown } 1596b4f9fe12SLen Brown 1597acc2472eSLionel Debroux static const struct backlight_ops toshiba_backlight_data = { 1598121b7b0dSAkio Idehara .options = BL_CORE_SUSPENDRESUME, 159962cce752SSeth Forshee .get_brightness = get_lcd_brightness, 1600b4f9fe12SLen Brown .update_status = set_lcd_status, 1601b4f9fe12SLen Brown }; 1602b4f9fe12SLen Brown 1603360f0f39SAzael Avalos /* 1604360f0f39SAzael Avalos * Sysfs files 1605360f0f39SAzael Avalos */ 16069d309848SAzael Avalos static ssize_t version_show(struct device *dev, 1607c6c68ff8SAzael Avalos struct device_attribute *attr, char *buf) 1608c6c68ff8SAzael Avalos { 1609c6c68ff8SAzael Avalos return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION); 1610c6c68ff8SAzael Avalos } 16110c3c0f10SAzael Avalos static DEVICE_ATTR_RO(version); 1612c6c68ff8SAzael Avalos 16139d309848SAzael Avalos static ssize_t fan_store(struct device *dev, 161494477d4cSAzael Avalos struct device_attribute *attr, 161594477d4cSAzael Avalos const char *buf, size_t count) 161694477d4cSAzael Avalos { 161794477d4cSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 161894477d4cSAzael Avalos u32 result; 161994477d4cSAzael Avalos int state; 162094477d4cSAzael Avalos int ret; 162194477d4cSAzael Avalos 162294477d4cSAzael Avalos ret = kstrtoint(buf, 0, &state); 162394477d4cSAzael Avalos if (ret) 162494477d4cSAzael Avalos return ret; 162594477d4cSAzael Avalos 162694477d4cSAzael Avalos if (state != 0 && state != 1) 162794477d4cSAzael Avalos return -EINVAL; 162894477d4cSAzael Avalos 1629d37782bdSAzael Avalos result = hci_write(toshiba, HCI_FAN, state); 163094477d4cSAzael Avalos if (result == TOS_FAILURE) 163194477d4cSAzael Avalos return -EIO; 163294477d4cSAzael Avalos else if (result == TOS_NOT_SUPPORTED) 163394477d4cSAzael Avalos return -ENODEV; 163494477d4cSAzael Avalos 163594477d4cSAzael Avalos return count; 163694477d4cSAzael Avalos } 163794477d4cSAzael Avalos 16389d309848SAzael Avalos static ssize_t fan_show(struct device *dev, 163994477d4cSAzael Avalos struct device_attribute *attr, char *buf) 164094477d4cSAzael Avalos { 164194477d4cSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 164294477d4cSAzael Avalos u32 value; 164394477d4cSAzael Avalos int ret; 164494477d4cSAzael Avalos 164594477d4cSAzael Avalos ret = get_fan_status(toshiba, &value); 164694477d4cSAzael Avalos if (ret) 164794477d4cSAzael Avalos return ret; 164894477d4cSAzael Avalos 164994477d4cSAzael Avalos return sprintf(buf, "%d\n", value); 165094477d4cSAzael Avalos } 16510c3c0f10SAzael Avalos static DEVICE_ATTR_RW(fan); 165294477d4cSAzael Avalos 16539d309848SAzael Avalos static ssize_t kbd_backlight_mode_store(struct device *dev, 1654360f0f39SAzael Avalos struct device_attribute *attr, 1655360f0f39SAzael Avalos const char *buf, size_t count) 1656360f0f39SAzael Avalos { 1657360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1658aeaac098SDan Carpenter int mode; 1659aeaac098SDan Carpenter int time; 1660aeaac098SDan Carpenter int ret; 1661360f0f39SAzael Avalos 1662aeaac098SDan Carpenter 1663aeaac098SDan Carpenter ret = kstrtoint(buf, 0, &mode); 1664aeaac098SDan Carpenter if (ret) 1665aeaac098SDan Carpenter return ret; 166693f8c16dSAzael Avalos 166793f8c16dSAzael Avalos /* Check for supported modes depending on keyboard backlight type */ 166893f8c16dSAzael Avalos if (toshiba->kbd_type == 1) { 166993f8c16dSAzael Avalos /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */ 1670aeaac098SDan Carpenter if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO) 1671360f0f39SAzael Avalos return -EINVAL; 167293f8c16dSAzael Avalos } else if (toshiba->kbd_type == 2) { 167393f8c16dSAzael Avalos /* Type 2 doesn't support SCI_KBD_MODE_FNZ */ 167493f8c16dSAzael Avalos if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON && 167593f8c16dSAzael Avalos mode != SCI_KBD_MODE_OFF) 167693f8c16dSAzael Avalos return -EINVAL; 167793f8c16dSAzael Avalos } 1678360f0f39SAzael Avalos 1679e0769fe6SDarren Hart /* 1680e0769fe6SDarren Hart * Set the Keyboard Backlight Mode where: 1681360f0f39SAzael Avalos * Auto - KBD backlight turns off automatically in given time 1682360f0f39SAzael Avalos * FN-Z - KBD backlight "toggles" when hotkey pressed 168393f8c16dSAzael Avalos * ON - KBD backlight is always on 168493f8c16dSAzael Avalos * OFF - KBD backlight is always off 1685360f0f39SAzael Avalos */ 168693f8c16dSAzael Avalos 168793f8c16dSAzael Avalos /* Only make a change if the actual mode has changed */ 1688aeaac098SDan Carpenter if (toshiba->kbd_mode != mode) { 168993f8c16dSAzael Avalos /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ 1690360f0f39SAzael Avalos time = toshiba->kbd_time << HCI_MISC_SHIFT; 169193f8c16dSAzael Avalos 169293f8c16dSAzael Avalos /* OR the "base time" to the actual method format */ 169393f8c16dSAzael Avalos if (toshiba->kbd_type == 1) { 169493f8c16dSAzael Avalos /* Type 1 requires the current mode */ 169593f8c16dSAzael Avalos time |= toshiba->kbd_mode; 169693f8c16dSAzael Avalos } else if (toshiba->kbd_type == 2) { 169793f8c16dSAzael Avalos /* Type 2 requires the desired mode */ 169893f8c16dSAzael Avalos time |= mode; 169993f8c16dSAzael Avalos } 170093f8c16dSAzael Avalos 1701aeaac098SDan Carpenter ret = toshiba_kbd_illum_status_set(toshiba, time); 1702aeaac098SDan Carpenter if (ret) 1703aeaac098SDan Carpenter return ret; 170493f8c16dSAzael Avalos 1705360f0f39SAzael Avalos toshiba->kbd_mode = mode; 1706360f0f39SAzael Avalos } 1707360f0f39SAzael Avalos 1708360f0f39SAzael Avalos return count; 1709360f0f39SAzael Avalos } 1710360f0f39SAzael Avalos 17119d309848SAzael Avalos static ssize_t kbd_backlight_mode_show(struct device *dev, 1712360f0f39SAzael Avalos struct device_attribute *attr, 1713360f0f39SAzael Avalos char *buf) 1714360f0f39SAzael Avalos { 1715360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1716360f0f39SAzael Avalos u32 time; 1717360f0f39SAzael Avalos 1718360f0f39SAzael Avalos if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) 1719360f0f39SAzael Avalos return -EIO; 1720360f0f39SAzael Avalos 172193f8c16dSAzael Avalos return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK); 172293f8c16dSAzael Avalos } 17230c3c0f10SAzael Avalos static DEVICE_ATTR_RW(kbd_backlight_mode); 172493f8c16dSAzael Avalos 17259d309848SAzael Avalos static ssize_t kbd_type_show(struct device *dev, 17269d309848SAzael Avalos struct device_attribute *attr, char *buf) 172793f8c16dSAzael Avalos { 172893f8c16dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 172993f8c16dSAzael Avalos 173093f8c16dSAzael Avalos return sprintf(buf, "%d\n", toshiba->kbd_type); 173193f8c16dSAzael Avalos } 17320c3c0f10SAzael Avalos static DEVICE_ATTR_RO(kbd_type); 173393f8c16dSAzael Avalos 17349d309848SAzael Avalos static ssize_t available_kbd_modes_show(struct device *dev, 173593f8c16dSAzael Avalos struct device_attribute *attr, 173693f8c16dSAzael Avalos char *buf) 173793f8c16dSAzael Avalos { 173893f8c16dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 173993f8c16dSAzael Avalos 174093f8c16dSAzael Avalos if (toshiba->kbd_type == 1) 174193f8c16dSAzael Avalos return sprintf(buf, "%x %x\n", 174293f8c16dSAzael Avalos SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO); 174393f8c16dSAzael Avalos 174493f8c16dSAzael Avalos return sprintf(buf, "%x %x %x\n", 174593f8c16dSAzael Avalos SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF); 1746360f0f39SAzael Avalos } 17470c3c0f10SAzael Avalos static DEVICE_ATTR_RO(available_kbd_modes); 1748360f0f39SAzael Avalos 17499d309848SAzael Avalos static ssize_t kbd_backlight_timeout_store(struct device *dev, 1750360f0f39SAzael Avalos struct device_attribute *attr, 1751360f0f39SAzael Avalos const char *buf, size_t count) 1752360f0f39SAzael Avalos { 1753360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1754eabde0faSAzael Avalos int time; 1755eabde0faSAzael Avalos int ret; 1756360f0f39SAzael Avalos 1757eabde0faSAzael Avalos ret = kstrtoint(buf, 0, &time); 1758eabde0faSAzael Avalos if (ret) 1759eabde0faSAzael Avalos return ret; 1760eabde0faSAzael Avalos 1761eabde0faSAzael Avalos /* Check for supported values depending on kbd_type */ 1762eabde0faSAzael Avalos if (toshiba->kbd_type == 1) { 1763eabde0faSAzael Avalos if (time < 0 || time > 60) 1764360f0f39SAzael Avalos return -EINVAL; 1765eabde0faSAzael Avalos } else if (toshiba->kbd_type == 2) { 1766eabde0faSAzael Avalos if (time < 1 || time > 60) 1767eabde0faSAzael Avalos return -EINVAL; 1768eabde0faSAzael Avalos } 1769360f0f39SAzael Avalos 1770eabde0faSAzael Avalos /* Set the Keyboard Backlight Timeout */ 1771eabde0faSAzael Avalos 1772eabde0faSAzael Avalos /* Only make a change if the actual timeout has changed */ 1773eabde0faSAzael Avalos if (toshiba->kbd_time != time) { 1774eabde0faSAzael Avalos /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ 1775360f0f39SAzael Avalos time = time << HCI_MISC_SHIFT; 1776eabde0faSAzael Avalos /* OR the "base time" to the actual method format */ 1777eabde0faSAzael Avalos if (toshiba->kbd_type == 1) 1778eabde0faSAzael Avalos time |= SCI_KBD_MODE_FNZ; 1779eabde0faSAzael Avalos else if (toshiba->kbd_type == 2) 1780eabde0faSAzael Avalos time |= SCI_KBD_MODE_AUTO; 1781eabde0faSAzael Avalos 1782eabde0faSAzael Avalos ret = toshiba_kbd_illum_status_set(toshiba, time); 1783eabde0faSAzael Avalos if (ret) 1784eabde0faSAzael Avalos return ret; 1785eabde0faSAzael Avalos 1786360f0f39SAzael Avalos toshiba->kbd_time = time >> HCI_MISC_SHIFT; 1787360f0f39SAzael Avalos } 1788360f0f39SAzael Avalos 1789360f0f39SAzael Avalos return count; 1790360f0f39SAzael Avalos } 1791360f0f39SAzael Avalos 17929d309848SAzael Avalos static ssize_t kbd_backlight_timeout_show(struct device *dev, 1793360f0f39SAzael Avalos struct device_attribute *attr, 1794360f0f39SAzael Avalos char *buf) 1795360f0f39SAzael Avalos { 1796360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1797360f0f39SAzael Avalos u32 time; 1798360f0f39SAzael Avalos 1799360f0f39SAzael Avalos if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) 1800360f0f39SAzael Avalos return -EIO; 1801360f0f39SAzael Avalos 1802360f0f39SAzael Avalos return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT); 1803360f0f39SAzael Avalos } 18040c3c0f10SAzael Avalos static DEVICE_ATTR_RW(kbd_backlight_timeout); 1805360f0f39SAzael Avalos 18069d309848SAzael Avalos static ssize_t touchpad_store(struct device *dev, 18079d8658acSAzael Avalos struct device_attribute *attr, 18089d8658acSAzael Avalos const char *buf, size_t count) 18099d8658acSAzael Avalos { 18109d8658acSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 18119d8658acSAzael Avalos int state; 1812c8a41669SAzael Avalos int ret; 18139d8658acSAzael Avalos 18149d8658acSAzael Avalos /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */ 1815c8a41669SAzael Avalos ret = kstrtoint(buf, 0, &state); 1816c8a41669SAzael Avalos if (ret) 1817c8a41669SAzael Avalos return ret; 1818c8a41669SAzael Avalos if (state != 0 && state != 1) 1819c8a41669SAzael Avalos return -EINVAL; 1820c8a41669SAzael Avalos 1821c8a41669SAzael Avalos ret = toshiba_touchpad_set(toshiba, state); 1822c8a41669SAzael Avalos if (ret) 1823c8a41669SAzael Avalos return ret; 18249d8658acSAzael Avalos 18259d8658acSAzael Avalos return count; 18269d8658acSAzael Avalos } 18279d8658acSAzael Avalos 18289d309848SAzael Avalos static ssize_t touchpad_show(struct device *dev, 18299d8658acSAzael Avalos struct device_attribute *attr, char *buf) 18309d8658acSAzael Avalos { 18319d8658acSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 18329d8658acSAzael Avalos u32 state; 18339d8658acSAzael Avalos int ret; 18349d8658acSAzael Avalos 18359d8658acSAzael Avalos ret = toshiba_touchpad_get(toshiba, &state); 18369d8658acSAzael Avalos if (ret < 0) 18379d8658acSAzael Avalos return ret; 18389d8658acSAzael Avalos 18399d8658acSAzael Avalos return sprintf(buf, "%i\n", state); 18409d8658acSAzael Avalos } 18410c3c0f10SAzael Avalos static DEVICE_ATTR_RW(touchpad); 18429d8658acSAzael Avalos 18439d309848SAzael Avalos static ssize_t position_show(struct device *dev, 18445a2813e9SAzael Avalos struct device_attribute *attr, char *buf) 18455a2813e9SAzael Avalos { 18465a2813e9SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 18475a2813e9SAzael Avalos u32 xyval, zval, tmp; 18485a2813e9SAzael Avalos u16 x, y, z; 18495a2813e9SAzael Avalos int ret; 18505a2813e9SAzael Avalos 18515a2813e9SAzael Avalos xyval = zval = 0; 18525a2813e9SAzael Avalos ret = toshiba_accelerometer_get(toshiba, &xyval, &zval); 18535a2813e9SAzael Avalos if (ret < 0) 18545a2813e9SAzael Avalos return ret; 18555a2813e9SAzael Avalos 18565a2813e9SAzael Avalos x = xyval & HCI_ACCEL_MASK; 18575a2813e9SAzael Avalos tmp = xyval >> HCI_MISC_SHIFT; 18585a2813e9SAzael Avalos y = tmp & HCI_ACCEL_MASK; 18595a2813e9SAzael Avalos z = zval & HCI_ACCEL_MASK; 18605a2813e9SAzael Avalos 18615a2813e9SAzael Avalos return sprintf(buf, "%d %d %d\n", x, y, z); 18625a2813e9SAzael Avalos } 18630c3c0f10SAzael Avalos static DEVICE_ATTR_RO(position); 18645a2813e9SAzael Avalos 18659d309848SAzael Avalos static ssize_t usb_sleep_charge_show(struct device *dev, 18669d309848SAzael Avalos struct device_attribute *attr, char *buf) 1867e26ffe51SAzael Avalos { 1868e26ffe51SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1869e26ffe51SAzael Avalos u32 mode; 1870e26ffe51SAzael Avalos int ret; 1871e26ffe51SAzael Avalos 1872e26ffe51SAzael Avalos ret = toshiba_usb_sleep_charge_get(toshiba, &mode); 1873e26ffe51SAzael Avalos if (ret < 0) 1874e26ffe51SAzael Avalos return ret; 1875e26ffe51SAzael Avalos 1876e26ffe51SAzael Avalos return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK); 1877e26ffe51SAzael Avalos } 1878e26ffe51SAzael Avalos 18799d309848SAzael Avalos static ssize_t usb_sleep_charge_store(struct device *dev, 1880e26ffe51SAzael Avalos struct device_attribute *attr, 1881e26ffe51SAzael Avalos const char *buf, size_t count) 1882e26ffe51SAzael Avalos { 1883e26ffe51SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1884e26ffe51SAzael Avalos u32 mode; 1885e26ffe51SAzael Avalos int state; 1886e26ffe51SAzael Avalos int ret; 1887e26ffe51SAzael Avalos 1888e26ffe51SAzael Avalos ret = kstrtoint(buf, 0, &state); 1889e26ffe51SAzael Avalos if (ret) 1890e26ffe51SAzael Avalos return ret; 1891e0769fe6SDarren Hart /* 1892e0769fe6SDarren Hart * Check for supported values, where: 1893e26ffe51SAzael Avalos * 0 - Disabled 1894e26ffe51SAzael Avalos * 1 - Alternate (Non USB conformant devices that require more power) 1895e26ffe51SAzael Avalos * 2 - Auto (USB conformant devices) 1896c8c91842SAzael Avalos * 3 - Typical 1897e26ffe51SAzael Avalos */ 1898c8c91842SAzael Avalos if (state != 0 && state != 1 && state != 2 && state != 3) 1899e26ffe51SAzael Avalos return -EINVAL; 1900e26ffe51SAzael Avalos 1901e26ffe51SAzael Avalos /* Set the USB charging mode to internal value */ 1902c8c91842SAzael Avalos mode = toshiba->usbsc_mode_base; 1903e26ffe51SAzael Avalos if (state == 0) 1904c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_DISABLED; 1905e26ffe51SAzael Avalos else if (state == 1) 1906c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_ALTERNATE; 1907e26ffe51SAzael Avalos else if (state == 2) 1908c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_AUTO; 1909c8c91842SAzael Avalos else if (state == 3) 1910c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_TYPICAL; 1911e26ffe51SAzael Avalos 1912e26ffe51SAzael Avalos ret = toshiba_usb_sleep_charge_set(toshiba, mode); 1913e26ffe51SAzael Avalos if (ret) 1914e26ffe51SAzael Avalos return ret; 1915e26ffe51SAzael Avalos 1916e26ffe51SAzael Avalos return count; 1917e26ffe51SAzael Avalos } 19180c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_sleep_charge); 1919e26ffe51SAzael Avalos 1920182bcaa5SAzael Avalos static ssize_t sleep_functions_on_battery_show(struct device *dev, 1921182bcaa5SAzael Avalos struct device_attribute *attr, 1922182bcaa5SAzael Avalos char *buf) 1923182bcaa5SAzael Avalos { 1924182bcaa5SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1925182bcaa5SAzael Avalos u32 state; 1926182bcaa5SAzael Avalos int bat_lvl; 1927182bcaa5SAzael Avalos int status; 1928182bcaa5SAzael Avalos int ret; 1929182bcaa5SAzael Avalos int tmp; 1930182bcaa5SAzael Avalos 1931182bcaa5SAzael Avalos ret = toshiba_sleep_functions_status_get(toshiba, &state); 1932182bcaa5SAzael Avalos if (ret < 0) 1933182bcaa5SAzael Avalos return ret; 1934182bcaa5SAzael Avalos 1935182bcaa5SAzael Avalos /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */ 1936182bcaa5SAzael Avalos tmp = state & SCI_USB_CHARGE_BAT_MASK; 1937182bcaa5SAzael Avalos status = (tmp == 0x4) ? 1 : 0; 1938182bcaa5SAzael Avalos /* Determine the battery level set */ 1939182bcaa5SAzael Avalos bat_lvl = state >> HCI_MISC_SHIFT; 1940182bcaa5SAzael Avalos 1941182bcaa5SAzael Avalos return sprintf(buf, "%d %d\n", status, bat_lvl); 1942182bcaa5SAzael Avalos } 1943182bcaa5SAzael Avalos 1944182bcaa5SAzael Avalos static ssize_t sleep_functions_on_battery_store(struct device *dev, 1945182bcaa5SAzael Avalos struct device_attribute *attr, 1946182bcaa5SAzael Avalos const char *buf, size_t count) 1947182bcaa5SAzael Avalos { 1948182bcaa5SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1949182bcaa5SAzael Avalos u32 status; 1950182bcaa5SAzael Avalos int value; 1951182bcaa5SAzael Avalos int ret; 1952182bcaa5SAzael Avalos int tmp; 1953182bcaa5SAzael Avalos 1954182bcaa5SAzael Avalos ret = kstrtoint(buf, 0, &value); 1955182bcaa5SAzael Avalos if (ret) 1956182bcaa5SAzael Avalos return ret; 1957182bcaa5SAzael Avalos 1958e0769fe6SDarren Hart /* 1959e0769fe6SDarren Hart * Set the status of the function: 1960182bcaa5SAzael Avalos * 0 - Disabled 1961182bcaa5SAzael Avalos * 1-100 - Enabled 1962182bcaa5SAzael Avalos */ 1963182bcaa5SAzael Avalos if (value < 0 || value > 100) 1964182bcaa5SAzael Avalos return -EINVAL; 1965182bcaa5SAzael Avalos 1966182bcaa5SAzael Avalos if (value == 0) { 1967182bcaa5SAzael Avalos tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT; 1968182bcaa5SAzael Avalos status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF; 1969182bcaa5SAzael Avalos } else { 1970182bcaa5SAzael Avalos tmp = value << HCI_MISC_SHIFT; 1971182bcaa5SAzael Avalos status = tmp | SCI_USB_CHARGE_BAT_LVL_ON; 1972182bcaa5SAzael Avalos } 1973182bcaa5SAzael Avalos ret = toshiba_sleep_functions_status_set(toshiba, status); 1974182bcaa5SAzael Avalos if (ret < 0) 1975182bcaa5SAzael Avalos return ret; 1976182bcaa5SAzael Avalos 1977182bcaa5SAzael Avalos toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT; 1978182bcaa5SAzael Avalos 1979182bcaa5SAzael Avalos return count; 1980182bcaa5SAzael Avalos } 19810c3c0f10SAzael Avalos static DEVICE_ATTR_RW(sleep_functions_on_battery); 1982182bcaa5SAzael Avalos 19839d309848SAzael Avalos static ssize_t usb_rapid_charge_show(struct device *dev, 19849d309848SAzael Avalos struct device_attribute *attr, char *buf) 1985bb3fe01fSAzael Avalos { 1986bb3fe01fSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1987bb3fe01fSAzael Avalos u32 state; 1988bb3fe01fSAzael Avalos int ret; 1989bb3fe01fSAzael Avalos 1990bb3fe01fSAzael Avalos ret = toshiba_usb_rapid_charge_get(toshiba, &state); 1991bb3fe01fSAzael Avalos if (ret < 0) 1992bb3fe01fSAzael Avalos return ret; 1993bb3fe01fSAzael Avalos 1994bb3fe01fSAzael Avalos return sprintf(buf, "%d\n", state); 1995bb3fe01fSAzael Avalos } 1996bb3fe01fSAzael Avalos 19979d309848SAzael Avalos static ssize_t usb_rapid_charge_store(struct device *dev, 1998bb3fe01fSAzael Avalos struct device_attribute *attr, 1999bb3fe01fSAzael Avalos const char *buf, size_t count) 2000bb3fe01fSAzael Avalos { 2001bb3fe01fSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2002bb3fe01fSAzael Avalos int state; 2003bb3fe01fSAzael Avalos int ret; 2004bb3fe01fSAzael Avalos 2005bb3fe01fSAzael Avalos ret = kstrtoint(buf, 0, &state); 2006bb3fe01fSAzael Avalos if (ret) 2007bb3fe01fSAzael Avalos return ret; 2008bb3fe01fSAzael Avalos if (state != 0 && state != 1) 2009bb3fe01fSAzael Avalos return -EINVAL; 2010bb3fe01fSAzael Avalos 2011bb3fe01fSAzael Avalos ret = toshiba_usb_rapid_charge_set(toshiba, state); 2012bb3fe01fSAzael Avalos if (ret) 2013bb3fe01fSAzael Avalos return ret; 2014bb3fe01fSAzael Avalos 2015bb3fe01fSAzael Avalos return count; 2016bb3fe01fSAzael Avalos } 20170c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_rapid_charge); 2018bb3fe01fSAzael Avalos 20199d309848SAzael Avalos static ssize_t usb_sleep_music_show(struct device *dev, 20209d309848SAzael Avalos struct device_attribute *attr, char *buf) 2021172ce0a9SAzael Avalos { 2022172ce0a9SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2023172ce0a9SAzael Avalos u32 state; 2024172ce0a9SAzael Avalos int ret; 2025172ce0a9SAzael Avalos 2026172ce0a9SAzael Avalos ret = toshiba_usb_sleep_music_get(toshiba, &state); 2027172ce0a9SAzael Avalos if (ret < 0) 2028172ce0a9SAzael Avalos return ret; 2029172ce0a9SAzael Avalos 2030172ce0a9SAzael Avalos return sprintf(buf, "%d\n", state); 2031172ce0a9SAzael Avalos } 2032172ce0a9SAzael Avalos 20339d309848SAzael Avalos static ssize_t usb_sleep_music_store(struct device *dev, 2034172ce0a9SAzael Avalos struct device_attribute *attr, 2035172ce0a9SAzael Avalos const char *buf, size_t count) 2036172ce0a9SAzael Avalos { 2037172ce0a9SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2038172ce0a9SAzael Avalos int state; 2039172ce0a9SAzael Avalos int ret; 2040172ce0a9SAzael Avalos 2041172ce0a9SAzael Avalos ret = kstrtoint(buf, 0, &state); 2042172ce0a9SAzael Avalos if (ret) 2043172ce0a9SAzael Avalos return ret; 2044172ce0a9SAzael Avalos if (state != 0 && state != 1) 2045172ce0a9SAzael Avalos return -EINVAL; 2046172ce0a9SAzael Avalos 2047172ce0a9SAzael Avalos ret = toshiba_usb_sleep_music_set(toshiba, state); 2048172ce0a9SAzael Avalos if (ret) 2049172ce0a9SAzael Avalos return ret; 2050172ce0a9SAzael Avalos 2051172ce0a9SAzael Avalos return count; 2052172ce0a9SAzael Avalos } 20530c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_sleep_music); 2054172ce0a9SAzael Avalos 20559d309848SAzael Avalos static ssize_t kbd_function_keys_show(struct device *dev, 20569d309848SAzael Avalos struct device_attribute *attr, char *buf) 2057bae84195SAzael Avalos { 2058bae84195SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2059bae84195SAzael Avalos int mode; 2060bae84195SAzael Avalos int ret; 2061bae84195SAzael Avalos 2062bae84195SAzael Avalos ret = toshiba_function_keys_get(toshiba, &mode); 2063bae84195SAzael Avalos if (ret < 0) 2064bae84195SAzael Avalos return ret; 2065bae84195SAzael Avalos 2066bae84195SAzael Avalos return sprintf(buf, "%d\n", mode); 2067bae84195SAzael Avalos } 2068bae84195SAzael Avalos 20699d309848SAzael Avalos static ssize_t kbd_function_keys_store(struct device *dev, 2070bae84195SAzael Avalos struct device_attribute *attr, 2071bae84195SAzael Avalos const char *buf, size_t count) 2072bae84195SAzael Avalos { 2073bae84195SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2074bae84195SAzael Avalos int mode; 2075bae84195SAzael Avalos int ret; 2076bae84195SAzael Avalos 2077bae84195SAzael Avalos ret = kstrtoint(buf, 0, &mode); 2078bae84195SAzael Avalos if (ret) 2079bae84195SAzael Avalos return ret; 2080e0769fe6SDarren Hart /* 2081e0769fe6SDarren Hart * Check for the function keys mode where: 2082bae84195SAzael Avalos * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12}) 2083bae84195SAzael Avalos * 1 - Special functions (Opposite of the above setting) 2084bae84195SAzael Avalos */ 2085bae84195SAzael Avalos if (mode != 0 && mode != 1) 2086bae84195SAzael Avalos return -EINVAL; 2087bae84195SAzael Avalos 2088bae84195SAzael Avalos ret = toshiba_function_keys_set(toshiba, mode); 2089bae84195SAzael Avalos if (ret) 2090bae84195SAzael Avalos return ret; 2091bae84195SAzael Avalos 2092bae84195SAzael Avalos pr_info("Reboot for changes to KBD Function Keys to take effect"); 2093bae84195SAzael Avalos 2094bae84195SAzael Avalos return count; 2095bae84195SAzael Avalos } 20960c3c0f10SAzael Avalos static DEVICE_ATTR_RW(kbd_function_keys); 2097bae84195SAzael Avalos 20989d309848SAzael Avalos static ssize_t panel_power_on_show(struct device *dev, 20999d309848SAzael Avalos struct device_attribute *attr, char *buf) 210035d53ceaSAzael Avalos { 210135d53ceaSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 210235d53ceaSAzael Avalos u32 state; 210335d53ceaSAzael Avalos int ret; 210435d53ceaSAzael Avalos 210535d53ceaSAzael Avalos ret = toshiba_panel_power_on_get(toshiba, &state); 210635d53ceaSAzael Avalos if (ret < 0) 210735d53ceaSAzael Avalos return ret; 210835d53ceaSAzael Avalos 210935d53ceaSAzael Avalos return sprintf(buf, "%d\n", state); 211035d53ceaSAzael Avalos } 211135d53ceaSAzael Avalos 21129d309848SAzael Avalos static ssize_t panel_power_on_store(struct device *dev, 211335d53ceaSAzael Avalos struct device_attribute *attr, 211435d53ceaSAzael Avalos const char *buf, size_t count) 211535d53ceaSAzael Avalos { 211635d53ceaSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 211735d53ceaSAzael Avalos int state; 211835d53ceaSAzael Avalos int ret; 211935d53ceaSAzael Avalos 212035d53ceaSAzael Avalos ret = kstrtoint(buf, 0, &state); 212135d53ceaSAzael Avalos if (ret) 212235d53ceaSAzael Avalos return ret; 212335d53ceaSAzael Avalos if (state != 0 && state != 1) 212435d53ceaSAzael Avalos return -EINVAL; 212535d53ceaSAzael Avalos 212635d53ceaSAzael Avalos ret = toshiba_panel_power_on_set(toshiba, state); 212735d53ceaSAzael Avalos if (ret) 212835d53ceaSAzael Avalos return ret; 212935d53ceaSAzael Avalos 213035d53ceaSAzael Avalos pr_info("Reboot for changes to Panel Power ON to take effect"); 213135d53ceaSAzael Avalos 213235d53ceaSAzael Avalos return count; 213335d53ceaSAzael Avalos } 21340c3c0f10SAzael Avalos static DEVICE_ATTR_RW(panel_power_on); 213535d53ceaSAzael Avalos 21369d309848SAzael Avalos static ssize_t usb_three_show(struct device *dev, 21379d309848SAzael Avalos struct device_attribute *attr, char *buf) 213817fe4b3dSAzael Avalos { 213917fe4b3dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 214017fe4b3dSAzael Avalos u32 state; 214117fe4b3dSAzael Avalos int ret; 214217fe4b3dSAzael Avalos 214317fe4b3dSAzael Avalos ret = toshiba_usb_three_get(toshiba, &state); 214417fe4b3dSAzael Avalos if (ret < 0) 214517fe4b3dSAzael Avalos return ret; 214617fe4b3dSAzael Avalos 214717fe4b3dSAzael Avalos return sprintf(buf, "%d\n", state); 214817fe4b3dSAzael Avalos } 214917fe4b3dSAzael Avalos 21509d309848SAzael Avalos static ssize_t usb_three_store(struct device *dev, 215117fe4b3dSAzael Avalos struct device_attribute *attr, 215217fe4b3dSAzael Avalos const char *buf, size_t count) 215317fe4b3dSAzael Avalos { 215417fe4b3dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 215517fe4b3dSAzael Avalos int state; 215617fe4b3dSAzael Avalos int ret; 215717fe4b3dSAzael Avalos 215817fe4b3dSAzael Avalos ret = kstrtoint(buf, 0, &state); 215917fe4b3dSAzael Avalos if (ret) 216017fe4b3dSAzael Avalos return ret; 2161e0769fe6SDarren Hart /* 2162e0769fe6SDarren Hart * Check for USB 3 mode where: 216317fe4b3dSAzael Avalos * 0 - Disabled (Acts like a USB 2 port, saving power) 216417fe4b3dSAzael Avalos * 1 - Enabled 216517fe4b3dSAzael Avalos */ 216617fe4b3dSAzael Avalos if (state != 0 && state != 1) 216717fe4b3dSAzael Avalos return -EINVAL; 216817fe4b3dSAzael Avalos 216917fe4b3dSAzael Avalos ret = toshiba_usb_three_set(toshiba, state); 217017fe4b3dSAzael Avalos if (ret) 217117fe4b3dSAzael Avalos return ret; 217217fe4b3dSAzael Avalos 217317fe4b3dSAzael Avalos pr_info("Reboot for changes to USB 3 to take effect"); 217417fe4b3dSAzael Avalos 217517fe4b3dSAzael Avalos return count; 217617fe4b3dSAzael Avalos } 21770c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_three); 21789bd1213bSAzael Avalos 21799bd1213bSAzael Avalos static struct attribute *toshiba_attributes[] = { 21809bd1213bSAzael Avalos &dev_attr_version.attr, 21819bd1213bSAzael Avalos &dev_attr_fan.attr, 21829bd1213bSAzael Avalos &dev_attr_kbd_backlight_mode.attr, 21839bd1213bSAzael Avalos &dev_attr_kbd_type.attr, 21849bd1213bSAzael Avalos &dev_attr_available_kbd_modes.attr, 21859bd1213bSAzael Avalos &dev_attr_kbd_backlight_timeout.attr, 21869bd1213bSAzael Avalos &dev_attr_touchpad.attr, 21879bd1213bSAzael Avalos &dev_attr_position.attr, 21889bd1213bSAzael Avalos &dev_attr_usb_sleep_charge.attr, 21899bd1213bSAzael Avalos &dev_attr_sleep_functions_on_battery.attr, 21909bd1213bSAzael Avalos &dev_attr_usb_rapid_charge.attr, 21919bd1213bSAzael Avalos &dev_attr_usb_sleep_music.attr, 21929bd1213bSAzael Avalos &dev_attr_kbd_function_keys.attr, 21939bd1213bSAzael Avalos &dev_attr_panel_power_on.attr, 21949bd1213bSAzael Avalos &dev_attr_usb_three.attr, 21959bd1213bSAzael Avalos NULL, 21969bd1213bSAzael Avalos }; 21979bd1213bSAzael Avalos 2198360f0f39SAzael Avalos static umode_t toshiba_sysfs_is_visible(struct kobject *kobj, 2199360f0f39SAzael Avalos struct attribute *attr, int idx) 2200360f0f39SAzael Avalos { 2201360f0f39SAzael Avalos struct device *dev = container_of(kobj, struct device, kobj); 2202360f0f39SAzael Avalos struct toshiba_acpi_dev *drv = dev_get_drvdata(dev); 2203360f0f39SAzael Avalos bool exists = true; 2204360f0f39SAzael Avalos 220594477d4cSAzael Avalos if (attr == &dev_attr_fan.attr) 220694477d4cSAzael Avalos exists = (drv->fan_supported) ? true : false; 220794477d4cSAzael Avalos else if (attr == &dev_attr_kbd_backlight_mode.attr) 2208360f0f39SAzael Avalos exists = (drv->kbd_illum_supported) ? true : false; 2209360f0f39SAzael Avalos else if (attr == &dev_attr_kbd_backlight_timeout.attr) 2210360f0f39SAzael Avalos exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false; 22119d8658acSAzael Avalos else if (attr == &dev_attr_touchpad.attr) 22129d8658acSAzael Avalos exists = (drv->touchpad_supported) ? true : false; 22135a2813e9SAzael Avalos else if (attr == &dev_attr_position.attr) 22145a2813e9SAzael Avalos exists = (drv->accelerometer_supported) ? true : false; 2215e26ffe51SAzael Avalos else if (attr == &dev_attr_usb_sleep_charge.attr) 2216e26ffe51SAzael Avalos exists = (drv->usb_sleep_charge_supported) ? true : false; 2217182bcaa5SAzael Avalos else if (attr == &dev_attr_sleep_functions_on_battery.attr) 2218182bcaa5SAzael Avalos exists = (drv->usb_sleep_charge_supported) ? true : false; 2219bb3fe01fSAzael Avalos else if (attr == &dev_attr_usb_rapid_charge.attr) 2220bb3fe01fSAzael Avalos exists = (drv->usb_rapid_charge_supported) ? true : false; 2221172ce0a9SAzael Avalos else if (attr == &dev_attr_usb_sleep_music.attr) 2222172ce0a9SAzael Avalos exists = (drv->usb_sleep_music_supported) ? true : false; 2223bae84195SAzael Avalos else if (attr == &dev_attr_kbd_function_keys.attr) 2224bae84195SAzael Avalos exists = (drv->kbd_function_keys_supported) ? true : false; 222535d53ceaSAzael Avalos else if (attr == &dev_attr_panel_power_on.attr) 222635d53ceaSAzael Avalos exists = (drv->panel_power_on_supported) ? true : false; 222717fe4b3dSAzael Avalos else if (attr == &dev_attr_usb_three.attr) 222817fe4b3dSAzael Avalos exists = (drv->usb_three_supported) ? true : false; 2229360f0f39SAzael Avalos 2230360f0f39SAzael Avalos return exists ? attr->mode : 0; 2231360f0f39SAzael Avalos } 2232360f0f39SAzael Avalos 22339bd1213bSAzael Avalos static struct attribute_group toshiba_attr_group = { 22349bd1213bSAzael Avalos .is_visible = toshiba_sysfs_is_visible, 22359bd1213bSAzael Avalos .attrs = toshiba_attributes, 22369bd1213bSAzael Avalos }; 22379bd1213bSAzael Avalos 22381f28f290SAzael Avalos /* 2239fc5462f8SAzael Avalos * Misc device 2240fc5462f8SAzael Avalos */ 2241fc5462f8SAzael Avalos static int toshiba_acpi_smm_bridge(SMMRegisters *regs) 2242fc5462f8SAzael Avalos { 2243fc5462f8SAzael Avalos u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx, 2244fc5462f8SAzael Avalos regs->edx, regs->esi, regs->edi }; 2245fc5462f8SAzael Avalos u32 out[TCI_WORDS]; 2246fc5462f8SAzael Avalos acpi_status status; 2247fc5462f8SAzael Avalos 2248fc5462f8SAzael Avalos status = tci_raw(toshiba_acpi, in, out); 2249fc5462f8SAzael Avalos if (ACPI_FAILURE(status)) { 2250fc5462f8SAzael Avalos pr_err("ACPI call to query SMM registers failed\n"); 2251fc5462f8SAzael Avalos return -EIO; 2252fc5462f8SAzael Avalos } 2253fc5462f8SAzael Avalos 2254fc5462f8SAzael Avalos /* Fillout the SMM struct with the TCI call results */ 2255fc5462f8SAzael Avalos regs->eax = out[0]; 2256fc5462f8SAzael Avalos regs->ebx = out[1]; 2257fc5462f8SAzael Avalos regs->ecx = out[2]; 2258fc5462f8SAzael Avalos regs->edx = out[3]; 2259fc5462f8SAzael Avalos regs->esi = out[4]; 2260fc5462f8SAzael Avalos regs->edi = out[5]; 2261fc5462f8SAzael Avalos 2262fc5462f8SAzael Avalos return 0; 2263fc5462f8SAzael Avalos } 2264fc5462f8SAzael Avalos 2265fc5462f8SAzael Avalos static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd, 2266fc5462f8SAzael Avalos unsigned long arg) 2267fc5462f8SAzael Avalos { 2268fc5462f8SAzael Avalos SMMRegisters __user *argp = (SMMRegisters __user *)arg; 2269fc5462f8SAzael Avalos SMMRegisters regs; 2270fc5462f8SAzael Avalos int ret; 2271fc5462f8SAzael Avalos 2272fc5462f8SAzael Avalos if (!argp) 2273fc5462f8SAzael Avalos return -EINVAL; 2274fc5462f8SAzael Avalos 2275fc5462f8SAzael Avalos switch (cmd) { 2276fc5462f8SAzael Avalos case TOSH_SMM: 2277fc5462f8SAzael Avalos if (copy_from_user(®s, argp, sizeof(SMMRegisters))) 2278fc5462f8SAzael Avalos return -EFAULT; 2279fc5462f8SAzael Avalos ret = toshiba_acpi_smm_bridge(®s); 2280fc5462f8SAzael Avalos if (ret) 2281fc5462f8SAzael Avalos return ret; 2282fc5462f8SAzael Avalos if (copy_to_user(argp, ®s, sizeof(SMMRegisters))) 2283fc5462f8SAzael Avalos return -EFAULT; 2284fc5462f8SAzael Avalos break; 2285fc5462f8SAzael Avalos case TOSHIBA_ACPI_SCI: 2286fc5462f8SAzael Avalos if (copy_from_user(®s, argp, sizeof(SMMRegisters))) 2287fc5462f8SAzael Avalos return -EFAULT; 2288fc5462f8SAzael Avalos /* Ensure we are being called with a SCI_{GET, SET} register */ 2289fc5462f8SAzael Avalos if (regs.eax != SCI_GET && regs.eax != SCI_SET) 2290fc5462f8SAzael Avalos return -EINVAL; 2291fc5462f8SAzael Avalos if (!sci_open(toshiba_acpi)) 2292fc5462f8SAzael Avalos return -EIO; 2293fc5462f8SAzael Avalos ret = toshiba_acpi_smm_bridge(®s); 2294fc5462f8SAzael Avalos sci_close(toshiba_acpi); 2295fc5462f8SAzael Avalos if (ret) 2296fc5462f8SAzael Avalos return ret; 2297fc5462f8SAzael Avalos if (copy_to_user(argp, ®s, sizeof(SMMRegisters))) 2298fc5462f8SAzael Avalos return -EFAULT; 2299fc5462f8SAzael Avalos break; 2300fc5462f8SAzael Avalos default: 2301fc5462f8SAzael Avalos return -EINVAL; 2302fc5462f8SAzael Avalos } 2303fc5462f8SAzael Avalos 2304fc5462f8SAzael Avalos return 0; 2305fc5462f8SAzael Avalos } 2306fc5462f8SAzael Avalos 2307fc5462f8SAzael Avalos static const struct file_operations toshiba_acpi_fops = { 2308fc5462f8SAzael Avalos .owner = THIS_MODULE, 2309fc5462f8SAzael Avalos .unlocked_ioctl = toshiba_acpi_ioctl, 2310fc5462f8SAzael Avalos .llseek = noop_llseek, 2311fc5462f8SAzael Avalos }; 2312fc5462f8SAzael Avalos 2313fc5462f8SAzael Avalos /* 23141f28f290SAzael Avalos * Hotkeys 23151f28f290SAzael Avalos */ 23161f28f290SAzael Avalos static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev) 23171f28f290SAzael Avalos { 23181f28f290SAzael Avalos acpi_status status; 23191f28f290SAzael Avalos u32 result; 23201f28f290SAzael Avalos 23211f28f290SAzael Avalos status = acpi_evaluate_object(dev->acpi_dev->handle, 23221f28f290SAzael Avalos "ENAB", NULL, NULL); 23231f28f290SAzael Avalos if (ACPI_FAILURE(status)) 23241f28f290SAzael Avalos return -ENODEV; 23251f28f290SAzael Avalos 2326d37782bdSAzael Avalos result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE); 23271f28f290SAzael Avalos if (result == TOS_FAILURE) 23281f28f290SAzael Avalos return -EIO; 23291f28f290SAzael Avalos else if (result == TOS_NOT_SUPPORTED) 23301f28f290SAzael Avalos return -ENODEV; 23311f28f290SAzael Avalos 23321f28f290SAzael Avalos return 0; 23331f28f290SAzael Avalos } 23341f28f290SAzael Avalos 2335fb42d1f4SAzael Avalos static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev) 2336fb42d1f4SAzael Avalos { 2337fb42d1f4SAzael Avalos u32 result; 2338fb42d1f4SAzael Avalos 2339fb42d1f4SAzael Avalos /* 2340fb42d1f4SAzael Avalos * Re-activate the hotkeys, but this time, we are using the 2341fb42d1f4SAzael Avalos * "Special Functions" mode. 2342fb42d1f4SAzael Avalos */ 2343d37782bdSAzael Avalos result = hci_write(dev, HCI_HOTKEY_EVENT, 2344fb42d1f4SAzael Avalos HCI_HOTKEY_SPECIAL_FUNCTIONS); 2345fb42d1f4SAzael Avalos if (result != TOS_SUCCESS) 2346fb42d1f4SAzael Avalos pr_err("Could not enable the Special Function mode\n"); 2347fb42d1f4SAzael Avalos } 2348fb42d1f4SAzael Avalos 234929cd293fSSeth Forshee static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str, 235029cd293fSSeth Forshee struct serio *port) 235129cd293fSSeth Forshee { 235298280374SGiedrius Statkevičius if (str & I8042_STR_AUXDATA) 235329cd293fSSeth Forshee return false; 235429cd293fSSeth Forshee 235529cd293fSSeth Forshee if (unlikely(data == 0xe0)) 235629cd293fSSeth Forshee return false; 235729cd293fSSeth Forshee 235829cd293fSSeth Forshee if ((data & 0x7f) == TOS1900_FN_SCAN) { 235929cd293fSSeth Forshee schedule_work(&toshiba_acpi->hotkey_work); 236029cd293fSSeth Forshee return true; 236129cd293fSSeth Forshee } 236229cd293fSSeth Forshee 236329cd293fSSeth Forshee return false; 236429cd293fSSeth Forshee } 236529cd293fSSeth Forshee 236629cd293fSSeth Forshee static void toshiba_acpi_hotkey_work(struct work_struct *work) 236729cd293fSSeth Forshee { 236829cd293fSSeth Forshee acpi_handle ec_handle = ec_get_handle(); 236929cd293fSSeth Forshee acpi_status status; 237029cd293fSSeth Forshee 237129cd293fSSeth Forshee if (!ec_handle) 237229cd293fSSeth Forshee return; 237329cd293fSSeth Forshee 237429cd293fSSeth Forshee status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL); 237529cd293fSSeth Forshee if (ACPI_FAILURE(status)) 237629cd293fSSeth Forshee pr_err("ACPI NTFY method execution failed\n"); 237729cd293fSSeth Forshee } 237829cd293fSSeth Forshee 237929cd293fSSeth Forshee /* 238029cd293fSSeth Forshee * Returns hotkey scancode, or < 0 on failure. 238129cd293fSSeth Forshee */ 238229cd293fSSeth Forshee static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev) 238329cd293fSSeth Forshee { 238474facaf7SZhang Rui unsigned long long value; 238529cd293fSSeth Forshee acpi_status status; 238629cd293fSSeth Forshee 238774facaf7SZhang Rui status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO", 238874facaf7SZhang Rui NULL, &value); 238974facaf7SZhang Rui if (ACPI_FAILURE(status)) { 239029cd293fSSeth Forshee pr_err("ACPI INFO method execution failed\n"); 239129cd293fSSeth Forshee return -EIO; 239229cd293fSSeth Forshee } 239329cd293fSSeth Forshee 239474facaf7SZhang Rui return value; 239529cd293fSSeth Forshee } 239629cd293fSSeth Forshee 239729cd293fSSeth Forshee static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev, 239829cd293fSSeth Forshee int scancode) 239929cd293fSSeth Forshee { 240029cd293fSSeth Forshee if (scancode == 0x100) 240129cd293fSSeth Forshee return; 240229cd293fSSeth Forshee 2403e0769fe6SDarren Hart /* Act on key press; ignore key release */ 240429cd293fSSeth Forshee if (scancode & 0x80) 240529cd293fSSeth Forshee return; 240629cd293fSSeth Forshee 240729cd293fSSeth Forshee if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true)) 240829cd293fSSeth Forshee pr_info("Unknown key %x\n", scancode); 240929cd293fSSeth Forshee } 241029cd293fSSeth Forshee 241171454d78SAzael Avalos static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev) 241271454d78SAzael Avalos { 241371454d78SAzael Avalos if (dev->info_supported) { 24147deef550SAzael Avalos int scancode = toshiba_acpi_query_hotkey(dev); 24157deef550SAzael Avalos 24167deef550SAzael Avalos if (scancode < 0) { 241771454d78SAzael Avalos pr_err("Failed to query hotkey event\n"); 24187deef550SAzael Avalos } else if (scancode != 0) { 241971454d78SAzael Avalos toshiba_acpi_report_hotkey(dev, scancode); 24207deef550SAzael Avalos dev->key_event_valid = 1; 24217deef550SAzael Avalos dev->last_key_event = scancode; 24227deef550SAzael Avalos } 242371454d78SAzael Avalos } else if (dev->system_event_supported) { 24247deef550SAzael Avalos u32 result; 24257deef550SAzael Avalos u32 value; 24267deef550SAzael Avalos int retries = 3; 24277deef550SAzael Avalos 242871454d78SAzael Avalos do { 24297deef550SAzael Avalos result = hci_read(dev, HCI_SYSTEM_EVENT, &value); 24307deef550SAzael Avalos switch (result) { 243171454d78SAzael Avalos case TOS_SUCCESS: 243271454d78SAzael Avalos toshiba_acpi_report_hotkey(dev, (int)value); 24337deef550SAzael Avalos dev->key_event_valid = 1; 24347deef550SAzael Avalos dev->last_key_event = value; 243571454d78SAzael Avalos break; 243671454d78SAzael Avalos case TOS_NOT_SUPPORTED: 243771454d78SAzael Avalos /* 243871454d78SAzael Avalos * This is a workaround for an unresolved 243971454d78SAzael Avalos * issue on some machines where system events 244071454d78SAzael Avalos * sporadically become disabled. 244171454d78SAzael Avalos */ 24427deef550SAzael Avalos result = hci_write(dev, HCI_SYSTEM_EVENT, 1); 24437deef550SAzael Avalos if (result == TOS_SUCCESS) 244471454d78SAzael Avalos pr_notice("Re-enabled hotkeys\n"); 2445e0769fe6SDarren Hart /* Fall through */ 244671454d78SAzael Avalos default: 244771454d78SAzael Avalos retries--; 244871454d78SAzael Avalos break; 244971454d78SAzael Avalos } 24507deef550SAzael Avalos } while (retries && result != TOS_FIFO_EMPTY); 245171454d78SAzael Avalos } 245271454d78SAzael Avalos } 245371454d78SAzael Avalos 2454b859f159SGreg Kroah-Hartman static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) 24556335e4d5SMatthew Garrett { 2456fe808bfbSTakashi Iwai const struct key_entry *keymap = toshiba_acpi_keymap; 2457a2b3471bSAzael Avalos acpi_handle ec_handle; 2458a2b3471bSAzael Avalos u32 events_type; 2459a2b3471bSAzael Avalos u32 hci_result; 2460a2b3471bSAzael Avalos int error; 2461a2b3471bSAzael Avalos 2462a88bc06eSAzael Avalos if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) { 2463a88bc06eSAzael Avalos pr_info("WMI event detected, hotkeys will not be monitored\n"); 2464a88bc06eSAzael Avalos return 0; 2465a88bc06eSAzael Avalos } 2466a88bc06eSAzael Avalos 2467a2b3471bSAzael Avalos error = toshiba_acpi_enable_hotkeys(dev); 2468a2b3471bSAzael Avalos if (error) 2469a2b3471bSAzael Avalos return error; 2470a2b3471bSAzael Avalos 2471a2b3471bSAzael Avalos error = toshiba_hotkey_event_type_get(dev, &events_type); 2472a2b3471bSAzael Avalos if (error) { 2473a2b3471bSAzael Avalos pr_err("Unable to query Hotkey Event Type\n"); 2474a2b3471bSAzael Avalos return error; 2475a2b3471bSAzael Avalos } 2476a2b3471bSAzael Avalos dev->hotkey_event_type = events_type; 2477135740deSSeth Forshee 2478135740deSSeth Forshee dev->hotkey_dev = input_allocate_device(); 2479b222cca6SJoe Perches if (!dev->hotkey_dev) 2480135740deSSeth Forshee return -ENOMEM; 2481135740deSSeth Forshee 2482135740deSSeth Forshee dev->hotkey_dev->name = "Toshiba input device"; 24836e02cc7eSSeth Forshee dev->hotkey_dev->phys = "toshiba_acpi/input0"; 2484135740deSSeth Forshee dev->hotkey_dev->id.bustype = BUS_HOST; 2485135740deSSeth Forshee 2486a2b3471bSAzael Avalos if (events_type == HCI_SYSTEM_TYPE1 || 2487a2b3471bSAzael Avalos !dev->kbd_function_keys_supported) 2488a2b3471bSAzael Avalos keymap = toshiba_acpi_keymap; 2489a2b3471bSAzael Avalos else if (events_type == HCI_SYSTEM_TYPE2 || 2490a2b3471bSAzael Avalos dev->kbd_function_keys_supported) 2491fe808bfbSTakashi Iwai keymap = toshiba_acpi_alt_keymap; 2492a2b3471bSAzael Avalos else 2493a2b3471bSAzael Avalos pr_info("Unknown event type received %x\n", events_type); 2494fe808bfbSTakashi Iwai error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL); 2495135740deSSeth Forshee if (error) 2496135740deSSeth Forshee goto err_free_dev; 2497135740deSSeth Forshee 249829cd293fSSeth Forshee /* 249929cd293fSSeth Forshee * For some machines the SCI responsible for providing hotkey 250029cd293fSSeth Forshee * notification doesn't fire. We can trigger the notification 250129cd293fSSeth Forshee * whenever the Fn key is pressed using the NTFY method, if 250229cd293fSSeth Forshee * supported, so if it's present set up an i8042 key filter 250329cd293fSSeth Forshee * for this purpose. 250429cd293fSSeth Forshee */ 250529cd293fSSeth Forshee ec_handle = ec_get_handle(); 2506e2e19606SZhang Rui if (ec_handle && acpi_has_method(ec_handle, "NTFY")) { 250729cd293fSSeth Forshee INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work); 250829cd293fSSeth Forshee 250929cd293fSSeth Forshee error = i8042_install_filter(toshiba_acpi_i8042_filter); 251029cd293fSSeth Forshee if (error) { 251129cd293fSSeth Forshee pr_err("Error installing key filter\n"); 251229cd293fSSeth Forshee goto err_free_keymap; 251329cd293fSSeth Forshee } 251429cd293fSSeth Forshee 251529cd293fSSeth Forshee dev->ntfy_supported = 1; 251629cd293fSSeth Forshee } 251729cd293fSSeth Forshee 251829cd293fSSeth Forshee /* 251929cd293fSSeth Forshee * Determine hotkey query interface. Prefer using the INFO 252029cd293fSSeth Forshee * method when it is available. 252129cd293fSSeth Forshee */ 2522e2e19606SZhang Rui if (acpi_has_method(dev->acpi_dev->handle, "INFO")) 252329cd293fSSeth Forshee dev->info_supported = 1; 2524e2e19606SZhang Rui else { 2525d37782bdSAzael Avalos hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1); 25261864bbc2SAzael Avalos if (hci_result == TOS_SUCCESS) 252729cd293fSSeth Forshee dev->system_event_supported = 1; 252829cd293fSSeth Forshee } 252929cd293fSSeth Forshee 253029cd293fSSeth Forshee if (!dev->info_supported && !dev->system_event_supported) { 253129cd293fSSeth Forshee pr_warn("No hotkey query interface found\n"); 253229cd293fSSeth Forshee goto err_remove_filter; 253329cd293fSSeth Forshee } 253429cd293fSSeth Forshee 2535135740deSSeth Forshee error = input_register_device(dev->hotkey_dev); 2536135740deSSeth Forshee if (error) { 2537135740deSSeth Forshee pr_info("Unable to register input device\n"); 253829cd293fSSeth Forshee goto err_remove_filter; 2539135740deSSeth Forshee } 2540135740deSSeth Forshee 2541135740deSSeth Forshee return 0; 2542135740deSSeth Forshee 254329cd293fSSeth Forshee err_remove_filter: 254429cd293fSSeth Forshee if (dev->ntfy_supported) 254529cd293fSSeth Forshee i8042_remove_filter(toshiba_acpi_i8042_filter); 2546135740deSSeth Forshee err_free_keymap: 2547135740deSSeth Forshee sparse_keymap_free(dev->hotkey_dev); 2548135740deSSeth Forshee err_free_dev: 2549135740deSSeth Forshee input_free_device(dev->hotkey_dev); 2550135740deSSeth Forshee dev->hotkey_dev = NULL; 2551135740deSSeth Forshee return error; 2552135740deSSeth Forshee } 2553135740deSSeth Forshee 2554b859f159SGreg Kroah-Hartman static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev) 255562cce752SSeth Forshee { 255662cce752SSeth Forshee struct backlight_properties props; 255762cce752SSeth Forshee int brightness; 255862cce752SSeth Forshee int ret; 255962cce752SSeth Forshee 256062cce752SSeth Forshee /* 256162cce752SSeth Forshee * Some machines don't support the backlight methods at all, and 256262cce752SSeth Forshee * others support it read-only. Either of these is pretty useless, 256362cce752SSeth Forshee * so only register the backlight device if the backlight method 256462cce752SSeth Forshee * supports both reads and writes. 256562cce752SSeth Forshee */ 256662cce752SSeth Forshee brightness = __get_lcd_brightness(dev); 256762cce752SSeth Forshee if (brightness < 0) 256862cce752SSeth Forshee return 0; 256962cce752SSeth Forshee ret = set_lcd_brightness(dev, brightness); 257062cce752SSeth Forshee if (ret) { 257162cce752SSeth Forshee pr_debug("Backlight method is read-only, disabling backlight support\n"); 257262cce752SSeth Forshee return 0; 257362cce752SSeth Forshee } 257462cce752SSeth Forshee 2575358d6a2cSHans de Goede /* 2576358d6a2cSHans de Goede * Tell acpi-video-detect code to prefer vendor backlight on all 2577358d6a2cSHans de Goede * systems with transflective backlight and on dmi matched systems. 2578358d6a2cSHans de Goede */ 2579358d6a2cSHans de Goede if (dev->tr_backlight_supported || 2580358d6a2cSHans de Goede dmi_check_system(toshiba_vendor_backlight_dmi)) 2581234b7cf8SHans de Goede acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); 2582358d6a2cSHans de Goede 2583234b7cf8SHans de Goede if (acpi_video_get_backlight_type() != acpi_backlight_vendor) 2584358d6a2cSHans de Goede return 0; 2585358d6a2cSHans de Goede 258653039f22SMatthew Garrett memset(&props, 0, sizeof(props)); 258762cce752SSeth Forshee props.type = BACKLIGHT_PLATFORM; 258862cce752SSeth Forshee props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; 258962cce752SSeth Forshee 2590e0769fe6SDarren Hart /* Adding an extra level and having 0 change to transflective mode */ 2591121b7b0dSAkio Idehara if (dev->tr_backlight_supported) 2592121b7b0dSAkio Idehara props.max_brightness++; 2593121b7b0dSAkio Idehara 259462cce752SSeth Forshee dev->backlight_dev = backlight_device_register("toshiba", 259562cce752SSeth Forshee &dev->acpi_dev->dev, 259662cce752SSeth Forshee dev, 259762cce752SSeth Forshee &toshiba_backlight_data, 259862cce752SSeth Forshee &props); 259962cce752SSeth Forshee if (IS_ERR(dev->backlight_dev)) { 260062cce752SSeth Forshee ret = PTR_ERR(dev->backlight_dev); 260162cce752SSeth Forshee pr_err("Could not register toshiba backlight device\n"); 260262cce752SSeth Forshee dev->backlight_dev = NULL; 260362cce752SSeth Forshee return ret; 260462cce752SSeth Forshee } 260562cce752SSeth Forshee 260662cce752SSeth Forshee dev->backlight_dev->props.brightness = brightness; 260762cce752SSeth Forshee return 0; 260862cce752SSeth Forshee } 260962cce752SSeth Forshee 261051fac838SRafael J. Wysocki static int toshiba_acpi_remove(struct acpi_device *acpi_dev) 2611135740deSSeth Forshee { 2612135740deSSeth Forshee struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); 2613135740deSSeth Forshee 2614fc5462f8SAzael Avalos misc_deregister(&dev->miscdev); 2615fc5462f8SAzael Avalos 261636d03f93SSeth Forshee remove_toshiba_proc_entries(dev); 2617135740deSSeth Forshee 2618360f0f39SAzael Avalos if (dev->sysfs_created) 2619360f0f39SAzael Avalos sysfs_remove_group(&dev->acpi_dev->dev.kobj, 2620360f0f39SAzael Avalos &toshiba_attr_group); 2621360f0f39SAzael Avalos 262229cd293fSSeth Forshee if (dev->ntfy_supported) { 262329cd293fSSeth Forshee i8042_remove_filter(toshiba_acpi_i8042_filter); 262429cd293fSSeth Forshee cancel_work_sync(&dev->hotkey_work); 262529cd293fSSeth Forshee } 262629cd293fSSeth Forshee 2627135740deSSeth Forshee if (dev->hotkey_dev) { 2628135740deSSeth Forshee input_unregister_device(dev->hotkey_dev); 2629135740deSSeth Forshee sparse_keymap_free(dev->hotkey_dev); 2630135740deSSeth Forshee } 2631135740deSSeth Forshee 2632135740deSSeth Forshee backlight_device_unregister(dev->backlight_dev); 2633135740deSSeth Forshee 263436d03f93SSeth Forshee if (dev->illumination_supported) 2635135740deSSeth Forshee led_classdev_unregister(&dev->led_dev); 2636135740deSSeth Forshee 2637360f0f39SAzael Avalos if (dev->kbd_led_registered) 2638360f0f39SAzael Avalos led_classdev_unregister(&dev->kbd_led); 2639360f0f39SAzael Avalos 2640def6c4e2SAzael Avalos if (dev->eco_supported) 2641def6c4e2SAzael Avalos led_classdev_unregister(&dev->eco_led); 2642def6c4e2SAzael Avalos 264329cd293fSSeth Forshee if (toshiba_acpi) 264429cd293fSSeth Forshee toshiba_acpi = NULL; 264529cd293fSSeth Forshee 2646135740deSSeth Forshee kfree(dev); 2647135740deSSeth Forshee 2648135740deSSeth Forshee return 0; 2649135740deSSeth Forshee } 2650135740deSSeth Forshee 2651b859f159SGreg Kroah-Hartman static const char *find_hci_method(acpi_handle handle) 2652a540d6b5SSeth Forshee { 2653e2e19606SZhang Rui if (acpi_has_method(handle, "GHCI")) 2654a540d6b5SSeth Forshee return "GHCI"; 2655a540d6b5SSeth Forshee 2656e2e19606SZhang Rui if (acpi_has_method(handle, "SPFC")) 2657a540d6b5SSeth Forshee return "SPFC"; 2658a540d6b5SSeth Forshee 2659a540d6b5SSeth Forshee return NULL; 2660a540d6b5SSeth Forshee } 2661a540d6b5SSeth Forshee 2662b859f159SGreg Kroah-Hartman static int toshiba_acpi_add(struct acpi_device *acpi_dev) 2663135740deSSeth Forshee { 2664135740deSSeth Forshee struct toshiba_acpi_dev *dev; 2665a540d6b5SSeth Forshee const char *hci_method; 2666fb42d1f4SAzael Avalos u32 special_functions; 266736d03f93SSeth Forshee u32 dummy; 2668135740deSSeth Forshee int ret = 0; 2669135740deSSeth Forshee 267029cd293fSSeth Forshee if (toshiba_acpi) 267129cd293fSSeth Forshee return -EBUSY; 267229cd293fSSeth Forshee 2673135740deSSeth Forshee pr_info("Toshiba Laptop ACPI Extras version %s\n", 2674135740deSSeth Forshee TOSHIBA_ACPI_VERSION); 2675135740deSSeth Forshee 2676a540d6b5SSeth Forshee hci_method = find_hci_method(acpi_dev->handle); 2677a540d6b5SSeth Forshee if (!hci_method) { 2678a540d6b5SSeth Forshee pr_err("HCI interface not found\n"); 26796e02cc7eSSeth Forshee return -ENODEV; 2680a540d6b5SSeth Forshee } 26816e02cc7eSSeth Forshee 2682135740deSSeth Forshee dev = kzalloc(sizeof(*dev), GFP_KERNEL); 2683135740deSSeth Forshee if (!dev) 2684135740deSSeth Forshee return -ENOMEM; 2685135740deSSeth Forshee dev->acpi_dev = acpi_dev; 2686a540d6b5SSeth Forshee dev->method_hci = hci_method; 2687fc5462f8SAzael Avalos dev->miscdev.minor = MISC_DYNAMIC_MINOR; 2688fc5462f8SAzael Avalos dev->miscdev.name = "toshiba_acpi"; 2689fc5462f8SAzael Avalos dev->miscdev.fops = &toshiba_acpi_fops; 2690fc5462f8SAzael Avalos 2691fc5462f8SAzael Avalos ret = misc_register(&dev->miscdev); 2692fc5462f8SAzael Avalos if (ret) { 2693fc5462f8SAzael Avalos pr_err("Failed to register miscdevice\n"); 2694fc5462f8SAzael Avalos kfree(dev); 2695fc5462f8SAzael Avalos return ret; 2696fc5462f8SAzael Avalos } 2697fc5462f8SAzael Avalos 2698135740deSSeth Forshee acpi_dev->driver_data = dev; 2699360f0f39SAzael Avalos dev_set_drvdata(&acpi_dev->dev, dev); 2700135740deSSeth Forshee 2701a2b3471bSAzael Avalos /* Query the BIOS for supported features */ 2702a2b3471bSAzael Avalos 2703a2b3471bSAzael Avalos /* 2704a2b3471bSAzael Avalos * The "Special Functions" are always supported by the laptops 2705a2b3471bSAzael Avalos * with the new keyboard layout, query for its presence to help 2706a2b3471bSAzael Avalos * determine the keymap layout to use. 2707a2b3471bSAzael Avalos */ 2708fb42d1f4SAzael Avalos ret = toshiba_function_keys_get(dev, &special_functions); 2709a2b3471bSAzael Avalos dev->kbd_function_keys_supported = !ret; 2710a2b3471bSAzael Avalos 27116e02cc7eSSeth Forshee if (toshiba_acpi_setup_keyboard(dev)) 2712135740deSSeth Forshee pr_info("Unable to activate hotkeys\n"); 2713135740deSSeth Forshee 2714*695f6060SAzael Avalos /* Determine whether or not BIOS supports transflective backlight */ 2715*695f6060SAzael Avalos ret = get_tr_backlight_status(dev, &dummy); 2716*695f6060SAzael Avalos dev->tr_backlight_supported = !ret; 2717*695f6060SAzael Avalos 271862cce752SSeth Forshee ret = toshiba_acpi_setup_backlight(dev); 271962cce752SSeth Forshee if (ret) 2720135740deSSeth Forshee goto error; 2721135740deSSeth Forshee 2722135740deSSeth Forshee if (toshiba_illumination_available(dev)) { 2723135740deSSeth Forshee dev->led_dev.name = "toshiba::illumination"; 2724135740deSSeth Forshee dev->led_dev.max_brightness = 1; 2725135740deSSeth Forshee dev->led_dev.brightness_set = toshiba_illumination_set; 2726135740deSSeth Forshee dev->led_dev.brightness_get = toshiba_illumination_get; 2727135740deSSeth Forshee if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev)) 272836d03f93SSeth Forshee dev->illumination_supported = 1; 2729135740deSSeth Forshee } 2730135740deSSeth Forshee 2731def6c4e2SAzael Avalos if (toshiba_eco_mode_available(dev)) { 2732def6c4e2SAzael Avalos dev->eco_led.name = "toshiba::eco_mode"; 2733def6c4e2SAzael Avalos dev->eco_led.max_brightness = 1; 2734def6c4e2SAzael Avalos dev->eco_led.brightness_set = toshiba_eco_mode_set_status; 2735def6c4e2SAzael Avalos dev->eco_led.brightness_get = toshiba_eco_mode_get_status; 2736def6c4e2SAzael Avalos if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led)) 2737def6c4e2SAzael Avalos dev->eco_supported = 1; 2738def6c4e2SAzael Avalos } 2739def6c4e2SAzael Avalos 274093f8c16dSAzael Avalos dev->kbd_illum_supported = toshiba_kbd_illum_available(dev); 2741360f0f39SAzael Avalos /* 2742360f0f39SAzael Avalos * Only register the LED if KBD illumination is supported 2743360f0f39SAzael Avalos * and the keyboard backlight operation mode is set to FN-Z 2744360f0f39SAzael Avalos */ 2745360f0f39SAzael Avalos if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) { 2746360f0f39SAzael Avalos dev->kbd_led.name = "toshiba::kbd_backlight"; 2747360f0f39SAzael Avalos dev->kbd_led.max_brightness = 1; 2748360f0f39SAzael Avalos dev->kbd_led.brightness_set = toshiba_kbd_backlight_set; 2749360f0f39SAzael Avalos dev->kbd_led.brightness_get = toshiba_kbd_backlight_get; 2750360f0f39SAzael Avalos if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led)) 2751360f0f39SAzael Avalos dev->kbd_led_registered = 1; 2752360f0f39SAzael Avalos } 2753360f0f39SAzael Avalos 27549d8658acSAzael Avalos ret = toshiba_touchpad_get(dev, &dummy); 27559d8658acSAzael Avalos dev->touchpad_supported = !ret; 27569d8658acSAzael Avalos 27575a2813e9SAzael Avalos ret = toshiba_accelerometer_supported(dev); 27585a2813e9SAzael Avalos dev->accelerometer_supported = !ret; 27595a2813e9SAzael Avalos 2760c8c91842SAzael Avalos toshiba_usb_sleep_charge_available(dev); 2761e26ffe51SAzael Avalos 2762bb3fe01fSAzael Avalos ret = toshiba_usb_rapid_charge_get(dev, &dummy); 2763bb3fe01fSAzael Avalos dev->usb_rapid_charge_supported = !ret; 2764bb3fe01fSAzael Avalos 2765172ce0a9SAzael Avalos ret = toshiba_usb_sleep_music_get(dev, &dummy); 2766172ce0a9SAzael Avalos dev->usb_sleep_music_supported = !ret; 2767172ce0a9SAzael Avalos 276835d53ceaSAzael Avalos ret = toshiba_panel_power_on_get(dev, &dummy); 276935d53ceaSAzael Avalos dev->panel_power_on_supported = !ret; 277035d53ceaSAzael Avalos 277117fe4b3dSAzael Avalos ret = toshiba_usb_three_get(dev, &dummy); 277217fe4b3dSAzael Avalos dev->usb_three_supported = !ret; 277317fe4b3dSAzael Avalos 277436d03f93SSeth Forshee ret = get_video_status(dev, &dummy); 277536d03f93SSeth Forshee dev->video_supported = !ret; 277636d03f93SSeth Forshee 277736d03f93SSeth Forshee ret = get_fan_status(dev, &dummy); 277836d03f93SSeth Forshee dev->fan_supported = !ret; 277936d03f93SSeth Forshee 2780fb42d1f4SAzael Avalos /* 2781fb42d1f4SAzael Avalos * Enable the "Special Functions" mode only if they are 2782fb42d1f4SAzael Avalos * supported and if they are activated. 2783fb42d1f4SAzael Avalos */ 2784fb42d1f4SAzael Avalos if (dev->kbd_function_keys_supported && special_functions) 2785fb42d1f4SAzael Avalos toshiba_acpi_enable_special_functions(dev); 2786fb42d1f4SAzael Avalos 2787360f0f39SAzael Avalos ret = sysfs_create_group(&dev->acpi_dev->dev.kobj, 2788360f0f39SAzael Avalos &toshiba_attr_group); 2789360f0f39SAzael Avalos if (ret) { 2790360f0f39SAzael Avalos dev->sysfs_created = 0; 2791360f0f39SAzael Avalos goto error; 2792360f0f39SAzael Avalos } 2793360f0f39SAzael Avalos dev->sysfs_created = !ret; 2794360f0f39SAzael Avalos 279536d03f93SSeth Forshee create_toshiba_proc_entries(dev); 279636d03f93SSeth Forshee 279729cd293fSSeth Forshee toshiba_acpi = dev; 279829cd293fSSeth Forshee 2799135740deSSeth Forshee return 0; 2800135740deSSeth Forshee 2801135740deSSeth Forshee error: 280251fac838SRafael J. Wysocki toshiba_acpi_remove(acpi_dev); 2803135740deSSeth Forshee return ret; 2804135740deSSeth Forshee } 2805135740deSSeth Forshee 2806135740deSSeth Forshee static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) 2807135740deSSeth Forshee { 2808135740deSSeth Forshee struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); 280980546905SAzael Avalos int ret; 28106335e4d5SMatthew Garrett 281171454d78SAzael Avalos switch (event) { 281271454d78SAzael Avalos case 0x80: /* Hotkeys and some system events */ 2813a88bc06eSAzael Avalos /* 2814a88bc06eSAzael Avalos * Machines with this WMI GUID aren't supported due to bugs in 2815a88bc06eSAzael Avalos * their AML. 2816a88bc06eSAzael Avalos * 2817a88bc06eSAzael Avalos * Return silently to avoid triggering a netlink event. 2818a88bc06eSAzael Avalos */ 2819a88bc06eSAzael Avalos if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) 2820a88bc06eSAzael Avalos return; 282171454d78SAzael Avalos toshiba_acpi_process_hotkeys(dev); 282211948b93SSeth Forshee break; 2823bab09e23SAzael Avalos case 0x81: /* Dock events */ 2824bab09e23SAzael Avalos case 0x82: 2825bab09e23SAzael Avalos case 0x83: 2826bab09e23SAzael Avalos pr_info("Dock event received %x\n", event); 2827bab09e23SAzael Avalos break; 2828bab09e23SAzael Avalos case 0x88: /* Thermal events */ 2829bab09e23SAzael Avalos pr_info("Thermal event received\n"); 2830bab09e23SAzael Avalos break; 2831bab09e23SAzael Avalos case 0x8f: /* LID closed */ 2832bab09e23SAzael Avalos case 0x90: /* LID is closed and Dock has been ejected */ 2833bab09e23SAzael Avalos break; 2834bab09e23SAzael Avalos case 0x8c: /* SATA power events */ 2835bab09e23SAzael Avalos case 0x8b: 2836bab09e23SAzael Avalos pr_info("SATA power event received %x\n", event); 2837bab09e23SAzael Avalos break; 283880546905SAzael Avalos case 0x92: /* Keyboard backlight mode changed */ 283980546905SAzael Avalos /* Update sysfs entries */ 284080546905SAzael Avalos ret = sysfs_update_group(&acpi_dev->dev.kobj, 284180546905SAzael Avalos &toshiba_attr_group); 284280546905SAzael Avalos if (ret) 284380546905SAzael Avalos pr_err("Unable to update sysfs entries\n"); 284480546905SAzael Avalos break; 2845bab09e23SAzael Avalos case 0x85: /* Unknown */ 2846bab09e23SAzael Avalos case 0x8d: /* Unknown */ 284771454d78SAzael Avalos case 0x8e: /* Unknown */ 2848bab09e23SAzael Avalos case 0x94: /* Unknown */ 2849bab09e23SAzael Avalos case 0x95: /* Unknown */ 285011948b93SSeth Forshee default: 285171454d78SAzael Avalos pr_info("Unknown event received %x\n", event); 285211948b93SSeth Forshee break; 28536335e4d5SMatthew Garrett } 2854bab09e23SAzael Avalos 2855bab09e23SAzael Avalos acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class, 2856bab09e23SAzael Avalos dev_name(&acpi_dev->dev), 2857bab09e23SAzael Avalos event, 0); 285829cd293fSSeth Forshee } 28596335e4d5SMatthew Garrett 28603567a4e2SRafael J. Wysocki #ifdef CONFIG_PM_SLEEP 286143d2fd3bSRafael J. Wysocki static int toshiba_acpi_suspend(struct device *device) 286229cd293fSSeth Forshee { 286343d2fd3bSRafael J. Wysocki struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); 286429cd293fSSeth Forshee u32 result; 286529cd293fSSeth Forshee 286629cd293fSSeth Forshee if (dev->hotkey_dev) 2867d37782bdSAzael Avalos result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE); 286829cd293fSSeth Forshee 286929cd293fSSeth Forshee return 0; 287029cd293fSSeth Forshee } 287129cd293fSSeth Forshee 287243d2fd3bSRafael J. Wysocki static int toshiba_acpi_resume(struct device *device) 287329cd293fSSeth Forshee { 287443d2fd3bSRafael J. Wysocki struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); 28751f28f290SAzael Avalos int error; 287629cd293fSSeth Forshee 2877e7fdb762SBenjamin Tissoires if (dev->hotkey_dev) { 28781f28f290SAzael Avalos error = toshiba_acpi_enable_hotkeys(dev); 28791f28f290SAzael Avalos if (error) 2880e7fdb762SBenjamin Tissoires pr_info("Unable to re-enable hotkeys\n"); 2881e7fdb762SBenjamin Tissoires } 288229cd293fSSeth Forshee 288329cd293fSSeth Forshee return 0; 288429cd293fSSeth Forshee } 28853567a4e2SRafael J. Wysocki #endif 28866335e4d5SMatthew Garrett 288743d2fd3bSRafael J. Wysocki static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm, 288843d2fd3bSRafael J. Wysocki toshiba_acpi_suspend, toshiba_acpi_resume); 288943d2fd3bSRafael J. Wysocki 2890135740deSSeth Forshee static struct acpi_driver toshiba_acpi_driver = { 2891135740deSSeth Forshee .name = "Toshiba ACPI driver", 2892135740deSSeth Forshee .owner = THIS_MODULE, 2893135740deSSeth Forshee .ids = toshiba_device_ids, 2894135740deSSeth Forshee .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, 2895135740deSSeth Forshee .ops = { 2896135740deSSeth Forshee .add = toshiba_acpi_add, 2897135740deSSeth Forshee .remove = toshiba_acpi_remove, 2898135740deSSeth Forshee .notify = toshiba_acpi_notify, 2899135740deSSeth Forshee }, 290043d2fd3bSRafael J. Wysocki .drv.pm = &toshiba_acpi_pm, 2901135740deSSeth Forshee }; 2902b4f9fe12SLen Brown 2903b4f9fe12SLen Brown static int __init toshiba_acpi_init(void) 2904b4f9fe12SLen Brown { 2905135740deSSeth Forshee int ret; 2906b4f9fe12SLen Brown 2907b4f9fe12SLen Brown toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir); 2908b4f9fe12SLen Brown if (!toshiba_proc_dir) { 2909135740deSSeth Forshee pr_err("Unable to create proc dir " PROC_TOSHIBA "\n"); 2910b4f9fe12SLen Brown return -ENODEV; 2911b4f9fe12SLen Brown } 2912b4f9fe12SLen Brown 2913135740deSSeth Forshee ret = acpi_bus_register_driver(&toshiba_acpi_driver); 2914b4f9fe12SLen Brown if (ret) { 2915135740deSSeth Forshee pr_err("Failed to register ACPI driver: %d\n", ret); 2916135740deSSeth Forshee remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 2917135740deSSeth Forshee } 2918135740deSSeth Forshee 2919b4f9fe12SLen Brown return ret; 2920b4f9fe12SLen Brown } 2921b4f9fe12SLen Brown 2922135740deSSeth Forshee static void __exit toshiba_acpi_exit(void) 2923135740deSSeth Forshee { 2924135740deSSeth Forshee acpi_bus_unregister_driver(&toshiba_acpi_driver); 2925135740deSSeth Forshee if (toshiba_proc_dir) 2926135740deSSeth Forshee remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 2927b4f9fe12SLen Brown } 2928b4f9fe12SLen Brown 2929b4f9fe12SLen Brown module_init(toshiba_acpi_init); 2930b4f9fe12SLen Brown module_exit(toshiba_acpi_exit); 2931