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