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