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