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