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