Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * toshiba_acpi.c - Toshiba Laptop ACPI Extras |
| 3 | * |
| 4 | * |
| 5 | * Copyright (C) 2002-2004 John Belmonte |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 6 | * Copyright (C) 2008 Philip Langdale |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 7 | * Copyright (C) 2010 Pierre Ducroquet |
Azael Avalos | 548c430 | 2014-03-25 20:38:35 -0600 | [diff] [blame] | 8 | * Copyright (C) 2014 Azael Avalos |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | * |
| 25 | * The devolpment page for this driver is located at |
| 26 | * http://memebeam.org/toys/ToshibaAcpiDriver. |
| 27 | * |
| 28 | * Credits: |
| 29 | * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse |
| 30 | * engineering the Windows drivers |
| 31 | * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5 |
| 32 | * Rob Miller - TV out and hotkeys help |
| 33 | * |
| 34 | * |
| 35 | * TODO |
| 36 | * |
| 37 | */ |
| 38 | |
Joe Perches | 7e33460 | 2011-03-29 15:21:52 -0700 | [diff] [blame] | 39 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 40 | |
Azael Avalos | 548c430 | 2014-03-25 20:38:35 -0600 | [diff] [blame] | 41 | #define TOSHIBA_ACPI_VERSION "0.20" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #define PROC_INTERFACE_VERSION 1 |
| 43 | |
| 44 | #include <linux/kernel.h> |
| 45 | #include <linux/module.h> |
| 46 | #include <linux/init.h> |
| 47 | #include <linux/types.h> |
| 48 | #include <linux/proc_fs.h> |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 49 | #include <linux/seq_file.h> |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 50 | #include <linux/backlight.h> |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 51 | #include <linux/rfkill.h> |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 52 | #include <linux/input.h> |
Dmitry Torokhov | 384a7cd | 2010-08-04 22:30:19 -0700 | [diff] [blame] | 53 | #include <linux/input/sparse-keymap.h> |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 54 | #include <linux/leds.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 55 | #include <linux/slab.h> |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 56 | #include <linux/workqueue.h> |
| 57 | #include <linux/i8042.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 58 | #include <linux/acpi.h> |
Takashi Iwai | fe808bfb | 2014-04-29 15:15:38 +0200 | [diff] [blame] | 59 | #include <linux/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include <asm/uaccess.h> |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | MODULE_AUTHOR("John Belmonte"); |
| 63 | MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver"); |
| 64 | MODULE_LICENSE("GPL"); |
| 65 | |
Seth Forshee | f11f999 | 2012-01-18 13:44:11 -0600 | [diff] [blame] | 66 | #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100" |
| 67 | |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 68 | /* Scan code for Fn key on TOS1900 models */ |
| 69 | #define TOS1900_FN_SCAN 0x6e |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* Toshiba ACPI method paths */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX" |
| 73 | |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 74 | /* The Toshiba configuration interface is composed of the HCI and the SCI, |
| 75 | * which are defined as follows: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | * |
| 77 | * HCI is Toshiba's "Hardware Control Interface" which is supposed to |
| 78 | * be uniform across all their models. Ideally we would just call |
| 79 | * dedicated ACPI methods instead of using this primitive interface. |
| 80 | * However the ACPI methods seem to be incomplete in some areas (for |
| 81 | * example they allow setting, but not reading, the LCD brightness value), |
| 82 | * so this is still useful. |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 83 | * |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 84 | * SCI stands for "System Configuration Interface" which aim is to |
| 85 | * conceal differences in hardware between different models. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | */ |
| 87 | |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 88 | #define TCI_WORDS 6 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | /* operations */ |
| 91 | #define HCI_SET 0xff00 |
| 92 | #define HCI_GET 0xfe00 |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 93 | #define SCI_OPEN 0xf100 |
| 94 | #define SCI_CLOSE 0xf200 |
| 95 | #define SCI_GET 0xf300 |
| 96 | #define SCI_SET 0xf400 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | /* return codes */ |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 99 | #define TOS_SUCCESS 0x0000 |
| 100 | #define TOS_OPEN_CLOSE_OK 0x0044 |
| 101 | #define TOS_FAILURE 0x1000 |
| 102 | #define TOS_NOT_SUPPORTED 0x8000 |
| 103 | #define TOS_ALREADY_OPEN 0x8100 |
| 104 | #define TOS_NOT_OPENED 0x8200 |
| 105 | #define TOS_INPUT_DATA_ERROR 0x8300 |
| 106 | #define TOS_WRITE_PROTECTED 0x8400 |
| 107 | #define TOS_NOT_PRESENT 0x8600 |
| 108 | #define TOS_FIFO_EMPTY 0x8c00 |
| 109 | #define TOS_DATA_NOT_AVAILABLE 0x8d20 |
| 110 | #define TOS_NOT_INITIALIZED 0x8d50 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | /* registers */ |
| 113 | #define HCI_FAN 0x0004 |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 114 | #define HCI_TR_BACKLIGHT 0x0005 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #define HCI_SYSTEM_EVENT 0x0016 |
| 116 | #define HCI_VIDEO_OUT 0x001c |
| 117 | #define HCI_HOTKEY_EVENT 0x001e |
| 118 | #define HCI_LCD_BRIGHTNESS 0x002a |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 119 | #define HCI_WIRELESS 0x0056 |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 120 | #define HCI_ACCELEROMETER 0x006d |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 121 | #define HCI_KBD_ILLUMINATION 0x0095 |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 122 | #define HCI_ECO_MODE 0x0097 |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 123 | #define HCI_ACCELEROMETER2 0x00a6 |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 124 | #define SCI_ILLUMINATION 0x014e |
Azael Avalos | e26ffe5 | 2015-01-18 18:30:22 -0700 | [diff] [blame] | 125 | #define SCI_USB_SLEEP_CHARGE 0x0150 |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 126 | #define SCI_KBD_ILLUM_STATUS 0x015c |
Azael Avalos | 172ce0a | 2015-01-18 18:30:25 -0700 | [diff] [blame^] | 127 | #define SCI_USB_SLEEP_MUSIC 0x015e |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 128 | #define SCI_TOUCHPAD 0x050e |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | /* field definitions */ |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 131 | #define HCI_ACCEL_MASK 0x7fff |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 132 | #define HCI_HOTKEY_DISABLE 0x0b |
| 133 | #define HCI_HOTKEY_ENABLE 0x09 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | #define HCI_LCD_BRIGHTNESS_BITS 3 |
| 135 | #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS) |
| 136 | #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS) |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 137 | #define HCI_MISC_SHIFT 0x10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #define HCI_VIDEO_OUT_LCD 0x1 |
| 139 | #define HCI_VIDEO_OUT_CRT 0x2 |
| 140 | #define HCI_VIDEO_OUT_TV 0x4 |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 141 | #define HCI_WIRELESS_KILL_SWITCH 0x01 |
| 142 | #define HCI_WIRELESS_BT_PRESENT 0x0f |
| 143 | #define HCI_WIRELESS_BT_ATTACH 0x40 |
| 144 | #define HCI_WIRELESS_BT_POWER 0x80 |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 145 | #define SCI_KBD_MODE_MASK 0x1f |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 146 | #define SCI_KBD_MODE_FNZ 0x1 |
| 147 | #define SCI_KBD_MODE_AUTO 0x2 |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 148 | #define SCI_KBD_MODE_ON 0x8 |
| 149 | #define SCI_KBD_MODE_OFF 0x10 |
| 150 | #define SCI_KBD_TIME_MAX 0x3c001a |
Azael Avalos | e26ffe5 | 2015-01-18 18:30:22 -0700 | [diff] [blame] | 151 | #define SCI_USB_CHARGE_MODE_MASK 0xff |
| 152 | #define SCI_USB_CHARGE_DISABLED 0x30000 |
| 153 | #define SCI_USB_CHARGE_ALTERNATE 0x30009 |
| 154 | #define SCI_USB_CHARGE_AUTO 0x30021 |
Azael Avalos | 182bcaa | 2015-01-18 18:30:23 -0700 | [diff] [blame] | 155 | #define SCI_USB_CHARGE_BAT_MASK 0x7 |
| 156 | #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1 |
| 157 | #define SCI_USB_CHARGE_BAT_LVL_ON 0x4 |
| 158 | #define SCI_USB_CHARGE_BAT_LVL 0x0200 |
Azael Avalos | bb3fe01 | 2015-01-18 18:30:24 -0700 | [diff] [blame] | 159 | #define SCI_USB_CHARGE_RAPID_DSP 0x0300 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 161 | struct toshiba_acpi_dev { |
| 162 | struct acpi_device *acpi_dev; |
| 163 | const char *method_hci; |
| 164 | struct rfkill *bt_rfk; |
| 165 | struct input_dev *hotkey_dev; |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 166 | struct work_struct hotkey_work; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 167 | struct backlight_device *backlight_dev; |
| 168 | struct led_classdev led_dev; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 169 | struct led_classdev kbd_led; |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 170 | struct led_classdev eco_led; |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 171 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 172 | int force_fan; |
| 173 | int last_key_event; |
| 174 | int key_event_valid; |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 175 | int kbd_type; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 176 | int kbd_mode; |
| 177 | int kbd_time; |
Azael Avalos | 182bcaa | 2015-01-18 18:30:23 -0700 | [diff] [blame] | 178 | int usbsc_bat_level; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 179 | |
Dan Carpenter | 592b746 | 2012-01-15 14:28:20 +0300 | [diff] [blame] | 180 | unsigned int illumination_supported:1; |
| 181 | unsigned int video_supported:1; |
| 182 | unsigned int fan_supported:1; |
| 183 | unsigned int system_event_supported:1; |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 184 | unsigned int ntfy_supported:1; |
| 185 | unsigned int info_supported:1; |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 186 | unsigned int tr_backlight_supported:1; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 187 | unsigned int kbd_illum_supported:1; |
| 188 | unsigned int kbd_led_registered:1; |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 189 | unsigned int touchpad_supported:1; |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 190 | unsigned int eco_supported:1; |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 191 | unsigned int accelerometer_supported:1; |
Azael Avalos | e26ffe5 | 2015-01-18 18:30:22 -0700 | [diff] [blame] | 192 | unsigned int usb_sleep_charge_supported:1; |
Azael Avalos | bb3fe01 | 2015-01-18 18:30:24 -0700 | [diff] [blame] | 193 | unsigned int usb_rapid_charge_supported:1; |
Azael Avalos | 172ce0a | 2015-01-18 18:30:25 -0700 | [diff] [blame^] | 194 | unsigned int usb_sleep_music_supported:1; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 195 | unsigned int sysfs_created:1; |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 196 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 197 | struct mutex mutex; |
| 198 | }; |
| 199 | |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 200 | static struct toshiba_acpi_dev *toshiba_acpi; |
| 201 | |
arvidjaar@mail.ru | 4db42c5 | 2008-03-04 15:06:34 -0800 | [diff] [blame] | 202 | static const struct acpi_device_id toshiba_device_ids[] = { |
| 203 | {"TOS6200", 0}, |
Ondrej Zary | 63a9e01 | 2014-11-10 00:11:54 +0100 | [diff] [blame] | 204 | {"TOS6207", 0}, |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 205 | {"TOS6208", 0}, |
arvidjaar@mail.ru | 4db42c5 | 2008-03-04 15:06:34 -0800 | [diff] [blame] | 206 | {"TOS1900", 0}, |
| 207 | {"", 0}, |
| 208 | }; |
| 209 | MODULE_DEVICE_TABLE(acpi, toshiba_device_ids); |
| 210 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 211 | static const struct key_entry toshiba_acpi_keymap[] = { |
Unai Uribarri | fec278a | 2014-01-14 11:06:47 +0100 | [diff] [blame] | 212 | { KE_KEY, 0x9e, { KEY_RFKILL } }, |
Dmitry Torokhov | 384a7cd | 2010-08-04 22:30:19 -0700 | [diff] [blame] | 213 | { KE_KEY, 0x101, { KEY_MUTE } }, |
| 214 | { KE_KEY, 0x102, { KEY_ZOOMOUT } }, |
| 215 | { KE_KEY, 0x103, { KEY_ZOOMIN } }, |
Azael Avalos | 408a5d1 | 2014-09-05 11:14:03 -0600 | [diff] [blame] | 216 | { KE_KEY, 0x10f, { KEY_TAB } }, |
Azael Avalos | af50283 | 2012-01-18 13:44:10 -0600 | [diff] [blame] | 217 | { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, |
| 218 | { KE_KEY, 0x139, { KEY_ZOOMRESET } }, |
Dmitry Torokhov | 384a7cd | 2010-08-04 22:30:19 -0700 | [diff] [blame] | 219 | { KE_KEY, 0x13b, { KEY_COFFEE } }, |
| 220 | { KE_KEY, 0x13c, { KEY_BATTERY } }, |
| 221 | { KE_KEY, 0x13d, { KEY_SLEEP } }, |
| 222 | { KE_KEY, 0x13e, { KEY_SUSPEND } }, |
| 223 | { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } }, |
| 224 | { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } }, |
| 225 | { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } }, |
| 226 | { KE_KEY, 0x142, { KEY_WLAN } }, |
Azael Avalos | af50283 | 2012-01-18 13:44:10 -0600 | [diff] [blame] | 227 | { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } }, |
Jon Dowland | a49010f | 2010-10-27 00:24:59 +0100 | [diff] [blame] | 228 | { KE_KEY, 0x17f, { KEY_FN } }, |
Dmitry Torokhov | 384a7cd | 2010-08-04 22:30:19 -0700 | [diff] [blame] | 229 | { KE_KEY, 0xb05, { KEY_PROG2 } }, |
| 230 | { KE_KEY, 0xb06, { KEY_WWW } }, |
| 231 | { KE_KEY, 0xb07, { KEY_MAIL } }, |
| 232 | { KE_KEY, 0xb30, { KEY_STOP } }, |
| 233 | { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } }, |
| 234 | { KE_KEY, 0xb32, { KEY_NEXTSONG } }, |
| 235 | { KE_KEY, 0xb33, { KEY_PLAYPAUSE } }, |
| 236 | { KE_KEY, 0xb5a, { KEY_MEDIA } }, |
Azael Avalos | 408a5d1 | 2014-09-05 11:14:03 -0600 | [diff] [blame] | 237 | { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */ |
| 238 | { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */ |
| 239 | { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */ |
| 240 | { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */ |
| 241 | { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */ |
Dmitry Torokhov | 384a7cd | 2010-08-04 22:30:19 -0700 | [diff] [blame] | 242 | { KE_END, 0 }, |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 243 | }; |
| 244 | |
Takashi Iwai | fe808bfb | 2014-04-29 15:15:38 +0200 | [diff] [blame] | 245 | /* alternative keymap */ |
| 246 | static const struct dmi_system_id toshiba_alt_keymap_dmi[] = { |
| 247 | { |
| 248 | .matches = { |
| 249 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 250 | DMI_MATCH(DMI_PRODUCT_NAME, "Satellite M840"), |
| 251 | }, |
| 252 | }, |
Azael Avalos | e6efad7 | 2014-08-04 09:21:02 -0600 | [diff] [blame] | 253 | { |
| 254 | .matches = { |
| 255 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 256 | DMI_MATCH(DMI_PRODUCT_NAME, "Qosmio X75-A"), |
| 257 | }, |
| 258 | }, |
Aaron Lu | b1bde68 | 2014-10-23 16:18:02 +0800 | [diff] [blame] | 259 | { |
| 260 | .matches = { |
| 261 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 262 | DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A50-A"), |
| 263 | }, |
| 264 | }, |
Takashi Iwai | fe808bfb | 2014-04-29 15:15:38 +0200 | [diff] [blame] | 265 | {} |
| 266 | }; |
| 267 | |
| 268 | static const struct key_entry toshiba_acpi_alt_keymap[] = { |
| 269 | { KE_KEY, 0x157, { KEY_MUTE } }, |
| 270 | { KE_KEY, 0x102, { KEY_ZOOMOUT } }, |
| 271 | { KE_KEY, 0x103, { KEY_ZOOMIN } }, |
Azael Avalos | e6efad7 | 2014-08-04 09:21:02 -0600 | [diff] [blame] | 272 | { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, |
Takashi Iwai | fe808bfb | 2014-04-29 15:15:38 +0200 | [diff] [blame] | 273 | { KE_KEY, 0x139, { KEY_ZOOMRESET } }, |
| 274 | { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } }, |
| 275 | { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } }, |
| 276 | { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } }, |
| 277 | { KE_KEY, 0x158, { KEY_WLAN } }, |
| 278 | { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } }, |
| 279 | { KE_END, 0 }, |
| 280 | }; |
| 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | /* utility |
| 283 | */ |
| 284 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | static __inline__ void _set_bit(u32 * word, u32 mask, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
| 287 | *word = (*word & ~mask) | (mask * value); |
| 288 | } |
| 289 | |
| 290 | /* acpi interface wrappers |
| 291 | */ |
| 292 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | static int write_acpi_int(const char *methodName, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | acpi_status status; |
| 296 | |
Zhang Rui | 619400d | 2013-09-03 08:31:56 +0800 | [diff] [blame] | 297 | status = acpi_execute_simple_method(NULL, (char *)methodName, val); |
Seth Forshee | 32bcd5c | 2011-09-20 16:55:50 -0500 | [diff] [blame] | 298 | return (status == AE_OK) ? 0 : -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 301 | /* Perform a raw configuration call. Here we don't care about input or output |
| 302 | * buffer format. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | */ |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 304 | static acpi_status tci_raw(struct toshiba_acpi_dev *dev, |
| 305 | const u32 in[TCI_WORDS], u32 out[TCI_WORDS]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
| 307 | struct acpi_object_list params; |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 308 | union acpi_object in_objs[TCI_WORDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | struct acpi_buffer results; |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 310 | union acpi_object out_objs[TCI_WORDS + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | acpi_status status; |
| 312 | int i; |
| 313 | |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 314 | params.count = TCI_WORDS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | params.pointer = in_objs; |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 316 | for (i = 0; i < TCI_WORDS; ++i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | in_objs[i].type = ACPI_TYPE_INTEGER; |
| 318 | in_objs[i].integer.value = in[i]; |
| 319 | } |
| 320 | |
| 321 | results.length = sizeof(out_objs); |
| 322 | results.pointer = out_objs; |
| 323 | |
Seth Forshee | 6e02cc7 | 2011-09-20 16:55:51 -0500 | [diff] [blame] | 324 | status = acpi_evaluate_object(dev->acpi_dev->handle, |
| 325 | (char *)dev->method_hci, ¶ms, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 326 | &results); |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 327 | if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | for (i = 0; i < out_objs->package.count; ++i) { |
| 329 | out[i] = out_objs->package.elements[i].integer.value; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | return status; |
| 334 | } |
| 335 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 336 | /* common hci tasks (get or set one or two value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | * |
| 338 | * In addition to the ACPI status, the HCI system returns a result which |
| 339 | * may be useful (such as "not supported"). |
| 340 | */ |
| 341 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 342 | static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 344 | u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; |
| 345 | u32 out[TCI_WORDS]; |
| 346 | acpi_status status = tci_raw(dev, in, out); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 347 | |
| 348 | return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 351 | static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 353 | u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; |
| 354 | u32 out[TCI_WORDS]; |
| 355 | acpi_status status = tci_raw(dev, in, out); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 356 | if (ACPI_FAILURE(status)) |
| 357 | return TOS_FAILURE; |
| 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | *out1 = out[2]; |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 360 | |
| 361 | return out[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 364 | static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2) |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 365 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 366 | u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 }; |
| 367 | u32 out[TCI_WORDS]; |
| 368 | acpi_status status = tci_raw(dev, in, out); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 369 | |
| 370 | return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 371 | } |
| 372 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 373 | static u32 hci_read2(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1, u32 *out2) |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 374 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 375 | u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 }; |
| 376 | u32 out[TCI_WORDS]; |
| 377 | acpi_status status = tci_raw(dev, in, out); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 378 | if (ACPI_FAILURE(status)) |
| 379 | return TOS_FAILURE; |
| 380 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 381 | *out1 = out[2]; |
| 382 | *out2 = out[3]; |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 383 | |
| 384 | return out[0]; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 385 | } |
| 386 | |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 387 | /* common sci tasks |
| 388 | */ |
| 389 | |
| 390 | static int sci_open(struct toshiba_acpi_dev *dev) |
| 391 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 392 | u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 }; |
| 393 | u32 out[TCI_WORDS]; |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 394 | acpi_status status; |
| 395 | |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 396 | status = tci_raw(dev, in, out); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 397 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 398 | pr_err("ACPI call to open SCI failed\n"); |
| 399 | return 0; |
| 400 | } |
| 401 | |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 402 | if (out[0] == TOS_OPEN_CLOSE_OK) { |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 403 | return 1; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 404 | } else if (out[0] == TOS_ALREADY_OPEN) { |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 405 | pr_info("Toshiba SCI already opened\n"); |
| 406 | return 1; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 407 | } else if (out[0] == TOS_NOT_PRESENT) { |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 408 | pr_info("Toshiba SCI is not present\n"); |
| 409 | } |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | static void sci_close(struct toshiba_acpi_dev *dev) |
| 415 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 416 | u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 }; |
| 417 | u32 out[TCI_WORDS]; |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 418 | acpi_status status; |
| 419 | |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 420 | status = tci_raw(dev, in, out); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 421 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 422 | pr_err("ACPI call to close SCI failed\n"); |
| 423 | return; |
| 424 | } |
| 425 | |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 426 | if (out[0] == TOS_OPEN_CLOSE_OK) |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 427 | return; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 428 | else if (out[0] == TOS_NOT_OPENED) |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 429 | pr_info("Toshiba SCI not opened\n"); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 430 | else if (out[0] == TOS_NOT_PRESENT) |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 431 | pr_info("Toshiba SCI is not present\n"); |
| 432 | } |
| 433 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 434 | static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1) |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 435 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 436 | u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 }; |
| 437 | u32 out[TCI_WORDS]; |
| 438 | acpi_status status = tci_raw(dev, in, out); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 439 | if (ACPI_FAILURE(status)) |
| 440 | return TOS_FAILURE; |
| 441 | |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 442 | *out1 = out[2]; |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 443 | |
| 444 | return out[0]; |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 445 | } |
| 446 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 447 | static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1) |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 448 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 449 | u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 }; |
| 450 | u32 out[TCI_WORDS]; |
| 451 | acpi_status status = tci_raw(dev, in, out); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 452 | |
| 453 | return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; |
Azael Avalos | 84a6273 | 2014-03-25 20:38:29 -0600 | [diff] [blame] | 454 | } |
| 455 | |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 456 | /* Illumination support */ |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 457 | static int toshiba_illumination_available(struct toshiba_acpi_dev *dev) |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 458 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 459 | u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 }; |
| 460 | u32 out[TCI_WORDS]; |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 461 | acpi_status status; |
| 462 | |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 463 | if (!sci_open(dev)) |
| 464 | return 0; |
| 465 | |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 466 | status = tci_raw(dev, in, out); |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 467 | sci_close(dev); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 468 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 469 | pr_err("ACPI call to query Illumination support failed\n"); |
| 470 | return 0; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 471 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
Joe Perches | 7e33460 | 2011-03-29 15:21:52 -0700 | [diff] [blame] | 472 | pr_info("Illumination device not available\n"); |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 473 | return 0; |
| 474 | } |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 475 | |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 476 | return 1; |
| 477 | } |
| 478 | |
| 479 | static void toshiba_illumination_set(struct led_classdev *cdev, |
| 480 | enum led_brightness brightness) |
| 481 | { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 482 | struct toshiba_acpi_dev *dev = container_of(cdev, |
| 483 | struct toshiba_acpi_dev, led_dev); |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 484 | u32 state, result; |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 485 | |
| 486 | /* First request : initialize communication. */ |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 487 | if (!sci_open(dev)) |
| 488 | return; |
| 489 | |
| 490 | /* Switch the illumination on/off */ |
| 491 | state = brightness ? 1 : 0; |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 492 | result = sci_write(dev, SCI_ILLUMINATION, state); |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 493 | sci_close(dev); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 494 | if (result == TOS_FAILURE) { |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 495 | pr_err("ACPI call for illumination failed\n"); |
| 496 | return; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 497 | } else if (result == TOS_NOT_SUPPORTED) { |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 498 | pr_info("Illumination not supported\n"); |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 499 | return; |
| 500 | } |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) |
| 504 | { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 505 | struct toshiba_acpi_dev *dev = container_of(cdev, |
| 506 | struct toshiba_acpi_dev, led_dev); |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 507 | u32 state, result; |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 508 | |
| 509 | /* First request : initialize communication. */ |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 510 | if (!sci_open(dev)) |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 511 | return LED_OFF; |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 512 | |
| 513 | /* Check the illumination */ |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 514 | result = sci_read(dev, SCI_ILLUMINATION, &state); |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 515 | sci_close(dev); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 516 | if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 517 | pr_err("ACPI call for illumination failed\n"); |
| 518 | return LED_OFF; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 519 | } else if (result == TOS_NOT_SUPPORTED) { |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 520 | pr_info("Illumination not supported\n"); |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 521 | return LED_OFF; |
| 522 | } |
| 523 | |
Azael Avalos | fdb7908 | 2014-03-25 20:38:30 -0600 | [diff] [blame] | 524 | return state ? LED_FULL : LED_OFF; |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 525 | } |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 526 | |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 527 | /* KBD Illumination */ |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 528 | static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev) |
| 529 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 530 | u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 }; |
| 531 | u32 out[TCI_WORDS]; |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 532 | acpi_status status; |
| 533 | |
| 534 | if (!sci_open(dev)) |
| 535 | return 0; |
| 536 | |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 537 | status = tci_raw(dev, in, out); |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 538 | sci_close(dev); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 539 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 540 | pr_err("ACPI call to query kbd illumination support failed\n"); |
| 541 | return 0; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 542 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 543 | pr_info("Keyboard illumination not available\n"); |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | /* Check for keyboard backlight timeout max value, |
| 548 | * previous kbd backlight implementation set this to |
| 549 | * 0x3c0003, and now the new implementation set this |
| 550 | * to 0x3c001a, use this to distinguish between them |
| 551 | */ |
| 552 | if (out[3] == SCI_KBD_TIME_MAX) |
| 553 | dev->kbd_type = 2; |
| 554 | else |
| 555 | dev->kbd_type = 1; |
| 556 | /* Get the current keyboard backlight mode */ |
| 557 | dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK; |
| 558 | /* Get the current time (1-60 seconds) */ |
| 559 | dev->kbd_time = out[2] >> HCI_MISC_SHIFT; |
| 560 | |
| 561 | return 1; |
| 562 | } |
| 563 | |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 564 | static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time) |
| 565 | { |
| 566 | u32 result; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 567 | |
| 568 | if (!sci_open(dev)) |
| 569 | return -EIO; |
| 570 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 571 | result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time); |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 572 | sci_close(dev); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 573 | if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 574 | pr_err("ACPI call to set KBD backlight status failed\n"); |
| 575 | return -EIO; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 576 | } else if (result == TOS_NOT_SUPPORTED) { |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 577 | pr_info("Keyboard backlight status not supported\n"); |
| 578 | return -ENODEV; |
| 579 | } |
| 580 | |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time) |
| 585 | { |
| 586 | u32 result; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 587 | |
| 588 | if (!sci_open(dev)) |
| 589 | return -EIO; |
| 590 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 591 | result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time); |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 592 | sci_close(dev); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 593 | if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 594 | pr_err("ACPI call to get KBD backlight status failed\n"); |
| 595 | return -EIO; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 596 | } else if (result == TOS_NOT_SUPPORTED) { |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 597 | pr_info("Keyboard backlight status not supported\n"); |
| 598 | return -ENODEV; |
| 599 | } |
| 600 | |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev) |
| 605 | { |
| 606 | struct toshiba_acpi_dev *dev = container_of(cdev, |
| 607 | struct toshiba_acpi_dev, kbd_led); |
| 608 | u32 state, result; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 609 | |
| 610 | /* Check the keyboard backlight state */ |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 611 | result = hci_read1(dev, HCI_KBD_ILLUMINATION, &state); |
| 612 | if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 613 | pr_err("ACPI call to get the keyboard backlight failed\n"); |
| 614 | return LED_OFF; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 615 | } else if (result == TOS_NOT_SUPPORTED) { |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 616 | pr_info("Keyboard backlight not supported\n"); |
| 617 | return LED_OFF; |
| 618 | } |
| 619 | |
| 620 | return state ? LED_FULL : LED_OFF; |
| 621 | } |
| 622 | |
| 623 | static void toshiba_kbd_backlight_set(struct led_classdev *cdev, |
| 624 | enum led_brightness brightness) |
| 625 | { |
| 626 | struct toshiba_acpi_dev *dev = container_of(cdev, |
| 627 | struct toshiba_acpi_dev, kbd_led); |
| 628 | u32 state, result; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 629 | |
| 630 | /* Set the keyboard backlight state */ |
| 631 | state = brightness ? 1 : 0; |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 632 | result = hci_write1(dev, HCI_KBD_ILLUMINATION, state); |
| 633 | if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 634 | pr_err("ACPI call to set KBD Illumination mode failed\n"); |
| 635 | return; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 636 | } else if (result == TOS_NOT_SUPPORTED) { |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 637 | pr_info("Keyboard backlight not supported\n"); |
| 638 | return; |
| 639 | } |
| 640 | } |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 641 | |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 642 | /* TouchPad support */ |
| 643 | static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state) |
| 644 | { |
| 645 | u32 result; |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 646 | |
| 647 | if (!sci_open(dev)) |
| 648 | return -EIO; |
| 649 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 650 | result = sci_write(dev, SCI_TOUCHPAD, state); |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 651 | sci_close(dev); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 652 | if (result == TOS_FAILURE) { |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 653 | pr_err("ACPI call to set the touchpad failed\n"); |
| 654 | return -EIO; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 655 | } else if (result == TOS_NOT_SUPPORTED) { |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 656 | return -ENODEV; |
| 657 | } |
| 658 | |
| 659 | return 0; |
| 660 | } |
| 661 | |
| 662 | static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state) |
| 663 | { |
| 664 | u32 result; |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 665 | |
| 666 | if (!sci_open(dev)) |
| 667 | return -EIO; |
| 668 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 669 | result = sci_read(dev, SCI_TOUCHPAD, state); |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 670 | sci_close(dev); |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 671 | if (result == TOS_FAILURE) { |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 672 | pr_err("ACPI call to query the touchpad failed\n"); |
| 673 | return -EIO; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 674 | } else if (result == TOS_NOT_SUPPORTED) { |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 675 | return -ENODEV; |
| 676 | } |
| 677 | |
| 678 | return 0; |
| 679 | } |
Pierre Ducroquet | 6c3f6e6 | 2010-07-29 11:56:59 +0200 | [diff] [blame] | 680 | |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 681 | /* Eco Mode support */ |
| 682 | static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev) |
| 683 | { |
| 684 | acpi_status status; |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 685 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 }; |
| 686 | u32 out[TCI_WORDS]; |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 687 | |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 688 | status = tci_raw(dev, in, out); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 689 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 690 | pr_info("ACPI call to get ECO led failed\n"); |
| 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | return 1; |
| 695 | } |
| 696 | |
| 697 | static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev *cdev) |
| 698 | { |
| 699 | struct toshiba_acpi_dev *dev = container_of(cdev, |
| 700 | struct toshiba_acpi_dev, eco_led); |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 701 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 }; |
| 702 | u32 out[TCI_WORDS]; |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 703 | acpi_status status; |
| 704 | |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 705 | status = tci_raw(dev, in, out); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 706 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 707 | pr_err("ACPI call to get ECO led failed\n"); |
| 708 | return LED_OFF; |
| 709 | } |
| 710 | |
| 711 | return out[2] ? LED_FULL : LED_OFF; |
| 712 | } |
| 713 | |
| 714 | static void toshiba_eco_mode_set_status(struct led_classdev *cdev, |
| 715 | enum led_brightness brightness) |
| 716 | { |
| 717 | struct toshiba_acpi_dev *dev = container_of(cdev, |
| 718 | struct toshiba_acpi_dev, eco_led); |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 719 | u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 }; |
| 720 | u32 out[TCI_WORDS]; |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 721 | acpi_status status; |
| 722 | |
| 723 | /* Switch the Eco Mode led on/off */ |
| 724 | in[2] = (brightness) ? 1 : 0; |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 725 | status = tci_raw(dev, in, out); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 726 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 727 | pr_err("ACPI call to set ECO led failed\n"); |
| 728 | return; |
| 729 | } |
| 730 | } |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 731 | |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 732 | /* Accelerometer support */ |
| 733 | static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev) |
| 734 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 735 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 }; |
| 736 | u32 out[TCI_WORDS]; |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 737 | acpi_status status; |
| 738 | |
| 739 | /* Check if the accelerometer call exists, |
| 740 | * this call also serves as initialization |
| 741 | */ |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 742 | status = tci_raw(dev, in, out); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 743 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 744 | pr_err("ACPI call to query the accelerometer failed\n"); |
| 745 | return -EIO; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 746 | } else if (out[0] == TOS_DATA_NOT_AVAILABLE || |
| 747 | out[0] == TOS_NOT_INITIALIZED) { |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 748 | pr_err("Accelerometer not initialized\n"); |
| 749 | return -EIO; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 750 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 751 | pr_info("Accelerometer not supported\n"); |
| 752 | return -ENODEV; |
| 753 | } |
| 754 | |
| 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, |
| 759 | u32 *xy, u32 *z) |
| 760 | { |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 761 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 }; |
| 762 | u32 out[TCI_WORDS]; |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 763 | acpi_status status; |
| 764 | |
| 765 | /* Check the Accelerometer status */ |
Azael Avalos | 258c590 | 2014-09-29 20:40:07 -0600 | [diff] [blame] | 766 | status = tci_raw(dev, in, out); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 767 | if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) { |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 768 | pr_err("ACPI call to query the accelerometer failed\n"); |
| 769 | return -EIO; |
| 770 | } |
| 771 | |
| 772 | *xy = out[2]; |
| 773 | *z = out[4]; |
| 774 | |
| 775 | return 0; |
| 776 | } |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 777 | |
Azael Avalos | e26ffe5 | 2015-01-18 18:30:22 -0700 | [diff] [blame] | 778 | /* Sleep (Charge and Music) utilities support */ |
| 779 | static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev, |
| 780 | u32 *mode) |
| 781 | { |
| 782 | u32 result; |
| 783 | |
| 784 | if (!sci_open(dev)) |
| 785 | return -EIO; |
| 786 | |
| 787 | result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode); |
| 788 | sci_close(dev); |
| 789 | if (result == TOS_FAILURE) { |
| 790 | pr_err("ACPI call to set USB S&C mode failed\n"); |
| 791 | return -EIO; |
| 792 | } else if (result == TOS_NOT_SUPPORTED) { |
| 793 | pr_info("USB Sleep and Charge not supported\n"); |
| 794 | return -ENODEV; |
| 795 | } else if (result == TOS_INPUT_DATA_ERROR) { |
| 796 | return -EIO; |
| 797 | } |
| 798 | |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev, |
| 803 | u32 mode) |
| 804 | { |
| 805 | u32 result; |
| 806 | |
| 807 | if (!sci_open(dev)) |
| 808 | return -EIO; |
| 809 | |
| 810 | result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode); |
| 811 | sci_close(dev); |
| 812 | if (result == TOS_FAILURE) { |
| 813 | pr_err("ACPI call to set USB S&C mode failed\n"); |
| 814 | return -EIO; |
| 815 | } else if (result == TOS_NOT_SUPPORTED) { |
| 816 | pr_info("USB Sleep and Charge not supported\n"); |
| 817 | return -ENODEV; |
| 818 | } else if (result == TOS_INPUT_DATA_ERROR) { |
| 819 | return -EIO; |
| 820 | } |
| 821 | |
| 822 | return 0; |
| 823 | } |
| 824 | |
Azael Avalos | 182bcaa | 2015-01-18 18:30:23 -0700 | [diff] [blame] | 825 | static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev, |
| 826 | u32 *mode) |
| 827 | { |
| 828 | u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; |
| 829 | u32 out[TCI_WORDS]; |
| 830 | acpi_status status; |
| 831 | |
| 832 | if (!sci_open(dev)) |
| 833 | return -EIO; |
| 834 | |
| 835 | in[5] = SCI_USB_CHARGE_BAT_LVL; |
| 836 | status = tci_raw(dev, in, out); |
| 837 | sci_close(dev); |
| 838 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
| 839 | pr_err("ACPI call to get USB S&C battery level failed\n"); |
| 840 | return -EIO; |
| 841 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
| 842 | pr_info("USB Sleep and Charge not supported\n"); |
| 843 | return -ENODEV; |
| 844 | } else if (out[0] == TOS_INPUT_DATA_ERROR) { |
| 845 | return -EIO; |
| 846 | } |
| 847 | |
| 848 | *mode = out[2]; |
| 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev, |
| 854 | u32 mode) |
| 855 | { |
| 856 | u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; |
| 857 | u32 out[TCI_WORDS]; |
| 858 | acpi_status status; |
| 859 | |
| 860 | if (!sci_open(dev)) |
| 861 | return -EIO; |
| 862 | |
| 863 | in[2] = mode; |
| 864 | in[5] = SCI_USB_CHARGE_BAT_LVL; |
| 865 | status = tci_raw(dev, in, out); |
| 866 | sci_close(dev); |
| 867 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
| 868 | pr_err("ACPI call to set USB S&C battery level failed\n"); |
| 869 | return -EIO; |
| 870 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
| 871 | pr_info("USB Sleep and Charge not supported\n"); |
| 872 | return -ENODEV; |
| 873 | } else if (out[0] == TOS_INPUT_DATA_ERROR) { |
| 874 | return -EIO; |
| 875 | } |
| 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | |
Azael Avalos | bb3fe01 | 2015-01-18 18:30:24 -0700 | [diff] [blame] | 880 | static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev, |
| 881 | u32 *state) |
| 882 | { |
| 883 | u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; |
| 884 | u32 out[TCI_WORDS]; |
| 885 | acpi_status status; |
| 886 | |
| 887 | if (!sci_open(dev)) |
| 888 | return -EIO; |
| 889 | |
| 890 | in[5] = SCI_USB_CHARGE_RAPID_DSP; |
| 891 | status = tci_raw(dev, in, out); |
| 892 | sci_close(dev); |
| 893 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
| 894 | pr_err("ACPI call to get USB S&C battery level failed\n"); |
| 895 | return -EIO; |
| 896 | } else if (out[0] == TOS_NOT_SUPPORTED || |
| 897 | out[0] == TOS_INPUT_DATA_ERROR) { |
| 898 | pr_info("USB Sleep and Charge not supported\n"); |
| 899 | return -ENODEV; |
| 900 | } |
| 901 | |
| 902 | *state = out[2]; |
| 903 | |
| 904 | return 0; |
| 905 | } |
| 906 | |
| 907 | static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev, |
| 908 | u32 state) |
| 909 | { |
| 910 | u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; |
| 911 | u32 out[TCI_WORDS]; |
| 912 | acpi_status status; |
| 913 | |
| 914 | if (!sci_open(dev)) |
| 915 | return -EIO; |
| 916 | |
| 917 | in[2] = state; |
| 918 | in[5] = SCI_USB_CHARGE_RAPID_DSP; |
| 919 | status = tci_raw(dev, in, out); |
| 920 | sci_close(dev); |
| 921 | if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) { |
| 922 | pr_err("ACPI call to set USB S&C battery level failed\n"); |
| 923 | return -EIO; |
| 924 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
| 925 | pr_info("USB Sleep and Charge not supported\n"); |
| 926 | return -ENODEV; |
| 927 | } else if (out[0] == TOS_INPUT_DATA_ERROR) { |
| 928 | return -EIO; |
| 929 | } |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
Azael Avalos | 172ce0a | 2015-01-18 18:30:25 -0700 | [diff] [blame^] | 934 | static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state) |
| 935 | { |
| 936 | u32 result; |
| 937 | |
| 938 | if (!sci_open(dev)) |
| 939 | return -EIO; |
| 940 | |
| 941 | result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state); |
| 942 | sci_close(dev); |
| 943 | if (result == TOS_FAILURE) { |
| 944 | pr_err("ACPI call to set USB S&C mode failed\n"); |
| 945 | return -EIO; |
| 946 | } else if (result == TOS_NOT_SUPPORTED) { |
| 947 | pr_info("USB Sleep and Charge not supported\n"); |
| 948 | return -ENODEV; |
| 949 | } else if (result == TOS_INPUT_DATA_ERROR) { |
| 950 | return -EIO; |
| 951 | } |
| 952 | |
| 953 | return 0; |
| 954 | } |
| 955 | |
| 956 | static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state) |
| 957 | { |
| 958 | u32 result; |
| 959 | |
| 960 | if (!sci_open(dev)) |
| 961 | return -EIO; |
| 962 | |
| 963 | result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state); |
| 964 | sci_close(dev); |
| 965 | if (result == TOS_FAILURE) { |
| 966 | pr_err("ACPI call to set USB S&C mode failed\n"); |
| 967 | return -EIO; |
| 968 | } else if (result == TOS_NOT_SUPPORTED) { |
| 969 | pr_info("USB Sleep and Charge not supported\n"); |
| 970 | return -ENODEV; |
| 971 | } else if (result == TOS_INPUT_DATA_ERROR) { |
| 972 | return -EIO; |
| 973 | } |
| 974 | |
| 975 | return 0; |
| 976 | } |
| 977 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 978 | /* Bluetooth rfkill handlers */ |
| 979 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 980 | static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present) |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 981 | { |
| 982 | u32 hci_result; |
| 983 | u32 value, value2; |
| 984 | |
| 985 | value = 0; |
| 986 | value2 = 0; |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 987 | hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 988 | if (hci_result == TOS_SUCCESS) |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 989 | *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false; |
| 990 | |
| 991 | return hci_result; |
| 992 | } |
| 993 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 994 | static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state) |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 995 | { |
| 996 | u32 hci_result; |
| 997 | u32 value, value2; |
| 998 | |
| 999 | value = 0; |
| 1000 | value2 = 0x0001; |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 1001 | hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1002 | |
| 1003 | *radio_state = value & HCI_WIRELESS_KILL_SWITCH; |
| 1004 | return hci_result; |
| 1005 | } |
| 1006 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1007 | static int bt_rfkill_set_block(void *data, bool blocked) |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1008 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1009 | struct toshiba_acpi_dev *dev = data; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1010 | u32 result1, result2; |
| 1011 | u32 value; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1012 | int err; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1013 | bool radio_state; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1014 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1015 | value = (blocked == false); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1016 | |
| 1017 | mutex_lock(&dev->mutex); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1018 | if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) { |
Seth Forshee | 32bcd5c | 2011-09-20 16:55:50 -0500 | [diff] [blame] | 1019 | err = -EIO; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1020 | goto out; |
| 1021 | } |
| 1022 | |
| 1023 | if (!radio_state) { |
| 1024 | err = 0; |
| 1025 | goto out; |
| 1026 | } |
| 1027 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 1028 | result1 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER); |
| 1029 | result2 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1030 | |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1031 | if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS) |
Seth Forshee | 32bcd5c | 2011-09-20 16:55:50 -0500 | [diff] [blame] | 1032 | err = -EIO; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1033 | else |
| 1034 | err = 0; |
| 1035 | out: |
| 1036 | mutex_unlock(&dev->mutex); |
| 1037 | return err; |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1040 | static void bt_rfkill_poll(struct rfkill *rfkill, void *data) |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1041 | { |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1042 | bool new_rfk_state; |
| 1043 | bool value; |
| 1044 | u32 hci_result; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1045 | struct toshiba_acpi_dev *dev = data; |
| 1046 | |
| 1047 | mutex_lock(&dev->mutex); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1048 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1049 | hci_result = hci_get_radio_state(dev, &value); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1050 | if (hci_result != TOS_SUCCESS) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1051 | /* Can't do anything useful */ |
| 1052 | mutex_unlock(&dev->mutex); |
Jiri Slaby | 82e7784 | 2009-08-06 15:57:51 -0700 | [diff] [blame] | 1053 | return; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1054 | } |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1055 | |
| 1056 | new_rfk_state = value; |
| 1057 | |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1058 | mutex_unlock(&dev->mutex); |
| 1059 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1060 | if (rfkill_set_hw_state(rfkill, !new_rfk_state)) |
| 1061 | bt_rfkill_set_block(data, true); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1064 | static const struct rfkill_ops toshiba_rfk_ops = { |
| 1065 | .set_block = bt_rfkill_set_block, |
| 1066 | .poll = bt_rfkill_poll, |
| 1067 | }; |
| 1068 | |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1069 | static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled) |
| 1070 | { |
| 1071 | u32 hci_result; |
| 1072 | u32 status; |
| 1073 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 1074 | hci_result = hci_read1(dev, HCI_TR_BACKLIGHT, &status); |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1075 | *enabled = !status; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1076 | return hci_result == TOS_SUCCESS ? 0 : -EIO; |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable) |
| 1080 | { |
| 1081 | u32 hci_result; |
| 1082 | u32 value = !enable; |
| 1083 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 1084 | hci_result = hci_write1(dev, HCI_TR_BACKLIGHT, value); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1085 | return hci_result == TOS_SUCCESS ? 0 : -EIO; |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1086 | } |
| 1087 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1088 | static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 1090 | static int __get_lcd_brightness(struct toshiba_acpi_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | { |
| 1092 | u32 hci_result; |
| 1093 | u32 value; |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1094 | int brightness = 0; |
| 1095 | |
| 1096 | if (dev->tr_backlight_supported) { |
| 1097 | bool enabled; |
| 1098 | int ret = get_tr_backlight_status(dev, &enabled); |
| 1099 | if (ret) |
| 1100 | return ret; |
| 1101 | if (enabled) |
| 1102 | return 0; |
| 1103 | brightness++; |
| 1104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 1106 | hci_result = hci_read1(dev, HCI_LCD_BRIGHTNESS, &value); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1107 | if (hci_result == TOS_SUCCESS) |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1108 | return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT); |
Seth Forshee | 32bcd5c | 2011-09-20 16:55:50 -0500 | [diff] [blame] | 1109 | |
| 1110 | return -EIO; |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 1113 | static int get_lcd_brightness(struct backlight_device *bd) |
| 1114 | { |
| 1115 | struct toshiba_acpi_dev *dev = bl_get_data(bd); |
| 1116 | return __get_lcd_brightness(dev); |
| 1117 | } |
| 1118 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1119 | static int lcd_proc_show(struct seq_file *m, void *v) |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1120 | { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1121 | struct toshiba_acpi_dev *dev = m->private; |
| 1122 | int value; |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1123 | int levels; |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1124 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1125 | if (!dev->backlight_dev) |
| 1126 | return -ENODEV; |
| 1127 | |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1128 | levels = dev->backlight_dev->props.max_brightness + 1; |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 1129 | value = get_lcd_brightness(dev->backlight_dev); |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1130 | if (value >= 0) { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1131 | seq_printf(m, "brightness: %d\n", value); |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1132 | seq_printf(m, "brightness_levels: %d\n", levels); |
Seth Forshee | 32bcd5c | 2011-09-20 16:55:50 -0500 | [diff] [blame] | 1133 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Seth Forshee | 32bcd5c | 2011-09-20 16:55:50 -0500 | [diff] [blame] | 1136 | pr_err("Error reading LCD brightness\n"); |
| 1137 | return -EIO; |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | static int lcd_proc_open(struct inode *inode, struct file *file) |
| 1141 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1142 | return single_open(file, lcd_proc_show, PDE_DATA(inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 1145 | static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value) |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1146 | { |
Azael Avalos | a39f46d | 2014-11-24 19:29:36 -0700 | [diff] [blame] | 1147 | u32 hci_result; |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1148 | |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1149 | if (dev->tr_backlight_supported) { |
| 1150 | bool enable = !value; |
| 1151 | int ret = set_tr_backlight_status(dev, enable); |
| 1152 | if (ret) |
| 1153 | return ret; |
| 1154 | if (value) |
| 1155 | value--; |
| 1156 | } |
| 1157 | |
Azael Avalos | a39f46d | 2014-11-24 19:29:36 -0700 | [diff] [blame] | 1158 | value = value << HCI_LCD_BRIGHTNESS_SHIFT; |
| 1159 | hci_result = hci_write1(dev, HCI_LCD_BRIGHTNESS, value); |
| 1160 | return hci_result == TOS_SUCCESS ? 0 : -EIO; |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | static int set_lcd_status(struct backlight_device *bd) |
| 1164 | { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1165 | struct toshiba_acpi_dev *dev = bl_get_data(bd); |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 1166 | return set_lcd_brightness(dev, bd->props.brightness); |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1169 | static ssize_t lcd_proc_write(struct file *file, const char __user *buf, |
| 1170 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1172 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1173 | char cmd[42]; |
| 1174 | size_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | int value; |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 1176 | int ret; |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1177 | int levels = dev->backlight_dev->props.max_brightness + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1179 | len = min(count, sizeof(cmd) - 1); |
| 1180 | if (copy_from_user(cmd, buf, len)) |
| 1181 | return -EFAULT; |
| 1182 | cmd[len] = '\0'; |
| 1183 | |
| 1184 | if (sscanf(cmd, " brightness : %i", &value) == 1 && |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1185 | value >= 0 && value < levels) { |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 1186 | ret = set_lcd_brightness(dev, value); |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 1187 | if (ret == 0) |
| 1188 | ret = count; |
| 1189 | } else { |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1190 | ret = -EINVAL; |
Matthijs van Otterdijk | c8af57e | 2007-01-05 16:37:03 -0800 | [diff] [blame] | 1191 | } |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1192 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1195 | static const struct file_operations lcd_proc_fops = { |
| 1196 | .owner = THIS_MODULE, |
| 1197 | .open = lcd_proc_open, |
| 1198 | .read = seq_read, |
| 1199 | .llseek = seq_lseek, |
| 1200 | .release = single_release, |
| 1201 | .write = lcd_proc_write, |
| 1202 | }; |
| 1203 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1204 | static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status) |
| 1205 | { |
| 1206 | u32 hci_result; |
| 1207 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 1208 | hci_result = hci_read1(dev, HCI_VIDEO_OUT, status); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1209 | return hci_result == TOS_SUCCESS ? 0 : -EIO; |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1210 | } |
| 1211 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1212 | static int video_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1214 | struct toshiba_acpi_dev *dev = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | u32 value; |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1216 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1218 | ret = get_video_status(dev, &value); |
| 1219 | if (!ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; |
| 1221 | int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1222 | int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0; |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1223 | seq_printf(m, "lcd_out: %d\n", is_lcd); |
| 1224 | seq_printf(m, "crt_out: %d\n", is_crt); |
| 1225 | seq_printf(m, "tv_out: %d\n", is_tv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1228 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1231 | static int video_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1233 | return single_open(file, video_proc_show, PDE_DATA(inode)); |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | static ssize_t video_proc_write(struct file *file, const char __user *buf, |
| 1237 | size_t count, loff_t *pos) |
| 1238 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1239 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1240 | char *cmd, *buffer; |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1241 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | int value; |
| 1243 | int remain = count; |
| 1244 | int lcd_out = -1; |
| 1245 | int crt_out = -1; |
| 1246 | int tv_out = -1; |
Al Viro | b4482a4 | 2007-10-14 19:35:40 +0100 | [diff] [blame] | 1247 | u32 video_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1249 | cmd = kmalloc(count + 1, GFP_KERNEL); |
| 1250 | if (!cmd) |
| 1251 | return -ENOMEM; |
| 1252 | if (copy_from_user(cmd, buf, count)) { |
| 1253 | kfree(cmd); |
| 1254 | return -EFAULT; |
| 1255 | } |
| 1256 | cmd[count] = '\0'; |
| 1257 | |
| 1258 | buffer = cmd; |
| 1259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | /* scan expression. Multiple expressions may be delimited with ; |
| 1261 | * |
| 1262 | * NOTE: to keep scanning simple, invalid fields are ignored |
| 1263 | */ |
| 1264 | while (remain) { |
| 1265 | if (sscanf(buffer, " lcd_out : %i", &value) == 1) |
| 1266 | lcd_out = value & 1; |
| 1267 | else if (sscanf(buffer, " crt_out : %i", &value) == 1) |
| 1268 | crt_out = value & 1; |
| 1269 | else if (sscanf(buffer, " tv_out : %i", &value) == 1) |
| 1270 | tv_out = value & 1; |
| 1271 | /* advance to one character past the next ; */ |
| 1272 | do { |
| 1273 | ++buffer; |
| 1274 | --remain; |
| 1275 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1276 | while (remain && *(buffer - 1) != ';'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1279 | kfree(cmd); |
| 1280 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1281 | ret = get_video_status(dev, &video_out); |
| 1282 | if (!ret) { |
Harvey Harrison | 9e113e0 | 2008-09-22 14:37:29 -0700 | [diff] [blame] | 1283 | unsigned int new_video_out = video_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | if (lcd_out != -1) |
| 1285 | _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out); |
| 1286 | if (crt_out != -1) |
| 1287 | _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out); |
| 1288 | if (tv_out != -1) |
| 1289 | _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out); |
| 1290 | /* To avoid unnecessary video disruption, only write the new |
| 1291 | * video setting if something changed. */ |
| 1292 | if (new_video_out != video_out) |
Seth Forshee | 32bcd5c | 2011-09-20 16:55:50 -0500 | [diff] [blame] | 1293 | ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
Seth Forshee | 32bcd5c | 2011-09-20 16:55:50 -0500 | [diff] [blame] | 1296 | return ret ? ret : count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1299 | static const struct file_operations video_proc_fops = { |
| 1300 | .owner = THIS_MODULE, |
| 1301 | .open = video_proc_open, |
| 1302 | .read = seq_read, |
| 1303 | .llseek = seq_lseek, |
| 1304 | .release = single_release, |
| 1305 | .write = video_proc_write, |
| 1306 | }; |
| 1307 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1308 | static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status) |
| 1309 | { |
| 1310 | u32 hci_result; |
| 1311 | |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 1312 | hci_result = hci_read1(dev, HCI_FAN, status); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1313 | return hci_result == TOS_SUCCESS ? 0 : -EIO; |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1314 | } |
| 1315 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1316 | static int fan_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1318 | struct toshiba_acpi_dev *dev = m->private; |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1319 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | u32 value; |
| 1321 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1322 | ret = get_fan_status(dev, &value); |
| 1323 | if (!ret) { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1324 | seq_printf(m, "running: %d\n", (value > 0)); |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1325 | seq_printf(m, "force_on: %d\n", dev->force_fan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1328 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1331 | static int fan_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1333 | return single_open(file, fan_proc_show, PDE_DATA(inode)); |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | static ssize_t fan_proc_write(struct file *file, const char __user *buf, |
| 1337 | size_t count, loff_t *pos) |
| 1338 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1339 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1340 | char cmd[42]; |
| 1341 | size_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | int value; |
| 1343 | u32 hci_result; |
| 1344 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1345 | len = min(count, sizeof(cmd) - 1); |
| 1346 | if (copy_from_user(cmd, buf, len)) |
| 1347 | return -EFAULT; |
| 1348 | cmd[len] = '\0'; |
| 1349 | |
| 1350 | if (sscanf(cmd, " force_on : %i", &value) == 1 && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1351 | value >= 0 && value <= 1) { |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 1352 | hci_result = hci_write1(dev, HCI_FAN, value); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1353 | if (hci_result != TOS_SUCCESS) |
Seth Forshee | 32bcd5c | 2011-09-20 16:55:50 -0500 | [diff] [blame] | 1354 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | else |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1356 | dev->force_fan = value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | } else { |
| 1358 | return -EINVAL; |
| 1359 | } |
| 1360 | |
| 1361 | return count; |
| 1362 | } |
| 1363 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1364 | static const struct file_operations fan_proc_fops = { |
| 1365 | .owner = THIS_MODULE, |
| 1366 | .open = fan_proc_open, |
| 1367 | .read = seq_read, |
| 1368 | .llseek = seq_lseek, |
| 1369 | .release = single_release, |
| 1370 | .write = fan_proc_write, |
| 1371 | }; |
| 1372 | |
| 1373 | static int keys_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1375 | struct toshiba_acpi_dev *dev = m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | u32 hci_result; |
| 1377 | u32 value; |
| 1378 | |
Seth Forshee | 11948b9 | 2011-11-16 17:37:45 -0600 | [diff] [blame] | 1379 | if (!dev->key_event_valid && dev->system_event_supported) { |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 1380 | hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1381 | if (hci_result == TOS_SUCCESS) { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1382 | dev->key_event_valid = 1; |
| 1383 | dev->last_key_event = value; |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1384 | } else if (hci_result == TOS_FIFO_EMPTY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | /* better luck next time */ |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 1386 | } else if (hci_result == TOS_NOT_SUPPORTED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | /* This is a workaround for an unresolved issue on |
| 1388 | * some machines where system events sporadically |
| 1389 | * become disabled. */ |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 1390 | hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1); |
Joe Perches | 7e33460 | 2011-03-29 15:21:52 -0700 | [diff] [blame] | 1391 | pr_notice("Re-enabled hotkeys\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | } else { |
Joe Perches | 7e33460 | 2011-03-29 15:21:52 -0700 | [diff] [blame] | 1393 | pr_err("Error reading hotkey status\n"); |
Seth Forshee | 32bcd5c | 2011-09-20 16:55:50 -0500 | [diff] [blame] | 1394 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1398 | seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid); |
| 1399 | seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event); |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1400 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1403 | static int keys_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1405 | return single_open(file, keys_proc_show, PDE_DATA(inode)); |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | static ssize_t keys_proc_write(struct file *file, const char __user *buf, |
| 1409 | size_t count, loff_t *pos) |
| 1410 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1411 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1412 | char cmd[42]; |
| 1413 | size_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | int value; |
| 1415 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1416 | len = min(count, sizeof(cmd) - 1); |
| 1417 | if (copy_from_user(cmd, buf, len)) |
| 1418 | return -EFAULT; |
| 1419 | cmd[len] = '\0'; |
| 1420 | |
| 1421 | if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1422 | dev->key_event_valid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | } else { |
| 1424 | return -EINVAL; |
| 1425 | } |
| 1426 | |
| 1427 | return count; |
| 1428 | } |
| 1429 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1430 | static const struct file_operations keys_proc_fops = { |
| 1431 | .owner = THIS_MODULE, |
| 1432 | .open = keys_proc_open, |
| 1433 | .read = seq_read, |
| 1434 | .llseek = seq_lseek, |
| 1435 | .release = single_release, |
| 1436 | .write = keys_proc_write, |
| 1437 | }; |
| 1438 | |
| 1439 | static int version_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | { |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1441 | seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION); |
| 1442 | seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION); |
| 1443 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1446 | static int version_proc_open(struct inode *inode, struct file *file) |
| 1447 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1448 | return single_open(file, version_proc_show, PDE_DATA(inode)); |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | static const struct file_operations version_proc_fops = { |
| 1452 | .owner = THIS_MODULE, |
| 1453 | .open = version_proc_open, |
| 1454 | .read = seq_read, |
| 1455 | .llseek = seq_lseek, |
| 1456 | .release = single_release, |
| 1457 | }; |
| 1458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | /* proc and module init |
| 1460 | */ |
| 1461 | |
| 1462 | #define PROC_TOSHIBA "toshiba" |
| 1463 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 1464 | static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | { |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1466 | if (dev->backlight_dev) |
| 1467 | proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, |
| 1468 | &lcd_proc_fops, dev); |
| 1469 | if (dev->video_supported) |
| 1470 | proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, |
| 1471 | &video_proc_fops, dev); |
| 1472 | if (dev->fan_supported) |
| 1473 | proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, |
| 1474 | &fan_proc_fops, dev); |
| 1475 | if (dev->hotkey_dev) |
| 1476 | proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, |
| 1477 | &keys_proc_fops, dev); |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 1478 | proc_create_data("version", S_IRUGO, toshiba_proc_dir, |
| 1479 | &version_proc_fops, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1482 | static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | { |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 1484 | if (dev->backlight_dev) |
| 1485 | remove_proc_entry("lcd", toshiba_proc_dir); |
| 1486 | if (dev->video_supported) |
| 1487 | remove_proc_entry("video", toshiba_proc_dir); |
| 1488 | if (dev->fan_supported) |
| 1489 | remove_proc_entry("fan", toshiba_proc_dir); |
| 1490 | if (dev->hotkey_dev) |
| 1491 | remove_proc_entry("keys", toshiba_proc_dir); |
Alexey Dobriyan | 936c8bc | 2009-12-21 16:20:02 -0800 | [diff] [blame] | 1492 | remove_proc_entry("version", toshiba_proc_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
Lionel Debroux | acc2472 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 1495 | static const struct backlight_ops toshiba_backlight_data = { |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 1496 | .options = BL_CORE_SUSPENDRESUME, |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 1497 | .get_brightness = get_lcd_brightness, |
| 1498 | .update_status = set_lcd_status, |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 1499 | }; |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 1500 | |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1501 | /* |
| 1502 | * Sysfs files |
| 1503 | */ |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1504 | static ssize_t toshiba_kbd_bl_mode_store(struct device *dev, |
| 1505 | struct device_attribute *attr, |
| 1506 | const char *buf, size_t count); |
| 1507 | static ssize_t toshiba_kbd_bl_mode_show(struct device *dev, |
| 1508 | struct device_attribute *attr, |
| 1509 | char *buf); |
| 1510 | static ssize_t toshiba_kbd_type_show(struct device *dev, |
| 1511 | struct device_attribute *attr, |
| 1512 | char *buf); |
| 1513 | static ssize_t toshiba_available_kbd_modes_show(struct device *dev, |
| 1514 | struct device_attribute *attr, |
| 1515 | char *buf); |
| 1516 | static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev, |
| 1517 | struct device_attribute *attr, |
| 1518 | const char *buf, size_t count); |
| 1519 | static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev, |
| 1520 | struct device_attribute *attr, |
| 1521 | char *buf); |
| 1522 | static ssize_t toshiba_touchpad_store(struct device *dev, |
| 1523 | struct device_attribute *attr, |
| 1524 | const char *buf, size_t count); |
| 1525 | static ssize_t toshiba_touchpad_show(struct device *dev, |
| 1526 | struct device_attribute *attr, |
| 1527 | char *buf); |
| 1528 | static ssize_t toshiba_position_show(struct device *dev, |
| 1529 | struct device_attribute *attr, |
| 1530 | char *buf); |
Azael Avalos | e26ffe5 | 2015-01-18 18:30:22 -0700 | [diff] [blame] | 1531 | static ssize_t toshiba_usb_sleep_charge_show(struct device *dev, |
| 1532 | struct device_attribute *attr, |
| 1533 | char *buf); |
| 1534 | static ssize_t toshiba_usb_sleep_charge_store(struct device *dev, |
| 1535 | struct device_attribute *attr, |
| 1536 | const char *buf, size_t count); |
Azael Avalos | 182bcaa | 2015-01-18 18:30:23 -0700 | [diff] [blame] | 1537 | static ssize_t sleep_functions_on_battery_show(struct device *dev, |
| 1538 | struct device_attribute *attr, |
| 1539 | char *buf); |
| 1540 | static ssize_t sleep_functions_on_battery_store(struct device *dev, |
| 1541 | struct device_attribute *attr, |
| 1542 | const char *buf, size_t count); |
Azael Avalos | bb3fe01 | 2015-01-18 18:30:24 -0700 | [diff] [blame] | 1543 | static ssize_t toshiba_usb_rapid_charge_show(struct device *dev, |
| 1544 | struct device_attribute *attr, |
| 1545 | char *buf); |
| 1546 | static ssize_t toshiba_usb_rapid_charge_store(struct device *dev, |
| 1547 | struct device_attribute *attr, |
| 1548 | const char *buf, size_t count); |
Azael Avalos | 172ce0a | 2015-01-18 18:30:25 -0700 | [diff] [blame^] | 1549 | static ssize_t toshiba_usb_sleep_music_show(struct device *dev, |
| 1550 | struct device_attribute *attr, |
| 1551 | char *buf); |
| 1552 | static ssize_t toshiba_usb_sleep_music_store(struct device *dev, |
| 1553 | struct device_attribute *attr, |
| 1554 | const char *buf, size_t count); |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1555 | |
| 1556 | static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR, |
| 1557 | toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store); |
| 1558 | static DEVICE_ATTR(kbd_type, S_IRUGO, toshiba_kbd_type_show, NULL); |
| 1559 | static DEVICE_ATTR(available_kbd_modes, S_IRUGO, |
| 1560 | toshiba_available_kbd_modes_show, NULL); |
| 1561 | static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR, |
| 1562 | toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store); |
| 1563 | static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR, |
| 1564 | toshiba_touchpad_show, toshiba_touchpad_store); |
| 1565 | static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL); |
Azael Avalos | e26ffe5 | 2015-01-18 18:30:22 -0700 | [diff] [blame] | 1566 | static DEVICE_ATTR(usb_sleep_charge, S_IRUGO | S_IWUSR, |
| 1567 | toshiba_usb_sleep_charge_show, |
| 1568 | toshiba_usb_sleep_charge_store); |
Azael Avalos | 182bcaa | 2015-01-18 18:30:23 -0700 | [diff] [blame] | 1569 | static DEVICE_ATTR(sleep_functions_on_battery, S_IRUGO | S_IWUSR, |
| 1570 | sleep_functions_on_battery_show, |
| 1571 | sleep_functions_on_battery_store); |
Azael Avalos | bb3fe01 | 2015-01-18 18:30:24 -0700 | [diff] [blame] | 1572 | static DEVICE_ATTR(usb_rapid_charge, S_IRUGO | S_IWUSR, |
| 1573 | toshiba_usb_rapid_charge_show, |
| 1574 | toshiba_usb_rapid_charge_store); |
Azael Avalos | 172ce0a | 2015-01-18 18:30:25 -0700 | [diff] [blame^] | 1575 | static DEVICE_ATTR(usb_sleep_music, S_IRUGO | S_IWUSR, |
| 1576 | toshiba_usb_sleep_music_show, |
| 1577 | toshiba_usb_sleep_music_store); |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1578 | |
| 1579 | static struct attribute *toshiba_attributes[] = { |
| 1580 | &dev_attr_kbd_backlight_mode.attr, |
| 1581 | &dev_attr_kbd_type.attr, |
| 1582 | &dev_attr_available_kbd_modes.attr, |
| 1583 | &dev_attr_kbd_backlight_timeout.attr, |
| 1584 | &dev_attr_touchpad.attr, |
| 1585 | &dev_attr_position.attr, |
Azael Avalos | e26ffe5 | 2015-01-18 18:30:22 -0700 | [diff] [blame] | 1586 | &dev_attr_usb_sleep_charge.attr, |
Azael Avalos | 182bcaa | 2015-01-18 18:30:23 -0700 | [diff] [blame] | 1587 | &dev_attr_sleep_functions_on_battery.attr, |
Azael Avalos | bb3fe01 | 2015-01-18 18:30:24 -0700 | [diff] [blame] | 1588 | &dev_attr_usb_rapid_charge.attr, |
Azael Avalos | 172ce0a | 2015-01-18 18:30:25 -0700 | [diff] [blame^] | 1589 | &dev_attr_usb_sleep_music.attr, |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1590 | NULL, |
| 1591 | }; |
| 1592 | |
| 1593 | static umode_t toshiba_sysfs_is_visible(struct kobject *, |
| 1594 | struct attribute *, int); |
| 1595 | |
| 1596 | static struct attribute_group toshiba_attr_group = { |
| 1597 | .is_visible = toshiba_sysfs_is_visible, |
| 1598 | .attrs = toshiba_attributes, |
| 1599 | }; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1600 | |
| 1601 | static ssize_t toshiba_kbd_bl_mode_store(struct device *dev, |
| 1602 | struct device_attribute *attr, |
| 1603 | const char *buf, size_t count) |
| 1604 | { |
| 1605 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
Dan Carpenter | aeaac09 | 2014-09-03 14:44:37 +0300 | [diff] [blame] | 1606 | int mode; |
| 1607 | int time; |
| 1608 | int ret; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1609 | |
Dan Carpenter | aeaac09 | 2014-09-03 14:44:37 +0300 | [diff] [blame] | 1610 | |
| 1611 | ret = kstrtoint(buf, 0, &mode); |
| 1612 | if (ret) |
| 1613 | return ret; |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1614 | |
| 1615 | /* Check for supported modes depending on keyboard backlight type */ |
| 1616 | if (toshiba->kbd_type == 1) { |
| 1617 | /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */ |
| 1618 | if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO) |
| 1619 | return -EINVAL; |
| 1620 | } else if (toshiba->kbd_type == 2) { |
| 1621 | /* Type 2 doesn't support SCI_KBD_MODE_FNZ */ |
| 1622 | if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON && |
| 1623 | mode != SCI_KBD_MODE_OFF) |
| 1624 | return -EINVAL; |
| 1625 | } |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1626 | |
| 1627 | /* Set the Keyboard Backlight Mode where: |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1628 | * Auto - KBD backlight turns off automatically in given time |
| 1629 | * FN-Z - KBD backlight "toggles" when hotkey pressed |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1630 | * ON - KBD backlight is always on |
| 1631 | * OFF - KBD backlight is always off |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1632 | */ |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1633 | |
| 1634 | /* Only make a change if the actual mode has changed */ |
Dan Carpenter | aeaac09 | 2014-09-03 14:44:37 +0300 | [diff] [blame] | 1635 | if (toshiba->kbd_mode != mode) { |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1636 | /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1637 | time = toshiba->kbd_time << HCI_MISC_SHIFT; |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1638 | |
| 1639 | /* OR the "base time" to the actual method format */ |
| 1640 | if (toshiba->kbd_type == 1) { |
| 1641 | /* Type 1 requires the current mode */ |
| 1642 | time |= toshiba->kbd_mode; |
| 1643 | } else if (toshiba->kbd_type == 2) { |
| 1644 | /* Type 2 requires the desired mode */ |
| 1645 | time |= mode; |
| 1646 | } |
| 1647 | |
Dan Carpenter | aeaac09 | 2014-09-03 14:44:37 +0300 | [diff] [blame] | 1648 | ret = toshiba_kbd_illum_status_set(toshiba, time); |
| 1649 | if (ret) |
| 1650 | return ret; |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1651 | |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1652 | toshiba->kbd_mode = mode; |
| 1653 | } |
| 1654 | |
| 1655 | return count; |
| 1656 | } |
| 1657 | |
| 1658 | static ssize_t toshiba_kbd_bl_mode_show(struct device *dev, |
| 1659 | struct device_attribute *attr, |
| 1660 | char *buf) |
| 1661 | { |
| 1662 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1663 | u32 time; |
| 1664 | |
| 1665 | if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) |
| 1666 | return -EIO; |
| 1667 | |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 1668 | return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK); |
| 1669 | } |
| 1670 | |
| 1671 | static ssize_t toshiba_kbd_type_show(struct device *dev, |
| 1672 | struct device_attribute *attr, |
| 1673 | char *buf) |
| 1674 | { |
| 1675 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1676 | |
| 1677 | return sprintf(buf, "%d\n", toshiba->kbd_type); |
| 1678 | } |
| 1679 | |
| 1680 | static ssize_t toshiba_available_kbd_modes_show(struct device *dev, |
| 1681 | struct device_attribute *attr, |
| 1682 | char *buf) |
| 1683 | { |
| 1684 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1685 | |
| 1686 | if (toshiba->kbd_type == 1) |
| 1687 | return sprintf(buf, "%x %x\n", |
| 1688 | SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO); |
| 1689 | |
| 1690 | return sprintf(buf, "%x %x %x\n", |
| 1691 | SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF); |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev, |
| 1695 | struct device_attribute *attr, |
| 1696 | const char *buf, size_t count) |
| 1697 | { |
| 1698 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
Azael Avalos | eabde0f | 2014-10-04 12:02:21 -0600 | [diff] [blame] | 1699 | int time; |
| 1700 | int ret; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1701 | |
Azael Avalos | eabde0f | 2014-10-04 12:02:21 -0600 | [diff] [blame] | 1702 | ret = kstrtoint(buf, 0, &time); |
| 1703 | if (ret) |
| 1704 | return ret; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1705 | |
Azael Avalos | eabde0f | 2014-10-04 12:02:21 -0600 | [diff] [blame] | 1706 | /* Check for supported values depending on kbd_type */ |
| 1707 | if (toshiba->kbd_type == 1) { |
| 1708 | if (time < 0 || time > 60) |
| 1709 | return -EINVAL; |
| 1710 | } else if (toshiba->kbd_type == 2) { |
| 1711 | if (time < 1 || time > 60) |
| 1712 | return -EINVAL; |
| 1713 | } |
| 1714 | |
| 1715 | /* Set the Keyboard Backlight Timeout */ |
| 1716 | |
| 1717 | /* Only make a change if the actual timeout has changed */ |
| 1718 | if (toshiba->kbd_time != time) { |
| 1719 | /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1720 | time = time << HCI_MISC_SHIFT; |
Azael Avalos | eabde0f | 2014-10-04 12:02:21 -0600 | [diff] [blame] | 1721 | /* OR the "base time" to the actual method format */ |
| 1722 | if (toshiba->kbd_type == 1) |
| 1723 | time |= SCI_KBD_MODE_FNZ; |
| 1724 | else if (toshiba->kbd_type == 2) |
| 1725 | time |= SCI_KBD_MODE_AUTO; |
| 1726 | |
| 1727 | ret = toshiba_kbd_illum_status_set(toshiba, time); |
| 1728 | if (ret) |
| 1729 | return ret; |
| 1730 | |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1731 | toshiba->kbd_time = time >> HCI_MISC_SHIFT; |
| 1732 | } |
| 1733 | |
| 1734 | return count; |
| 1735 | } |
| 1736 | |
| 1737 | static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev, |
| 1738 | struct device_attribute *attr, |
| 1739 | char *buf) |
| 1740 | { |
| 1741 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1742 | u32 time; |
| 1743 | |
| 1744 | if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) |
| 1745 | return -EIO; |
| 1746 | |
| 1747 | return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT); |
| 1748 | } |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 1749 | |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 1750 | static ssize_t toshiba_touchpad_store(struct device *dev, |
| 1751 | struct device_attribute *attr, |
| 1752 | const char *buf, size_t count) |
| 1753 | { |
| 1754 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1755 | int state; |
Azael Avalos | c8a4166 | 2014-09-10 21:01:57 -0600 | [diff] [blame] | 1756 | int ret; |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 1757 | |
| 1758 | /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */ |
Azael Avalos | c8a4166 | 2014-09-10 21:01:57 -0600 | [diff] [blame] | 1759 | ret = kstrtoint(buf, 0, &state); |
| 1760 | if (ret) |
| 1761 | return ret; |
| 1762 | if (state != 0 && state != 1) |
| 1763 | return -EINVAL; |
| 1764 | |
| 1765 | ret = toshiba_touchpad_set(toshiba, state); |
| 1766 | if (ret) |
| 1767 | return ret; |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 1768 | |
| 1769 | return count; |
| 1770 | } |
| 1771 | |
| 1772 | static ssize_t toshiba_touchpad_show(struct device *dev, |
| 1773 | struct device_attribute *attr, char *buf) |
| 1774 | { |
| 1775 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1776 | u32 state; |
| 1777 | int ret; |
| 1778 | |
| 1779 | ret = toshiba_touchpad_get(toshiba, &state); |
| 1780 | if (ret < 0) |
| 1781 | return ret; |
| 1782 | |
| 1783 | return sprintf(buf, "%i\n", state); |
| 1784 | } |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 1785 | |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 1786 | static ssize_t toshiba_position_show(struct device *dev, |
| 1787 | struct device_attribute *attr, char *buf) |
| 1788 | { |
| 1789 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1790 | u32 xyval, zval, tmp; |
| 1791 | u16 x, y, z; |
| 1792 | int ret; |
| 1793 | |
| 1794 | xyval = zval = 0; |
| 1795 | ret = toshiba_accelerometer_get(toshiba, &xyval, &zval); |
| 1796 | if (ret < 0) |
| 1797 | return ret; |
| 1798 | |
| 1799 | x = xyval & HCI_ACCEL_MASK; |
| 1800 | tmp = xyval >> HCI_MISC_SHIFT; |
| 1801 | y = tmp & HCI_ACCEL_MASK; |
| 1802 | z = zval & HCI_ACCEL_MASK; |
| 1803 | |
| 1804 | return sprintf(buf, "%d %d %d\n", x, y, z); |
| 1805 | } |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1806 | |
Azael Avalos | e26ffe5 | 2015-01-18 18:30:22 -0700 | [diff] [blame] | 1807 | static ssize_t toshiba_usb_sleep_charge_show(struct device *dev, |
| 1808 | struct device_attribute *attr, |
| 1809 | char *buf) |
| 1810 | { |
| 1811 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1812 | u32 mode; |
| 1813 | int ret; |
| 1814 | |
| 1815 | ret = toshiba_usb_sleep_charge_get(toshiba, &mode); |
| 1816 | if (ret < 0) |
| 1817 | return ret; |
| 1818 | |
| 1819 | return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK); |
| 1820 | } |
| 1821 | |
| 1822 | static ssize_t toshiba_usb_sleep_charge_store(struct device *dev, |
| 1823 | struct device_attribute *attr, |
| 1824 | const char *buf, size_t count) |
| 1825 | { |
| 1826 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1827 | u32 mode; |
| 1828 | int state; |
| 1829 | int ret; |
| 1830 | |
| 1831 | ret = kstrtoint(buf, 0, &state); |
| 1832 | if (ret) |
| 1833 | return ret; |
| 1834 | /* Check for supported values, where: |
| 1835 | * 0 - Disabled |
| 1836 | * 1 - Alternate (Non USB conformant devices that require more power) |
| 1837 | * 2 - Auto (USB conformant devices) |
| 1838 | */ |
| 1839 | if (state != 0 && state != 1 && state != 2) |
| 1840 | return -EINVAL; |
| 1841 | |
| 1842 | /* Set the USB charging mode to internal value */ |
| 1843 | if (state == 0) |
| 1844 | mode = SCI_USB_CHARGE_DISABLED; |
| 1845 | else if (state == 1) |
| 1846 | mode = SCI_USB_CHARGE_ALTERNATE; |
| 1847 | else if (state == 2) |
| 1848 | mode = SCI_USB_CHARGE_AUTO; |
| 1849 | |
| 1850 | ret = toshiba_usb_sleep_charge_set(toshiba, mode); |
| 1851 | if (ret) |
| 1852 | return ret; |
| 1853 | |
| 1854 | return count; |
| 1855 | } |
| 1856 | |
Azael Avalos | 182bcaa | 2015-01-18 18:30:23 -0700 | [diff] [blame] | 1857 | static ssize_t sleep_functions_on_battery_show(struct device *dev, |
| 1858 | struct device_attribute *attr, |
| 1859 | char *buf) |
| 1860 | { |
| 1861 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1862 | u32 state; |
| 1863 | int bat_lvl; |
| 1864 | int status; |
| 1865 | int ret; |
| 1866 | int tmp; |
| 1867 | |
| 1868 | ret = toshiba_sleep_functions_status_get(toshiba, &state); |
| 1869 | if (ret < 0) |
| 1870 | return ret; |
| 1871 | |
| 1872 | /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */ |
| 1873 | tmp = state & SCI_USB_CHARGE_BAT_MASK; |
| 1874 | status = (tmp == 0x4) ? 1 : 0; |
| 1875 | /* Determine the battery level set */ |
| 1876 | bat_lvl = state >> HCI_MISC_SHIFT; |
| 1877 | |
| 1878 | return sprintf(buf, "%d %d\n", status, bat_lvl); |
| 1879 | } |
| 1880 | |
| 1881 | static ssize_t sleep_functions_on_battery_store(struct device *dev, |
| 1882 | struct device_attribute *attr, |
| 1883 | const char *buf, size_t count) |
| 1884 | { |
| 1885 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1886 | u32 status; |
| 1887 | int value; |
| 1888 | int ret; |
| 1889 | int tmp; |
| 1890 | |
| 1891 | ret = kstrtoint(buf, 0, &value); |
| 1892 | if (ret) |
| 1893 | return ret; |
| 1894 | |
| 1895 | /* Set the status of the function: |
| 1896 | * 0 - Disabled |
| 1897 | * 1-100 - Enabled |
| 1898 | */ |
| 1899 | if (value < 0 || value > 100) |
| 1900 | return -EINVAL; |
| 1901 | |
| 1902 | if (value == 0) { |
| 1903 | tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT; |
| 1904 | status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF; |
| 1905 | } else { |
| 1906 | tmp = value << HCI_MISC_SHIFT; |
| 1907 | status = tmp | SCI_USB_CHARGE_BAT_LVL_ON; |
| 1908 | } |
| 1909 | ret = toshiba_sleep_functions_status_set(toshiba, status); |
| 1910 | if (ret < 0) |
| 1911 | return ret; |
| 1912 | |
| 1913 | toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT; |
| 1914 | |
| 1915 | return count; |
| 1916 | } |
| 1917 | |
Azael Avalos | bb3fe01 | 2015-01-18 18:30:24 -0700 | [diff] [blame] | 1918 | static ssize_t toshiba_usb_rapid_charge_show(struct device *dev, |
| 1919 | struct device_attribute *attr, |
| 1920 | char *buf) |
| 1921 | { |
| 1922 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1923 | u32 state; |
| 1924 | int ret; |
| 1925 | |
| 1926 | ret = toshiba_usb_rapid_charge_get(toshiba, &state); |
| 1927 | if (ret < 0) |
| 1928 | return ret; |
| 1929 | |
| 1930 | return sprintf(buf, "%d\n", state); |
| 1931 | } |
| 1932 | |
| 1933 | static ssize_t toshiba_usb_rapid_charge_store(struct device *dev, |
| 1934 | struct device_attribute *attr, |
| 1935 | const char *buf, size_t count) |
| 1936 | { |
| 1937 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1938 | int state; |
| 1939 | int ret; |
| 1940 | |
| 1941 | ret = kstrtoint(buf, 0, &state); |
| 1942 | if (ret) |
| 1943 | return ret; |
| 1944 | if (state != 0 && state != 1) |
| 1945 | return -EINVAL; |
| 1946 | |
| 1947 | ret = toshiba_usb_rapid_charge_set(toshiba, state); |
| 1948 | if (ret) |
| 1949 | return ret; |
| 1950 | |
| 1951 | return count; |
| 1952 | } |
| 1953 | |
Azael Avalos | 172ce0a | 2015-01-18 18:30:25 -0700 | [diff] [blame^] | 1954 | static ssize_t toshiba_usb_sleep_music_show(struct device *dev, |
| 1955 | struct device_attribute *attr, |
| 1956 | char *buf) |
| 1957 | { |
| 1958 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1959 | u32 state; |
| 1960 | int ret; |
| 1961 | |
| 1962 | ret = toshiba_usb_sleep_music_get(toshiba, &state); |
| 1963 | if (ret < 0) |
| 1964 | return ret; |
| 1965 | |
| 1966 | return sprintf(buf, "%d\n", state); |
| 1967 | } |
| 1968 | |
| 1969 | static ssize_t toshiba_usb_sleep_music_store(struct device *dev, |
| 1970 | struct device_attribute *attr, |
| 1971 | const char *buf, size_t count) |
| 1972 | { |
| 1973 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); |
| 1974 | int state; |
| 1975 | int ret; |
| 1976 | |
| 1977 | ret = kstrtoint(buf, 0, &state); |
| 1978 | if (ret) |
| 1979 | return ret; |
| 1980 | if (state != 0 && state != 1) |
| 1981 | return -EINVAL; |
| 1982 | |
| 1983 | ret = toshiba_usb_sleep_music_set(toshiba, state); |
| 1984 | if (ret) |
| 1985 | return ret; |
| 1986 | |
| 1987 | return count; |
| 1988 | } |
| 1989 | |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 1990 | static umode_t toshiba_sysfs_is_visible(struct kobject *kobj, |
| 1991 | struct attribute *attr, int idx) |
| 1992 | { |
| 1993 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1994 | struct toshiba_acpi_dev *drv = dev_get_drvdata(dev); |
| 1995 | bool exists = true; |
| 1996 | |
| 1997 | if (attr == &dev_attr_kbd_backlight_mode.attr) |
| 1998 | exists = (drv->kbd_illum_supported) ? true : false; |
| 1999 | else if (attr == &dev_attr_kbd_backlight_timeout.attr) |
| 2000 | exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false; |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 2001 | else if (attr == &dev_attr_touchpad.attr) |
| 2002 | exists = (drv->touchpad_supported) ? true : false; |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 2003 | else if (attr == &dev_attr_position.attr) |
| 2004 | exists = (drv->accelerometer_supported) ? true : false; |
Azael Avalos | e26ffe5 | 2015-01-18 18:30:22 -0700 | [diff] [blame] | 2005 | else if (attr == &dev_attr_usb_sleep_charge.attr) |
| 2006 | exists = (drv->usb_sleep_charge_supported) ? true : false; |
Azael Avalos | 182bcaa | 2015-01-18 18:30:23 -0700 | [diff] [blame] | 2007 | else if (attr == &dev_attr_sleep_functions_on_battery.attr) |
| 2008 | exists = (drv->usb_sleep_charge_supported) ? true : false; |
Azael Avalos | bb3fe01 | 2015-01-18 18:30:24 -0700 | [diff] [blame] | 2009 | else if (attr == &dev_attr_usb_rapid_charge.attr) |
| 2010 | exists = (drv->usb_rapid_charge_supported) ? true : false; |
Azael Avalos | 172ce0a | 2015-01-18 18:30:25 -0700 | [diff] [blame^] | 2011 | else if (attr == &dev_attr_usb_sleep_music.attr) |
| 2012 | exists = (drv->usb_sleep_music_supported) ? true : false; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 2013 | |
| 2014 | return exists ? attr->mode : 0; |
| 2015 | } |
| 2016 | |
Azael Avalos | 1f28f29 | 2014-12-04 20:22:45 -0700 | [diff] [blame] | 2017 | /* |
| 2018 | * Hotkeys |
| 2019 | */ |
| 2020 | static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev) |
| 2021 | { |
| 2022 | acpi_status status; |
| 2023 | u32 result; |
| 2024 | |
| 2025 | status = acpi_evaluate_object(dev->acpi_dev->handle, |
| 2026 | "ENAB", NULL, NULL); |
| 2027 | if (ACPI_FAILURE(status)) |
| 2028 | return -ENODEV; |
| 2029 | |
| 2030 | result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE); |
| 2031 | if (result == TOS_FAILURE) |
| 2032 | return -EIO; |
| 2033 | else if (result == TOS_NOT_SUPPORTED) |
| 2034 | return -ENODEV; |
| 2035 | |
| 2036 | return 0; |
| 2037 | } |
| 2038 | |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2039 | static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str, |
| 2040 | struct serio *port) |
| 2041 | { |
Giedrius Statkevičius | 9828037 | 2014-10-18 02:57:20 +0300 | [diff] [blame] | 2042 | if (str & I8042_STR_AUXDATA) |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2043 | return false; |
| 2044 | |
| 2045 | if (unlikely(data == 0xe0)) |
| 2046 | return false; |
| 2047 | |
| 2048 | if ((data & 0x7f) == TOS1900_FN_SCAN) { |
| 2049 | schedule_work(&toshiba_acpi->hotkey_work); |
| 2050 | return true; |
| 2051 | } |
| 2052 | |
| 2053 | return false; |
| 2054 | } |
| 2055 | |
| 2056 | static void toshiba_acpi_hotkey_work(struct work_struct *work) |
| 2057 | { |
| 2058 | acpi_handle ec_handle = ec_get_handle(); |
| 2059 | acpi_status status; |
| 2060 | |
| 2061 | if (!ec_handle) |
| 2062 | return; |
| 2063 | |
| 2064 | status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL); |
| 2065 | if (ACPI_FAILURE(status)) |
| 2066 | pr_err("ACPI NTFY method execution failed\n"); |
| 2067 | } |
| 2068 | |
| 2069 | /* |
| 2070 | * Returns hotkey scancode, or < 0 on failure. |
| 2071 | */ |
| 2072 | static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev) |
| 2073 | { |
Zhang Rui | 74facaf | 2013-09-03 08:32:15 +0800 | [diff] [blame] | 2074 | unsigned long long value; |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2075 | acpi_status status; |
| 2076 | |
Zhang Rui | 74facaf | 2013-09-03 08:32:15 +0800 | [diff] [blame] | 2077 | status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO", |
| 2078 | NULL, &value); |
| 2079 | if (ACPI_FAILURE(status)) { |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2080 | pr_err("ACPI INFO method execution failed\n"); |
| 2081 | return -EIO; |
| 2082 | } |
| 2083 | |
Zhang Rui | 74facaf | 2013-09-03 08:32:15 +0800 | [diff] [blame] | 2084 | return value; |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev, |
| 2088 | int scancode) |
| 2089 | { |
| 2090 | if (scancode == 0x100) |
| 2091 | return; |
| 2092 | |
| 2093 | /* act on key press; ignore key release */ |
| 2094 | if (scancode & 0x80) |
| 2095 | return; |
| 2096 | |
| 2097 | if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true)) |
| 2098 | pr_info("Unknown key %x\n", scancode); |
| 2099 | } |
| 2100 | |
Azael Avalos | 71454d7 | 2014-12-04 20:22:46 -0700 | [diff] [blame] | 2101 | static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev) |
| 2102 | { |
| 2103 | u32 hci_result, value; |
| 2104 | int retries = 3; |
| 2105 | int scancode; |
| 2106 | |
| 2107 | if (dev->info_supported) { |
| 2108 | scancode = toshiba_acpi_query_hotkey(dev); |
| 2109 | if (scancode < 0) |
| 2110 | pr_err("Failed to query hotkey event\n"); |
| 2111 | else if (scancode != 0) |
| 2112 | toshiba_acpi_report_hotkey(dev, scancode); |
| 2113 | } else if (dev->system_event_supported) { |
| 2114 | do { |
| 2115 | hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value); |
| 2116 | switch (hci_result) { |
| 2117 | case TOS_SUCCESS: |
| 2118 | toshiba_acpi_report_hotkey(dev, (int)value); |
| 2119 | break; |
| 2120 | case TOS_NOT_SUPPORTED: |
| 2121 | /* |
| 2122 | * This is a workaround for an unresolved |
| 2123 | * issue on some machines where system events |
| 2124 | * sporadically become disabled. |
| 2125 | */ |
| 2126 | hci_result = |
| 2127 | hci_write1(dev, HCI_SYSTEM_EVENT, 1); |
| 2128 | pr_notice("Re-enabled hotkeys\n"); |
| 2129 | /* fall through */ |
| 2130 | default: |
| 2131 | retries--; |
| 2132 | break; |
| 2133 | } |
| 2134 | } while (retries && hci_result != TOS_FIFO_EMPTY); |
| 2135 | } |
| 2136 | } |
| 2137 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 2138 | static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 2139 | { |
Zhang Rui | e2e1960 | 2013-09-03 08:32:06 +0800 | [diff] [blame] | 2140 | acpi_handle ec_handle; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2141 | int error; |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2142 | u32 hci_result; |
Takashi Iwai | fe808bfb | 2014-04-29 15:15:38 +0200 | [diff] [blame] | 2143 | const struct key_entry *keymap = toshiba_acpi_keymap; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2144 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2145 | dev->hotkey_dev = input_allocate_device(); |
Joe Perches | b222cca | 2013-10-23 12:14:52 -0700 | [diff] [blame] | 2146 | if (!dev->hotkey_dev) |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2147 | return -ENOMEM; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2148 | |
| 2149 | dev->hotkey_dev->name = "Toshiba input device"; |
Seth Forshee | 6e02cc7 | 2011-09-20 16:55:51 -0500 | [diff] [blame] | 2150 | dev->hotkey_dev->phys = "toshiba_acpi/input0"; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2151 | dev->hotkey_dev->id.bustype = BUS_HOST; |
| 2152 | |
Takashi Iwai | fe808bfb | 2014-04-29 15:15:38 +0200 | [diff] [blame] | 2153 | if (dmi_check_system(toshiba_alt_keymap_dmi)) |
| 2154 | keymap = toshiba_acpi_alt_keymap; |
| 2155 | error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL); |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2156 | if (error) |
| 2157 | goto err_free_dev; |
| 2158 | |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2159 | /* |
| 2160 | * For some machines the SCI responsible for providing hotkey |
| 2161 | * notification doesn't fire. We can trigger the notification |
| 2162 | * whenever the Fn key is pressed using the NTFY method, if |
| 2163 | * supported, so if it's present set up an i8042 key filter |
| 2164 | * for this purpose. |
| 2165 | */ |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2166 | ec_handle = ec_get_handle(); |
Zhang Rui | e2e1960 | 2013-09-03 08:32:06 +0800 | [diff] [blame] | 2167 | if (ec_handle && acpi_has_method(ec_handle, "NTFY")) { |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2168 | INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work); |
| 2169 | |
| 2170 | error = i8042_install_filter(toshiba_acpi_i8042_filter); |
| 2171 | if (error) { |
| 2172 | pr_err("Error installing key filter\n"); |
| 2173 | goto err_free_keymap; |
| 2174 | } |
| 2175 | |
| 2176 | dev->ntfy_supported = 1; |
| 2177 | } |
| 2178 | |
| 2179 | /* |
| 2180 | * Determine hotkey query interface. Prefer using the INFO |
| 2181 | * method when it is available. |
| 2182 | */ |
Zhang Rui | e2e1960 | 2013-09-03 08:32:06 +0800 | [diff] [blame] | 2183 | if (acpi_has_method(dev->acpi_dev->handle, "INFO")) |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2184 | dev->info_supported = 1; |
Zhang Rui | e2e1960 | 2013-09-03 08:32:06 +0800 | [diff] [blame] | 2185 | else { |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 2186 | hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1); |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 2187 | if (hci_result == TOS_SUCCESS) |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2188 | dev->system_event_supported = 1; |
| 2189 | } |
| 2190 | |
| 2191 | if (!dev->info_supported && !dev->system_event_supported) { |
| 2192 | pr_warn("No hotkey query interface found\n"); |
| 2193 | goto err_remove_filter; |
| 2194 | } |
| 2195 | |
Azael Avalos | 1f28f29 | 2014-12-04 20:22:45 -0700 | [diff] [blame] | 2196 | error = toshiba_acpi_enable_hotkeys(dev); |
| 2197 | if (error) { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2198 | pr_info("Unable to enable hotkeys\n"); |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2199 | goto err_remove_filter; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | error = input_register_device(dev->hotkey_dev); |
| 2203 | if (error) { |
| 2204 | pr_info("Unable to register input device\n"); |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2205 | goto err_remove_filter; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | return 0; |
| 2209 | |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2210 | err_remove_filter: |
| 2211 | if (dev->ntfy_supported) |
| 2212 | i8042_remove_filter(toshiba_acpi_i8042_filter); |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2213 | err_free_keymap: |
| 2214 | sparse_keymap_free(dev->hotkey_dev); |
| 2215 | err_free_dev: |
| 2216 | input_free_device(dev->hotkey_dev); |
| 2217 | dev->hotkey_dev = NULL; |
| 2218 | return error; |
| 2219 | } |
| 2220 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 2221 | static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev) |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 2222 | { |
| 2223 | struct backlight_properties props; |
| 2224 | int brightness; |
| 2225 | int ret; |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 2226 | bool enabled; |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 2227 | |
| 2228 | /* |
| 2229 | * Some machines don't support the backlight methods at all, and |
| 2230 | * others support it read-only. Either of these is pretty useless, |
| 2231 | * so only register the backlight device if the backlight method |
| 2232 | * supports both reads and writes. |
| 2233 | */ |
| 2234 | brightness = __get_lcd_brightness(dev); |
| 2235 | if (brightness < 0) |
| 2236 | return 0; |
| 2237 | ret = set_lcd_brightness(dev, brightness); |
| 2238 | if (ret) { |
| 2239 | pr_debug("Backlight method is read-only, disabling backlight support\n"); |
| 2240 | return 0; |
| 2241 | } |
| 2242 | |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 2243 | /* Determine whether or not BIOS supports transflective backlight */ |
| 2244 | ret = get_tr_backlight_status(dev, &enabled); |
| 2245 | dev->tr_backlight_supported = !ret; |
| 2246 | |
Matthew Garrett | 53039f2 | 2012-06-01 11:02:36 -0400 | [diff] [blame] | 2247 | memset(&props, 0, sizeof(props)); |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 2248 | props.type = BACKLIGHT_PLATFORM; |
| 2249 | props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 2250 | |
Akio Idehara | 121b7b0 | 2012-04-06 01:46:43 +0900 | [diff] [blame] | 2251 | /* adding an extra level and having 0 change to transflective mode */ |
| 2252 | if (dev->tr_backlight_supported) |
| 2253 | props.max_brightness++; |
| 2254 | |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 2255 | dev->backlight_dev = backlight_device_register("toshiba", |
| 2256 | &dev->acpi_dev->dev, |
| 2257 | dev, |
| 2258 | &toshiba_backlight_data, |
| 2259 | &props); |
| 2260 | if (IS_ERR(dev->backlight_dev)) { |
| 2261 | ret = PTR_ERR(dev->backlight_dev); |
| 2262 | pr_err("Could not register toshiba backlight device\n"); |
| 2263 | dev->backlight_dev = NULL; |
| 2264 | return ret; |
| 2265 | } |
| 2266 | |
| 2267 | dev->backlight_dev->props.brightness = brightness; |
| 2268 | return 0; |
| 2269 | } |
| 2270 | |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 2271 | static int toshiba_acpi_remove(struct acpi_device *acpi_dev) |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2272 | { |
| 2273 | struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); |
| 2274 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 2275 | remove_toshiba_proc_entries(dev); |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 2276 | |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 2277 | if (dev->sysfs_created) |
| 2278 | sysfs_remove_group(&dev->acpi_dev->dev.kobj, |
| 2279 | &toshiba_attr_group); |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2280 | |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2281 | if (dev->ntfy_supported) { |
| 2282 | i8042_remove_filter(toshiba_acpi_i8042_filter); |
| 2283 | cancel_work_sync(&dev->hotkey_work); |
| 2284 | } |
| 2285 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2286 | if (dev->hotkey_dev) { |
| 2287 | input_unregister_device(dev->hotkey_dev); |
| 2288 | sparse_keymap_free(dev->hotkey_dev); |
| 2289 | } |
| 2290 | |
| 2291 | if (dev->bt_rfk) { |
| 2292 | rfkill_unregister(dev->bt_rfk); |
| 2293 | rfkill_destroy(dev->bt_rfk); |
| 2294 | } |
| 2295 | |
Markus Elfring | 0098181 | 2014-11-24 20:30:29 +0100 | [diff] [blame] | 2296 | backlight_device_unregister(dev->backlight_dev); |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2297 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 2298 | if (dev->illumination_supported) |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2299 | led_classdev_unregister(&dev->led_dev); |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 2300 | |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 2301 | if (dev->kbd_led_registered) |
| 2302 | led_classdev_unregister(&dev->kbd_led); |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 2303 | |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 2304 | if (dev->eco_supported) |
| 2305 | led_classdev_unregister(&dev->eco_led); |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2306 | |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2307 | if (toshiba_acpi) |
| 2308 | toshiba_acpi = NULL; |
| 2309 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2310 | kfree(dev); |
| 2311 | |
| 2312 | return 0; |
| 2313 | } |
| 2314 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 2315 | static const char *find_hci_method(acpi_handle handle) |
Seth Forshee | a540d6b | 2011-09-20 16:55:52 -0500 | [diff] [blame] | 2316 | { |
Zhang Rui | e2e1960 | 2013-09-03 08:32:06 +0800 | [diff] [blame] | 2317 | if (acpi_has_method(handle, "GHCI")) |
Seth Forshee | a540d6b | 2011-09-20 16:55:52 -0500 | [diff] [blame] | 2318 | return "GHCI"; |
| 2319 | |
Zhang Rui | e2e1960 | 2013-09-03 08:32:06 +0800 | [diff] [blame] | 2320 | if (acpi_has_method(handle, "SPFC")) |
Seth Forshee | a540d6b | 2011-09-20 16:55:52 -0500 | [diff] [blame] | 2321 | return "SPFC"; |
| 2322 | |
| 2323 | return NULL; |
| 2324 | } |
| 2325 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 2326 | static int toshiba_acpi_add(struct acpi_device *acpi_dev) |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2327 | { |
| 2328 | struct toshiba_acpi_dev *dev; |
Seth Forshee | a540d6b | 2011-09-20 16:55:52 -0500 | [diff] [blame] | 2329 | const char *hci_method; |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 2330 | u32 dummy; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2331 | bool bt_present; |
| 2332 | int ret = 0; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2333 | |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2334 | if (toshiba_acpi) |
| 2335 | return -EBUSY; |
| 2336 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2337 | pr_info("Toshiba Laptop ACPI Extras version %s\n", |
| 2338 | TOSHIBA_ACPI_VERSION); |
| 2339 | |
Seth Forshee | a540d6b | 2011-09-20 16:55:52 -0500 | [diff] [blame] | 2340 | hci_method = find_hci_method(acpi_dev->handle); |
| 2341 | if (!hci_method) { |
| 2342 | pr_err("HCI interface not found\n"); |
Seth Forshee | 6e02cc7 | 2011-09-20 16:55:51 -0500 | [diff] [blame] | 2343 | return -ENODEV; |
Seth Forshee | a540d6b | 2011-09-20 16:55:52 -0500 | [diff] [blame] | 2344 | } |
Seth Forshee | 6e02cc7 | 2011-09-20 16:55:51 -0500 | [diff] [blame] | 2345 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2346 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 2347 | if (!dev) |
| 2348 | return -ENOMEM; |
| 2349 | dev->acpi_dev = acpi_dev; |
Seth Forshee | a540d6b | 2011-09-20 16:55:52 -0500 | [diff] [blame] | 2350 | dev->method_hci = hci_method; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2351 | acpi_dev->driver_data = dev; |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 2352 | dev_set_drvdata(&acpi_dev->dev, dev); |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2353 | |
Seth Forshee | 6e02cc7 | 2011-09-20 16:55:51 -0500 | [diff] [blame] | 2354 | if (toshiba_acpi_setup_keyboard(dev)) |
| 2355 | pr_info("Unable to activate hotkeys\n"); |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2356 | |
| 2357 | mutex_init(&dev->mutex); |
| 2358 | |
Seth Forshee | 62cce75 | 2012-04-19 11:23:50 -0500 | [diff] [blame] | 2359 | ret = toshiba_acpi_setup_backlight(dev); |
| 2360 | if (ret) |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2361 | goto error; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2362 | |
| 2363 | /* Register rfkill switch for Bluetooth */ |
Azael Avalos | 1864bbc | 2014-09-29 20:40:08 -0600 | [diff] [blame] | 2364 | if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2365 | dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth", |
| 2366 | &acpi_dev->dev, |
| 2367 | RFKILL_TYPE_BLUETOOTH, |
| 2368 | &toshiba_rfk_ops, |
| 2369 | dev); |
| 2370 | if (!dev->bt_rfk) { |
| 2371 | pr_err("unable to allocate rfkill device\n"); |
| 2372 | ret = -ENOMEM; |
| 2373 | goto error; |
| 2374 | } |
| 2375 | |
| 2376 | ret = rfkill_register(dev->bt_rfk); |
| 2377 | if (ret) { |
| 2378 | pr_err("unable to register rfkill device\n"); |
| 2379 | rfkill_destroy(dev->bt_rfk); |
| 2380 | goto error; |
| 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | if (toshiba_illumination_available(dev)) { |
| 2385 | dev->led_dev.name = "toshiba::illumination"; |
| 2386 | dev->led_dev.max_brightness = 1; |
| 2387 | dev->led_dev.brightness_set = toshiba_illumination_set; |
| 2388 | dev->led_dev.brightness_get = toshiba_illumination_get; |
| 2389 | if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev)) |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 2390 | dev->illumination_supported = 1; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2391 | } |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 2392 | |
Azael Avalos | def6c4e | 2014-03-25 20:38:33 -0600 | [diff] [blame] | 2393 | if (toshiba_eco_mode_available(dev)) { |
| 2394 | dev->eco_led.name = "toshiba::eco_mode"; |
| 2395 | dev->eco_led.max_brightness = 1; |
| 2396 | dev->eco_led.brightness_set = toshiba_eco_mode_set_status; |
| 2397 | dev->eco_led.brightness_get = toshiba_eco_mode_get_status; |
| 2398 | if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led)) |
| 2399 | dev->eco_supported = 1; |
| 2400 | } |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 2401 | |
Azael Avalos | 93f8c16 | 2014-09-12 18:50:36 -0600 | [diff] [blame] | 2402 | dev->kbd_illum_supported = toshiba_kbd_illum_available(dev); |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 2403 | /* |
| 2404 | * Only register the LED if KBD illumination is supported |
| 2405 | * and the keyboard backlight operation mode is set to FN-Z |
| 2406 | */ |
| 2407 | if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) { |
| 2408 | dev->kbd_led.name = "toshiba::kbd_backlight"; |
| 2409 | dev->kbd_led.max_brightness = 1; |
| 2410 | dev->kbd_led.brightness_set = toshiba_kbd_backlight_set; |
| 2411 | dev->kbd_led.brightness_get = toshiba_kbd_backlight_get; |
| 2412 | if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led)) |
| 2413 | dev->kbd_led_registered = 1; |
| 2414 | } |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 2415 | |
Azael Avalos | 9d8658a | 2014-03-25 20:38:32 -0600 | [diff] [blame] | 2416 | ret = toshiba_touchpad_get(dev, &dummy); |
| 2417 | dev->touchpad_supported = !ret; |
Matthew Garrett | ea6b31f | 2014-04-04 14:22:34 -0400 | [diff] [blame] | 2418 | |
Azael Avalos | 5a2813e | 2014-03-25 20:38:34 -0600 | [diff] [blame] | 2419 | ret = toshiba_accelerometer_supported(dev); |
| 2420 | dev->accelerometer_supported = !ret; |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2421 | |
Azael Avalos | e26ffe5 | 2015-01-18 18:30:22 -0700 | [diff] [blame] | 2422 | ret = toshiba_usb_sleep_charge_get(dev, &dummy); |
| 2423 | dev->usb_sleep_charge_supported = !ret; |
| 2424 | |
Azael Avalos | bb3fe01 | 2015-01-18 18:30:24 -0700 | [diff] [blame] | 2425 | ret = toshiba_usb_rapid_charge_get(dev, &dummy); |
| 2426 | dev->usb_rapid_charge_supported = !ret; |
| 2427 | |
Azael Avalos | 172ce0a | 2015-01-18 18:30:25 -0700 | [diff] [blame^] | 2428 | ret = toshiba_usb_sleep_music_get(dev, &dummy); |
| 2429 | dev->usb_sleep_music_supported = !ret; |
| 2430 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 2431 | /* Determine whether or not BIOS supports fan and video interfaces */ |
| 2432 | |
| 2433 | ret = get_video_status(dev, &dummy); |
| 2434 | dev->video_supported = !ret; |
| 2435 | |
| 2436 | ret = get_fan_status(dev, &dummy); |
| 2437 | dev->fan_supported = !ret; |
| 2438 | |
Azael Avalos | 360f0f3 | 2014-03-25 20:38:31 -0600 | [diff] [blame] | 2439 | ret = sysfs_create_group(&dev->acpi_dev->dev.kobj, |
| 2440 | &toshiba_attr_group); |
| 2441 | if (ret) { |
| 2442 | dev->sysfs_created = 0; |
| 2443 | goto error; |
| 2444 | } |
| 2445 | dev->sysfs_created = !ret; |
| 2446 | |
Seth Forshee | 36d03f9 | 2011-09-20 16:55:53 -0500 | [diff] [blame] | 2447 | create_toshiba_proc_entries(dev); |
| 2448 | |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2449 | toshiba_acpi = dev; |
| 2450 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2451 | return 0; |
| 2452 | |
| 2453 | error: |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 2454 | toshiba_acpi_remove(acpi_dev); |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2455 | return ret; |
| 2456 | } |
| 2457 | |
| 2458 | static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) |
| 2459 | { |
| 2460 | struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); |
Azael Avalos | 8054690 | 2014-12-04 20:22:47 -0700 | [diff] [blame] | 2461 | int ret; |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 2462 | |
Azael Avalos | 71454d7 | 2014-12-04 20:22:46 -0700 | [diff] [blame] | 2463 | switch (event) { |
| 2464 | case 0x80: /* Hotkeys and some system events */ |
| 2465 | toshiba_acpi_process_hotkeys(dev); |
| 2466 | break; |
Azael Avalos | 8054690 | 2014-12-04 20:22:47 -0700 | [diff] [blame] | 2467 | case 0x92: /* Keyboard backlight mode changed */ |
| 2468 | /* Update sysfs entries */ |
| 2469 | ret = sysfs_update_group(&acpi_dev->dev.kobj, |
| 2470 | &toshiba_attr_group); |
| 2471 | if (ret) |
| 2472 | pr_err("Unable to update sysfs entries\n"); |
| 2473 | break; |
Azael Avalos | 71454d7 | 2014-12-04 20:22:46 -0700 | [diff] [blame] | 2474 | case 0x81: /* Unknown */ |
| 2475 | case 0x82: /* Unknown */ |
| 2476 | case 0x83: /* Unknown */ |
| 2477 | case 0x8c: /* Unknown */ |
| 2478 | case 0x8e: /* Unknown */ |
| 2479 | case 0x8f: /* Unknown */ |
| 2480 | case 0x90: /* Unknown */ |
| 2481 | default: |
| 2482 | pr_info("Unknown event received %x\n", event); |
| 2483 | break; |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2484 | } |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 2485 | } |
| 2486 | |
Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 2487 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | 43d2fd3 | 2012-06-27 23:27:16 +0200 | [diff] [blame] | 2488 | static int toshiba_acpi_suspend(struct device *device) |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2489 | { |
Rafael J. Wysocki | 43d2fd3 | 2012-06-27 23:27:16 +0200 | [diff] [blame] | 2490 | struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2491 | u32 result; |
| 2492 | |
| 2493 | if (dev->hotkey_dev) |
Azael Avalos | 893f3f6 | 2014-09-29 20:40:09 -0600 | [diff] [blame] | 2494 | result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE); |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2495 | |
| 2496 | return 0; |
| 2497 | } |
| 2498 | |
Rafael J. Wysocki | 43d2fd3 | 2012-06-27 23:27:16 +0200 | [diff] [blame] | 2499 | static int toshiba_acpi_resume(struct device *device) |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2500 | { |
Rafael J. Wysocki | 43d2fd3 | 2012-06-27 23:27:16 +0200 | [diff] [blame] | 2501 | struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); |
Azael Avalos | 1f28f29 | 2014-12-04 20:22:45 -0700 | [diff] [blame] | 2502 | int error; |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2503 | |
Benjamin Tissoires | e7fdb76 | 2014-09-02 14:04:19 -0400 | [diff] [blame] | 2504 | if (dev->hotkey_dev) { |
Azael Avalos | 1f28f29 | 2014-12-04 20:22:45 -0700 | [diff] [blame] | 2505 | error = toshiba_acpi_enable_hotkeys(dev); |
| 2506 | if (error) |
Benjamin Tissoires | e7fdb76 | 2014-09-02 14:04:19 -0400 | [diff] [blame] | 2507 | pr_info("Unable to re-enable hotkeys\n"); |
Benjamin Tissoires | e7fdb76 | 2014-09-02 14:04:19 -0400 | [diff] [blame] | 2508 | } |
Seth Forshee | 29cd293 | 2012-01-18 13:44:09 -0600 | [diff] [blame] | 2509 | |
| 2510 | return 0; |
| 2511 | } |
Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 2512 | #endif |
Matthew Garrett | 6335e4d | 2010-02-25 15:20:54 -0500 | [diff] [blame] | 2513 | |
Rafael J. Wysocki | 43d2fd3 | 2012-06-27 23:27:16 +0200 | [diff] [blame] | 2514 | static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm, |
| 2515 | toshiba_acpi_suspend, toshiba_acpi_resume); |
| 2516 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2517 | static struct acpi_driver toshiba_acpi_driver = { |
| 2518 | .name = "Toshiba ACPI driver", |
| 2519 | .owner = THIS_MODULE, |
| 2520 | .ids = toshiba_device_ids, |
| 2521 | .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, |
| 2522 | .ops = { |
| 2523 | .add = toshiba_acpi_add, |
| 2524 | .remove = toshiba_acpi_remove, |
| 2525 | .notify = toshiba_acpi_notify, |
| 2526 | }, |
Rafael J. Wysocki | 43d2fd3 | 2012-06-27 23:27:16 +0200 | [diff] [blame] | 2527 | .drv.pm = &toshiba_acpi_pm, |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2528 | }; |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 2529 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2530 | static int __init toshiba_acpi_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2532 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | |
Seth Forshee | f11f999 | 2012-01-18 13:44:11 -0600 | [diff] [blame] | 2534 | /* |
| 2535 | * Machines with this WMI guid aren't supported due to bugs in |
| 2536 | * their AML. This check relies on wmi initializing before |
| 2537 | * toshiba_acpi to guarantee guids have been identified. |
| 2538 | */ |
| 2539 | if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) |
| 2540 | return -ENODEV; |
| 2541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir); |
| 2543 | if (!toshiba_proc_dir) { |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2544 | pr_err("Unable to create proc dir " PROC_TOSHIBA "\n"); |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 2545 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2548 | ret = acpi_bus_register_driver(&toshiba_acpi_driver); |
| 2549 | if (ret) { |
| 2550 | pr_err("Failed to register ACPI driver: %d\n", ret); |
| 2551 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); |
Holger Macht | c926355 | 2006-10-20 14:30:29 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2554 | return ret; |
| 2555 | } |
philipl@overt.org | c41a40c | 2008-08-30 11:57:39 -0400 | [diff] [blame] | 2556 | |
Seth Forshee | 135740d | 2011-09-20 16:55:49 -0500 | [diff] [blame] | 2557 | static void __exit toshiba_acpi_exit(void) |
| 2558 | { |
| 2559 | acpi_bus_unregister_driver(&toshiba_acpi_driver); |
| 2560 | if (toshiba_proc_dir) |
| 2561 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | } |
| 2563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | module_init(toshiba_acpi_init); |
| 2565 | module_exit(toshiba_acpi_exit); |