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 */ 1190121b7b0dSAkio Idehara static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled) 1191121b7b0dSAkio Idehara { 1192121b7b0dSAkio Idehara u32 hci_result; 1193121b7b0dSAkio Idehara u32 status; 1194121b7b0dSAkio Idehara 1195d37782bdSAzael Avalos hci_result = hci_read(dev, HCI_TR_BACKLIGHT, &status); 1196121b7b0dSAkio Idehara *enabled = !status; 11971864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 1198121b7b0dSAkio Idehara } 1199121b7b0dSAkio Idehara 1200121b7b0dSAkio Idehara static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable) 1201121b7b0dSAkio Idehara { 1202121b7b0dSAkio Idehara u32 hci_result; 1203121b7b0dSAkio Idehara u32 value = !enable; 1204121b7b0dSAkio Idehara 1205d37782bdSAzael Avalos hci_result = hci_write(dev, HCI_TR_BACKLIGHT, value); 12061864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 1207121b7b0dSAkio Idehara } 1208121b7b0dSAkio Idehara 12093f75bbe9SAzael Avalos static struct proc_dir_entry *toshiba_proc_dir; 1210b4f9fe12SLen Brown 12113f75bbe9SAzael Avalos /* LCD Brightness */ 121262cce752SSeth Forshee static int __get_lcd_brightness(struct toshiba_acpi_dev *dev) 1213b4f9fe12SLen Brown { 1214b4f9fe12SLen Brown u32 hci_result; 1215b4f9fe12SLen Brown u32 value; 1216121b7b0dSAkio Idehara int brightness = 0; 1217121b7b0dSAkio Idehara 1218121b7b0dSAkio Idehara if (dev->tr_backlight_supported) { 1219121b7b0dSAkio Idehara bool enabled; 1220121b7b0dSAkio Idehara int ret = get_tr_backlight_status(dev, &enabled); 1221b5163992SAzael Avalos 1222121b7b0dSAkio Idehara if (ret) 1223121b7b0dSAkio Idehara return ret; 1224121b7b0dSAkio Idehara if (enabled) 1225121b7b0dSAkio Idehara return 0; 1226121b7b0dSAkio Idehara brightness++; 1227121b7b0dSAkio Idehara } 1228b4f9fe12SLen Brown 1229d37782bdSAzael Avalos hci_result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value); 12301864bbc2SAzael Avalos if (hci_result == TOS_SUCCESS) 1231121b7b0dSAkio Idehara return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT); 123232bcd5cbSSeth Forshee 123332bcd5cbSSeth Forshee return -EIO; 1234b4f9fe12SLen Brown } 1235b4f9fe12SLen Brown 123662cce752SSeth Forshee static int get_lcd_brightness(struct backlight_device *bd) 123762cce752SSeth Forshee { 123862cce752SSeth Forshee struct toshiba_acpi_dev *dev = bl_get_data(bd); 1239b5163992SAzael Avalos 124062cce752SSeth Forshee return __get_lcd_brightness(dev); 124162cce752SSeth Forshee } 124262cce752SSeth Forshee 1243936c8bcdSAlexey Dobriyan static int lcd_proc_show(struct seq_file *m, void *v) 1244b4f9fe12SLen Brown { 1245135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 1246135740deSSeth Forshee int value; 1247121b7b0dSAkio Idehara int levels; 1248b4f9fe12SLen Brown 1249135740deSSeth Forshee if (!dev->backlight_dev) 1250135740deSSeth Forshee return -ENODEV; 1251135740deSSeth Forshee 1252121b7b0dSAkio Idehara levels = dev->backlight_dev->props.max_brightness + 1; 125362cce752SSeth Forshee value = get_lcd_brightness(dev->backlight_dev); 1254b4f9fe12SLen Brown if (value >= 0) { 1255936c8bcdSAlexey Dobriyan seq_printf(m, "brightness: %d\n", value); 1256121b7b0dSAkio Idehara seq_printf(m, "brightness_levels: %d\n", levels); 125732bcd5cbSSeth Forshee return 0; 1258b4f9fe12SLen Brown } 1259b4f9fe12SLen Brown 126032bcd5cbSSeth Forshee pr_err("Error reading LCD brightness\n"); 126132bcd5cbSSeth Forshee return -EIO; 1262936c8bcdSAlexey Dobriyan } 1263936c8bcdSAlexey Dobriyan 1264936c8bcdSAlexey Dobriyan static int lcd_proc_open(struct inode *inode, struct file *file) 1265936c8bcdSAlexey Dobriyan { 1266d9dda78bSAl Viro return single_open(file, lcd_proc_show, PDE_DATA(inode)); 1267b4f9fe12SLen Brown } 1268b4f9fe12SLen Brown 126962cce752SSeth Forshee static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value) 1270b4f9fe12SLen Brown { 1271a39f46dfSAzael Avalos u32 hci_result; 1272b4f9fe12SLen Brown 1273121b7b0dSAkio Idehara if (dev->tr_backlight_supported) { 1274121b7b0dSAkio Idehara bool enable = !value; 1275121b7b0dSAkio Idehara int ret = set_tr_backlight_status(dev, enable); 1276b5163992SAzael Avalos 1277121b7b0dSAkio Idehara if (ret) 1278121b7b0dSAkio Idehara return ret; 1279121b7b0dSAkio Idehara if (value) 1280121b7b0dSAkio Idehara value--; 1281121b7b0dSAkio Idehara } 1282121b7b0dSAkio Idehara 1283a39f46dfSAzael Avalos value = value << HCI_LCD_BRIGHTNESS_SHIFT; 1284d37782bdSAzael Avalos hci_result = hci_write(dev, HCI_LCD_BRIGHTNESS, value); 1285a39f46dfSAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 1286b4f9fe12SLen Brown } 1287b4f9fe12SLen Brown 1288b4f9fe12SLen Brown static int set_lcd_status(struct backlight_device *bd) 1289b4f9fe12SLen Brown { 1290135740deSSeth Forshee struct toshiba_acpi_dev *dev = bl_get_data(bd); 1291b5163992SAzael Avalos 129262cce752SSeth Forshee return set_lcd_brightness(dev, bd->props.brightness); 1293b4f9fe12SLen Brown } 1294b4f9fe12SLen Brown 1295936c8bcdSAlexey Dobriyan static ssize_t lcd_proc_write(struct file *file, const char __user *buf, 1296936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1297b4f9fe12SLen Brown { 1298d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1299936c8bcdSAlexey Dobriyan char cmd[42]; 1300936c8bcdSAlexey Dobriyan size_t len; 1301b4f9fe12SLen Brown int value; 1302b4f9fe12SLen Brown int ret; 1303121b7b0dSAkio Idehara int levels = dev->backlight_dev->props.max_brightness + 1; 1304b4f9fe12SLen Brown 1305936c8bcdSAlexey Dobriyan len = min(count, sizeof(cmd) - 1); 1306936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, len)) 1307936c8bcdSAlexey Dobriyan return -EFAULT; 1308936c8bcdSAlexey Dobriyan cmd[len] = '\0'; 1309936c8bcdSAlexey Dobriyan 1310936c8bcdSAlexey Dobriyan if (sscanf(cmd, " brightness : %i", &value) == 1 && 1311121b7b0dSAkio Idehara value >= 0 && value < levels) { 131262cce752SSeth Forshee ret = set_lcd_brightness(dev, value); 1313b4f9fe12SLen Brown if (ret == 0) 1314b4f9fe12SLen Brown ret = count; 1315b4f9fe12SLen Brown } else { 1316b4f9fe12SLen Brown ret = -EINVAL; 1317b4f9fe12SLen Brown } 1318b4f9fe12SLen Brown return ret; 1319b4f9fe12SLen Brown } 1320b4f9fe12SLen Brown 1321936c8bcdSAlexey Dobriyan static const struct file_operations lcd_proc_fops = { 1322936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1323936c8bcdSAlexey Dobriyan .open = lcd_proc_open, 1324936c8bcdSAlexey Dobriyan .read = seq_read, 1325936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1326936c8bcdSAlexey Dobriyan .release = single_release, 1327936c8bcdSAlexey Dobriyan .write = lcd_proc_write, 1328936c8bcdSAlexey Dobriyan }; 1329936c8bcdSAlexey Dobriyan 133036d03f93SSeth Forshee static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status) 133136d03f93SSeth Forshee { 133236d03f93SSeth Forshee u32 hci_result; 133336d03f93SSeth Forshee 1334d37782bdSAzael Avalos hci_result = hci_read(dev, HCI_VIDEO_OUT, status); 13351864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 133636d03f93SSeth Forshee } 133736d03f93SSeth Forshee 1338936c8bcdSAlexey Dobriyan static int video_proc_show(struct seq_file *m, void *v) 1339b4f9fe12SLen Brown { 1340135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 1341b4f9fe12SLen Brown u32 value; 134236d03f93SSeth Forshee int ret; 1343b4f9fe12SLen Brown 134436d03f93SSeth Forshee ret = get_video_status(dev, &value); 134536d03f93SSeth Forshee if (!ret) { 1346b4f9fe12SLen Brown int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; 1347b4f9fe12SLen Brown int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; 1348b4f9fe12SLen Brown int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0; 1349b5163992SAzael Avalos 1350936c8bcdSAlexey Dobriyan seq_printf(m, "lcd_out: %d\n", is_lcd); 1351936c8bcdSAlexey Dobriyan seq_printf(m, "crt_out: %d\n", is_crt); 1352936c8bcdSAlexey Dobriyan seq_printf(m, "tv_out: %d\n", is_tv); 1353b4f9fe12SLen Brown } 1354b4f9fe12SLen Brown 135536d03f93SSeth Forshee return ret; 1356b4f9fe12SLen Brown } 1357b4f9fe12SLen Brown 1358936c8bcdSAlexey Dobriyan static int video_proc_open(struct inode *inode, struct file *file) 1359b4f9fe12SLen Brown { 1360d9dda78bSAl Viro return single_open(file, video_proc_show, PDE_DATA(inode)); 1361936c8bcdSAlexey Dobriyan } 1362936c8bcdSAlexey Dobriyan 1363936c8bcdSAlexey Dobriyan static ssize_t video_proc_write(struct file *file, const char __user *buf, 1364936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1365936c8bcdSAlexey Dobriyan { 1366d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1367936c8bcdSAlexey Dobriyan char *cmd, *buffer; 136836d03f93SSeth Forshee int ret; 1369b4f9fe12SLen Brown int value; 1370b4f9fe12SLen Brown int remain = count; 1371b4f9fe12SLen Brown int lcd_out = -1; 1372b4f9fe12SLen Brown int crt_out = -1; 1373b4f9fe12SLen Brown int tv_out = -1; 1374b4f9fe12SLen Brown u32 video_out; 1375b4f9fe12SLen Brown 1376936c8bcdSAlexey Dobriyan cmd = kmalloc(count + 1, GFP_KERNEL); 1377936c8bcdSAlexey Dobriyan if (!cmd) 1378936c8bcdSAlexey Dobriyan return -ENOMEM; 1379936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, count)) { 1380936c8bcdSAlexey Dobriyan kfree(cmd); 1381936c8bcdSAlexey Dobriyan return -EFAULT; 1382936c8bcdSAlexey Dobriyan } 1383936c8bcdSAlexey Dobriyan cmd[count] = '\0'; 1384936c8bcdSAlexey Dobriyan 1385936c8bcdSAlexey Dobriyan buffer = cmd; 1386936c8bcdSAlexey Dobriyan 1387e0769fe6SDarren Hart /* 1388e0769fe6SDarren Hart * Scan expression. Multiple expressions may be delimited with ; 1389e0769fe6SDarren Hart * NOTE: To keep scanning simple, invalid fields are ignored. 1390b4f9fe12SLen Brown */ 1391b4f9fe12SLen Brown while (remain) { 1392b4f9fe12SLen Brown if (sscanf(buffer, " lcd_out : %i", &value) == 1) 1393b4f9fe12SLen Brown lcd_out = value & 1; 1394b4f9fe12SLen Brown else if (sscanf(buffer, " crt_out : %i", &value) == 1) 1395b4f9fe12SLen Brown crt_out = value & 1; 1396b4f9fe12SLen Brown else if (sscanf(buffer, " tv_out : %i", &value) == 1) 1397b4f9fe12SLen Brown tv_out = value & 1; 1398e0769fe6SDarren Hart /* Advance to one character past the next ; */ 1399b4f9fe12SLen Brown do { 1400b4f9fe12SLen Brown ++buffer; 1401b4f9fe12SLen Brown --remain; 1402b5163992SAzael Avalos } while (remain && *(buffer - 1) != ';'); 1403b4f9fe12SLen Brown } 1404b4f9fe12SLen Brown 1405936c8bcdSAlexey Dobriyan kfree(cmd); 1406936c8bcdSAlexey Dobriyan 140736d03f93SSeth Forshee ret = get_video_status(dev, &video_out); 140836d03f93SSeth Forshee if (!ret) { 1409b4f9fe12SLen Brown unsigned int new_video_out = video_out; 1410b5163992SAzael Avalos 1411b4f9fe12SLen Brown if (lcd_out != -1) 1412b4f9fe12SLen Brown _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out); 1413b4f9fe12SLen Brown if (crt_out != -1) 1414b4f9fe12SLen Brown _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out); 1415b4f9fe12SLen Brown if (tv_out != -1) 1416b4f9fe12SLen Brown _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out); 1417e0769fe6SDarren Hart /* 1418e0769fe6SDarren Hart * To avoid unnecessary video disruption, only write the new 14193f75bbe9SAzael Avalos * video setting if something changed. 14203f75bbe9SAzael Avalos */ 1421b4f9fe12SLen Brown if (new_video_out != video_out) 142232bcd5cbSSeth Forshee ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out); 1423b4f9fe12SLen Brown } 1424b4f9fe12SLen Brown 142532bcd5cbSSeth Forshee return ret ? ret : count; 1426b4f9fe12SLen Brown } 1427b4f9fe12SLen Brown 1428936c8bcdSAlexey Dobriyan static const struct file_operations video_proc_fops = { 1429936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1430936c8bcdSAlexey Dobriyan .open = video_proc_open, 1431936c8bcdSAlexey Dobriyan .read = seq_read, 1432936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1433936c8bcdSAlexey Dobriyan .release = single_release, 1434936c8bcdSAlexey Dobriyan .write = video_proc_write, 1435936c8bcdSAlexey Dobriyan }; 1436936c8bcdSAlexey Dobriyan 143736d03f93SSeth Forshee static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status) 143836d03f93SSeth Forshee { 143936d03f93SSeth Forshee u32 hci_result; 144036d03f93SSeth Forshee 1441d37782bdSAzael Avalos hci_result = hci_read(dev, HCI_FAN, status); 14421864bbc2SAzael Avalos return hci_result == TOS_SUCCESS ? 0 : -EIO; 144336d03f93SSeth Forshee } 144436d03f93SSeth Forshee 1445936c8bcdSAlexey Dobriyan static int fan_proc_show(struct seq_file *m, void *v) 1446b4f9fe12SLen Brown { 1447135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 144836d03f93SSeth Forshee int ret; 1449b4f9fe12SLen Brown u32 value; 1450b4f9fe12SLen Brown 145136d03f93SSeth Forshee ret = get_fan_status(dev, &value); 145236d03f93SSeth Forshee if (!ret) { 1453936c8bcdSAlexey Dobriyan seq_printf(m, "running: %d\n", (value > 0)); 1454135740deSSeth Forshee seq_printf(m, "force_on: %d\n", dev->force_fan); 1455b4f9fe12SLen Brown } 1456b4f9fe12SLen Brown 145736d03f93SSeth Forshee return ret; 1458b4f9fe12SLen Brown } 1459b4f9fe12SLen Brown 1460936c8bcdSAlexey Dobriyan static int fan_proc_open(struct inode *inode, struct file *file) 1461b4f9fe12SLen Brown { 1462d9dda78bSAl Viro return single_open(file, fan_proc_show, PDE_DATA(inode)); 1463936c8bcdSAlexey Dobriyan } 1464936c8bcdSAlexey Dobriyan 1465936c8bcdSAlexey Dobriyan static ssize_t fan_proc_write(struct file *file, const char __user *buf, 1466936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1467936c8bcdSAlexey Dobriyan { 1468d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1469936c8bcdSAlexey Dobriyan char cmd[42]; 1470936c8bcdSAlexey Dobriyan size_t len; 1471b4f9fe12SLen Brown int value; 1472b4f9fe12SLen Brown u32 hci_result; 1473b4f9fe12SLen Brown 1474936c8bcdSAlexey Dobriyan len = min(count, sizeof(cmd) - 1); 1475936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, len)) 1476936c8bcdSAlexey Dobriyan return -EFAULT; 1477936c8bcdSAlexey Dobriyan cmd[len] = '\0'; 1478936c8bcdSAlexey Dobriyan 1479936c8bcdSAlexey Dobriyan if (sscanf(cmd, " force_on : %i", &value) == 1 && 1480b4f9fe12SLen Brown value >= 0 && value <= 1) { 1481d37782bdSAzael Avalos hci_result = hci_write(dev, HCI_FAN, value); 1482b5163992SAzael Avalos if (hci_result == TOS_SUCCESS) 1483135740deSSeth Forshee dev->force_fan = value; 1484b5163992SAzael Avalos else 1485b5163992SAzael Avalos return -EIO; 1486b4f9fe12SLen Brown } else { 1487b4f9fe12SLen Brown return -EINVAL; 1488b4f9fe12SLen Brown } 1489b4f9fe12SLen Brown 1490b4f9fe12SLen Brown return count; 1491b4f9fe12SLen Brown } 1492b4f9fe12SLen Brown 1493936c8bcdSAlexey Dobriyan static const struct file_operations fan_proc_fops = { 1494936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1495936c8bcdSAlexey Dobriyan .open = fan_proc_open, 1496936c8bcdSAlexey Dobriyan .read = seq_read, 1497936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1498936c8bcdSAlexey Dobriyan .release = single_release, 1499936c8bcdSAlexey Dobriyan .write = fan_proc_write, 1500936c8bcdSAlexey Dobriyan }; 1501936c8bcdSAlexey Dobriyan 1502936c8bcdSAlexey Dobriyan static int keys_proc_show(struct seq_file *m, void *v) 1503b4f9fe12SLen Brown { 1504135740deSSeth Forshee struct toshiba_acpi_dev *dev = m->private; 1505b4f9fe12SLen Brown 1506135740deSSeth Forshee seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid); 1507135740deSSeth Forshee seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event); 15087deef550SAzael Avalos 1509936c8bcdSAlexey Dobriyan return 0; 1510b4f9fe12SLen Brown } 1511b4f9fe12SLen Brown 1512936c8bcdSAlexey Dobriyan static int keys_proc_open(struct inode *inode, struct file *file) 1513b4f9fe12SLen Brown { 1514d9dda78bSAl Viro return single_open(file, keys_proc_show, PDE_DATA(inode)); 1515936c8bcdSAlexey Dobriyan } 1516936c8bcdSAlexey Dobriyan 1517936c8bcdSAlexey Dobriyan static ssize_t keys_proc_write(struct file *file, const char __user *buf, 1518936c8bcdSAlexey Dobriyan size_t count, loff_t *pos) 1519936c8bcdSAlexey Dobriyan { 1520d9dda78bSAl Viro struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); 1521936c8bcdSAlexey Dobriyan char cmd[42]; 1522936c8bcdSAlexey Dobriyan size_t len; 1523b4f9fe12SLen Brown int value; 1524b4f9fe12SLen Brown 1525936c8bcdSAlexey Dobriyan len = min(count, sizeof(cmd) - 1); 1526936c8bcdSAlexey Dobriyan if (copy_from_user(cmd, buf, len)) 1527936c8bcdSAlexey Dobriyan return -EFAULT; 1528936c8bcdSAlexey Dobriyan cmd[len] = '\0'; 1529936c8bcdSAlexey Dobriyan 1530b5163992SAzael Avalos if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) 1531135740deSSeth Forshee dev->key_event_valid = 0; 1532b5163992SAzael Avalos else 1533b4f9fe12SLen Brown return -EINVAL; 1534b4f9fe12SLen Brown 1535b4f9fe12SLen Brown return count; 1536b4f9fe12SLen Brown } 1537b4f9fe12SLen Brown 1538936c8bcdSAlexey Dobriyan static const struct file_operations keys_proc_fops = { 1539936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1540936c8bcdSAlexey Dobriyan .open = keys_proc_open, 1541936c8bcdSAlexey Dobriyan .read = seq_read, 1542936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1543936c8bcdSAlexey Dobriyan .release = single_release, 1544936c8bcdSAlexey Dobriyan .write = keys_proc_write, 1545936c8bcdSAlexey Dobriyan }; 1546936c8bcdSAlexey Dobriyan 1547936c8bcdSAlexey Dobriyan static int version_proc_show(struct seq_file *m, void *v) 1548b4f9fe12SLen Brown { 1549936c8bcdSAlexey Dobriyan seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION); 1550936c8bcdSAlexey Dobriyan seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION); 1551936c8bcdSAlexey Dobriyan return 0; 1552b4f9fe12SLen Brown } 1553b4f9fe12SLen Brown 1554936c8bcdSAlexey Dobriyan static int version_proc_open(struct inode *inode, struct file *file) 1555936c8bcdSAlexey Dobriyan { 1556d9dda78bSAl Viro return single_open(file, version_proc_show, PDE_DATA(inode)); 1557936c8bcdSAlexey Dobriyan } 1558936c8bcdSAlexey Dobriyan 1559936c8bcdSAlexey Dobriyan static const struct file_operations version_proc_fops = { 1560936c8bcdSAlexey Dobriyan .owner = THIS_MODULE, 1561936c8bcdSAlexey Dobriyan .open = version_proc_open, 1562936c8bcdSAlexey Dobriyan .read = seq_read, 1563936c8bcdSAlexey Dobriyan .llseek = seq_lseek, 1564936c8bcdSAlexey Dobriyan .release = single_release, 1565936c8bcdSAlexey Dobriyan }; 1566936c8bcdSAlexey Dobriyan 1567e0769fe6SDarren Hart /* 1568e0769fe6SDarren Hart * Proc and module init 1569b4f9fe12SLen Brown */ 1570b4f9fe12SLen Brown 1571b4f9fe12SLen Brown #define PROC_TOSHIBA "toshiba" 1572b4f9fe12SLen Brown 1573b859f159SGreg Kroah-Hartman static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev) 1574b4f9fe12SLen Brown { 157536d03f93SSeth Forshee if (dev->backlight_dev) 1576135740deSSeth Forshee proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1577135740deSSeth Forshee &lcd_proc_fops, dev); 157836d03f93SSeth Forshee if (dev->video_supported) 1579135740deSSeth Forshee proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1580135740deSSeth Forshee &video_proc_fops, dev); 158136d03f93SSeth Forshee if (dev->fan_supported) 1582135740deSSeth Forshee proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1583135740deSSeth Forshee &fan_proc_fops, dev); 158436d03f93SSeth Forshee if (dev->hotkey_dev) 1585135740deSSeth Forshee proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, 1586135740deSSeth Forshee &keys_proc_fops, dev); 1587135740deSSeth Forshee proc_create_data("version", S_IRUGO, toshiba_proc_dir, 1588135740deSSeth Forshee &version_proc_fops, dev); 1589b4f9fe12SLen Brown } 1590b4f9fe12SLen Brown 159136d03f93SSeth Forshee static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev) 1592b4f9fe12SLen Brown { 159336d03f93SSeth Forshee if (dev->backlight_dev) 1594936c8bcdSAlexey Dobriyan remove_proc_entry("lcd", toshiba_proc_dir); 159536d03f93SSeth Forshee if (dev->video_supported) 1596936c8bcdSAlexey Dobriyan remove_proc_entry("video", toshiba_proc_dir); 159736d03f93SSeth Forshee if (dev->fan_supported) 1598936c8bcdSAlexey Dobriyan remove_proc_entry("fan", toshiba_proc_dir); 159936d03f93SSeth Forshee if (dev->hotkey_dev) 1600936c8bcdSAlexey Dobriyan remove_proc_entry("keys", toshiba_proc_dir); 1601936c8bcdSAlexey Dobriyan remove_proc_entry("version", toshiba_proc_dir); 1602b4f9fe12SLen Brown } 1603b4f9fe12SLen Brown 1604acc2472eSLionel Debroux static const struct backlight_ops toshiba_backlight_data = { 1605121b7b0dSAkio Idehara .options = BL_CORE_SUSPENDRESUME, 160662cce752SSeth Forshee .get_brightness = get_lcd_brightness, 1607b4f9fe12SLen Brown .update_status = set_lcd_status, 1608b4f9fe12SLen Brown }; 1609b4f9fe12SLen Brown 1610360f0f39SAzael Avalos /* 1611360f0f39SAzael Avalos * Sysfs files 1612360f0f39SAzael Avalos */ 16139d309848SAzael Avalos static ssize_t version_show(struct device *dev, 1614c6c68ff8SAzael Avalos struct device_attribute *attr, char *buf) 1615c6c68ff8SAzael Avalos { 1616c6c68ff8SAzael Avalos return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION); 1617c6c68ff8SAzael Avalos } 16180c3c0f10SAzael Avalos static DEVICE_ATTR_RO(version); 1619c6c68ff8SAzael Avalos 16209d309848SAzael Avalos static ssize_t fan_store(struct device *dev, 162194477d4cSAzael Avalos struct device_attribute *attr, 162294477d4cSAzael Avalos const char *buf, size_t count) 162394477d4cSAzael Avalos { 162494477d4cSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 162594477d4cSAzael Avalos u32 result; 162694477d4cSAzael Avalos int state; 162794477d4cSAzael Avalos int ret; 162894477d4cSAzael Avalos 162994477d4cSAzael Avalos ret = kstrtoint(buf, 0, &state); 163094477d4cSAzael Avalos if (ret) 163194477d4cSAzael Avalos return ret; 163294477d4cSAzael Avalos 163394477d4cSAzael Avalos if (state != 0 && state != 1) 163494477d4cSAzael Avalos return -EINVAL; 163594477d4cSAzael Avalos 1636d37782bdSAzael Avalos result = hci_write(toshiba, HCI_FAN, state); 163794477d4cSAzael Avalos if (result == TOS_FAILURE) 163894477d4cSAzael Avalos return -EIO; 163994477d4cSAzael Avalos else if (result == TOS_NOT_SUPPORTED) 164094477d4cSAzael Avalos return -ENODEV; 164194477d4cSAzael Avalos 164294477d4cSAzael Avalos return count; 164394477d4cSAzael Avalos } 164494477d4cSAzael Avalos 16459d309848SAzael Avalos static ssize_t fan_show(struct device *dev, 164694477d4cSAzael Avalos struct device_attribute *attr, char *buf) 164794477d4cSAzael Avalos { 164894477d4cSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 164994477d4cSAzael Avalos u32 value; 165094477d4cSAzael Avalos int ret; 165194477d4cSAzael Avalos 165294477d4cSAzael Avalos ret = get_fan_status(toshiba, &value); 165394477d4cSAzael Avalos if (ret) 165494477d4cSAzael Avalos return ret; 165594477d4cSAzael Avalos 165694477d4cSAzael Avalos return sprintf(buf, "%d\n", value); 165794477d4cSAzael Avalos } 16580c3c0f10SAzael Avalos static DEVICE_ATTR_RW(fan); 165994477d4cSAzael Avalos 16609d309848SAzael Avalos static ssize_t kbd_backlight_mode_store(struct device *dev, 1661360f0f39SAzael Avalos struct device_attribute *attr, 1662360f0f39SAzael Avalos const char *buf, size_t count) 1663360f0f39SAzael Avalos { 1664360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1665aeaac098SDan Carpenter int mode; 1666aeaac098SDan Carpenter int time; 1667aeaac098SDan Carpenter int ret; 1668360f0f39SAzael Avalos 1669aeaac098SDan Carpenter 1670aeaac098SDan Carpenter ret = kstrtoint(buf, 0, &mode); 1671aeaac098SDan Carpenter if (ret) 1672aeaac098SDan Carpenter return ret; 167393f8c16dSAzael Avalos 167493f8c16dSAzael Avalos /* Check for supported modes depending on keyboard backlight type */ 167593f8c16dSAzael Avalos if (toshiba->kbd_type == 1) { 167693f8c16dSAzael Avalos /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */ 1677aeaac098SDan Carpenter if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO) 1678360f0f39SAzael Avalos return -EINVAL; 167993f8c16dSAzael Avalos } else if (toshiba->kbd_type == 2) { 168093f8c16dSAzael Avalos /* Type 2 doesn't support SCI_KBD_MODE_FNZ */ 168193f8c16dSAzael Avalos if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON && 168293f8c16dSAzael Avalos mode != SCI_KBD_MODE_OFF) 168393f8c16dSAzael Avalos return -EINVAL; 168493f8c16dSAzael Avalos } 1685360f0f39SAzael Avalos 1686e0769fe6SDarren Hart /* 1687e0769fe6SDarren Hart * Set the Keyboard Backlight Mode where: 1688360f0f39SAzael Avalos * Auto - KBD backlight turns off automatically in given time 1689360f0f39SAzael Avalos * FN-Z - KBD backlight "toggles" when hotkey pressed 169093f8c16dSAzael Avalos * ON - KBD backlight is always on 169193f8c16dSAzael Avalos * OFF - KBD backlight is always off 1692360f0f39SAzael Avalos */ 169393f8c16dSAzael Avalos 169493f8c16dSAzael Avalos /* Only make a change if the actual mode has changed */ 1695aeaac098SDan Carpenter if (toshiba->kbd_mode != mode) { 169693f8c16dSAzael Avalos /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ 1697360f0f39SAzael Avalos time = toshiba->kbd_time << HCI_MISC_SHIFT; 169893f8c16dSAzael Avalos 169993f8c16dSAzael Avalos /* OR the "base time" to the actual method format */ 170093f8c16dSAzael Avalos if (toshiba->kbd_type == 1) { 170193f8c16dSAzael Avalos /* Type 1 requires the current mode */ 170293f8c16dSAzael Avalos time |= toshiba->kbd_mode; 170393f8c16dSAzael Avalos } else if (toshiba->kbd_type == 2) { 170493f8c16dSAzael Avalos /* Type 2 requires the desired mode */ 170593f8c16dSAzael Avalos time |= mode; 170693f8c16dSAzael Avalos } 170793f8c16dSAzael Avalos 1708aeaac098SDan Carpenter ret = toshiba_kbd_illum_status_set(toshiba, time); 1709aeaac098SDan Carpenter if (ret) 1710aeaac098SDan Carpenter return ret; 171193f8c16dSAzael Avalos 1712360f0f39SAzael Avalos toshiba->kbd_mode = mode; 1713360f0f39SAzael Avalos } 1714360f0f39SAzael Avalos 1715360f0f39SAzael Avalos return count; 1716360f0f39SAzael Avalos } 1717360f0f39SAzael Avalos 17189d309848SAzael Avalos static ssize_t kbd_backlight_mode_show(struct device *dev, 1719360f0f39SAzael Avalos struct device_attribute *attr, 1720360f0f39SAzael Avalos char *buf) 1721360f0f39SAzael Avalos { 1722360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1723360f0f39SAzael Avalos u32 time; 1724360f0f39SAzael Avalos 1725360f0f39SAzael Avalos if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) 1726360f0f39SAzael Avalos return -EIO; 1727360f0f39SAzael Avalos 172893f8c16dSAzael Avalos return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK); 172993f8c16dSAzael Avalos } 17300c3c0f10SAzael Avalos static DEVICE_ATTR_RW(kbd_backlight_mode); 173193f8c16dSAzael Avalos 17329d309848SAzael Avalos static ssize_t kbd_type_show(struct device *dev, 17339d309848SAzael Avalos struct device_attribute *attr, char *buf) 173493f8c16dSAzael Avalos { 173593f8c16dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 173693f8c16dSAzael Avalos 173793f8c16dSAzael Avalos return sprintf(buf, "%d\n", toshiba->kbd_type); 173893f8c16dSAzael Avalos } 17390c3c0f10SAzael Avalos static DEVICE_ATTR_RO(kbd_type); 174093f8c16dSAzael Avalos 17419d309848SAzael Avalos static ssize_t available_kbd_modes_show(struct device *dev, 174293f8c16dSAzael Avalos struct device_attribute *attr, 174393f8c16dSAzael Avalos char *buf) 174493f8c16dSAzael Avalos { 174593f8c16dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 174693f8c16dSAzael Avalos 174793f8c16dSAzael Avalos if (toshiba->kbd_type == 1) 174893f8c16dSAzael Avalos return sprintf(buf, "%x %x\n", 174993f8c16dSAzael Avalos SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO); 175093f8c16dSAzael Avalos 175193f8c16dSAzael Avalos return sprintf(buf, "%x %x %x\n", 175293f8c16dSAzael Avalos SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF); 1753360f0f39SAzael Avalos } 17540c3c0f10SAzael Avalos static DEVICE_ATTR_RO(available_kbd_modes); 1755360f0f39SAzael Avalos 17569d309848SAzael Avalos static ssize_t kbd_backlight_timeout_store(struct device *dev, 1757360f0f39SAzael Avalos struct device_attribute *attr, 1758360f0f39SAzael Avalos const char *buf, size_t count) 1759360f0f39SAzael Avalos { 1760360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1761eabde0faSAzael Avalos int time; 1762eabde0faSAzael Avalos int ret; 1763360f0f39SAzael Avalos 1764eabde0faSAzael Avalos ret = kstrtoint(buf, 0, &time); 1765eabde0faSAzael Avalos if (ret) 1766eabde0faSAzael Avalos return ret; 1767eabde0faSAzael Avalos 1768eabde0faSAzael Avalos /* Check for supported values depending on kbd_type */ 1769eabde0faSAzael Avalos if (toshiba->kbd_type == 1) { 1770eabde0faSAzael Avalos if (time < 0 || time > 60) 1771360f0f39SAzael Avalos return -EINVAL; 1772eabde0faSAzael Avalos } else if (toshiba->kbd_type == 2) { 1773eabde0faSAzael Avalos if (time < 1 || time > 60) 1774eabde0faSAzael Avalos return -EINVAL; 1775eabde0faSAzael Avalos } 1776360f0f39SAzael Avalos 1777eabde0faSAzael Avalos /* Set the Keyboard Backlight Timeout */ 1778eabde0faSAzael Avalos 1779eabde0faSAzael Avalos /* Only make a change if the actual timeout has changed */ 1780eabde0faSAzael Avalos if (toshiba->kbd_time != time) { 1781eabde0faSAzael Avalos /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ 1782360f0f39SAzael Avalos time = time << HCI_MISC_SHIFT; 1783eabde0faSAzael Avalos /* OR the "base time" to the actual method format */ 1784eabde0faSAzael Avalos if (toshiba->kbd_type == 1) 1785eabde0faSAzael Avalos time |= SCI_KBD_MODE_FNZ; 1786eabde0faSAzael Avalos else if (toshiba->kbd_type == 2) 1787eabde0faSAzael Avalos time |= SCI_KBD_MODE_AUTO; 1788eabde0faSAzael Avalos 1789eabde0faSAzael Avalos ret = toshiba_kbd_illum_status_set(toshiba, time); 1790eabde0faSAzael Avalos if (ret) 1791eabde0faSAzael Avalos return ret; 1792eabde0faSAzael Avalos 1793360f0f39SAzael Avalos toshiba->kbd_time = time >> HCI_MISC_SHIFT; 1794360f0f39SAzael Avalos } 1795360f0f39SAzael Avalos 1796360f0f39SAzael Avalos return count; 1797360f0f39SAzael Avalos } 1798360f0f39SAzael Avalos 17999d309848SAzael Avalos static ssize_t kbd_backlight_timeout_show(struct device *dev, 1800360f0f39SAzael Avalos struct device_attribute *attr, 1801360f0f39SAzael Avalos char *buf) 1802360f0f39SAzael Avalos { 1803360f0f39SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1804360f0f39SAzael Avalos u32 time; 1805360f0f39SAzael Avalos 1806360f0f39SAzael Avalos if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) 1807360f0f39SAzael Avalos return -EIO; 1808360f0f39SAzael Avalos 1809360f0f39SAzael Avalos return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT); 1810360f0f39SAzael Avalos } 18110c3c0f10SAzael Avalos static DEVICE_ATTR_RW(kbd_backlight_timeout); 1812360f0f39SAzael Avalos 18139d309848SAzael Avalos static ssize_t touchpad_store(struct device *dev, 18149d8658acSAzael Avalos struct device_attribute *attr, 18159d8658acSAzael Avalos const char *buf, size_t count) 18169d8658acSAzael Avalos { 18179d8658acSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 18189d8658acSAzael Avalos int state; 1819c8a41669SAzael Avalos int ret; 18209d8658acSAzael Avalos 18219d8658acSAzael Avalos /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */ 1822c8a41669SAzael Avalos ret = kstrtoint(buf, 0, &state); 1823c8a41669SAzael Avalos if (ret) 1824c8a41669SAzael Avalos return ret; 1825c8a41669SAzael Avalos if (state != 0 && state != 1) 1826c8a41669SAzael Avalos return -EINVAL; 1827c8a41669SAzael Avalos 1828c8a41669SAzael Avalos ret = toshiba_touchpad_set(toshiba, state); 1829c8a41669SAzael Avalos if (ret) 1830c8a41669SAzael Avalos return ret; 18319d8658acSAzael Avalos 18329d8658acSAzael Avalos return count; 18339d8658acSAzael Avalos } 18349d8658acSAzael Avalos 18359d309848SAzael Avalos static ssize_t touchpad_show(struct device *dev, 18369d8658acSAzael Avalos struct device_attribute *attr, char *buf) 18379d8658acSAzael Avalos { 18389d8658acSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 18399d8658acSAzael Avalos u32 state; 18409d8658acSAzael Avalos int ret; 18419d8658acSAzael Avalos 18429d8658acSAzael Avalos ret = toshiba_touchpad_get(toshiba, &state); 18439d8658acSAzael Avalos if (ret < 0) 18449d8658acSAzael Avalos return ret; 18459d8658acSAzael Avalos 18469d8658acSAzael Avalos return sprintf(buf, "%i\n", state); 18479d8658acSAzael Avalos } 18480c3c0f10SAzael Avalos static DEVICE_ATTR_RW(touchpad); 18499d8658acSAzael Avalos 18509d309848SAzael Avalos static ssize_t position_show(struct device *dev, 18515a2813e9SAzael Avalos struct device_attribute *attr, char *buf) 18525a2813e9SAzael Avalos { 18535a2813e9SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 18545a2813e9SAzael Avalos u32 xyval, zval, tmp; 18555a2813e9SAzael Avalos u16 x, y, z; 18565a2813e9SAzael Avalos int ret; 18575a2813e9SAzael Avalos 18585a2813e9SAzael Avalos xyval = zval = 0; 18595a2813e9SAzael Avalos ret = toshiba_accelerometer_get(toshiba, &xyval, &zval); 18605a2813e9SAzael Avalos if (ret < 0) 18615a2813e9SAzael Avalos return ret; 18625a2813e9SAzael Avalos 18635a2813e9SAzael Avalos x = xyval & HCI_ACCEL_MASK; 18645a2813e9SAzael Avalos tmp = xyval >> HCI_MISC_SHIFT; 18655a2813e9SAzael Avalos y = tmp & HCI_ACCEL_MASK; 18665a2813e9SAzael Avalos z = zval & HCI_ACCEL_MASK; 18675a2813e9SAzael Avalos 18685a2813e9SAzael Avalos return sprintf(buf, "%d %d %d\n", x, y, z); 18695a2813e9SAzael Avalos } 18700c3c0f10SAzael Avalos static DEVICE_ATTR_RO(position); 18715a2813e9SAzael Avalos 18729d309848SAzael Avalos static ssize_t usb_sleep_charge_show(struct device *dev, 18739d309848SAzael Avalos struct device_attribute *attr, char *buf) 1874e26ffe51SAzael Avalos { 1875e26ffe51SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1876e26ffe51SAzael Avalos u32 mode; 1877e26ffe51SAzael Avalos int ret; 1878e26ffe51SAzael Avalos 1879e26ffe51SAzael Avalos ret = toshiba_usb_sleep_charge_get(toshiba, &mode); 1880e26ffe51SAzael Avalos if (ret < 0) 1881e26ffe51SAzael Avalos return ret; 1882e26ffe51SAzael Avalos 1883e26ffe51SAzael Avalos return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK); 1884e26ffe51SAzael Avalos } 1885e26ffe51SAzael Avalos 18869d309848SAzael Avalos static ssize_t usb_sleep_charge_store(struct device *dev, 1887e26ffe51SAzael Avalos struct device_attribute *attr, 1888e26ffe51SAzael Avalos const char *buf, size_t count) 1889e26ffe51SAzael Avalos { 1890e26ffe51SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1891e26ffe51SAzael Avalos u32 mode; 1892e26ffe51SAzael Avalos int state; 1893e26ffe51SAzael Avalos int ret; 1894e26ffe51SAzael Avalos 1895e26ffe51SAzael Avalos ret = kstrtoint(buf, 0, &state); 1896e26ffe51SAzael Avalos if (ret) 1897e26ffe51SAzael Avalos return ret; 1898e0769fe6SDarren Hart /* 1899e0769fe6SDarren Hart * Check for supported values, where: 1900e26ffe51SAzael Avalos * 0 - Disabled 1901e26ffe51SAzael Avalos * 1 - Alternate (Non USB conformant devices that require more power) 1902e26ffe51SAzael Avalos * 2 - Auto (USB conformant devices) 1903c8c91842SAzael Avalos * 3 - Typical 1904e26ffe51SAzael Avalos */ 1905c8c91842SAzael Avalos if (state != 0 && state != 1 && state != 2 && state != 3) 1906e26ffe51SAzael Avalos return -EINVAL; 1907e26ffe51SAzael Avalos 1908e26ffe51SAzael Avalos /* Set the USB charging mode to internal value */ 1909c8c91842SAzael Avalos mode = toshiba->usbsc_mode_base; 1910e26ffe51SAzael Avalos if (state == 0) 1911c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_DISABLED; 1912e26ffe51SAzael Avalos else if (state == 1) 1913c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_ALTERNATE; 1914e26ffe51SAzael Avalos else if (state == 2) 1915c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_AUTO; 1916c8c91842SAzael Avalos else if (state == 3) 1917c8c91842SAzael Avalos mode |= SCI_USB_CHARGE_TYPICAL; 1918e26ffe51SAzael Avalos 1919e26ffe51SAzael Avalos ret = toshiba_usb_sleep_charge_set(toshiba, mode); 1920e26ffe51SAzael Avalos if (ret) 1921e26ffe51SAzael Avalos return ret; 1922e26ffe51SAzael Avalos 1923e26ffe51SAzael Avalos return count; 1924e26ffe51SAzael Avalos } 19250c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_sleep_charge); 1926e26ffe51SAzael Avalos 1927182bcaa5SAzael Avalos static ssize_t sleep_functions_on_battery_show(struct device *dev, 1928182bcaa5SAzael Avalos struct device_attribute *attr, 1929182bcaa5SAzael Avalos char *buf) 1930182bcaa5SAzael Avalos { 1931182bcaa5SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1932182bcaa5SAzael Avalos u32 state; 1933182bcaa5SAzael Avalos int bat_lvl; 1934182bcaa5SAzael Avalos int status; 1935182bcaa5SAzael Avalos int ret; 1936182bcaa5SAzael Avalos int tmp; 1937182bcaa5SAzael Avalos 1938182bcaa5SAzael Avalos ret = toshiba_sleep_functions_status_get(toshiba, &state); 1939182bcaa5SAzael Avalos if (ret < 0) 1940182bcaa5SAzael Avalos return ret; 1941182bcaa5SAzael Avalos 1942182bcaa5SAzael Avalos /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */ 1943182bcaa5SAzael Avalos tmp = state & SCI_USB_CHARGE_BAT_MASK; 1944182bcaa5SAzael Avalos status = (tmp == 0x4) ? 1 : 0; 1945182bcaa5SAzael Avalos /* Determine the battery level set */ 1946182bcaa5SAzael Avalos bat_lvl = state >> HCI_MISC_SHIFT; 1947182bcaa5SAzael Avalos 1948182bcaa5SAzael Avalos return sprintf(buf, "%d %d\n", status, bat_lvl); 1949182bcaa5SAzael Avalos } 1950182bcaa5SAzael Avalos 1951182bcaa5SAzael Avalos static ssize_t sleep_functions_on_battery_store(struct device *dev, 1952182bcaa5SAzael Avalos struct device_attribute *attr, 1953182bcaa5SAzael Avalos const char *buf, size_t count) 1954182bcaa5SAzael Avalos { 1955182bcaa5SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1956182bcaa5SAzael Avalos u32 status; 1957182bcaa5SAzael Avalos int value; 1958182bcaa5SAzael Avalos int ret; 1959182bcaa5SAzael Avalos int tmp; 1960182bcaa5SAzael Avalos 1961182bcaa5SAzael Avalos ret = kstrtoint(buf, 0, &value); 1962182bcaa5SAzael Avalos if (ret) 1963182bcaa5SAzael Avalos return ret; 1964182bcaa5SAzael Avalos 1965e0769fe6SDarren Hart /* 1966e0769fe6SDarren Hart * Set the status of the function: 1967182bcaa5SAzael Avalos * 0 - Disabled 1968182bcaa5SAzael Avalos * 1-100 - Enabled 1969182bcaa5SAzael Avalos */ 1970182bcaa5SAzael Avalos if (value < 0 || value > 100) 1971182bcaa5SAzael Avalos return -EINVAL; 1972182bcaa5SAzael Avalos 1973182bcaa5SAzael Avalos if (value == 0) { 1974182bcaa5SAzael Avalos tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT; 1975182bcaa5SAzael Avalos status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF; 1976182bcaa5SAzael Avalos } else { 1977182bcaa5SAzael Avalos tmp = value << HCI_MISC_SHIFT; 1978182bcaa5SAzael Avalos status = tmp | SCI_USB_CHARGE_BAT_LVL_ON; 1979182bcaa5SAzael Avalos } 1980182bcaa5SAzael Avalos ret = toshiba_sleep_functions_status_set(toshiba, status); 1981182bcaa5SAzael Avalos if (ret < 0) 1982182bcaa5SAzael Avalos return ret; 1983182bcaa5SAzael Avalos 1984182bcaa5SAzael Avalos toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT; 1985182bcaa5SAzael Avalos 1986182bcaa5SAzael Avalos return count; 1987182bcaa5SAzael Avalos } 19880c3c0f10SAzael Avalos static DEVICE_ATTR_RW(sleep_functions_on_battery); 1989182bcaa5SAzael Avalos 19909d309848SAzael Avalos static ssize_t usb_rapid_charge_show(struct device *dev, 19919d309848SAzael Avalos struct device_attribute *attr, char *buf) 1992bb3fe01fSAzael Avalos { 1993bb3fe01fSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 1994bb3fe01fSAzael Avalos u32 state; 1995bb3fe01fSAzael Avalos int ret; 1996bb3fe01fSAzael Avalos 1997bb3fe01fSAzael Avalos ret = toshiba_usb_rapid_charge_get(toshiba, &state); 1998bb3fe01fSAzael Avalos if (ret < 0) 1999bb3fe01fSAzael Avalos return ret; 2000bb3fe01fSAzael Avalos 2001bb3fe01fSAzael Avalos return sprintf(buf, "%d\n", state); 2002bb3fe01fSAzael Avalos } 2003bb3fe01fSAzael Avalos 20049d309848SAzael Avalos static ssize_t usb_rapid_charge_store(struct device *dev, 2005bb3fe01fSAzael Avalos struct device_attribute *attr, 2006bb3fe01fSAzael Avalos const char *buf, size_t count) 2007bb3fe01fSAzael Avalos { 2008bb3fe01fSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2009bb3fe01fSAzael Avalos int state; 2010bb3fe01fSAzael Avalos int ret; 2011bb3fe01fSAzael Avalos 2012bb3fe01fSAzael Avalos ret = kstrtoint(buf, 0, &state); 2013bb3fe01fSAzael Avalos if (ret) 2014bb3fe01fSAzael Avalos return ret; 2015bb3fe01fSAzael Avalos if (state != 0 && state != 1) 2016bb3fe01fSAzael Avalos return -EINVAL; 2017bb3fe01fSAzael Avalos 2018bb3fe01fSAzael Avalos ret = toshiba_usb_rapid_charge_set(toshiba, state); 2019bb3fe01fSAzael Avalos if (ret) 2020bb3fe01fSAzael Avalos return ret; 2021bb3fe01fSAzael Avalos 2022bb3fe01fSAzael Avalos return count; 2023bb3fe01fSAzael Avalos } 20240c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_rapid_charge); 2025bb3fe01fSAzael Avalos 20269d309848SAzael Avalos static ssize_t usb_sleep_music_show(struct device *dev, 20279d309848SAzael Avalos struct device_attribute *attr, char *buf) 2028172ce0a9SAzael Avalos { 2029172ce0a9SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2030172ce0a9SAzael Avalos u32 state; 2031172ce0a9SAzael Avalos int ret; 2032172ce0a9SAzael Avalos 2033172ce0a9SAzael Avalos ret = toshiba_usb_sleep_music_get(toshiba, &state); 2034172ce0a9SAzael Avalos if (ret < 0) 2035172ce0a9SAzael Avalos return ret; 2036172ce0a9SAzael Avalos 2037172ce0a9SAzael Avalos return sprintf(buf, "%d\n", state); 2038172ce0a9SAzael Avalos } 2039172ce0a9SAzael Avalos 20409d309848SAzael Avalos static ssize_t usb_sleep_music_store(struct device *dev, 2041172ce0a9SAzael Avalos struct device_attribute *attr, 2042172ce0a9SAzael Avalos const char *buf, size_t count) 2043172ce0a9SAzael Avalos { 2044172ce0a9SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2045172ce0a9SAzael Avalos int state; 2046172ce0a9SAzael Avalos int ret; 2047172ce0a9SAzael Avalos 2048172ce0a9SAzael Avalos ret = kstrtoint(buf, 0, &state); 2049172ce0a9SAzael Avalos if (ret) 2050172ce0a9SAzael Avalos return ret; 2051172ce0a9SAzael Avalos if (state != 0 && state != 1) 2052172ce0a9SAzael Avalos return -EINVAL; 2053172ce0a9SAzael Avalos 2054172ce0a9SAzael Avalos ret = toshiba_usb_sleep_music_set(toshiba, state); 2055172ce0a9SAzael Avalos if (ret) 2056172ce0a9SAzael Avalos return ret; 2057172ce0a9SAzael Avalos 2058172ce0a9SAzael Avalos return count; 2059172ce0a9SAzael Avalos } 20600c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_sleep_music); 2061172ce0a9SAzael Avalos 20629d309848SAzael Avalos static ssize_t kbd_function_keys_show(struct device *dev, 20639d309848SAzael Avalos struct device_attribute *attr, char *buf) 2064bae84195SAzael Avalos { 2065bae84195SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2066bae84195SAzael Avalos int mode; 2067bae84195SAzael Avalos int ret; 2068bae84195SAzael Avalos 2069bae84195SAzael Avalos ret = toshiba_function_keys_get(toshiba, &mode); 2070bae84195SAzael Avalos if (ret < 0) 2071bae84195SAzael Avalos return ret; 2072bae84195SAzael Avalos 2073bae84195SAzael Avalos return sprintf(buf, "%d\n", mode); 2074bae84195SAzael Avalos } 2075bae84195SAzael Avalos 20769d309848SAzael Avalos static ssize_t kbd_function_keys_store(struct device *dev, 2077bae84195SAzael Avalos struct device_attribute *attr, 2078bae84195SAzael Avalos const char *buf, size_t count) 2079bae84195SAzael Avalos { 2080bae84195SAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 2081bae84195SAzael Avalos int mode; 2082bae84195SAzael Avalos int ret; 2083bae84195SAzael Avalos 2084bae84195SAzael Avalos ret = kstrtoint(buf, 0, &mode); 2085bae84195SAzael Avalos if (ret) 2086bae84195SAzael Avalos return ret; 2087e0769fe6SDarren Hart /* 2088e0769fe6SDarren Hart * Check for the function keys mode where: 2089bae84195SAzael Avalos * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12}) 2090bae84195SAzael Avalos * 1 - Special functions (Opposite of the above setting) 2091bae84195SAzael Avalos */ 2092bae84195SAzael Avalos if (mode != 0 && mode != 1) 2093bae84195SAzael Avalos return -EINVAL; 2094bae84195SAzael Avalos 2095bae84195SAzael Avalos ret = toshiba_function_keys_set(toshiba, mode); 2096bae84195SAzael Avalos if (ret) 2097bae84195SAzael Avalos return ret; 2098bae84195SAzael Avalos 2099bae84195SAzael Avalos pr_info("Reboot for changes to KBD Function Keys to take effect"); 2100bae84195SAzael Avalos 2101bae84195SAzael Avalos return count; 2102bae84195SAzael Avalos } 21030c3c0f10SAzael Avalos static DEVICE_ATTR_RW(kbd_function_keys); 2104bae84195SAzael Avalos 21059d309848SAzael Avalos static ssize_t panel_power_on_show(struct device *dev, 21069d309848SAzael Avalos struct device_attribute *attr, char *buf) 210735d53ceaSAzael Avalos { 210835d53ceaSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 210935d53ceaSAzael Avalos u32 state; 211035d53ceaSAzael Avalos int ret; 211135d53ceaSAzael Avalos 211235d53ceaSAzael Avalos ret = toshiba_panel_power_on_get(toshiba, &state); 211335d53ceaSAzael Avalos if (ret < 0) 211435d53ceaSAzael Avalos return ret; 211535d53ceaSAzael Avalos 211635d53ceaSAzael Avalos return sprintf(buf, "%d\n", state); 211735d53ceaSAzael Avalos } 211835d53ceaSAzael Avalos 21199d309848SAzael Avalos static ssize_t panel_power_on_store(struct device *dev, 212035d53ceaSAzael Avalos struct device_attribute *attr, 212135d53ceaSAzael Avalos const char *buf, size_t count) 212235d53ceaSAzael Avalos { 212335d53ceaSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 212435d53ceaSAzael Avalos int state; 212535d53ceaSAzael Avalos int ret; 212635d53ceaSAzael Avalos 212735d53ceaSAzael Avalos ret = kstrtoint(buf, 0, &state); 212835d53ceaSAzael Avalos if (ret) 212935d53ceaSAzael Avalos return ret; 213035d53ceaSAzael Avalos if (state != 0 && state != 1) 213135d53ceaSAzael Avalos return -EINVAL; 213235d53ceaSAzael Avalos 213335d53ceaSAzael Avalos ret = toshiba_panel_power_on_set(toshiba, state); 213435d53ceaSAzael Avalos if (ret) 213535d53ceaSAzael Avalos return ret; 213635d53ceaSAzael Avalos 213735d53ceaSAzael Avalos pr_info("Reboot for changes to Panel Power ON to take effect"); 213835d53ceaSAzael Avalos 213935d53ceaSAzael Avalos return count; 214035d53ceaSAzael Avalos } 21410c3c0f10SAzael Avalos static DEVICE_ATTR_RW(panel_power_on); 214235d53ceaSAzael Avalos 21439d309848SAzael Avalos static ssize_t usb_three_show(struct device *dev, 21449d309848SAzael Avalos struct device_attribute *attr, char *buf) 214517fe4b3dSAzael Avalos { 214617fe4b3dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 214717fe4b3dSAzael Avalos u32 state; 214817fe4b3dSAzael Avalos int ret; 214917fe4b3dSAzael Avalos 215017fe4b3dSAzael Avalos ret = toshiba_usb_three_get(toshiba, &state); 215117fe4b3dSAzael Avalos if (ret < 0) 215217fe4b3dSAzael Avalos return ret; 215317fe4b3dSAzael Avalos 215417fe4b3dSAzael Avalos return sprintf(buf, "%d\n", state); 215517fe4b3dSAzael Avalos } 215617fe4b3dSAzael Avalos 21579d309848SAzael Avalos static ssize_t usb_three_store(struct device *dev, 215817fe4b3dSAzael Avalos struct device_attribute *attr, 215917fe4b3dSAzael Avalos const char *buf, size_t count) 216017fe4b3dSAzael Avalos { 216117fe4b3dSAzael Avalos struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); 216217fe4b3dSAzael Avalos int state; 216317fe4b3dSAzael Avalos int ret; 216417fe4b3dSAzael Avalos 216517fe4b3dSAzael Avalos ret = kstrtoint(buf, 0, &state); 216617fe4b3dSAzael Avalos if (ret) 216717fe4b3dSAzael Avalos return ret; 2168e0769fe6SDarren Hart /* 2169e0769fe6SDarren Hart * Check for USB 3 mode where: 217017fe4b3dSAzael Avalos * 0 - Disabled (Acts like a USB 2 port, saving power) 217117fe4b3dSAzael Avalos * 1 - Enabled 217217fe4b3dSAzael Avalos */ 217317fe4b3dSAzael Avalos if (state != 0 && state != 1) 217417fe4b3dSAzael Avalos return -EINVAL; 217517fe4b3dSAzael Avalos 217617fe4b3dSAzael Avalos ret = toshiba_usb_three_set(toshiba, state); 217717fe4b3dSAzael Avalos if (ret) 217817fe4b3dSAzael Avalos return ret; 217917fe4b3dSAzael Avalos 218017fe4b3dSAzael Avalos pr_info("Reboot for changes to USB 3 to take effect"); 218117fe4b3dSAzael Avalos 218217fe4b3dSAzael Avalos return count; 218317fe4b3dSAzael Avalos } 21840c3c0f10SAzael Avalos static DEVICE_ATTR_RW(usb_three); 21859bd1213bSAzael Avalos 21869bd1213bSAzael Avalos static struct attribute *toshiba_attributes[] = { 21879bd1213bSAzael Avalos &dev_attr_version.attr, 21889bd1213bSAzael Avalos &dev_attr_fan.attr, 21899bd1213bSAzael Avalos &dev_attr_kbd_backlight_mode.attr, 21909bd1213bSAzael Avalos &dev_attr_kbd_type.attr, 21919bd1213bSAzael Avalos &dev_attr_available_kbd_modes.attr, 21929bd1213bSAzael Avalos &dev_attr_kbd_backlight_timeout.attr, 21939bd1213bSAzael Avalos &dev_attr_touchpad.attr, 21949bd1213bSAzael Avalos &dev_attr_position.attr, 21959bd1213bSAzael Avalos &dev_attr_usb_sleep_charge.attr, 21969bd1213bSAzael Avalos &dev_attr_sleep_functions_on_battery.attr, 21979bd1213bSAzael Avalos &dev_attr_usb_rapid_charge.attr, 21989bd1213bSAzael Avalos &dev_attr_usb_sleep_music.attr, 21999bd1213bSAzael Avalos &dev_attr_kbd_function_keys.attr, 22009bd1213bSAzael Avalos &dev_attr_panel_power_on.attr, 22019bd1213bSAzael Avalos &dev_attr_usb_three.attr, 22029bd1213bSAzael Avalos NULL, 22039bd1213bSAzael Avalos }; 22049bd1213bSAzael Avalos 2205360f0f39SAzael Avalos static umode_t toshiba_sysfs_is_visible(struct kobject *kobj, 2206360f0f39SAzael Avalos struct attribute *attr, int idx) 2207360f0f39SAzael Avalos { 2208360f0f39SAzael Avalos struct device *dev = container_of(kobj, struct device, kobj); 2209360f0f39SAzael Avalos struct toshiba_acpi_dev *drv = dev_get_drvdata(dev); 2210360f0f39SAzael Avalos bool exists = true; 2211360f0f39SAzael Avalos 221294477d4cSAzael Avalos if (attr == &dev_attr_fan.attr) 221394477d4cSAzael Avalos exists = (drv->fan_supported) ? true : false; 221494477d4cSAzael Avalos else if (attr == &dev_attr_kbd_backlight_mode.attr) 2215360f0f39SAzael Avalos exists = (drv->kbd_illum_supported) ? true : false; 2216360f0f39SAzael Avalos else if (attr == &dev_attr_kbd_backlight_timeout.attr) 2217360f0f39SAzael Avalos exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false; 22189d8658acSAzael Avalos else if (attr == &dev_attr_touchpad.attr) 22199d8658acSAzael Avalos exists = (drv->touchpad_supported) ? true : false; 22205a2813e9SAzael Avalos else if (attr == &dev_attr_position.attr) 22215a2813e9SAzael Avalos exists = (drv->accelerometer_supported) ? true : false; 2222e26ffe51SAzael Avalos else if (attr == &dev_attr_usb_sleep_charge.attr) 2223e26ffe51SAzael Avalos exists = (drv->usb_sleep_charge_supported) ? true : false; 2224182bcaa5SAzael Avalos else if (attr == &dev_attr_sleep_functions_on_battery.attr) 2225182bcaa5SAzael Avalos exists = (drv->usb_sleep_charge_supported) ? true : false; 2226bb3fe01fSAzael Avalos else if (attr == &dev_attr_usb_rapid_charge.attr) 2227bb3fe01fSAzael Avalos exists = (drv->usb_rapid_charge_supported) ? true : false; 2228172ce0a9SAzael Avalos else if (attr == &dev_attr_usb_sleep_music.attr) 2229172ce0a9SAzael Avalos exists = (drv->usb_sleep_music_supported) ? true : false; 2230bae84195SAzael Avalos else if (attr == &dev_attr_kbd_function_keys.attr) 2231bae84195SAzael Avalos exists = (drv->kbd_function_keys_supported) ? true : false; 223235d53ceaSAzael Avalos else if (attr == &dev_attr_panel_power_on.attr) 223335d53ceaSAzael Avalos exists = (drv->panel_power_on_supported) ? true : false; 223417fe4b3dSAzael Avalos else if (attr == &dev_attr_usb_three.attr) 223517fe4b3dSAzael Avalos exists = (drv->usb_three_supported) ? true : false; 2236360f0f39SAzael Avalos 2237360f0f39SAzael Avalos return exists ? attr->mode : 0; 2238360f0f39SAzael Avalos } 2239360f0f39SAzael Avalos 22409bd1213bSAzael Avalos static struct attribute_group toshiba_attr_group = { 22419bd1213bSAzael Avalos .is_visible = toshiba_sysfs_is_visible, 22429bd1213bSAzael Avalos .attrs = toshiba_attributes, 22439bd1213bSAzael Avalos }; 22449bd1213bSAzael Avalos 22451f28f290SAzael Avalos /* 2246fc5462f8SAzael Avalos * Misc device 2247fc5462f8SAzael Avalos */ 2248fc5462f8SAzael Avalos static int toshiba_acpi_smm_bridge(SMMRegisters *regs) 2249fc5462f8SAzael Avalos { 2250fc5462f8SAzael Avalos u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx, 2251fc5462f8SAzael Avalos regs->edx, regs->esi, regs->edi }; 2252fc5462f8SAzael Avalos u32 out[TCI_WORDS]; 2253fc5462f8SAzael Avalos acpi_status status; 2254fc5462f8SAzael Avalos 2255fc5462f8SAzael Avalos status = tci_raw(toshiba_acpi, in, out); 2256fc5462f8SAzael Avalos if (ACPI_FAILURE(status)) { 2257fc5462f8SAzael Avalos pr_err("ACPI call to query SMM registers failed\n"); 2258fc5462f8SAzael Avalos return -EIO; 2259fc5462f8SAzael Avalos } 2260fc5462f8SAzael Avalos 2261fc5462f8SAzael Avalos /* Fillout the SMM struct with the TCI call results */ 2262fc5462f8SAzael Avalos regs->eax = out[0]; 2263fc5462f8SAzael Avalos regs->ebx = out[1]; 2264fc5462f8SAzael Avalos regs->ecx = out[2]; 2265fc5462f8SAzael Avalos regs->edx = out[3]; 2266fc5462f8SAzael Avalos regs->esi = out[4]; 2267fc5462f8SAzael Avalos regs->edi = out[5]; 2268fc5462f8SAzael Avalos 2269fc5462f8SAzael Avalos return 0; 2270fc5462f8SAzael Avalos } 2271fc5462f8SAzael Avalos 2272fc5462f8SAzael Avalos static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd, 2273fc5462f8SAzael Avalos unsigned long arg) 2274fc5462f8SAzael Avalos { 2275fc5462f8SAzael Avalos SMMRegisters __user *argp = (SMMRegisters __user *)arg; 2276fc5462f8SAzael Avalos SMMRegisters regs; 2277fc5462f8SAzael Avalos int ret; 2278fc5462f8SAzael Avalos 2279fc5462f8SAzael Avalos if (!argp) 2280fc5462f8SAzael Avalos return -EINVAL; 2281fc5462f8SAzael Avalos 2282fc5462f8SAzael Avalos switch (cmd) { 2283fc5462f8SAzael Avalos case TOSH_SMM: 2284fc5462f8SAzael Avalos if (copy_from_user(®s, argp, sizeof(SMMRegisters))) 2285fc5462f8SAzael Avalos return -EFAULT; 2286fc5462f8SAzael Avalos ret = toshiba_acpi_smm_bridge(®s); 2287fc5462f8SAzael Avalos if (ret) 2288fc5462f8SAzael Avalos return ret; 2289fc5462f8SAzael Avalos if (copy_to_user(argp, ®s, sizeof(SMMRegisters))) 2290fc5462f8SAzael Avalos return -EFAULT; 2291fc5462f8SAzael Avalos break; 2292fc5462f8SAzael Avalos case TOSHIBA_ACPI_SCI: 2293fc5462f8SAzael Avalos if (copy_from_user(®s, argp, sizeof(SMMRegisters))) 2294fc5462f8SAzael Avalos return -EFAULT; 2295fc5462f8SAzael Avalos /* Ensure we are being called with a SCI_{GET, SET} register */ 2296fc5462f8SAzael Avalos if (regs.eax != SCI_GET && regs.eax != SCI_SET) 2297fc5462f8SAzael Avalos return -EINVAL; 2298fc5462f8SAzael Avalos if (!sci_open(toshiba_acpi)) 2299fc5462f8SAzael Avalos return -EIO; 2300fc5462f8SAzael Avalos ret = toshiba_acpi_smm_bridge(®s); 2301fc5462f8SAzael Avalos sci_close(toshiba_acpi); 2302fc5462f8SAzael Avalos if (ret) 2303fc5462f8SAzael Avalos return ret; 2304fc5462f8SAzael Avalos if (copy_to_user(argp, ®s, sizeof(SMMRegisters))) 2305fc5462f8SAzael Avalos return -EFAULT; 2306fc5462f8SAzael Avalos break; 2307fc5462f8SAzael Avalos default: 2308fc5462f8SAzael Avalos return -EINVAL; 2309fc5462f8SAzael Avalos } 2310fc5462f8SAzael Avalos 2311fc5462f8SAzael Avalos return 0; 2312fc5462f8SAzael Avalos } 2313fc5462f8SAzael Avalos 2314fc5462f8SAzael Avalos static const struct file_operations toshiba_acpi_fops = { 2315fc5462f8SAzael Avalos .owner = THIS_MODULE, 2316fc5462f8SAzael Avalos .unlocked_ioctl = toshiba_acpi_ioctl, 2317fc5462f8SAzael Avalos .llseek = noop_llseek, 2318fc5462f8SAzael Avalos }; 2319fc5462f8SAzael Avalos 2320fc5462f8SAzael Avalos /* 23211f28f290SAzael Avalos * Hotkeys 23221f28f290SAzael Avalos */ 23231f28f290SAzael Avalos static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev) 23241f28f290SAzael Avalos { 23251f28f290SAzael Avalos acpi_status status; 23261f28f290SAzael Avalos u32 result; 23271f28f290SAzael Avalos 23281f28f290SAzael Avalos status = acpi_evaluate_object(dev->acpi_dev->handle, 23291f28f290SAzael Avalos "ENAB", NULL, NULL); 23301f28f290SAzael Avalos if (ACPI_FAILURE(status)) 23311f28f290SAzael Avalos return -ENODEV; 23321f28f290SAzael Avalos 2333d37782bdSAzael Avalos result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE); 23341f28f290SAzael Avalos if (result == TOS_FAILURE) 23351f28f290SAzael Avalos return -EIO; 23361f28f290SAzael Avalos else if (result == TOS_NOT_SUPPORTED) 23371f28f290SAzael Avalos return -ENODEV; 23381f28f290SAzael Avalos 23391f28f290SAzael Avalos return 0; 23401f28f290SAzael Avalos } 23411f28f290SAzael Avalos 2342fb42d1f4SAzael Avalos static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev) 2343fb42d1f4SAzael Avalos { 2344fb42d1f4SAzael Avalos u32 result; 2345fb42d1f4SAzael Avalos 2346fb42d1f4SAzael Avalos /* 2347fb42d1f4SAzael Avalos * Re-activate the hotkeys, but this time, we are using the 2348fb42d1f4SAzael Avalos * "Special Functions" mode. 2349fb42d1f4SAzael Avalos */ 2350d37782bdSAzael Avalos result = hci_write(dev, HCI_HOTKEY_EVENT, 2351fb42d1f4SAzael Avalos HCI_HOTKEY_SPECIAL_FUNCTIONS); 2352fb42d1f4SAzael Avalos if (result != TOS_SUCCESS) 2353fb42d1f4SAzael Avalos pr_err("Could not enable the Special Function mode\n"); 2354fb42d1f4SAzael Avalos } 2355fb42d1f4SAzael Avalos 235629cd293fSSeth Forshee static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str, 235729cd293fSSeth Forshee struct serio *port) 235829cd293fSSeth Forshee { 235998280374SGiedrius Statkevičius if (str & I8042_STR_AUXDATA) 236029cd293fSSeth Forshee return false; 236129cd293fSSeth Forshee 236229cd293fSSeth Forshee if (unlikely(data == 0xe0)) 236329cd293fSSeth Forshee return false; 236429cd293fSSeth Forshee 236529cd293fSSeth Forshee if ((data & 0x7f) == TOS1900_FN_SCAN) { 236629cd293fSSeth Forshee schedule_work(&toshiba_acpi->hotkey_work); 236729cd293fSSeth Forshee return true; 236829cd293fSSeth Forshee } 236929cd293fSSeth Forshee 237029cd293fSSeth Forshee return false; 237129cd293fSSeth Forshee } 237229cd293fSSeth Forshee 237329cd293fSSeth Forshee static void toshiba_acpi_hotkey_work(struct work_struct *work) 237429cd293fSSeth Forshee { 237529cd293fSSeth Forshee acpi_handle ec_handle = ec_get_handle(); 237629cd293fSSeth Forshee acpi_status status; 237729cd293fSSeth Forshee 237829cd293fSSeth Forshee if (!ec_handle) 237929cd293fSSeth Forshee return; 238029cd293fSSeth Forshee 238129cd293fSSeth Forshee status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL); 238229cd293fSSeth Forshee if (ACPI_FAILURE(status)) 238329cd293fSSeth Forshee pr_err("ACPI NTFY method execution failed\n"); 238429cd293fSSeth Forshee } 238529cd293fSSeth Forshee 238629cd293fSSeth Forshee /* 238729cd293fSSeth Forshee * Returns hotkey scancode, or < 0 on failure. 238829cd293fSSeth Forshee */ 238929cd293fSSeth Forshee static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev) 239029cd293fSSeth Forshee { 239174facaf7SZhang Rui unsigned long long value; 239229cd293fSSeth Forshee acpi_status status; 239329cd293fSSeth Forshee 239474facaf7SZhang Rui status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO", 239574facaf7SZhang Rui NULL, &value); 239674facaf7SZhang Rui if (ACPI_FAILURE(status)) { 239729cd293fSSeth Forshee pr_err("ACPI INFO method execution failed\n"); 239829cd293fSSeth Forshee return -EIO; 239929cd293fSSeth Forshee } 240029cd293fSSeth Forshee 240174facaf7SZhang Rui return value; 240229cd293fSSeth Forshee } 240329cd293fSSeth Forshee 240429cd293fSSeth Forshee static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev, 240529cd293fSSeth Forshee int scancode) 240629cd293fSSeth Forshee { 240729cd293fSSeth Forshee if (scancode == 0x100) 240829cd293fSSeth Forshee return; 240929cd293fSSeth Forshee 2410e0769fe6SDarren Hart /* Act on key press; ignore key release */ 241129cd293fSSeth Forshee if (scancode & 0x80) 241229cd293fSSeth Forshee return; 241329cd293fSSeth Forshee 241429cd293fSSeth Forshee if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true)) 241529cd293fSSeth Forshee pr_info("Unknown key %x\n", scancode); 241629cd293fSSeth Forshee } 241729cd293fSSeth Forshee 241871454d78SAzael Avalos static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev) 241971454d78SAzael Avalos { 242071454d78SAzael Avalos if (dev->info_supported) { 24217deef550SAzael Avalos int scancode = toshiba_acpi_query_hotkey(dev); 24227deef550SAzael Avalos 24237deef550SAzael Avalos if (scancode < 0) { 242471454d78SAzael Avalos pr_err("Failed to query hotkey event\n"); 24257deef550SAzael Avalos } else if (scancode != 0) { 242671454d78SAzael Avalos toshiba_acpi_report_hotkey(dev, scancode); 24277deef550SAzael Avalos dev->key_event_valid = 1; 24287deef550SAzael Avalos dev->last_key_event = scancode; 24297deef550SAzael Avalos } 243071454d78SAzael Avalos } else if (dev->system_event_supported) { 24317deef550SAzael Avalos u32 result; 24327deef550SAzael Avalos u32 value; 24337deef550SAzael Avalos int retries = 3; 24347deef550SAzael Avalos 243571454d78SAzael Avalos do { 24367deef550SAzael Avalos result = hci_read(dev, HCI_SYSTEM_EVENT, &value); 24377deef550SAzael Avalos switch (result) { 243871454d78SAzael Avalos case TOS_SUCCESS: 243971454d78SAzael Avalos toshiba_acpi_report_hotkey(dev, (int)value); 24407deef550SAzael Avalos dev->key_event_valid = 1; 24417deef550SAzael Avalos dev->last_key_event = value; 244271454d78SAzael Avalos break; 244371454d78SAzael Avalos case TOS_NOT_SUPPORTED: 244471454d78SAzael Avalos /* 244571454d78SAzael Avalos * This is a workaround for an unresolved 244671454d78SAzael Avalos * issue on some machines where system events 244771454d78SAzael Avalos * sporadically become disabled. 244871454d78SAzael Avalos */ 24497deef550SAzael Avalos result = hci_write(dev, HCI_SYSTEM_EVENT, 1); 24507deef550SAzael Avalos if (result == TOS_SUCCESS) 245171454d78SAzael Avalos pr_notice("Re-enabled hotkeys\n"); 2452e0769fe6SDarren Hart /* Fall through */ 245371454d78SAzael Avalos default: 245471454d78SAzael Avalos retries--; 245571454d78SAzael Avalos break; 245671454d78SAzael Avalos } 24577deef550SAzael Avalos } while (retries && result != TOS_FIFO_EMPTY); 245871454d78SAzael Avalos } 245971454d78SAzael Avalos } 246071454d78SAzael Avalos 2461b859f159SGreg Kroah-Hartman static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) 24626335e4d5SMatthew Garrett { 2463fe808bfbSTakashi Iwai const struct key_entry *keymap = toshiba_acpi_keymap; 2464a2b3471bSAzael Avalos acpi_handle ec_handle; 2465a2b3471bSAzael Avalos u32 events_type; 2466a2b3471bSAzael Avalos u32 hci_result; 2467a2b3471bSAzael Avalos int error; 2468a2b3471bSAzael Avalos 2469*a88bc06eSAzael Avalos if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) { 2470*a88bc06eSAzael Avalos pr_info("WMI event detected, hotkeys will not be monitored\n"); 2471*a88bc06eSAzael Avalos return 0; 2472*a88bc06eSAzael Avalos } 2473*a88bc06eSAzael Avalos 2474a2b3471bSAzael Avalos error = toshiba_acpi_enable_hotkeys(dev); 2475a2b3471bSAzael Avalos if (error) 2476a2b3471bSAzael Avalos return error; 2477a2b3471bSAzael Avalos 2478a2b3471bSAzael Avalos error = toshiba_hotkey_event_type_get(dev, &events_type); 2479a2b3471bSAzael Avalos if (error) { 2480a2b3471bSAzael Avalos pr_err("Unable to query Hotkey Event Type\n"); 2481a2b3471bSAzael Avalos return error; 2482a2b3471bSAzael Avalos } 2483a2b3471bSAzael Avalos dev->hotkey_event_type = events_type; 2484135740deSSeth Forshee 2485135740deSSeth Forshee dev->hotkey_dev = input_allocate_device(); 2486b222cca6SJoe Perches if (!dev->hotkey_dev) 2487135740deSSeth Forshee return -ENOMEM; 2488135740deSSeth Forshee 2489135740deSSeth Forshee dev->hotkey_dev->name = "Toshiba input device"; 24906e02cc7eSSeth Forshee dev->hotkey_dev->phys = "toshiba_acpi/input0"; 2491135740deSSeth Forshee dev->hotkey_dev->id.bustype = BUS_HOST; 2492135740deSSeth Forshee 2493a2b3471bSAzael Avalos if (events_type == HCI_SYSTEM_TYPE1 || 2494a2b3471bSAzael Avalos !dev->kbd_function_keys_supported) 2495a2b3471bSAzael Avalos keymap = toshiba_acpi_keymap; 2496a2b3471bSAzael Avalos else if (events_type == HCI_SYSTEM_TYPE2 || 2497a2b3471bSAzael Avalos dev->kbd_function_keys_supported) 2498fe808bfbSTakashi Iwai keymap = toshiba_acpi_alt_keymap; 2499a2b3471bSAzael Avalos else 2500a2b3471bSAzael Avalos pr_info("Unknown event type received %x\n", events_type); 2501fe808bfbSTakashi Iwai error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL); 2502135740deSSeth Forshee if (error) 2503135740deSSeth Forshee goto err_free_dev; 2504135740deSSeth Forshee 250529cd293fSSeth Forshee /* 250629cd293fSSeth Forshee * For some machines the SCI responsible for providing hotkey 250729cd293fSSeth Forshee * notification doesn't fire. We can trigger the notification 250829cd293fSSeth Forshee * whenever the Fn key is pressed using the NTFY method, if 250929cd293fSSeth Forshee * supported, so if it's present set up an i8042 key filter 251029cd293fSSeth Forshee * for this purpose. 251129cd293fSSeth Forshee */ 251229cd293fSSeth Forshee ec_handle = ec_get_handle(); 2513e2e19606SZhang Rui if (ec_handle && acpi_has_method(ec_handle, "NTFY")) { 251429cd293fSSeth Forshee INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work); 251529cd293fSSeth Forshee 251629cd293fSSeth Forshee error = i8042_install_filter(toshiba_acpi_i8042_filter); 251729cd293fSSeth Forshee if (error) { 251829cd293fSSeth Forshee pr_err("Error installing key filter\n"); 251929cd293fSSeth Forshee goto err_free_keymap; 252029cd293fSSeth Forshee } 252129cd293fSSeth Forshee 252229cd293fSSeth Forshee dev->ntfy_supported = 1; 252329cd293fSSeth Forshee } 252429cd293fSSeth Forshee 252529cd293fSSeth Forshee /* 252629cd293fSSeth Forshee * Determine hotkey query interface. Prefer using the INFO 252729cd293fSSeth Forshee * method when it is available. 252829cd293fSSeth Forshee */ 2529e2e19606SZhang Rui if (acpi_has_method(dev->acpi_dev->handle, "INFO")) 253029cd293fSSeth Forshee dev->info_supported = 1; 2531e2e19606SZhang Rui else { 2532d37782bdSAzael Avalos hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1); 25331864bbc2SAzael Avalos if (hci_result == TOS_SUCCESS) 253429cd293fSSeth Forshee dev->system_event_supported = 1; 253529cd293fSSeth Forshee } 253629cd293fSSeth Forshee 253729cd293fSSeth Forshee if (!dev->info_supported && !dev->system_event_supported) { 253829cd293fSSeth Forshee pr_warn("No hotkey query interface found\n"); 253929cd293fSSeth Forshee goto err_remove_filter; 254029cd293fSSeth Forshee } 254129cd293fSSeth Forshee 2542135740deSSeth Forshee error = input_register_device(dev->hotkey_dev); 2543135740deSSeth Forshee if (error) { 2544135740deSSeth Forshee pr_info("Unable to register input device\n"); 254529cd293fSSeth Forshee goto err_remove_filter; 2546135740deSSeth Forshee } 2547135740deSSeth Forshee 2548135740deSSeth Forshee return 0; 2549135740deSSeth Forshee 255029cd293fSSeth Forshee err_remove_filter: 255129cd293fSSeth Forshee if (dev->ntfy_supported) 255229cd293fSSeth Forshee i8042_remove_filter(toshiba_acpi_i8042_filter); 2553135740deSSeth Forshee err_free_keymap: 2554135740deSSeth Forshee sparse_keymap_free(dev->hotkey_dev); 2555135740deSSeth Forshee err_free_dev: 2556135740deSSeth Forshee input_free_device(dev->hotkey_dev); 2557135740deSSeth Forshee dev->hotkey_dev = NULL; 2558135740deSSeth Forshee return error; 2559135740deSSeth Forshee } 2560135740deSSeth Forshee 2561b859f159SGreg Kroah-Hartman static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev) 256262cce752SSeth Forshee { 256362cce752SSeth Forshee struct backlight_properties props; 256462cce752SSeth Forshee int brightness; 256562cce752SSeth Forshee int ret; 2566121b7b0dSAkio Idehara bool enabled; 256762cce752SSeth Forshee 256862cce752SSeth Forshee /* 256962cce752SSeth Forshee * Some machines don't support the backlight methods at all, and 257062cce752SSeth Forshee * others support it read-only. Either of these is pretty useless, 257162cce752SSeth Forshee * so only register the backlight device if the backlight method 257262cce752SSeth Forshee * supports both reads and writes. 257362cce752SSeth Forshee */ 257462cce752SSeth Forshee brightness = __get_lcd_brightness(dev); 257562cce752SSeth Forshee if (brightness < 0) 257662cce752SSeth Forshee return 0; 257762cce752SSeth Forshee ret = set_lcd_brightness(dev, brightness); 257862cce752SSeth Forshee if (ret) { 257962cce752SSeth Forshee pr_debug("Backlight method is read-only, disabling backlight support\n"); 258062cce752SSeth Forshee return 0; 258162cce752SSeth Forshee } 258262cce752SSeth Forshee 2583121b7b0dSAkio Idehara /* Determine whether or not BIOS supports transflective backlight */ 2584121b7b0dSAkio Idehara ret = get_tr_backlight_status(dev, &enabled); 2585121b7b0dSAkio Idehara dev->tr_backlight_supported = !ret; 2586121b7b0dSAkio Idehara 2587358d6a2cSHans de Goede /* 2588358d6a2cSHans de Goede * Tell acpi-video-detect code to prefer vendor backlight on all 2589358d6a2cSHans de Goede * systems with transflective backlight and on dmi matched systems. 2590358d6a2cSHans de Goede */ 2591358d6a2cSHans de Goede if (dev->tr_backlight_supported || 2592358d6a2cSHans de Goede dmi_check_system(toshiba_vendor_backlight_dmi)) 2593234b7cf8SHans de Goede acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); 2594358d6a2cSHans de Goede 2595234b7cf8SHans de Goede if (acpi_video_get_backlight_type() != acpi_backlight_vendor) 2596358d6a2cSHans de Goede return 0; 2597358d6a2cSHans de Goede 259853039f22SMatthew Garrett memset(&props, 0, sizeof(props)); 259962cce752SSeth Forshee props.type = BACKLIGHT_PLATFORM; 260062cce752SSeth Forshee props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; 260162cce752SSeth Forshee 2602e0769fe6SDarren Hart /* Adding an extra level and having 0 change to transflective mode */ 2603121b7b0dSAkio Idehara if (dev->tr_backlight_supported) 2604121b7b0dSAkio Idehara props.max_brightness++; 2605121b7b0dSAkio Idehara 260662cce752SSeth Forshee dev->backlight_dev = backlight_device_register("toshiba", 260762cce752SSeth Forshee &dev->acpi_dev->dev, 260862cce752SSeth Forshee dev, 260962cce752SSeth Forshee &toshiba_backlight_data, 261062cce752SSeth Forshee &props); 261162cce752SSeth Forshee if (IS_ERR(dev->backlight_dev)) { 261262cce752SSeth Forshee ret = PTR_ERR(dev->backlight_dev); 261362cce752SSeth Forshee pr_err("Could not register toshiba backlight device\n"); 261462cce752SSeth Forshee dev->backlight_dev = NULL; 261562cce752SSeth Forshee return ret; 261662cce752SSeth Forshee } 261762cce752SSeth Forshee 261862cce752SSeth Forshee dev->backlight_dev->props.brightness = brightness; 261962cce752SSeth Forshee return 0; 262062cce752SSeth Forshee } 262162cce752SSeth Forshee 262251fac838SRafael J. Wysocki static int toshiba_acpi_remove(struct acpi_device *acpi_dev) 2623135740deSSeth Forshee { 2624135740deSSeth Forshee struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); 2625135740deSSeth Forshee 2626fc5462f8SAzael Avalos misc_deregister(&dev->miscdev); 2627fc5462f8SAzael Avalos 262836d03f93SSeth Forshee remove_toshiba_proc_entries(dev); 2629135740deSSeth Forshee 2630360f0f39SAzael Avalos if (dev->sysfs_created) 2631360f0f39SAzael Avalos sysfs_remove_group(&dev->acpi_dev->dev.kobj, 2632360f0f39SAzael Avalos &toshiba_attr_group); 2633360f0f39SAzael Avalos 263429cd293fSSeth Forshee if (dev->ntfy_supported) { 263529cd293fSSeth Forshee i8042_remove_filter(toshiba_acpi_i8042_filter); 263629cd293fSSeth Forshee cancel_work_sync(&dev->hotkey_work); 263729cd293fSSeth Forshee } 263829cd293fSSeth Forshee 2639135740deSSeth Forshee if (dev->hotkey_dev) { 2640135740deSSeth Forshee input_unregister_device(dev->hotkey_dev); 2641135740deSSeth Forshee sparse_keymap_free(dev->hotkey_dev); 2642135740deSSeth Forshee } 2643135740deSSeth Forshee 2644135740deSSeth Forshee backlight_device_unregister(dev->backlight_dev); 2645135740deSSeth Forshee 264636d03f93SSeth Forshee if (dev->illumination_supported) 2647135740deSSeth Forshee led_classdev_unregister(&dev->led_dev); 2648135740deSSeth Forshee 2649360f0f39SAzael Avalos if (dev->kbd_led_registered) 2650360f0f39SAzael Avalos led_classdev_unregister(&dev->kbd_led); 2651360f0f39SAzael Avalos 2652def6c4e2SAzael Avalos if (dev->eco_supported) 2653def6c4e2SAzael Avalos led_classdev_unregister(&dev->eco_led); 2654def6c4e2SAzael Avalos 265529cd293fSSeth Forshee if (toshiba_acpi) 265629cd293fSSeth Forshee toshiba_acpi = NULL; 265729cd293fSSeth Forshee 2658135740deSSeth Forshee kfree(dev); 2659135740deSSeth Forshee 2660135740deSSeth Forshee return 0; 2661135740deSSeth Forshee } 2662135740deSSeth Forshee 2663b859f159SGreg Kroah-Hartman static const char *find_hci_method(acpi_handle handle) 2664a540d6b5SSeth Forshee { 2665e2e19606SZhang Rui if (acpi_has_method(handle, "GHCI")) 2666a540d6b5SSeth Forshee return "GHCI"; 2667a540d6b5SSeth Forshee 2668e2e19606SZhang Rui if (acpi_has_method(handle, "SPFC")) 2669a540d6b5SSeth Forshee return "SPFC"; 2670a540d6b5SSeth Forshee 2671a540d6b5SSeth Forshee return NULL; 2672a540d6b5SSeth Forshee } 2673a540d6b5SSeth Forshee 2674b859f159SGreg Kroah-Hartman static int toshiba_acpi_add(struct acpi_device *acpi_dev) 2675135740deSSeth Forshee { 2676135740deSSeth Forshee struct toshiba_acpi_dev *dev; 2677a540d6b5SSeth Forshee const char *hci_method; 2678fb42d1f4SAzael Avalos u32 special_functions; 267936d03f93SSeth Forshee u32 dummy; 2680135740deSSeth Forshee int ret = 0; 2681135740deSSeth Forshee 268229cd293fSSeth Forshee if (toshiba_acpi) 268329cd293fSSeth Forshee return -EBUSY; 268429cd293fSSeth Forshee 2685135740deSSeth Forshee pr_info("Toshiba Laptop ACPI Extras version %s\n", 2686135740deSSeth Forshee TOSHIBA_ACPI_VERSION); 2687135740deSSeth Forshee 2688a540d6b5SSeth Forshee hci_method = find_hci_method(acpi_dev->handle); 2689a540d6b5SSeth Forshee if (!hci_method) { 2690a540d6b5SSeth Forshee pr_err("HCI interface not found\n"); 26916e02cc7eSSeth Forshee return -ENODEV; 2692a540d6b5SSeth Forshee } 26936e02cc7eSSeth Forshee 2694135740deSSeth Forshee dev = kzalloc(sizeof(*dev), GFP_KERNEL); 2695135740deSSeth Forshee if (!dev) 2696135740deSSeth Forshee return -ENOMEM; 2697135740deSSeth Forshee dev->acpi_dev = acpi_dev; 2698a540d6b5SSeth Forshee dev->method_hci = hci_method; 2699fc5462f8SAzael Avalos dev->miscdev.minor = MISC_DYNAMIC_MINOR; 2700fc5462f8SAzael Avalos dev->miscdev.name = "toshiba_acpi"; 2701fc5462f8SAzael Avalos dev->miscdev.fops = &toshiba_acpi_fops; 2702fc5462f8SAzael Avalos 2703fc5462f8SAzael Avalos ret = misc_register(&dev->miscdev); 2704fc5462f8SAzael Avalos if (ret) { 2705fc5462f8SAzael Avalos pr_err("Failed to register miscdevice\n"); 2706fc5462f8SAzael Avalos kfree(dev); 2707fc5462f8SAzael Avalos return ret; 2708fc5462f8SAzael Avalos } 2709fc5462f8SAzael Avalos 2710135740deSSeth Forshee acpi_dev->driver_data = dev; 2711360f0f39SAzael Avalos dev_set_drvdata(&acpi_dev->dev, dev); 2712135740deSSeth Forshee 2713a2b3471bSAzael Avalos /* Query the BIOS for supported features */ 2714a2b3471bSAzael Avalos 2715a2b3471bSAzael Avalos /* 2716a2b3471bSAzael Avalos * The "Special Functions" are always supported by the laptops 2717a2b3471bSAzael Avalos * with the new keyboard layout, query for its presence to help 2718a2b3471bSAzael Avalos * determine the keymap layout to use. 2719a2b3471bSAzael Avalos */ 2720fb42d1f4SAzael Avalos ret = toshiba_function_keys_get(dev, &special_functions); 2721a2b3471bSAzael Avalos dev->kbd_function_keys_supported = !ret; 2722a2b3471bSAzael Avalos 27236e02cc7eSSeth Forshee if (toshiba_acpi_setup_keyboard(dev)) 2724135740deSSeth Forshee pr_info("Unable to activate hotkeys\n"); 2725135740deSSeth Forshee 272662cce752SSeth Forshee ret = toshiba_acpi_setup_backlight(dev); 272762cce752SSeth Forshee if (ret) 2728135740deSSeth Forshee goto error; 2729135740deSSeth Forshee 2730135740deSSeth Forshee if (toshiba_illumination_available(dev)) { 2731135740deSSeth Forshee dev->led_dev.name = "toshiba::illumination"; 2732135740deSSeth Forshee dev->led_dev.max_brightness = 1; 2733135740deSSeth Forshee dev->led_dev.brightness_set = toshiba_illumination_set; 2734135740deSSeth Forshee dev->led_dev.brightness_get = toshiba_illumination_get; 2735135740deSSeth Forshee if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev)) 273636d03f93SSeth Forshee dev->illumination_supported = 1; 2737135740deSSeth Forshee } 2738135740deSSeth Forshee 2739def6c4e2SAzael Avalos if (toshiba_eco_mode_available(dev)) { 2740def6c4e2SAzael Avalos dev->eco_led.name = "toshiba::eco_mode"; 2741def6c4e2SAzael Avalos dev->eco_led.max_brightness = 1; 2742def6c4e2SAzael Avalos dev->eco_led.brightness_set = toshiba_eco_mode_set_status; 2743def6c4e2SAzael Avalos dev->eco_led.brightness_get = toshiba_eco_mode_get_status; 2744def6c4e2SAzael Avalos if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led)) 2745def6c4e2SAzael Avalos dev->eco_supported = 1; 2746def6c4e2SAzael Avalos } 2747def6c4e2SAzael Avalos 274893f8c16dSAzael Avalos dev->kbd_illum_supported = toshiba_kbd_illum_available(dev); 2749360f0f39SAzael Avalos /* 2750360f0f39SAzael Avalos * Only register the LED if KBD illumination is supported 2751360f0f39SAzael Avalos * and the keyboard backlight operation mode is set to FN-Z 2752360f0f39SAzael Avalos */ 2753360f0f39SAzael Avalos if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) { 2754360f0f39SAzael Avalos dev->kbd_led.name = "toshiba::kbd_backlight"; 2755360f0f39SAzael Avalos dev->kbd_led.max_brightness = 1; 2756360f0f39SAzael Avalos dev->kbd_led.brightness_set = toshiba_kbd_backlight_set; 2757360f0f39SAzael Avalos dev->kbd_led.brightness_get = toshiba_kbd_backlight_get; 2758360f0f39SAzael Avalos if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led)) 2759360f0f39SAzael Avalos dev->kbd_led_registered = 1; 2760360f0f39SAzael Avalos } 2761360f0f39SAzael Avalos 27629d8658acSAzael Avalos ret = toshiba_touchpad_get(dev, &dummy); 27639d8658acSAzael Avalos dev->touchpad_supported = !ret; 27649d8658acSAzael Avalos 27655a2813e9SAzael Avalos ret = toshiba_accelerometer_supported(dev); 27665a2813e9SAzael Avalos dev->accelerometer_supported = !ret; 27675a2813e9SAzael Avalos 2768c8c91842SAzael Avalos toshiba_usb_sleep_charge_available(dev); 2769e26ffe51SAzael Avalos 2770bb3fe01fSAzael Avalos ret = toshiba_usb_rapid_charge_get(dev, &dummy); 2771bb3fe01fSAzael Avalos dev->usb_rapid_charge_supported = !ret; 2772bb3fe01fSAzael Avalos 2773172ce0a9SAzael Avalos ret = toshiba_usb_sleep_music_get(dev, &dummy); 2774172ce0a9SAzael Avalos dev->usb_sleep_music_supported = !ret; 2775172ce0a9SAzael Avalos 277635d53ceaSAzael Avalos ret = toshiba_panel_power_on_get(dev, &dummy); 277735d53ceaSAzael Avalos dev->panel_power_on_supported = !ret; 277835d53ceaSAzael Avalos 277917fe4b3dSAzael Avalos ret = toshiba_usb_three_get(dev, &dummy); 278017fe4b3dSAzael Avalos dev->usb_three_supported = !ret; 278117fe4b3dSAzael Avalos 278236d03f93SSeth Forshee ret = get_video_status(dev, &dummy); 278336d03f93SSeth Forshee dev->video_supported = !ret; 278436d03f93SSeth Forshee 278536d03f93SSeth Forshee ret = get_fan_status(dev, &dummy); 278636d03f93SSeth Forshee dev->fan_supported = !ret; 278736d03f93SSeth Forshee 2788fb42d1f4SAzael Avalos /* 2789fb42d1f4SAzael Avalos * Enable the "Special Functions" mode only if they are 2790fb42d1f4SAzael Avalos * supported and if they are activated. 2791fb42d1f4SAzael Avalos */ 2792fb42d1f4SAzael Avalos if (dev->kbd_function_keys_supported && special_functions) 2793fb42d1f4SAzael Avalos toshiba_acpi_enable_special_functions(dev); 2794fb42d1f4SAzael Avalos 2795360f0f39SAzael Avalos ret = sysfs_create_group(&dev->acpi_dev->dev.kobj, 2796360f0f39SAzael Avalos &toshiba_attr_group); 2797360f0f39SAzael Avalos if (ret) { 2798360f0f39SAzael Avalos dev->sysfs_created = 0; 2799360f0f39SAzael Avalos goto error; 2800360f0f39SAzael Avalos } 2801360f0f39SAzael Avalos dev->sysfs_created = !ret; 2802360f0f39SAzael Avalos 280336d03f93SSeth Forshee create_toshiba_proc_entries(dev); 280436d03f93SSeth Forshee 280529cd293fSSeth Forshee toshiba_acpi = dev; 280629cd293fSSeth Forshee 2807135740deSSeth Forshee return 0; 2808135740deSSeth Forshee 2809135740deSSeth Forshee error: 281051fac838SRafael J. Wysocki toshiba_acpi_remove(acpi_dev); 2811135740deSSeth Forshee return ret; 2812135740deSSeth Forshee } 2813135740deSSeth Forshee 2814135740deSSeth Forshee static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) 2815135740deSSeth Forshee { 2816135740deSSeth Forshee struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); 281780546905SAzael Avalos int ret; 28186335e4d5SMatthew Garrett 281971454d78SAzael Avalos switch (event) { 282071454d78SAzael Avalos case 0x80: /* Hotkeys and some system events */ 2821*a88bc06eSAzael Avalos /* 2822*a88bc06eSAzael Avalos * Machines with this WMI GUID aren't supported due to bugs in 2823*a88bc06eSAzael Avalos * their AML. 2824*a88bc06eSAzael Avalos * 2825*a88bc06eSAzael Avalos * Return silently to avoid triggering a netlink event. 2826*a88bc06eSAzael Avalos */ 2827*a88bc06eSAzael Avalos if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) 2828*a88bc06eSAzael Avalos return; 282971454d78SAzael Avalos toshiba_acpi_process_hotkeys(dev); 283011948b93SSeth Forshee break; 2831bab09e23SAzael Avalos case 0x81: /* Dock events */ 2832bab09e23SAzael Avalos case 0x82: 2833bab09e23SAzael Avalos case 0x83: 2834bab09e23SAzael Avalos pr_info("Dock event received %x\n", event); 2835bab09e23SAzael Avalos break; 2836bab09e23SAzael Avalos case 0x88: /* Thermal events */ 2837bab09e23SAzael Avalos pr_info("Thermal event received\n"); 2838bab09e23SAzael Avalos break; 2839bab09e23SAzael Avalos case 0x8f: /* LID closed */ 2840bab09e23SAzael Avalos case 0x90: /* LID is closed and Dock has been ejected */ 2841bab09e23SAzael Avalos break; 2842bab09e23SAzael Avalos case 0x8c: /* SATA power events */ 2843bab09e23SAzael Avalos case 0x8b: 2844bab09e23SAzael Avalos pr_info("SATA power event received %x\n", event); 2845bab09e23SAzael Avalos break; 284680546905SAzael Avalos case 0x92: /* Keyboard backlight mode changed */ 284780546905SAzael Avalos /* Update sysfs entries */ 284880546905SAzael Avalos ret = sysfs_update_group(&acpi_dev->dev.kobj, 284980546905SAzael Avalos &toshiba_attr_group); 285080546905SAzael Avalos if (ret) 285180546905SAzael Avalos pr_err("Unable to update sysfs entries\n"); 285280546905SAzael Avalos break; 2853bab09e23SAzael Avalos case 0x85: /* Unknown */ 2854bab09e23SAzael Avalos case 0x8d: /* Unknown */ 285571454d78SAzael Avalos case 0x8e: /* Unknown */ 2856bab09e23SAzael Avalos case 0x94: /* Unknown */ 2857bab09e23SAzael Avalos case 0x95: /* Unknown */ 285811948b93SSeth Forshee default: 285971454d78SAzael Avalos pr_info("Unknown event received %x\n", event); 286011948b93SSeth Forshee break; 28616335e4d5SMatthew Garrett } 2862bab09e23SAzael Avalos 2863bab09e23SAzael Avalos acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class, 2864bab09e23SAzael Avalos dev_name(&acpi_dev->dev), 2865bab09e23SAzael Avalos event, 0); 286629cd293fSSeth Forshee } 28676335e4d5SMatthew Garrett 28683567a4e2SRafael J. Wysocki #ifdef CONFIG_PM_SLEEP 286943d2fd3bSRafael J. Wysocki static int toshiba_acpi_suspend(struct device *device) 287029cd293fSSeth Forshee { 287143d2fd3bSRafael J. Wysocki struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); 287229cd293fSSeth Forshee u32 result; 287329cd293fSSeth Forshee 287429cd293fSSeth Forshee if (dev->hotkey_dev) 2875d37782bdSAzael Avalos result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE); 287629cd293fSSeth Forshee 287729cd293fSSeth Forshee return 0; 287829cd293fSSeth Forshee } 287929cd293fSSeth Forshee 288043d2fd3bSRafael J. Wysocki static int toshiba_acpi_resume(struct device *device) 288129cd293fSSeth Forshee { 288243d2fd3bSRafael J. Wysocki struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); 28831f28f290SAzael Avalos int error; 288429cd293fSSeth Forshee 2885e7fdb762SBenjamin Tissoires if (dev->hotkey_dev) { 28861f28f290SAzael Avalos error = toshiba_acpi_enable_hotkeys(dev); 28871f28f290SAzael Avalos if (error) 2888e7fdb762SBenjamin Tissoires pr_info("Unable to re-enable hotkeys\n"); 2889e7fdb762SBenjamin Tissoires } 289029cd293fSSeth Forshee 289129cd293fSSeth Forshee return 0; 289229cd293fSSeth Forshee } 28933567a4e2SRafael J. Wysocki #endif 28946335e4d5SMatthew Garrett 289543d2fd3bSRafael J. Wysocki static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm, 289643d2fd3bSRafael J. Wysocki toshiba_acpi_suspend, toshiba_acpi_resume); 289743d2fd3bSRafael J. Wysocki 2898135740deSSeth Forshee static struct acpi_driver toshiba_acpi_driver = { 2899135740deSSeth Forshee .name = "Toshiba ACPI driver", 2900135740deSSeth Forshee .owner = THIS_MODULE, 2901135740deSSeth Forshee .ids = toshiba_device_ids, 2902135740deSSeth Forshee .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, 2903135740deSSeth Forshee .ops = { 2904135740deSSeth Forshee .add = toshiba_acpi_add, 2905135740deSSeth Forshee .remove = toshiba_acpi_remove, 2906135740deSSeth Forshee .notify = toshiba_acpi_notify, 2907135740deSSeth Forshee }, 290843d2fd3bSRafael J. Wysocki .drv.pm = &toshiba_acpi_pm, 2909135740deSSeth Forshee }; 2910b4f9fe12SLen Brown 2911b4f9fe12SLen Brown static int __init toshiba_acpi_init(void) 2912b4f9fe12SLen Brown { 2913135740deSSeth Forshee int ret; 2914b4f9fe12SLen Brown 2915b4f9fe12SLen Brown toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir); 2916b4f9fe12SLen Brown if (!toshiba_proc_dir) { 2917135740deSSeth Forshee pr_err("Unable to create proc dir " PROC_TOSHIBA "\n"); 2918b4f9fe12SLen Brown return -ENODEV; 2919b4f9fe12SLen Brown } 2920b4f9fe12SLen Brown 2921135740deSSeth Forshee ret = acpi_bus_register_driver(&toshiba_acpi_driver); 2922b4f9fe12SLen Brown if (ret) { 2923135740deSSeth Forshee pr_err("Failed to register ACPI driver: %d\n", ret); 2924135740deSSeth Forshee remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 2925135740deSSeth Forshee } 2926135740deSSeth Forshee 2927b4f9fe12SLen Brown return ret; 2928b4f9fe12SLen Brown } 2929b4f9fe12SLen Brown 2930135740deSSeth Forshee static void __exit toshiba_acpi_exit(void) 2931135740deSSeth Forshee { 2932135740deSSeth Forshee acpi_bus_unregister_driver(&toshiba_acpi_driver); 2933135740deSSeth Forshee if (toshiba_proc_dir) 2934135740deSSeth Forshee remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 2935b4f9fe12SLen Brown } 2936b4f9fe12SLen Brown 2937b4f9fe12SLen Brown module_init(toshiba_acpi_init); 2938b4f9fe12SLen Brown module_exit(toshiba_acpi_exit); 2939