Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 2 | * thinkpad_acpi.c - ThinkPad ACPI Extras |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> |
Henrique de Moraes Holschuh | 1c762ca | 2009-04-04 04:25:42 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
Henrique de Moraes Holschuh | a62bc91 | 2007-03-23 17:33:58 -0300 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 21 | * 02110-1301, USA. |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 22 | */ |
| 23 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 25 | |
David Henningsson | 420f973 | 2013-10-16 23:10:31 +0200 | [diff] [blame] | 26 | #define TPACPI_VERSION "0.25" |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 27 | #define TPACPI_SYSFS_VERSION 0x020700 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 28 | |
| 29 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * Changelog: |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 31 | * 2007-10-20 changelog trimmed down |
| 32 | * |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 33 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
| 34 | * drivers/misc. |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 35 | * |
| 36 | * 2006-11-22 0.13 new maintainer |
| 37 | * changelog now lives in git commit history, and will |
| 38 | * not be updated further in-file. |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 39 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 40 | * 2005-03-17 0.11 support for 600e, 770x |
| 41 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 42 | * |
| 43 | * 2005-01-16 0.9 use MODULE_VERSION |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 44 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
| 45 | * fix parameter passing on module loading |
| 46 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
| 47 | * thanks to Jim Radford <radford@blackbean.org> |
| 48 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
| 49 | * thanks to Chris Wright <chrisw@osdl.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | */ |
| 51 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 52 | #include <linux/kernel.h> |
| 53 | #include <linux/module.h> |
| 54 | #include <linux/init.h> |
| 55 | #include <linux/types.h> |
| 56 | #include <linux/string.h> |
| 57 | #include <linux/list.h> |
| 58 | #include <linux/mutex.h> |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 59 | #include <linux/sched.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 60 | #include <linux/kthread.h> |
| 61 | #include <linux/freezer.h> |
| 62 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 63 | #include <linux/slab.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 64 | #include <linux/nvram.h> |
| 65 | #include <linux/proc_fs.h> |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 66 | #include <linux/seq_file.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 67 | #include <linux/sysfs.h> |
| 68 | #include <linux/backlight.h> |
| 69 | #include <linux/fb.h> |
| 70 | #include <linux/platform_device.h> |
| 71 | #include <linux/hwmon.h> |
| 72 | #include <linux/hwmon-sysfs.h> |
| 73 | #include <linux/input.h> |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 74 | #include <linux/leds.h> |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 75 | #include <linux/rfkill.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 76 | #include <linux/dmi.h> |
| 77 | #include <linux/jiffies.h> |
| 78 | #include <linux/workqueue.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 79 | #include <linux/acpi.h> |
| 80 | #include <linux/pci_ids.h> |
| 81 | #include <linux/thinkpad_acpi.h> |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 82 | #include <sound/core.h> |
| 83 | #include <sound/control.h> |
| 84 | #include <sound/initval.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 85 | #include <asm/uaccess.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 86 | |
| 87 | /* ThinkPad CMOS commands */ |
| 88 | #define TP_CMOS_VOLUME_DOWN 0 |
| 89 | #define TP_CMOS_VOLUME_UP 1 |
| 90 | #define TP_CMOS_VOLUME_MUTE 2 |
| 91 | #define TP_CMOS_BRIGHTNESS_UP 4 |
| 92 | #define TP_CMOS_BRIGHTNESS_DOWN 5 |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 93 | #define TP_CMOS_THINKLIGHT_ON 12 |
| 94 | #define TP_CMOS_THINKLIGHT_OFF 13 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 95 | |
| 96 | /* NVRAM Addresses */ |
| 97 | enum tp_nvram_addr { |
| 98 | TP_NVRAM_ADDR_HK2 = 0x57, |
| 99 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, |
| 100 | TP_NVRAM_ADDR_VIDEO = 0x59, |
| 101 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, |
| 102 | TP_NVRAM_ADDR_MIXER = 0x60, |
| 103 | }; |
| 104 | |
| 105 | /* NVRAM bit masks */ |
| 106 | enum { |
| 107 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, |
| 108 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, |
| 109 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, |
| 110 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, |
| 111 | TP_NVRAM_MASK_THINKLIGHT = 0x10, |
| 112 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, |
| 113 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, |
| 114 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, |
| 115 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, |
| 116 | TP_NVRAM_MASK_MUTE = 0x40, |
| 117 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, |
| 118 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, |
| 119 | TP_NVRAM_POS_LEVEL_VOLUME = 0, |
| 120 | }; |
| 121 | |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 122 | /* Misc NVRAM-related */ |
| 123 | enum { |
| 124 | TP_NVRAM_LEVEL_VOLUME_MAX = 14, |
| 125 | }; |
| 126 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 127 | /* ACPI HIDs */ |
Manoj Iyer | 9fbdaeb | 2011-05-08 18:04:29 -0400 | [diff] [blame] | 128 | #define TPACPI_ACPI_IBM_HKEY_HID "IBM0068" |
| 129 | #define TPACPI_ACPI_LENOVO_HKEY_HID "LEN0068" |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 130 | #define TPACPI_ACPI_EC_HID "PNP0C09" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 131 | |
| 132 | /* Input IDs */ |
| 133 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ |
| 134 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 |
| 135 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 136 | /* ACPI \WGSV commands */ |
| 137 | enum { |
| 138 | TP_ACPI_WGSV_GET_STATE = 0x01, /* Get state information */ |
| 139 | TP_ACPI_WGSV_PWR_ON_ON_RESUME = 0x02, /* Resume WWAN powered on */ |
| 140 | TP_ACPI_WGSV_PWR_OFF_ON_RESUME = 0x03, /* Resume WWAN powered off */ |
| 141 | TP_ACPI_WGSV_SAVE_STATE = 0x04, /* Save state for S4/S5 */ |
| 142 | }; |
| 143 | |
| 144 | /* TP_ACPI_WGSV_GET_STATE bits */ |
| 145 | enum { |
| 146 | TP_ACPI_WGSV_STATE_WWANEXIST = 0x0001, /* WWAN hw available */ |
| 147 | TP_ACPI_WGSV_STATE_WWANPWR = 0x0002, /* WWAN radio enabled */ |
| 148 | TP_ACPI_WGSV_STATE_WWANPWRRES = 0x0004, /* WWAN state at resume */ |
| 149 | TP_ACPI_WGSV_STATE_WWANBIOSOFF = 0x0008, /* WWAN disabled in BIOS */ |
| 150 | TP_ACPI_WGSV_STATE_BLTHEXIST = 0x0001, /* BLTH hw available */ |
| 151 | TP_ACPI_WGSV_STATE_BLTHPWR = 0x0002, /* BLTH radio enabled */ |
| 152 | TP_ACPI_WGSV_STATE_BLTHPWRRES = 0x0004, /* BLTH state at resume */ |
| 153 | TP_ACPI_WGSV_STATE_BLTHBIOSOFF = 0x0008, /* BLTH disabled in BIOS */ |
| 154 | TP_ACPI_WGSV_STATE_UWBEXIST = 0x0010, /* UWB hw available */ |
| 155 | TP_ACPI_WGSV_STATE_UWBPWR = 0x0020, /* UWB radio enabled */ |
| 156 | }; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 157 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 158 | /* HKEY events */ |
| 159 | enum tpacpi_hkey_event_t { |
| 160 | /* Hotkey-related */ |
| 161 | TP_HKEY_EV_HOTKEY_BASE = 0x1001, /* first hotkey (FN+F1) */ |
| 162 | TP_HKEY_EV_BRGHT_UP = 0x1010, /* Brightness up */ |
| 163 | TP_HKEY_EV_BRGHT_DOWN = 0x1011, /* Brightness down */ |
| 164 | TP_HKEY_EV_VOL_UP = 0x1015, /* Volume up or unmute */ |
| 165 | TP_HKEY_EV_VOL_DOWN = 0x1016, /* Volume down or unmute */ |
| 166 | TP_HKEY_EV_VOL_MUTE = 0x1017, /* Mixer output mute */ |
| 167 | |
| 168 | /* Reasons for waking up from S3/S4 */ |
| 169 | TP_HKEY_EV_WKUP_S3_UNDOCK = 0x2304, /* undock requested, S3 */ |
| 170 | TP_HKEY_EV_WKUP_S4_UNDOCK = 0x2404, /* undock requested, S4 */ |
| 171 | TP_HKEY_EV_WKUP_S3_BAYEJ = 0x2305, /* bay ejection req, S3 */ |
| 172 | TP_HKEY_EV_WKUP_S4_BAYEJ = 0x2405, /* bay ejection req, S4 */ |
| 173 | TP_HKEY_EV_WKUP_S3_BATLOW = 0x2313, /* battery empty, S3 */ |
| 174 | TP_HKEY_EV_WKUP_S4_BATLOW = 0x2413, /* battery empty, S4 */ |
| 175 | |
| 176 | /* Auto-sleep after eject request */ |
| 177 | TP_HKEY_EV_BAYEJ_ACK = 0x3003, /* bay ejection complete */ |
| 178 | TP_HKEY_EV_UNDOCK_ACK = 0x4003, /* undock complete */ |
| 179 | |
| 180 | /* Misc bay events */ |
| 181 | TP_HKEY_EV_OPTDRV_EJ = 0x3006, /* opt. drive tray ejected */ |
Henrique de Moraes Holschuh | a50245a | 2011-06-05 16:22:35 -0300 | [diff] [blame] | 182 | TP_HKEY_EV_HOTPLUG_DOCK = 0x4010, /* docked into hotplug dock |
| 183 | or port replicator */ |
| 184 | TP_HKEY_EV_HOTPLUG_UNDOCK = 0x4011, /* undocked from hotplug |
| 185 | dock or port replicator */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 186 | |
| 187 | /* User-interface events */ |
| 188 | TP_HKEY_EV_LID_CLOSE = 0x5001, /* laptop lid closed */ |
| 189 | TP_HKEY_EV_LID_OPEN = 0x5002, /* laptop lid opened */ |
| 190 | TP_HKEY_EV_TABLET_TABLET = 0x5009, /* tablet swivel up */ |
| 191 | TP_HKEY_EV_TABLET_NOTEBOOK = 0x500a, /* tablet swivel down */ |
| 192 | TP_HKEY_EV_PEN_INSERTED = 0x500b, /* tablet pen inserted */ |
| 193 | TP_HKEY_EV_PEN_REMOVED = 0x500c, /* tablet pen removed */ |
| 194 | TP_HKEY_EV_BRGHT_CHANGED = 0x5010, /* backlight control event */ |
| 195 | |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 196 | /* Key-related user-interface events */ |
| 197 | TP_HKEY_EV_KEY_NUMLOCK = 0x6000, /* NumLock key pressed */ |
| 198 | TP_HKEY_EV_KEY_FN = 0x6005, /* Fn key pressed? E420 */ |
Xavier Naveira | 67ab624 | 2015-02-10 08:45:18 +0100 | [diff] [blame] | 199 | TP_HKEY_EV_KEY_FN_ESC = 0x6060, /* Fn+Esc key pressed X240 */ |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 200 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 201 | /* Thermal events */ |
| 202 | TP_HKEY_EV_ALARM_BAT_HOT = 0x6011, /* battery too hot */ |
| 203 | TP_HKEY_EV_ALARM_BAT_XHOT = 0x6012, /* battery critically hot */ |
| 204 | TP_HKEY_EV_ALARM_SENSOR_HOT = 0x6021, /* sensor too hot */ |
| 205 | TP_HKEY_EV_ALARM_SENSOR_XHOT = 0x6022, /* sensor critically hot */ |
| 206 | TP_HKEY_EV_THM_TABLE_CHANGED = 0x6030, /* thermal table changed */ |
| 207 | |
Richard Hartmann | 6f62bc3 | 2012-12-29 22:51:49 +0100 | [diff] [blame] | 208 | /* AC-related events */ |
| 209 | TP_HKEY_EV_AC_CHANGED = 0x6040, /* AC status changed */ |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 210 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 211 | /* Misc */ |
| 212 | TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */ |
| 213 | }; |
| 214 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 215 | /**************************************************************************** |
| 216 | * Main driver |
| 217 | */ |
| 218 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 219 | #define TPACPI_NAME "thinkpad" |
| 220 | #define TPACPI_DESC "ThinkPad ACPI Extras" |
| 221 | #define TPACPI_FILE TPACPI_NAME "_acpi" |
| 222 | #define TPACPI_URL "http://ibm-acpi.sf.net/" |
| 223 | #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 224 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 225 | #define TPACPI_PROC_DIR "ibm" |
| 226 | #define TPACPI_ACPI_EVENT_PREFIX "ibm" |
| 227 | #define TPACPI_DRVR_NAME TPACPI_FILE |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 228 | #define TPACPI_DRVR_SHORTNAME "tpacpi" |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 229 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 230 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 231 | #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd" |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 232 | #define TPACPI_WORKQUEUE_NAME "ktpacpid" |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 233 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 234 | #define TPACPI_MAX_ACPI_ARGS 3 |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 235 | |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 236 | /* Debugging printk groups */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 237 | #define TPACPI_DBG_ALL 0xffff |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 238 | #define TPACPI_DBG_DISCLOSETASK 0x8000 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 239 | #define TPACPI_DBG_INIT 0x0001 |
| 240 | #define TPACPI_DBG_EXIT 0x0002 |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 241 | #define TPACPI_DBG_RFKILL 0x0004 |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 242 | #define TPACPI_DBG_HKEY 0x0008 |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 243 | #define TPACPI_DBG_FAN 0x0010 |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 244 | #define TPACPI_DBG_BRGHT 0x0020 |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 245 | #define TPACPI_DBG_MIXER 0x0040 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 246 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 247 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 248 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 249 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 250 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 251 | |
| 252 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 253 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 254 | */ |
| 255 | |
| 256 | struct ibm_struct; |
| 257 | |
| 258 | struct tp_acpi_drv_struct { |
| 259 | const struct acpi_device_id *hid; |
| 260 | struct acpi_driver *driver; |
| 261 | |
| 262 | void (*notify) (struct ibm_struct *, u32); |
| 263 | acpi_handle *handle; |
| 264 | u32 type; |
| 265 | struct acpi_device *device; |
| 266 | }; |
| 267 | |
| 268 | struct ibm_struct { |
| 269 | char *name; |
| 270 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 271 | int (*read) (struct seq_file *); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 272 | int (*write) (char *); |
| 273 | void (*exit) (void); |
| 274 | void (*resume) (void); |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 275 | void (*suspend) (void); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 276 | void (*shutdown) (void); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 277 | |
| 278 | struct list_head all_drivers; |
| 279 | |
| 280 | struct tp_acpi_drv_struct *acpi; |
| 281 | |
| 282 | struct { |
| 283 | u8 acpi_driver_registered:1; |
| 284 | u8 acpi_notify_installed:1; |
| 285 | u8 proc_created:1; |
| 286 | u8 init_called:1; |
| 287 | u8 experimental:1; |
| 288 | } flags; |
| 289 | }; |
| 290 | |
| 291 | struct ibm_init_struct { |
| 292 | char param[32]; |
| 293 | |
| 294 | int (*init) (struct ibm_init_struct *); |
Al Viro | d161a13 | 2011-07-24 03:36:29 -0400 | [diff] [blame] | 295 | umode_t base_procfs_mode; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 296 | struct ibm_struct *data; |
| 297 | }; |
| 298 | |
| 299 | static struct { |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 300 | u32 bluetooth:1; |
| 301 | u32 hotkey:1; |
| 302 | u32 hotkey_mask:1; |
| 303 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 304 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 305 | u32 light:1; |
| 306 | u32 light_status:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 307 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 308 | u32 bright_unkfw:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 309 | u32 wan:1; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 310 | u32 uwb:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 311 | u32 fan_ctrl_status_undef:1; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 312 | u32 second_fan:1; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 313 | u32 beep_needs_two_args:1; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 314 | u32 mixer_no_level_control:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 315 | u32 input_device_registered:1; |
| 316 | u32 platform_drv_registered:1; |
| 317 | u32 platform_drv_attrs_registered:1; |
| 318 | u32 sensors_pdrv_registered:1; |
| 319 | u32 sensors_pdrv_attrs_registered:1; |
| 320 | u32 sensors_pdev_attrs_registered:1; |
| 321 | u32 hotkey_poll_active:1; |
Bastien Nocera | f23a5bc | 2015-03-02 14:45:16 +0100 | [diff] [blame] | 322 | u32 has_adaptive_kbd:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 323 | } tp_features; |
| 324 | |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 325 | static struct { |
| 326 | u16 hotkey_mask_ff:1; |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 327 | u16 volume_ctrl_forbidden:1; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 328 | } tp_warned; |
| 329 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 330 | struct thinkpad_id_data { |
| 331 | unsigned int vendor; /* ThinkPad vendor: |
| 332 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 333 | |
| 334 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 335 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 336 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 337 | u16 bios_model; /* 1Y = 0x5931, 0 = unknown */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 338 | u16 ec_model; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 339 | u16 bios_release; /* 1ZETK1WW = 0x314b, 0 = unknown */ |
| 340 | u16 ec_release; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 341 | |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 342 | char *model_str; /* ThinkPad T43 */ |
| 343 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 344 | }; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 345 | static struct thinkpad_id_data thinkpad_id; |
| 346 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 347 | static enum { |
| 348 | TPACPI_LIFE_INIT = 0, |
| 349 | TPACPI_LIFE_RUNNING, |
| 350 | TPACPI_LIFE_EXITING, |
| 351 | } tpacpi_lifecycle; |
| 352 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 353 | static int experimental; |
| 354 | static u32 dbg_level; |
| 355 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 356 | static struct workqueue_struct *tpacpi_wq; |
| 357 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 358 | enum led_status_t { |
| 359 | TPACPI_LED_OFF = 0, |
| 360 | TPACPI_LED_ON, |
| 361 | TPACPI_LED_BLINK, |
| 362 | }; |
| 363 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 364 | /* Special LED class that can defer work */ |
| 365 | struct tpacpi_led_classdev { |
| 366 | struct led_classdev led_classdev; |
| 367 | struct work_struct work; |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 368 | enum led_status_t new_state; |
Adam Lee | edf2d77 | 2013-06-08 16:51:15 +0800 | [diff] [blame] | 369 | int led; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 370 | }; |
| 371 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 372 | /* brightness level capabilities */ |
| 373 | static unsigned int bright_maxlvl; /* 0 = unknown */ |
| 374 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 375 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 376 | static int dbg_wlswemul; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 377 | static bool tpacpi_wlsw_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 378 | static int dbg_bluetoothemul; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 379 | static bool tpacpi_bluetooth_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 380 | static int dbg_wwanemul; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 381 | static bool tpacpi_wwan_emulstate; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 382 | static int dbg_uwbemul; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 383 | static bool tpacpi_uwb_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 384 | #endif |
| 385 | |
| 386 | |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 387 | /************************************************************************* |
| 388 | * Debugging helpers |
| 389 | */ |
| 390 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 391 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 392 | do { \ |
| 393 | if (dbg_level & (a_dbg_level)) \ |
| 394 | printk(KERN_DEBUG pr_fmt("%s: " format), \ |
| 395 | __func__, ##arg); \ |
| 396 | } while (0) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 397 | |
| 398 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 399 | #define vdbg_printk dbg_printk |
| 400 | static const char *str_supported(int is_supported); |
| 401 | #else |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 402 | static inline const char *str_supported(int is_supported) { return ""; } |
| 403 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 404 | no_printk(format, ##arg) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 405 | #endif |
| 406 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 407 | static void tpacpi_log_usertask(const char * const what) |
| 408 | { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 409 | printk(KERN_DEBUG pr_fmt("%s: access by process with PID %d\n"), |
| 410 | what, task_tgid_vnr(current)); |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 413 | #define tpacpi_disclose_usertask(what, format, arg...) \ |
| 414 | do { \ |
| 415 | if (unlikely((dbg_level & TPACPI_DBG_DISCLOSETASK) && \ |
| 416 | (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \ |
| 417 | printk(KERN_DEBUG pr_fmt("%s: PID %d: " format), \ |
| 418 | what, task_tgid_vnr(current), ## arg); \ |
| 419 | } \ |
| 420 | } while (0) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 421 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 422 | /* |
| 423 | * Quirk handling helpers |
| 424 | * |
| 425 | * ThinkPad IDs and versions seen in the field so far |
| 426 | * are two-characters from the set [0-9A-Z], i.e. base 36. |
| 427 | * |
| 428 | * We use values well outside that range as specials. |
| 429 | */ |
| 430 | |
| 431 | #define TPACPI_MATCH_ANY 0xffffU |
| 432 | #define TPACPI_MATCH_UNKNOWN 0U |
| 433 | |
| 434 | /* TPID('1', 'Y') == 0x5931 */ |
| 435 | #define TPID(__c1, __c2) (((__c2) << 8) | (__c1)) |
| 436 | |
| 437 | #define TPACPI_Q_IBM(__id1, __id2, __quirk) \ |
| 438 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 439 | .bios = TPID(__id1, __id2), \ |
| 440 | .ec = TPACPI_MATCH_ANY, \ |
| 441 | .quirks = (__quirk) } |
| 442 | |
| 443 | #define TPACPI_Q_LNV(__id1, __id2, __quirk) \ |
| 444 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 445 | .bios = TPID(__id1, __id2), \ |
| 446 | .ec = TPACPI_MATCH_ANY, \ |
| 447 | .quirks = (__quirk) } |
| 448 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 449 | #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \ |
| 450 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 451 | .bios = TPACPI_MATCH_ANY, \ |
| 452 | .ec = TPID(__id1, __id2), \ |
| 453 | .quirks = (__quirk) } |
| 454 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 455 | struct tpacpi_quirk { |
| 456 | unsigned int vendor; |
| 457 | u16 bios; |
| 458 | u16 ec; |
| 459 | unsigned long quirks; |
| 460 | }; |
| 461 | |
| 462 | /** |
| 463 | * tpacpi_check_quirks() - search BIOS/EC version on a list |
| 464 | * @qlist: array of &struct tpacpi_quirk |
| 465 | * @qlist_size: number of elements in @qlist |
| 466 | * |
| 467 | * Iterates over a quirks list until one is found that matches the |
| 468 | * ThinkPad's vendor, BIOS and EC model. |
| 469 | * |
| 470 | * Returns 0 if nothing matches, otherwise returns the quirks field of |
| 471 | * the matching &struct tpacpi_quirk entry. |
| 472 | * |
| 473 | * The match criteria is: vendor, ec and bios much match. |
| 474 | */ |
| 475 | static unsigned long __init tpacpi_check_quirks( |
| 476 | const struct tpacpi_quirk *qlist, |
| 477 | unsigned int qlist_size) |
| 478 | { |
| 479 | while (qlist_size) { |
| 480 | if ((qlist->vendor == thinkpad_id.vendor || |
| 481 | qlist->vendor == TPACPI_MATCH_ANY) && |
| 482 | (qlist->bios == thinkpad_id.bios_model || |
| 483 | qlist->bios == TPACPI_MATCH_ANY) && |
| 484 | (qlist->ec == thinkpad_id.ec_model || |
| 485 | qlist->ec == TPACPI_MATCH_ANY)) |
| 486 | return qlist->quirks; |
| 487 | |
| 488 | qlist_size--; |
| 489 | qlist++; |
| 490 | } |
| 491 | return 0; |
| 492 | } |
| 493 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 494 | static inline bool __pure __init tpacpi_is_lenovo(void) |
| 495 | { |
| 496 | return thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO; |
| 497 | } |
| 498 | |
| 499 | static inline bool __pure __init tpacpi_is_ibm(void) |
| 500 | { |
| 501 | return thinkpad_id.vendor == PCI_VENDOR_ID_IBM; |
| 502 | } |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 503 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 504 | /**************************************************************************** |
| 505 | **************************************************************************** |
| 506 | * |
| 507 | * ACPI Helpers and device model |
| 508 | * |
| 509 | **************************************************************************** |
| 510 | ****************************************************************************/ |
| 511 | |
| 512 | /************************************************************************* |
| 513 | * ACPI basic handles |
| 514 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 516 | static acpi_handle root_handle; |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 517 | static acpi_handle ec_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 519 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | static acpi_handle object##_handle; \ |
Andi Kleen | 3bd0189 | 2012-10-04 17:12:01 -0700 | [diff] [blame] | 521 | static const acpi_handle * const object##_parent __initconst = \ |
Henrique de Moraes Holschuh | ef07a5a | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 522 | &parent##_handle; \ |
| 523 | static char *object##_paths[] __initdata = { paths } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 525 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 526 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 528 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 529 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 530 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 531 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 532 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 533 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 534 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 535 | "^HKEY", /* R30, R31 */ |
| 536 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 537 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 538 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 539 | /************************************************************************* |
| 540 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 541 | */ |
| 542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | static int acpi_evalf(acpi_handle handle, |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 544 | int *res, char *method, char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
| 546 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 547 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 548 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 549 | struct acpi_buffer result, *resultp; |
| 550 | union acpi_object out_obj; |
| 551 | acpi_status status; |
| 552 | va_list ap; |
| 553 | char res_type; |
| 554 | int success; |
| 555 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | if (!*fmt) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 558 | pr_err("acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | if (*fmt == 'q') { |
| 563 | quiet = 1; |
| 564 | fmt++; |
| 565 | } else |
| 566 | quiet = 0; |
| 567 | |
| 568 | res_type = *(fmt++); |
| 569 | |
| 570 | params.count = 0; |
| 571 | params.pointer = &in_objs[0]; |
| 572 | |
| 573 | va_start(ap, fmt); |
| 574 | while (*fmt) { |
| 575 | char c = *(fmt++); |
| 576 | switch (c) { |
| 577 | case 'd': /* int */ |
| 578 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 579 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 580 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 581 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | default: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 583 | pr_err("acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | "with invalid format character '%c'\n", c); |
Jesper Juhl | 2136585 | 2010-12-24 19:56:28 +0100 | [diff] [blame] | 585 | va_end(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | return 0; |
| 587 | } |
| 588 | } |
| 589 | va_end(ap); |
| 590 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 591 | if (res_type != 'v') { |
| 592 | result.length = sizeof(out_obj); |
| 593 | result.pointer = &out_obj; |
| 594 | resultp = &result; |
| 595 | } else |
| 596 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 598 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
| 600 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 601 | case 'd': /* int */ |
Henrique de Moraes Holschuh | 263f4a3 | 2010-05-16 19:45:45 -0300 | [diff] [blame] | 602 | success = (status == AE_OK && |
| 603 | out_obj.type == ACPI_TYPE_INTEGER); |
| 604 | if (success && res) |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 605 | *res = out_obj.integer.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 607 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | success = status == AE_OK; |
| 609 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 610 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | default: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 612 | pr_err("acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | "with invalid format character '%c'\n", res_type); |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | if (!success && !quiet) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 618 | pr_err("acpi_evalf(%s, %s, ...) failed: %s\n", |
Henrique de Moraes Holschuh | 263f4a3 | 2010-05-16 19:45:45 -0300 | [diff] [blame] | 619 | method, fmt0, acpi_format_exception(status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
| 621 | return success; |
| 622 | } |
| 623 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 624 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 625 | { |
| 626 | int v; |
| 627 | |
| 628 | if (ecrd_handle) { |
| 629 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 630 | return 0; |
| 631 | *p = v; |
| 632 | } else { |
| 633 | if (ec_read(i, p) < 0) |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | return 1; |
| 638 | } |
| 639 | |
| 640 | static int acpi_ec_write(int i, u8 v) |
| 641 | { |
| 642 | if (ecwr_handle) { |
| 643 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 644 | return 0; |
| 645 | } else { |
| 646 | if (ec_write(i, v) < 0) |
| 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | return 1; |
| 651 | } |
| 652 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 653 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 654 | { |
| 655 | if (!cmos_handle) |
| 656 | return -ENXIO; |
| 657 | |
| 658 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 659 | return -EIO; |
| 660 | |
| 661 | return 0; |
| 662 | } |
| 663 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 664 | /************************************************************************* |
| 665 | * ACPI device model |
| 666 | */ |
| 667 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 668 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 669 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | ef07a5a | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 670 | object##_paths, ARRAY_SIZE(object##_paths)) |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 671 | |
Henrique de Moraes Holschuh | ef07a5a | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 672 | static void __init drv_acpi_handle_init(const char *name, |
| 673 | acpi_handle *handle, const acpi_handle parent, |
| 674 | char **paths, const int num_paths) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 675 | { |
| 676 | int i; |
| 677 | acpi_status status; |
| 678 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 679 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 680 | name); |
| 681 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 682 | for (i = 0; i < num_paths; i++) { |
| 683 | status = acpi_get_handle(parent, paths[i], handle); |
| 684 | if (ACPI_SUCCESS(status)) { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 685 | dbg_printk(TPACPI_DBG_INIT, |
| 686 | "Found ACPI handle %s for %s\n", |
Henrique de Moraes Holschuh | ef07a5a | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 687 | paths[i], name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 688 | return; |
| 689 | } |
| 690 | } |
| 691 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 692 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 693 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 694 | *handle = NULL; |
| 695 | } |
| 696 | |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 697 | static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle, |
| 698 | u32 level, void *context, void **return_value) |
| 699 | { |
Aaron Lu | 46445b6 | 2013-10-11 21:27:46 +0800 | [diff] [blame] | 700 | struct acpi_device *dev; |
| 701 | if (!strcmp(context, "video")) { |
| 702 | if (acpi_bus_get_device(handle, &dev)) |
| 703 | return AE_OK; |
| 704 | if (strcmp(ACPI_VIDEO_HID, acpi_device_hid(dev))) |
| 705 | return AE_OK; |
| 706 | } |
| 707 | |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 708 | *(acpi_handle *)return_value = handle; |
| 709 | |
| 710 | return AE_CTRL_TERMINATE; |
| 711 | } |
| 712 | |
| 713 | static void __init tpacpi_acpi_handle_locate(const char *name, |
| 714 | const char *hid, |
| 715 | acpi_handle *handle) |
| 716 | { |
| 717 | acpi_status status; |
| 718 | acpi_handle device_found; |
| 719 | |
Aaron Lu | 46445b6 | 2013-10-11 21:27:46 +0800 | [diff] [blame] | 720 | BUG_ON(!name || !handle); |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 721 | vdbg_printk(TPACPI_DBG_INIT, |
| 722 | "trying to locate ACPI handle for %s, using HID %s\n", |
Aaron Lu | 46445b6 | 2013-10-11 21:27:46 +0800 | [diff] [blame] | 723 | name, hid ? hid : "NULL"); |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 724 | |
| 725 | memset(&device_found, 0, sizeof(device_found)); |
| 726 | status = acpi_get_devices(hid, tpacpi_acpi_handle_locate_callback, |
| 727 | (void *)name, &device_found); |
| 728 | |
| 729 | *handle = NULL; |
| 730 | |
| 731 | if (ACPI_SUCCESS(status)) { |
| 732 | *handle = device_found; |
| 733 | dbg_printk(TPACPI_DBG_INIT, |
| 734 | "Found ACPI handle for %s\n", name); |
| 735 | } else { |
| 736 | vdbg_printk(TPACPI_DBG_INIT, |
| 737 | "Could not locate an ACPI handle for %s: %s\n", |
| 738 | name, acpi_format_exception(status)); |
| 739 | } |
| 740 | } |
| 741 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 742 | static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 743 | { |
| 744 | struct ibm_struct *ibm = data; |
| 745 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 746 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 747 | return; |
| 748 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 749 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 750 | return; |
| 751 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 752 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 753 | } |
| 754 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 755 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 756 | { |
| 757 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 758 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 759 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 760 | BUG_ON(!ibm->acpi); |
| 761 | |
| 762 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 763 | return 0; |
| 764 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 765 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 766 | "setting up ACPI notify for %s\n", ibm->name); |
| 767 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 768 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 769 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 770 | pr_err("acpi_bus_get_device(%s) failed: %d\n", ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 771 | return -ENODEV; |
| 772 | } |
| 773 | |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 774 | ibm->acpi->device->driver_data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 775 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 776 | TPACPI_ACPI_EVENT_PREFIX, |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 777 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 778 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 779 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 780 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 781 | if (ACPI_FAILURE(status)) { |
| 782 | if (status == AE_ALREADY_EXISTS) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 783 | pr_notice("another device driver is already " |
| 784 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 785 | } else { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 786 | pr_err("acpi_install_notify_handler(%s) failed: %s\n", |
Henrique de Moraes Holschuh | 72f1992 | 2010-05-16 19:45:48 -0300 | [diff] [blame] | 787 | ibm->name, acpi_format_exception(status)); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 788 | } |
| 789 | return -ENODEV; |
| 790 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 791 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 792 | return 0; |
| 793 | } |
| 794 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 795 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 796 | { |
| 797 | return 0; |
| 798 | } |
| 799 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 800 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 801 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 802 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 803 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 804 | dbg_printk(TPACPI_DBG_INIT, |
| 805 | "registering %s as an ACPI driver\n", ibm->name); |
| 806 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 807 | BUG_ON(!ibm->acpi); |
| 808 | |
| 809 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 810 | if (!ibm->acpi->driver) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 811 | pr_err("failed to allocate memory for ibm->acpi->driver\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 812 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 813 | } |
| 814 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 815 | sprintf(ibm->acpi->driver->name, "%s_%s", TPACPI_NAME, ibm->name); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 816 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 817 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 818 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 819 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 820 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 821 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 822 | pr_err("acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 823 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 824 | kfree(ibm->acpi->driver); |
| 825 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 826 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 827 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 828 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 829 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | |
| 833 | /**************************************************************************** |
| 834 | **************************************************************************** |
| 835 | * |
| 836 | * Procfs Helpers |
| 837 | * |
| 838 | **************************************************************************** |
| 839 | ****************************************************************************/ |
| 840 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 841 | static int dispatch_proc_show(struct seq_file *m, void *v) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 842 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 843 | struct ibm_struct *ibm = m->private; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 844 | |
| 845 | if (!ibm || !ibm->read) |
| 846 | return -EINVAL; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 847 | return ibm->read(m); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 848 | } |
| 849 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 850 | static int dispatch_proc_open(struct inode *inode, struct file *file) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 851 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 852 | return single_open(file, dispatch_proc_show, PDE_DATA(inode)); |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | static ssize_t dispatch_proc_write(struct file *file, |
| 856 | const char __user *userbuf, |
| 857 | size_t count, loff_t *pos) |
| 858 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 859 | struct ibm_struct *ibm = PDE_DATA(file_inode(file)); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 860 | char *kernbuf; |
| 861 | int ret; |
| 862 | |
| 863 | if (!ibm || !ibm->write) |
| 864 | return -EINVAL; |
Michael Buesch | 5b05d46 | 2009-08-01 12:04:19 -0300 | [diff] [blame] | 865 | if (count > PAGE_SIZE - 2) |
| 866 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 867 | |
| 868 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 869 | if (!kernbuf) |
| 870 | return -ENOMEM; |
| 871 | |
| 872 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 873 | kfree(kernbuf); |
| 874 | return -EFAULT; |
| 875 | } |
| 876 | |
| 877 | kernbuf[count] = 0; |
| 878 | strcat(kernbuf, ","); |
| 879 | ret = ibm->write(kernbuf); |
| 880 | if (ret == 0) |
| 881 | ret = count; |
| 882 | |
| 883 | kfree(kernbuf); |
| 884 | |
| 885 | return ret; |
| 886 | } |
| 887 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 888 | static const struct file_operations dispatch_proc_fops = { |
| 889 | .owner = THIS_MODULE, |
| 890 | .open = dispatch_proc_open, |
| 891 | .read = seq_read, |
| 892 | .llseek = seq_lseek, |
| 893 | .release = single_release, |
| 894 | .write = dispatch_proc_write, |
| 895 | }; |
| 896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | static char *next_cmd(char **cmds) |
| 898 | { |
| 899 | char *start = *cmds; |
| 900 | char *end; |
| 901 | |
| 902 | while ((end = strchr(start, ',')) && end == start) |
| 903 | start = end + 1; |
| 904 | |
| 905 | if (!end) |
| 906 | return NULL; |
| 907 | |
| 908 | *end = 0; |
| 909 | *cmds = end + 1; |
| 910 | return start; |
| 911 | } |
| 912 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 913 | |
| 914 | /**************************************************************************** |
| 915 | **************************************************************************** |
| 916 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 917 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 918 | * |
| 919 | **************************************************************************** |
| 920 | ****************************************************************************/ |
| 921 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 922 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 923 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 924 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 925 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 926 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 927 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 928 | |
Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 929 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | 4959a78 | 2012-06-27 23:19:01 +0200 | [diff] [blame] | 930 | static int tpacpi_suspend_handler(struct device *dev) |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 931 | { |
| 932 | struct ibm_struct *ibm, *itmp; |
| 933 | |
| 934 | list_for_each_entry_safe(ibm, itmp, |
| 935 | &tpacpi_all_drivers, |
| 936 | all_drivers) { |
| 937 | if (ibm->suspend) |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 938 | (ibm->suspend)(); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | return 0; |
| 942 | } |
| 943 | |
Rafael J. Wysocki | 4959a78 | 2012-06-27 23:19:01 +0200 | [diff] [blame] | 944 | static int tpacpi_resume_handler(struct device *dev) |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 945 | { |
| 946 | struct ibm_struct *ibm, *itmp; |
| 947 | |
| 948 | list_for_each_entry_safe(ibm, itmp, |
| 949 | &tpacpi_all_drivers, |
| 950 | all_drivers) { |
| 951 | if (ibm->resume) |
| 952 | (ibm->resume)(); |
| 953 | } |
| 954 | |
| 955 | return 0; |
| 956 | } |
Rafael J. Wysocki | 3567a4e | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 957 | #endif |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 958 | |
Rafael J. Wysocki | 4959a78 | 2012-06-27 23:19:01 +0200 | [diff] [blame] | 959 | static SIMPLE_DEV_PM_OPS(tpacpi_pm, |
| 960 | tpacpi_suspend_handler, tpacpi_resume_handler); |
| 961 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 962 | static void tpacpi_shutdown_handler(struct platform_device *pdev) |
| 963 | { |
| 964 | struct ibm_struct *ibm, *itmp; |
| 965 | |
| 966 | list_for_each_entry_safe(ibm, itmp, |
| 967 | &tpacpi_all_drivers, |
| 968 | all_drivers) { |
| 969 | if (ibm->shutdown) |
| 970 | (ibm->shutdown)(); |
| 971 | } |
| 972 | } |
| 973 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 974 | static struct platform_driver tpacpi_pdriver = { |
| 975 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 976 | .name = TPACPI_DRVR_NAME, |
Rafael J. Wysocki | 4959a78 | 2012-06-27 23:19:01 +0200 | [diff] [blame] | 977 | .pm = &tpacpi_pm, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 978 | }, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 979 | .shutdown = tpacpi_shutdown_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 980 | }; |
| 981 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 982 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 983 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 984 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 985 | }, |
| 986 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 987 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 988 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 989 | * sysfs support helpers |
| 990 | */ |
| 991 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 992 | struct attribute_set { |
| 993 | unsigned int members, max_members; |
| 994 | struct attribute_group group; |
| 995 | }; |
| 996 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 997 | struct attribute_set_obj { |
| 998 | struct attribute_set s; |
| 999 | struct attribute *a; |
| 1000 | } __attribute__((packed)); |
| 1001 | |
| 1002 | static struct attribute_set *create_attr_set(unsigned int max_members, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1003 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1004 | { |
| 1005 | struct attribute_set_obj *sobj; |
| 1006 | |
| 1007 | if (max_members == 0) |
| 1008 | return NULL; |
| 1009 | |
| 1010 | /* Allocates space for implicit NULL at the end too */ |
| 1011 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 1012 | max_members * sizeof(struct attribute *), |
| 1013 | GFP_KERNEL); |
| 1014 | if (!sobj) |
| 1015 | return NULL; |
| 1016 | sobj->s.max_members = max_members; |
| 1017 | sobj->s.group.attrs = &sobj->a; |
| 1018 | sobj->s.group.name = name; |
| 1019 | |
| 1020 | return &sobj->s; |
| 1021 | } |
| 1022 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1023 | #define destroy_attr_set(_set) \ |
| 1024 | kfree(_set); |
| 1025 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1026 | /* not multi-threaded safe, use it in a single thread per set */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1027 | static int add_to_attr_set(struct attribute_set *s, struct attribute *attr) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1028 | { |
| 1029 | if (!s || !attr) |
| 1030 | return -EINVAL; |
| 1031 | |
| 1032 | if (s->members >= s->max_members) |
| 1033 | return -ENOMEM; |
| 1034 | |
| 1035 | s->group.attrs[s->members] = attr; |
| 1036 | s->members++; |
| 1037 | |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1041 | static int add_many_to_attr_set(struct attribute_set *s, |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1042 | struct attribute **attr, |
| 1043 | unsigned int count) |
| 1044 | { |
| 1045 | int i, res; |
| 1046 | |
| 1047 | for (i = 0; i < count; i++) { |
| 1048 | res = add_to_attr_set(s, attr[i]); |
| 1049 | if (res) |
| 1050 | return res; |
| 1051 | } |
| 1052 | |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1056 | static void delete_attr_set(struct attribute_set *s, struct kobject *kobj) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1057 | { |
| 1058 | sysfs_remove_group(kobj, &s->group); |
| 1059 | destroy_attr_set(s); |
| 1060 | } |
| 1061 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1062 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 1063 | sysfs_create_group(_kobj, &_attr_set->group) |
| 1064 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1065 | static int parse_strtoul(const char *buf, |
| 1066 | unsigned long max, unsigned long *value) |
| 1067 | { |
| 1068 | char *endp; |
| 1069 | |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 1070 | *value = simple_strtoul(skip_spaces(buf), &endp, 0); |
| 1071 | endp = skip_spaces(endp); |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1072 | if (*endp || *value > max) |
| 1073 | return -EINVAL; |
| 1074 | |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 1078 | static void tpacpi_disable_brightness_delay(void) |
| 1079 | { |
| 1080 | if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0)) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1081 | pr_notice("ACPI backlight control delay disabled\n"); |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 1082 | } |
| 1083 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1084 | static void printk_deprecated_attribute(const char * const what, |
| 1085 | const char * const details) |
| 1086 | { |
| 1087 | tpacpi_log_usertask("deprecated sysfs attribute"); |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1088 | pr_warn("WARNING: sysfs attribute %s is deprecated and " |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1089 | "will be removed. %s\n", |
| 1090 | what, details); |
| 1091 | } |
| 1092 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1093 | /************************************************************************* |
| 1094 | * rfkill and radio control support helpers |
| 1095 | */ |
| 1096 | |
| 1097 | /* |
| 1098 | * ThinkPad-ACPI firmware handling model: |
| 1099 | * |
| 1100 | * WLSW (master wireless switch) is event-driven, and is common to all |
| 1101 | * firmware-controlled radios. It cannot be controlled, just monitored, |
| 1102 | * as expected. It overrides all radio state in firmware |
| 1103 | * |
| 1104 | * The kernel, a masked-off hotkey, and WLSW can change the radio state |
| 1105 | * (TODO: verify how WLSW interacts with the returned radio state). |
| 1106 | * |
| 1107 | * The only time there are shadow radio state changes, is when |
| 1108 | * masked-off hotkeys are used. |
| 1109 | */ |
| 1110 | |
| 1111 | /* |
| 1112 | * Internal driver API for radio state: |
| 1113 | * |
| 1114 | * int: < 0 = error, otherwise enum tpacpi_rfkill_state |
| 1115 | * bool: true means radio blocked (off) |
| 1116 | */ |
| 1117 | enum tpacpi_rfkill_state { |
| 1118 | TPACPI_RFK_RADIO_OFF = 0, |
| 1119 | TPACPI_RFK_RADIO_ON |
| 1120 | }; |
| 1121 | |
| 1122 | /* rfkill switches */ |
| 1123 | enum tpacpi_rfk_id { |
| 1124 | TPACPI_RFK_BLUETOOTH_SW_ID = 0, |
| 1125 | TPACPI_RFK_WWAN_SW_ID, |
| 1126 | TPACPI_RFK_UWB_SW_ID, |
| 1127 | TPACPI_RFK_SW_MAX |
| 1128 | }; |
| 1129 | |
| 1130 | static const char *tpacpi_rfkill_names[] = { |
| 1131 | [TPACPI_RFK_BLUETOOTH_SW_ID] = "bluetooth", |
| 1132 | [TPACPI_RFK_WWAN_SW_ID] = "wwan", |
| 1133 | [TPACPI_RFK_UWB_SW_ID] = "uwb", |
| 1134 | [TPACPI_RFK_SW_MAX] = NULL |
| 1135 | }; |
| 1136 | |
| 1137 | /* ThinkPad-ACPI rfkill subdriver */ |
| 1138 | struct tpacpi_rfk { |
| 1139 | struct rfkill *rfkill; |
| 1140 | enum tpacpi_rfk_id id; |
| 1141 | const struct tpacpi_rfk_ops *ops; |
| 1142 | }; |
| 1143 | |
| 1144 | struct tpacpi_rfk_ops { |
| 1145 | /* firmware interface */ |
| 1146 | int (*get_status)(void); |
| 1147 | int (*set_status)(const enum tpacpi_rfkill_state); |
| 1148 | }; |
| 1149 | |
| 1150 | static struct tpacpi_rfk *tpacpi_rfkill_switches[TPACPI_RFK_SW_MAX]; |
| 1151 | |
| 1152 | /* Query FW and update rfkill sw state for a given rfkill switch */ |
| 1153 | static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk *tp_rfk) |
| 1154 | { |
| 1155 | int status; |
| 1156 | |
| 1157 | if (!tp_rfk) |
| 1158 | return -ENODEV; |
| 1159 | |
| 1160 | status = (tp_rfk->ops->get_status)(); |
| 1161 | if (status < 0) |
| 1162 | return status; |
| 1163 | |
| 1164 | rfkill_set_sw_state(tp_rfk->rfkill, |
| 1165 | (status == TPACPI_RFK_RADIO_OFF)); |
| 1166 | |
| 1167 | return status; |
| 1168 | } |
| 1169 | |
| 1170 | /* Query FW and update rfkill sw state for all rfkill switches */ |
| 1171 | static void tpacpi_rfk_update_swstate_all(void) |
| 1172 | { |
| 1173 | unsigned int i; |
| 1174 | |
| 1175 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) |
| 1176 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[i]); |
| 1177 | } |
| 1178 | |
| 1179 | /* |
| 1180 | * Sync the HW-blocking state of all rfkill switches, |
| 1181 | * do notice it causes the rfkill core to schedule uevents |
| 1182 | */ |
| 1183 | static void tpacpi_rfk_update_hwblock_state(bool blocked) |
| 1184 | { |
| 1185 | unsigned int i; |
| 1186 | struct tpacpi_rfk *tp_rfk; |
| 1187 | |
| 1188 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) { |
| 1189 | tp_rfk = tpacpi_rfkill_switches[i]; |
| 1190 | if (tp_rfk) { |
| 1191 | if (rfkill_set_hw_state(tp_rfk->rfkill, |
| 1192 | blocked)) { |
| 1193 | /* ignore -- we track sw block */ |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | /* Call to get the WLSW state from the firmware */ |
| 1200 | static int hotkey_get_wlsw(void); |
| 1201 | |
| 1202 | /* Call to query WLSW state and update all rfkill switches */ |
| 1203 | static bool tpacpi_rfk_check_hwblock_state(void) |
| 1204 | { |
| 1205 | int res = hotkey_get_wlsw(); |
| 1206 | int hw_blocked; |
| 1207 | |
| 1208 | /* When unknown or unsupported, we have to assume it is unblocked */ |
| 1209 | if (res < 0) |
| 1210 | return false; |
| 1211 | |
| 1212 | hw_blocked = (res == TPACPI_RFK_RADIO_OFF); |
| 1213 | tpacpi_rfk_update_hwblock_state(hw_blocked); |
| 1214 | |
| 1215 | return hw_blocked; |
| 1216 | } |
| 1217 | |
| 1218 | static int tpacpi_rfk_hook_set_block(void *data, bool blocked) |
| 1219 | { |
| 1220 | struct tpacpi_rfk *tp_rfk = data; |
| 1221 | int res; |
| 1222 | |
| 1223 | dbg_printk(TPACPI_DBG_RFKILL, |
| 1224 | "request to change radio state to %s\n", |
| 1225 | blocked ? "blocked" : "unblocked"); |
| 1226 | |
| 1227 | /* try to set radio state */ |
| 1228 | res = (tp_rfk->ops->set_status)(blocked ? |
| 1229 | TPACPI_RFK_RADIO_OFF : TPACPI_RFK_RADIO_ON); |
| 1230 | |
| 1231 | /* and update the rfkill core with whatever the FW really did */ |
| 1232 | tpacpi_rfk_update_swstate(tp_rfk); |
| 1233 | |
| 1234 | return (res < 0) ? res : 0; |
| 1235 | } |
| 1236 | |
| 1237 | static const struct rfkill_ops tpacpi_rfk_rfkill_ops = { |
| 1238 | .set_block = tpacpi_rfk_hook_set_block, |
| 1239 | }; |
| 1240 | |
| 1241 | static int __init tpacpi_new_rfkill(const enum tpacpi_rfk_id id, |
| 1242 | const struct tpacpi_rfk_ops *tp_rfkops, |
| 1243 | const enum rfkill_type rfktype, |
| 1244 | const char *name, |
| 1245 | const bool set_default) |
| 1246 | { |
| 1247 | struct tpacpi_rfk *atp_rfk; |
| 1248 | int res; |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1249 | bool sw_state = false; |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1250 | bool hw_state; |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1251 | int sw_status; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1252 | |
| 1253 | BUG_ON(id >= TPACPI_RFK_SW_MAX || tpacpi_rfkill_switches[id]); |
| 1254 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1255 | atp_rfk = kzalloc(sizeof(struct tpacpi_rfk), GFP_KERNEL); |
| 1256 | if (atp_rfk) |
| 1257 | atp_rfk->rfkill = rfkill_alloc(name, |
| 1258 | &tpacpi_pdev->dev, |
| 1259 | rfktype, |
| 1260 | &tpacpi_rfk_rfkill_ops, |
| 1261 | atp_rfk); |
| 1262 | if (!atp_rfk || !atp_rfk->rfkill) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1263 | pr_err("failed to allocate memory for rfkill class\n"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1264 | kfree(atp_rfk); |
| 1265 | return -ENOMEM; |
| 1266 | } |
| 1267 | |
| 1268 | atp_rfk->id = id; |
| 1269 | atp_rfk->ops = tp_rfkops; |
| 1270 | |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1271 | sw_status = (tp_rfkops->get_status)(); |
| 1272 | if (sw_status < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1273 | pr_err("failed to read initial state for %s, error %d\n", |
| 1274 | name, sw_status); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1275 | } else { |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1276 | sw_state = (sw_status == TPACPI_RFK_RADIO_OFF); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1277 | if (set_default) { |
| 1278 | /* try to keep the initial state, since we ask the |
| 1279 | * firmware to preserve it across S5 in NVRAM */ |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1280 | rfkill_init_sw_state(atp_rfk->rfkill, sw_state); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1281 | } |
| 1282 | } |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1283 | hw_state = tpacpi_rfk_check_hwblock_state(); |
| 1284 | rfkill_set_hw_state(atp_rfk->rfkill, hw_state); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1285 | |
| 1286 | res = rfkill_register(atp_rfk->rfkill); |
| 1287 | if (res < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1288 | pr_err("failed to register %s rfkill switch: %d\n", name, res); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1289 | rfkill_destroy(atp_rfk->rfkill); |
| 1290 | kfree(atp_rfk); |
| 1291 | return res; |
| 1292 | } |
| 1293 | |
| 1294 | tpacpi_rfkill_switches[id] = atp_rfk; |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1295 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1296 | pr_info("rfkill switch %s: radio is %sblocked\n", |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1297 | name, (sw_state || hw_state) ? "" : "un"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1298 | return 0; |
| 1299 | } |
| 1300 | |
| 1301 | static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id) |
| 1302 | { |
| 1303 | struct tpacpi_rfk *tp_rfk; |
| 1304 | |
| 1305 | BUG_ON(id >= TPACPI_RFK_SW_MAX); |
| 1306 | |
| 1307 | tp_rfk = tpacpi_rfkill_switches[id]; |
| 1308 | if (tp_rfk) { |
| 1309 | rfkill_unregister(tp_rfk->rfkill); |
Corentin Chary | 5f0dadb | 2009-09-14 12:43:52 +0200 | [diff] [blame] | 1310 | rfkill_destroy(tp_rfk->rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1311 | tpacpi_rfkill_switches[id] = NULL; |
| 1312 | kfree(tp_rfk); |
| 1313 | } |
| 1314 | } |
| 1315 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1316 | static void printk_deprecated_rfkill_attribute(const char * const what) |
| 1317 | { |
| 1318 | printk_deprecated_attribute(what, |
| 1319 | "Please switch to generic rfkill before year 2010"); |
| 1320 | } |
| 1321 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1322 | /* sysfs <radio> enable ------------------------------------------------ */ |
| 1323 | static ssize_t tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id, |
| 1324 | struct device_attribute *attr, |
| 1325 | char *buf) |
| 1326 | { |
| 1327 | int status; |
| 1328 | |
| 1329 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1330 | |
| 1331 | /* This is in the ABI... */ |
| 1332 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1333 | status = TPACPI_RFK_RADIO_OFF; |
| 1334 | } else { |
| 1335 | status = tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1336 | if (status < 0) |
| 1337 | return status; |
| 1338 | } |
| 1339 | |
| 1340 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1341 | (status == TPACPI_RFK_RADIO_ON) ? 1 : 0); |
| 1342 | } |
| 1343 | |
| 1344 | static ssize_t tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id, |
| 1345 | struct device_attribute *attr, |
| 1346 | const char *buf, size_t count) |
| 1347 | { |
| 1348 | unsigned long t; |
| 1349 | int res; |
| 1350 | |
| 1351 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1352 | |
| 1353 | if (parse_strtoul(buf, 1, &t)) |
| 1354 | return -EINVAL; |
| 1355 | |
| 1356 | tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); |
| 1357 | |
| 1358 | /* This is in the ABI... */ |
| 1359 | if (tpacpi_rfk_check_hwblock_state() && !!t) |
| 1360 | return -EPERM; |
| 1361 | |
| 1362 | res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? |
| 1363 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF); |
| 1364 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1365 | |
| 1366 | return (res < 0) ? res : count; |
| 1367 | } |
| 1368 | |
| 1369 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1370 | static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id, struct seq_file *m) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1371 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1372 | if (id >= TPACPI_RFK_SW_MAX) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1373 | seq_printf(m, "status:\t\tnot supported\n"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1374 | else { |
| 1375 | int status; |
| 1376 | |
| 1377 | /* This is in the ABI... */ |
| 1378 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1379 | status = TPACPI_RFK_RADIO_OFF; |
| 1380 | } else { |
| 1381 | status = tpacpi_rfk_update_swstate( |
| 1382 | tpacpi_rfkill_switches[id]); |
| 1383 | if (status < 0) |
| 1384 | return status; |
| 1385 | } |
| 1386 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1387 | seq_printf(m, "status:\t\t%s\n", |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1388 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1389 | "enabled" : "disabled"); |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1390 | seq_printf(m, "commands:\tenable, disable\n"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1391 | } |
| 1392 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1393 | return 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf) |
| 1397 | { |
| 1398 | char *cmd; |
| 1399 | int status = -1; |
| 1400 | int res = 0; |
| 1401 | |
| 1402 | if (id >= TPACPI_RFK_SW_MAX) |
| 1403 | return -ENODEV; |
| 1404 | |
| 1405 | while ((cmd = next_cmd(&buf))) { |
| 1406 | if (strlencmp(cmd, "enable") == 0) |
| 1407 | status = TPACPI_RFK_RADIO_ON; |
| 1408 | else if (strlencmp(cmd, "disable") == 0) |
| 1409 | status = TPACPI_RFK_RADIO_OFF; |
| 1410 | else |
| 1411 | return -EINVAL; |
| 1412 | } |
| 1413 | |
| 1414 | if (status != -1) { |
| 1415 | tpacpi_disclose_usertask("procfs", "attempt to %s %s\n", |
| 1416 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1417 | "enable" : "disable", |
| 1418 | tpacpi_rfkill_names[id]); |
| 1419 | res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); |
| 1420 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1421 | } |
| 1422 | |
| 1423 | return res; |
| 1424 | } |
| 1425 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1426 | /************************************************************************* |
| 1427 | * thinkpad-acpi driver attributes |
| 1428 | */ |
| 1429 | |
| 1430 | /* interface_version --------------------------------------------------- */ |
| 1431 | static ssize_t tpacpi_driver_interface_version_show( |
| 1432 | struct device_driver *drv, |
| 1433 | char *buf) |
| 1434 | { |
| 1435 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 1436 | } |
| 1437 | |
| 1438 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 1439 | tpacpi_driver_interface_version_show, NULL); |
| 1440 | |
| 1441 | /* debug_level --------------------------------------------------------- */ |
| 1442 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 1443 | char *buf) |
| 1444 | { |
| 1445 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 1446 | } |
| 1447 | |
| 1448 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 1449 | const char *buf, size_t count) |
| 1450 | { |
| 1451 | unsigned long t; |
| 1452 | |
| 1453 | if (parse_strtoul(buf, 0xffff, &t)) |
| 1454 | return -EINVAL; |
| 1455 | |
| 1456 | dbg_level = t; |
| 1457 | |
| 1458 | return count; |
| 1459 | } |
| 1460 | |
| 1461 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1462 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 1463 | |
| 1464 | /* version ------------------------------------------------------------- */ |
| 1465 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 1466 | char *buf) |
| 1467 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1468 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 1469 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | static DRIVER_ATTR(version, S_IRUGO, |
| 1473 | tpacpi_driver_version_show, NULL); |
| 1474 | |
| 1475 | /* --------------------------------------------------------------------- */ |
| 1476 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1477 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1478 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1479 | /* wlsw_emulstate ------------------------------------------------------ */ |
| 1480 | static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv, |
| 1481 | char *buf) |
| 1482 | { |
| 1483 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate); |
| 1484 | } |
| 1485 | |
| 1486 | static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv, |
| 1487 | const char *buf, size_t count) |
| 1488 | { |
| 1489 | unsigned long t; |
| 1490 | |
| 1491 | if (parse_strtoul(buf, 1, &t)) |
| 1492 | return -EINVAL; |
| 1493 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1494 | if (tpacpi_wlsw_emulstate != !!t) { |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1495 | tpacpi_wlsw_emulstate = !!t; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1496 | tpacpi_rfk_update_hwblock_state(!t); /* negative logic */ |
| 1497 | } |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1498 | |
| 1499 | return count; |
| 1500 | } |
| 1501 | |
| 1502 | static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO, |
| 1503 | tpacpi_driver_wlsw_emulstate_show, |
| 1504 | tpacpi_driver_wlsw_emulstate_store); |
| 1505 | |
| 1506 | /* bluetooth_emulstate ------------------------------------------------- */ |
| 1507 | static ssize_t tpacpi_driver_bluetooth_emulstate_show( |
| 1508 | struct device_driver *drv, |
| 1509 | char *buf) |
| 1510 | { |
| 1511 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate); |
| 1512 | } |
| 1513 | |
| 1514 | static ssize_t tpacpi_driver_bluetooth_emulstate_store( |
| 1515 | struct device_driver *drv, |
| 1516 | const char *buf, size_t count) |
| 1517 | { |
| 1518 | unsigned long t; |
| 1519 | |
| 1520 | if (parse_strtoul(buf, 1, &t)) |
| 1521 | return -EINVAL; |
| 1522 | |
| 1523 | tpacpi_bluetooth_emulstate = !!t; |
| 1524 | |
| 1525 | return count; |
| 1526 | } |
| 1527 | |
| 1528 | static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO, |
| 1529 | tpacpi_driver_bluetooth_emulstate_show, |
| 1530 | tpacpi_driver_bluetooth_emulstate_store); |
| 1531 | |
| 1532 | /* wwan_emulstate ------------------------------------------------- */ |
| 1533 | static ssize_t tpacpi_driver_wwan_emulstate_show( |
| 1534 | struct device_driver *drv, |
| 1535 | char *buf) |
| 1536 | { |
| 1537 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate); |
| 1538 | } |
| 1539 | |
| 1540 | static ssize_t tpacpi_driver_wwan_emulstate_store( |
| 1541 | struct device_driver *drv, |
| 1542 | const char *buf, size_t count) |
| 1543 | { |
| 1544 | unsigned long t; |
| 1545 | |
| 1546 | if (parse_strtoul(buf, 1, &t)) |
| 1547 | return -EINVAL; |
| 1548 | |
| 1549 | tpacpi_wwan_emulstate = !!t; |
| 1550 | |
| 1551 | return count; |
| 1552 | } |
| 1553 | |
| 1554 | static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO, |
| 1555 | tpacpi_driver_wwan_emulstate_show, |
| 1556 | tpacpi_driver_wwan_emulstate_store); |
| 1557 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1558 | /* uwb_emulstate ------------------------------------------------- */ |
| 1559 | static ssize_t tpacpi_driver_uwb_emulstate_show( |
| 1560 | struct device_driver *drv, |
| 1561 | char *buf) |
| 1562 | { |
| 1563 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate); |
| 1564 | } |
| 1565 | |
| 1566 | static ssize_t tpacpi_driver_uwb_emulstate_store( |
| 1567 | struct device_driver *drv, |
| 1568 | const char *buf, size_t count) |
| 1569 | { |
| 1570 | unsigned long t; |
| 1571 | |
| 1572 | if (parse_strtoul(buf, 1, &t)) |
| 1573 | return -EINVAL; |
| 1574 | |
| 1575 | tpacpi_uwb_emulstate = !!t; |
| 1576 | |
| 1577 | return count; |
| 1578 | } |
| 1579 | |
| 1580 | static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO, |
| 1581 | tpacpi_driver_uwb_emulstate_show, |
| 1582 | tpacpi_driver_uwb_emulstate_store); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1583 | #endif |
| 1584 | |
| 1585 | /* --------------------------------------------------------------------- */ |
| 1586 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1587 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1588 | &driver_attr_debug_level, &driver_attr_version, |
| 1589 | &driver_attr_interface_version, |
| 1590 | }; |
| 1591 | |
| 1592 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 1593 | { |
| 1594 | int i, res; |
| 1595 | |
| 1596 | i = 0; |
| 1597 | res = 0; |
| 1598 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 1599 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 1600 | i++; |
| 1601 | } |
| 1602 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1603 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1604 | if (!res && dbg_wlswemul) |
| 1605 | res = driver_create_file(drv, &driver_attr_wlsw_emulstate); |
| 1606 | if (!res && dbg_bluetoothemul) |
| 1607 | res = driver_create_file(drv, &driver_attr_bluetooth_emulstate); |
| 1608 | if (!res && dbg_wwanemul) |
| 1609 | res = driver_create_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1610 | if (!res && dbg_uwbemul) |
| 1611 | res = driver_create_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1612 | #endif |
| 1613 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1614 | return res; |
| 1615 | } |
| 1616 | |
| 1617 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 1618 | { |
| 1619 | int i; |
| 1620 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1621 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1622 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1623 | |
| 1624 | #ifdef THINKPAD_ACPI_DEBUGFACILITIES |
| 1625 | driver_remove_file(drv, &driver_attr_wlsw_emulstate); |
| 1626 | driver_remove_file(drv, &driver_attr_bluetooth_emulstate); |
| 1627 | driver_remove_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1628 | driver_remove_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1629 | #endif |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1630 | } |
| 1631 | |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1632 | /************************************************************************* |
| 1633 | * Firmware Data |
| 1634 | */ |
| 1635 | |
| 1636 | /* |
| 1637 | * Table of recommended minimum BIOS versions |
| 1638 | * |
| 1639 | * Reasons for listing: |
Uwe Kleine-König | 9ddc5b6 | 2010-01-20 17:02:24 +0100 | [diff] [blame] | 1640 | * 1. Stable BIOS, listed because the unknown amount of |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1641 | * bugs and bad ACPI behaviour on older versions |
| 1642 | * |
| 1643 | * 2. BIOS or EC fw with known bugs that trigger on Linux |
| 1644 | * |
| 1645 | * 3. BIOS with known reduced functionality in older versions |
| 1646 | * |
| 1647 | * We recommend the latest BIOS and EC version. |
| 1648 | * We only support the latest BIOS and EC fw version as a rule. |
| 1649 | * |
| 1650 | * Sources: IBM ThinkPad Public Web Documents (update changelogs), |
| 1651 | * Information from users in ThinkWiki |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1652 | * |
| 1653 | * WARNING: we use this table also to detect that the machine is |
| 1654 | * a ThinkPad in some cases, so don't remove entries lightly. |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1655 | */ |
| 1656 | |
| 1657 | #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \ |
| 1658 | { .vendor = (__v), \ |
| 1659 | .bios = TPID(__id1, __id2), \ |
| 1660 | .ec = TPACPI_MATCH_ANY, \ |
| 1661 | .quirks = TPACPI_MATCH_ANY << 16 \ |
| 1662 | | (__bv1) << 8 | (__bv2) } |
| 1663 | |
| 1664 | #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1665 | __eid, __ev1, __ev2) \ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1666 | { .vendor = (__v), \ |
| 1667 | .bios = TPID(__bid1, __bid2), \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1668 | .ec = __eid, \ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1669 | .quirks = (__ev1) << 24 | (__ev2) << 16 \ |
| 1670 | | (__bv1) << 8 | (__bv2) } |
| 1671 | |
| 1672 | #define TPV_QI0(__id1, __id2, __bv1, __bv2) \ |
| 1673 | TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2) |
| 1674 | |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1675 | /* Outdated IBM BIOSes often lack the EC id string */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1676 | #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1677 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1678 | __bv1, __bv2, TPID(__id1, __id2), \ |
| 1679 | __ev1, __ev2), \ |
| 1680 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
| 1681 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ |
| 1682 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1683 | |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1684 | /* Outdated IBM BIOSes often lack the EC id string */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1685 | #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \ |
| 1686 | __eid1, __eid2, __ev1, __ev2) \ |
| 1687 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1688 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
| 1689 | __ev1, __ev2), \ |
| 1690 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
| 1691 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ |
| 1692 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1693 | |
| 1694 | #define TPV_QL0(__id1, __id2, __bv1, __bv2) \ |
| 1695 | TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2) |
| 1696 | |
| 1697 | #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1698 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1699 | __bv1, __bv2, TPID(__id1, __id2), \ |
| 1700 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1701 | |
| 1702 | #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \ |
| 1703 | __eid1, __eid2, __ev1, __ev2) \ |
| 1704 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1705 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
| 1706 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1707 | |
| 1708 | static const struct tpacpi_quirk tpacpi_bios_version_qtable[] __initconst = { |
| 1709 | /* Numeric models ------------------ */ |
| 1710 | /* FW MODEL BIOS VERS */ |
| 1711 | TPV_QI0('I', 'M', '6', '5'), /* 570 */ |
| 1712 | TPV_QI0('I', 'U', '2', '6'), /* 570E */ |
| 1713 | TPV_QI0('I', 'B', '5', '4'), /* 600 */ |
| 1714 | TPV_QI0('I', 'H', '4', '7'), /* 600E */ |
| 1715 | TPV_QI0('I', 'N', '3', '6'), /* 600E */ |
| 1716 | TPV_QI0('I', 'T', '5', '5'), /* 600X */ |
| 1717 | TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */ |
| 1718 | TPV_QI0('I', 'I', '4', '2'), /* 770X */ |
| 1719 | TPV_QI0('I', 'O', '2', '3'), /* 770Z */ |
| 1720 | |
| 1721 | /* A-series ------------------------- */ |
| 1722 | /* FW MODEL BIOS VERS EC VERS */ |
| 1723 | TPV_QI0('I', 'W', '5', '9'), /* A20m */ |
| 1724 | TPV_QI0('I', 'V', '6', '9'), /* A20p */ |
| 1725 | TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */ |
| 1726 | TPV_QI0('K', 'U', '3', '6'), /* A21e */ |
| 1727 | TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */ |
| 1728 | TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */ |
| 1729 | TPV_QI0('1', 'B', '1', '7'), /* A22e */ |
| 1730 | TPV_QI0('1', '3', '2', '0'), /* A22m */ |
| 1731 | TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */ |
| 1732 | TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */ |
| 1733 | TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */ |
| 1734 | |
| 1735 | /* G-series ------------------------- */ |
| 1736 | /* FW MODEL BIOS VERS */ |
| 1737 | TPV_QI0('1', 'T', 'A', '6'), /* G40 */ |
| 1738 | TPV_QI0('1', 'X', '5', '7'), /* G41 */ |
| 1739 | |
| 1740 | /* R-series, T-series --------------- */ |
| 1741 | /* FW MODEL BIOS VERS EC VERS */ |
| 1742 | TPV_QI0('1', 'C', 'F', '0'), /* R30 */ |
| 1743 | TPV_QI0('1', 'F', 'F', '1'), /* R31 */ |
| 1744 | TPV_QI0('1', 'M', '9', '7'), /* R32 */ |
| 1745 | TPV_QI0('1', 'O', '6', '1'), /* R40 */ |
| 1746 | TPV_QI0('1', 'P', '6', '5'), /* R40 */ |
| 1747 | TPV_QI0('1', 'S', '7', '0'), /* R40e */ |
| 1748 | TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51, |
| 1749 | T40/p, T41/p, T42/p (1) */ |
| 1750 | TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */ |
| 1751 | TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */ |
| 1752 | TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */ |
| 1753 | TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */ |
| 1754 | |
| 1755 | TPV_QI0('I', 'Y', '6', '1'), /* T20 */ |
| 1756 | TPV_QI0('K', 'Z', '3', '4'), /* T21 */ |
| 1757 | TPV_QI0('1', '6', '3', '2'), /* T22 */ |
| 1758 | TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */ |
| 1759 | TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */ |
| 1760 | TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */ |
| 1761 | |
| 1762 | TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */ |
| 1763 | TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */ |
Henrique de Moraes Holschuh | 90765c6 | 2009-12-09 01:36:23 +0000 | [diff] [blame] | 1764 | TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1765 | |
| 1766 | /* BIOS FW BIOS VERS EC FW EC VERS */ |
| 1767 | TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */ |
| 1768 | TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */ |
| 1769 | |
| 1770 | /* X-series ------------------------- */ |
| 1771 | /* FW MODEL BIOS VERS EC VERS */ |
| 1772 | TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */ |
| 1773 | TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */ |
| 1774 | TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */ |
| 1775 | TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */ |
| 1776 | TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */ |
| 1777 | TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */ |
| 1778 | TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */ |
| 1779 | |
Henrique de Moraes Holschuh | 90765c6 | 2009-12-09 01:36:23 +0000 | [diff] [blame] | 1780 | TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */ |
| 1781 | TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1782 | |
| 1783 | /* (0) - older versions lack DMI EC fw string and functionality */ |
| 1784 | /* (1) - older versions known to lack functionality */ |
| 1785 | }; |
| 1786 | |
| 1787 | #undef TPV_QL1 |
| 1788 | #undef TPV_QL0 |
| 1789 | #undef TPV_QI2 |
| 1790 | #undef TPV_QI1 |
| 1791 | #undef TPV_QI0 |
| 1792 | #undef TPV_Q_X |
| 1793 | #undef TPV_Q |
| 1794 | |
| 1795 | static void __init tpacpi_check_outdated_fw(void) |
| 1796 | { |
| 1797 | unsigned long fwvers; |
| 1798 | u16 ec_version, bios_version; |
| 1799 | |
| 1800 | fwvers = tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1801 | ARRAY_SIZE(tpacpi_bios_version_qtable)); |
| 1802 | |
| 1803 | if (!fwvers) |
| 1804 | return; |
| 1805 | |
| 1806 | bios_version = fwvers & 0xffffU; |
| 1807 | ec_version = (fwvers >> 16) & 0xffffU; |
| 1808 | |
| 1809 | /* note that unknown versions are set to 0x0000 and we use that */ |
| 1810 | if ((bios_version > thinkpad_id.bios_release) || |
| 1811 | (ec_version > thinkpad_id.ec_release && |
| 1812 | ec_version != TPACPI_MATCH_ANY)) { |
| 1813 | /* |
| 1814 | * The changelogs would let us track down the exact |
| 1815 | * reason, but it is just too much of a pain to track |
| 1816 | * it. We only list BIOSes that are either really |
| 1817 | * broken, or really stable to begin with, so it is |
| 1818 | * best if the user upgrades the firmware anyway. |
| 1819 | */ |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1820 | pr_warn("WARNING: Outdated ThinkPad BIOS/EC firmware\n"); |
| 1821 | pr_warn("WARNING: This firmware may be missing critical bug " |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1822 | "fixes and/or important features\n"); |
| 1823 | } |
| 1824 | } |
| 1825 | |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1826 | static bool __init tpacpi_is_fw_known(void) |
| 1827 | { |
| 1828 | return tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1829 | ARRAY_SIZE(tpacpi_bios_version_qtable)) != 0; |
| 1830 | } |
| 1831 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1832 | /**************************************************************************** |
| 1833 | **************************************************************************** |
| 1834 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1835 | * Subdrivers |
| 1836 | * |
| 1837 | **************************************************************************** |
| 1838 | ****************************************************************************/ |
| 1839 | |
| 1840 | /************************************************************************* |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 1841 | * thinkpad-acpi metadata subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1842 | */ |
| 1843 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1844 | static int thinkpad_acpi_driver_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1846 | seq_printf(m, "driver:\t\t%s\n", TPACPI_DESC); |
| 1847 | seq_printf(m, "version:\t%s\n", TPACPI_VERSION); |
| 1848 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1851 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1852 | .name = "driver", |
| 1853 | .read = thinkpad_acpi_driver_read, |
| 1854 | }; |
| 1855 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1856 | /************************************************************************* |
| 1857 | * Hotkey subdriver |
| 1858 | */ |
| 1859 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1860 | /* |
| 1861 | * ThinkPad firmware event model |
| 1862 | * |
| 1863 | * The ThinkPad firmware has two main event interfaces: normal ACPI |
| 1864 | * notifications (which follow the ACPI standard), and a private event |
| 1865 | * interface. |
| 1866 | * |
| 1867 | * The private event interface also issues events for the hotkeys. As |
| 1868 | * the driver gained features, the event handling code ended up being |
| 1869 | * built around the hotkey subdriver. This will need to be refactored |
| 1870 | * to a more formal event API eventually. |
| 1871 | * |
| 1872 | * Some "hotkeys" are actually supposed to be used as event reports, |
| 1873 | * such as "brightness has changed", "volume has changed", depending on |
| 1874 | * the ThinkPad model and how the firmware is operating. |
| 1875 | * |
| 1876 | * Unlike other classes, hotkey-class events have mask/unmask control on |
| 1877 | * non-ancient firmware. However, how it behaves changes a lot with the |
| 1878 | * firmware model and version. |
| 1879 | */ |
| 1880 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1881 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1882 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1883 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1884 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1885 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1886 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1887 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1888 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1889 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1890 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1891 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1892 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1893 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1894 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1895 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1896 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1897 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1898 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1899 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1900 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1901 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1902 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1903 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1904 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1905 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
Henrique de Moraes Holschuh | 34a656d2 | 2010-08-09 23:48:20 -0300 | [diff] [blame] | 1906 | TP_ACPI_HOTKEYSCAN_UNK1, |
| 1907 | TP_ACPI_HOTKEYSCAN_UNK2, |
| 1908 | TP_ACPI_HOTKEYSCAN_UNK3, |
| 1909 | TP_ACPI_HOTKEYSCAN_UNK4, |
| 1910 | TP_ACPI_HOTKEYSCAN_UNK5, |
| 1911 | TP_ACPI_HOTKEYSCAN_UNK6, |
| 1912 | TP_ACPI_HOTKEYSCAN_UNK7, |
| 1913 | TP_ACPI_HOTKEYSCAN_UNK8, |
| 1914 | |
Bastien Nocera | 6a68d85 | 2015-03-02 14:45:31 +0100 | [diff] [blame] | 1915 | TP_ACPI_HOTKEYSCAN_MUTE2, |
| 1916 | TP_ACPI_HOTKEYSCAN_BRIGHTNESS_ZERO, |
| 1917 | TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL, |
| 1918 | TP_ACPI_HOTKEYSCAN_CLOUD, |
| 1919 | TP_ACPI_HOTKEYSCAN_UNK9, |
| 1920 | TP_ACPI_HOTKEYSCAN_VOICE, |
| 1921 | TP_ACPI_HOTKEYSCAN_UNK10, |
| 1922 | TP_ACPI_HOTKEYSCAN_GESTURES, |
| 1923 | TP_ACPI_HOTKEYSCAN_UNK11, |
| 1924 | TP_ACPI_HOTKEYSCAN_UNK12, |
| 1925 | TP_ACPI_HOTKEYSCAN_UNK13, |
| 1926 | TP_ACPI_HOTKEYSCAN_CONFIG, |
| 1927 | TP_ACPI_HOTKEYSCAN_NEW_TAB, |
| 1928 | TP_ACPI_HOTKEYSCAN_RELOAD, |
| 1929 | TP_ACPI_HOTKEYSCAN_BACK, |
| 1930 | TP_ACPI_HOTKEYSCAN_MIC_DOWN, |
| 1931 | TP_ACPI_HOTKEYSCAN_MIC_UP, |
| 1932 | TP_ACPI_HOTKEYSCAN_MIC_CANCELLATION, |
| 1933 | TP_ACPI_HOTKEYSCAN_CAMERA_MODE, |
| 1934 | TP_ACPI_HOTKEYSCAN_ROTATE_DISPLAY, |
| 1935 | |
Henrique de Moraes Holschuh | 34a656d2 | 2010-08-09 23:48:20 -0300 | [diff] [blame] | 1936 | /* Hotkey keymap size */ |
| 1937 | TPACPI_HOTKEY_MAP_LEN |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1938 | }; |
| 1939 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1940 | enum { /* Keys/events available through NVRAM polling */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1941 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1942 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1943 | }; |
| 1944 | |
| 1945 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1946 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1947 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1948 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1949 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1950 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1951 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1952 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1953 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1954 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1955 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1956 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1957 | }; |
| 1958 | |
| 1959 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1960 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1961 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1962 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1963 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1964 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1965 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1966 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1967 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1968 | TP_ACPI_HKEY_MUTE_MASK, |
| 1969 | }; |
| 1970 | |
| 1971 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1972 | struct tp_nvram_state { |
| 1973 | u16 thinkpad_toggle:1; |
| 1974 | u16 zoom_toggle:1; |
| 1975 | u16 display_toggle:1; |
| 1976 | u16 thinklight_toggle:1; |
| 1977 | u16 hibernate_toggle:1; |
| 1978 | u16 displayexp_toggle:1; |
| 1979 | u16 display_state:1; |
| 1980 | u16 brightness_toggle:1; |
| 1981 | u16 volume_toggle:1; |
| 1982 | u16 mute:1; |
| 1983 | |
| 1984 | u8 brightness_level; |
| 1985 | u8 volume_level; |
| 1986 | }; |
| 1987 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1988 | /* kthread for the hotkey poller */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1989 | static struct task_struct *tpacpi_hotkey_task; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1990 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1991 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1992 | * Acquire mutex to write poller control variables as an |
| 1993 | * atomic block. |
| 1994 | * |
| 1995 | * Increment hotkey_config_change when changing them if you |
| 1996 | * want the kthread to forget old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1997 | * |
| 1998 | * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 1999 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2000 | static struct mutex hotkey_thread_data_mutex; |
| 2001 | static unsigned int hotkey_config_change; |
| 2002 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2003 | /* |
| 2004 | * hotkey poller control variables |
| 2005 | * |
| 2006 | * Must be atomic or readers will also need to acquire mutex |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2007 | * |
| 2008 | * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 2009 | * should be used only when the changes need to be taken as |
| 2010 | * a block, OR when one needs to force the kthread to forget |
| 2011 | * old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2012 | */ |
| 2013 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 2014 | static unsigned int hotkey_poll_freq = 10; /* Hz */ |
| 2015 | |
| 2016 | #define HOTKEY_CONFIG_CRITICAL_START \ |
| 2017 | do { \ |
| 2018 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 2019 | hotkey_config_change++; \ |
| 2020 | } while (0); |
| 2021 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 2022 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2023 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2024 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2025 | |
| 2026 | #define hotkey_source_mask 0U |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2027 | #define HOTKEY_CONFIG_CRITICAL_START |
| 2028 | #define HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2029 | |
| 2030 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2031 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2032 | static struct mutex hotkey_mutex; |
| 2033 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2034 | static enum { /* Reasons for waking up */ |
| 2035 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 2036 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 2037 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 2038 | } hotkey_wakeup_reason; |
| 2039 | |
| 2040 | static int hotkey_autosleep_ack; |
| 2041 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2042 | static u32 hotkey_orig_mask; /* events the BIOS had enabled */ |
| 2043 | static u32 hotkey_all_mask; /* all events supported in fw */ |
| 2044 | static u32 hotkey_reserved_mask; /* events better left disabled */ |
| 2045 | static u32 hotkey_driver_mask; /* events needed by the driver */ |
| 2046 | static u32 hotkey_user_mask; /* events visible to userspace */ |
| 2047 | static u32 hotkey_acpi_mask; /* events enabled in firmware */ |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2048 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2049 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2050 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 2051 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2052 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2053 | static void tpacpi_driver_event(const unsigned int hkey_event); |
| 2054 | static void hotkey_driver_event(const unsigned int scancode); |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2055 | static void hotkey_poll_setup(const bool may_warn); |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2056 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2057 | /* HKEY.MHKG() return bits */ |
| 2058 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 2059 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2060 | static int hotkey_get_wlsw(void) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2061 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2062 | int status; |
| 2063 | |
| 2064 | if (!tp_features.hotkey_wlsw) |
| 2065 | return -ENODEV; |
| 2066 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2067 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2068 | if (dbg_wlswemul) |
| 2069 | return (tpacpi_wlsw_emulstate) ? |
| 2070 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2071 | #endif |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2072 | |
| 2073 | if (!acpi_evalf(hkey_handle, &status, "WLSW", "d")) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2074 | return -EIO; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2075 | |
| 2076 | return (status) ? TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2077 | } |
| 2078 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2079 | static int hotkey_get_tablet_mode(int *status) |
| 2080 | { |
| 2081 | int s; |
| 2082 | |
| 2083 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 2084 | return -EIO; |
| 2085 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 2086 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 2087 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2088 | } |
| 2089 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2090 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2091 | * Reads current event mask from firmware, and updates |
| 2092 | * hotkey_acpi_mask accordingly. Also resets any bits |
| 2093 | * from hotkey_user_mask that are unavailable to be |
| 2094 | * delivered (shadow requirement of the userspace ABI). |
| 2095 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2096 | * Call with hotkey_mutex held |
| 2097 | */ |
| 2098 | static int hotkey_mask_get(void) |
| 2099 | { |
| 2100 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2101 | u32 m = 0; |
| 2102 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2103 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2104 | return -EIO; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2105 | |
| 2106 | hotkey_acpi_mask = m; |
| 2107 | } else { |
| 2108 | /* no mask support doesn't mean no event support... */ |
| 2109 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2110 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2111 | |
| 2112 | /* sync userspace-visible mask */ |
| 2113 | hotkey_user_mask &= (hotkey_acpi_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2114 | |
| 2115 | return 0; |
| 2116 | } |
| 2117 | |
Jean Delvare | df6dd1b | 2015-04-27 09:45:06 +0200 | [diff] [blame] | 2118 | static void hotkey_mask_warn_incomplete_mask(void) |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2119 | { |
| 2120 | /* log only what the user can fix... */ |
| 2121 | const u32 wantedmask = hotkey_driver_mask & |
| 2122 | ~(hotkey_acpi_mask | hotkey_source_mask) & |
| 2123 | (hotkey_all_mask | TPACPI_HKEY_NVRAM_KNOWN_MASK); |
| 2124 | |
| 2125 | if (wantedmask) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2126 | pr_notice("required events 0x%08x not enabled!\n", wantedmask); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2127 | } |
| 2128 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2129 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2130 | * Set the firmware mask when supported |
| 2131 | * |
| 2132 | * Also calls hotkey_mask_get to update hotkey_acpi_mask. |
| 2133 | * |
| 2134 | * NOTE: does not set bits in hotkey_user_mask, but may reset them. |
| 2135 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2136 | * Call with hotkey_mutex held |
| 2137 | */ |
| 2138 | static int hotkey_mask_set(u32 mask) |
| 2139 | { |
| 2140 | int i; |
| 2141 | int rc = 0; |
| 2142 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2143 | const u32 fwmask = mask & ~hotkey_source_mask; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 2144 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2145 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2146 | for (i = 0; i < 32; i++) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2147 | if (!acpi_evalf(hkey_handle, |
| 2148 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2149 | !!(mask & (1 << i)))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2150 | rc = -EIO; |
| 2151 | break; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2152 | } |
| 2153 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2154 | } |
| 2155 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2156 | /* |
| 2157 | * We *must* make an inconditional call to hotkey_mask_get to |
| 2158 | * refresh hotkey_acpi_mask and update hotkey_user_mask |
| 2159 | * |
| 2160 | * Take the opportunity to also log when we cannot _enable_ |
| 2161 | * a given event. |
| 2162 | */ |
| 2163 | if (!hotkey_mask_get() && !rc && (fwmask & ~hotkey_acpi_mask)) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2164 | pr_notice("asked for hotkey mask 0x%08x, but " |
| 2165 | "firmware forced it to 0x%08x\n", |
| 2166 | fwmask, hotkey_acpi_mask); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2167 | } |
| 2168 | |
Henrique de Moraes Holschuh | 6b30eb7 | 2009-12-09 01:36:25 +0000 | [diff] [blame] | 2169 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING) |
| 2170 | hotkey_mask_warn_incomplete_mask(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2171 | |
| 2172 | return rc; |
| 2173 | } |
| 2174 | |
| 2175 | /* |
| 2176 | * Sets hotkey_user_mask and tries to set the firmware mask |
| 2177 | * |
| 2178 | * Call with hotkey_mutex held |
| 2179 | */ |
| 2180 | static int hotkey_user_mask_set(const u32 mask) |
| 2181 | { |
| 2182 | int rc; |
| 2183 | |
| 2184 | /* Give people a chance to notice they are doing something that |
| 2185 | * is bound to go boom on their users sooner or later */ |
| 2186 | if (!tp_warned.hotkey_mask_ff && |
| 2187 | (mask == 0xffff || mask == 0xffffff || |
| 2188 | mask == 0xffffffff)) { |
| 2189 | tp_warned.hotkey_mask_ff = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2190 | pr_notice("setting the hotkey mask to 0x%08x is likely " |
| 2191 | "not the best way to go about it\n", mask); |
| 2192 | pr_notice("please consider using the driver defaults, " |
| 2193 | "and refer to up-to-date thinkpad-acpi " |
| 2194 | "documentation\n"); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | /* Try to enable what the user asked for, plus whatever we need. |
| 2198 | * this syncs everything but won't enable bits in hotkey_user_mask */ |
| 2199 | rc = hotkey_mask_set((mask | hotkey_driver_mask) & ~hotkey_source_mask); |
| 2200 | |
| 2201 | /* Enable the available bits in hotkey_user_mask */ |
| 2202 | hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask); |
| 2203 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2204 | return rc; |
| 2205 | } |
| 2206 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2207 | /* |
| 2208 | * Sets the driver hotkey mask. |
| 2209 | * |
| 2210 | * Can be called even if the hotkey subdriver is inactive |
| 2211 | */ |
| 2212 | static int tpacpi_hotkey_driver_mask_set(const u32 mask) |
| 2213 | { |
| 2214 | int rc; |
| 2215 | |
| 2216 | /* Do the right thing if hotkey_init has not been called yet */ |
| 2217 | if (!tp_features.hotkey) { |
| 2218 | hotkey_driver_mask = mask; |
| 2219 | return 0; |
| 2220 | } |
| 2221 | |
| 2222 | mutex_lock(&hotkey_mutex); |
| 2223 | |
| 2224 | HOTKEY_CONFIG_CRITICAL_START |
| 2225 | hotkey_driver_mask = mask; |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2226 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2227 | hotkey_source_mask |= (mask & ~hotkey_all_mask); |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2228 | #endif |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2229 | HOTKEY_CONFIG_CRITICAL_END |
| 2230 | |
| 2231 | rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) & |
| 2232 | ~hotkey_source_mask); |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2233 | hotkey_poll_setup(true); |
| 2234 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2235 | mutex_unlock(&hotkey_mutex); |
| 2236 | |
| 2237 | return rc; |
| 2238 | } |
| 2239 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2240 | static int hotkey_status_get(int *status) |
| 2241 | { |
| 2242 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 2243 | return -EIO; |
| 2244 | |
| 2245 | return 0; |
| 2246 | } |
| 2247 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2248 | static int hotkey_status_set(bool enable) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2249 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2250 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", enable ? 1 : 0)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2251 | return -EIO; |
| 2252 | |
| 2253 | return 0; |
| 2254 | } |
| 2255 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2256 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2257 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2258 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2259 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2260 | if (tp_features.hotkey_tablet && |
| 2261 | !hotkey_get_tablet_mode(&state)) { |
| 2262 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2263 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2264 | input_report_switch(tpacpi_inputdev, |
| 2265 | SW_TABLET_MODE, !!state); |
| 2266 | input_sync(tpacpi_inputdev); |
| 2267 | |
| 2268 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2269 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2270 | } |
| 2271 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2272 | /* Do NOT call without validating scancode first */ |
| 2273 | static void tpacpi_input_send_key(const unsigned int scancode) |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2274 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2275 | const unsigned int keycode = hotkey_keycode_map[scancode]; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2276 | |
| 2277 | if (keycode != KEY_RESERVED) { |
| 2278 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2279 | |
Seth Forshee | 5ffba7e | 2011-01-14 15:54:39 -0600 | [diff] [blame] | 2280 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2281 | input_report_key(tpacpi_inputdev, keycode, 1); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2282 | input_sync(tpacpi_inputdev); |
| 2283 | |
Seth Forshee | 5ffba7e | 2011-01-14 15:54:39 -0600 | [diff] [blame] | 2284 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2285 | input_report_key(tpacpi_inputdev, keycode, 0); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2286 | input_sync(tpacpi_inputdev); |
| 2287 | |
| 2288 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2289 | } |
| 2290 | } |
| 2291 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2292 | /* Do NOT call without validating scancode first */ |
| 2293 | static void tpacpi_input_send_key_masked(const unsigned int scancode) |
| 2294 | { |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2295 | hotkey_driver_event(scancode); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2296 | if (hotkey_user_mask & (1 << scancode)) |
| 2297 | tpacpi_input_send_key(scancode); |
| 2298 | } |
| 2299 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2300 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2301 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 2302 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2303 | /* Do NOT call without validating scancode first */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2304 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 2305 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2306 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2307 | } |
| 2308 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2309 | static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2310 | { |
| 2311 | u8 d; |
| 2312 | |
| 2313 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 2314 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 2315 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 2316 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 2317 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 2318 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 2319 | } |
| 2320 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 2321 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 2322 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 2323 | } |
| 2324 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 2325 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 2326 | n->displayexp_toggle = |
| 2327 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 2328 | } |
| 2329 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 2330 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 2331 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 2332 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 2333 | n->brightness_toggle = |
| 2334 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 2335 | } |
| 2336 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 2337 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 2338 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 2339 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 2340 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 2341 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 2342 | } |
| 2343 | } |
| 2344 | |
Behan Webster | a4d44ba | 2014-02-12 21:58:46 +0100 | [diff] [blame] | 2345 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
| 2346 | do { \ |
| 2347 | if ((event_mask & (1 << __scancode)) && \ |
| 2348 | oldn->__member != newn->__member) \ |
| 2349 | tpacpi_hotkey_send_key(__scancode); \ |
| 2350 | } while (0) |
| 2351 | |
| 2352 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
| 2353 | do { \ |
| 2354 | if (event_mask & (1 << __scancode)) \ |
| 2355 | tpacpi_hotkey_send_key(__scancode); \ |
| 2356 | } while (0) |
| 2357 | |
| 2358 | static void issue_volchange(const unsigned int oldvol, |
| 2359 | const unsigned int newvol, |
| 2360 | const u32 event_mask) |
| 2361 | { |
| 2362 | unsigned int i = oldvol; |
| 2363 | |
| 2364 | while (i > newvol) { |
| 2365 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2366 | i--; |
| 2367 | } |
| 2368 | while (i < newvol) { |
| 2369 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2370 | i++; |
| 2371 | } |
| 2372 | } |
| 2373 | |
| 2374 | static void issue_brightnesschange(const unsigned int oldbrt, |
| 2375 | const unsigned int newbrt, |
| 2376 | const u32 event_mask) |
| 2377 | { |
| 2378 | unsigned int i = oldbrt; |
| 2379 | |
| 2380 | while (i > newbrt) { |
| 2381 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2382 | i--; |
| 2383 | } |
| 2384 | while (i < newbrt) { |
| 2385 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2386 | i++; |
| 2387 | } |
| 2388 | } |
| 2389 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2390 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
| 2391 | struct tp_nvram_state *newn, |
| 2392 | const u32 event_mask) |
| 2393 | { |
| 2394 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2395 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 2396 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 2397 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 2398 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 2399 | |
| 2400 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 2401 | |
| 2402 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 2403 | |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2404 | /* |
| 2405 | * Handle volume |
| 2406 | * |
| 2407 | * This code is supposed to duplicate the IBM firmware behaviour: |
| 2408 | * - Pressing MUTE issues mute hotkey message, even when already mute |
| 2409 | * - Pressing Volume up/down issues volume up/down hotkey messages, |
Lucas De Marchi | c844033 | 2011-03-17 17:18:22 -0300 | [diff] [blame] | 2410 | * even when already at maximum or minimum volume |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2411 | * - The act of unmuting issues volume up/down notification, |
| 2412 | * depending which key was used to unmute |
| 2413 | * |
| 2414 | * We are constrained to what the NVRAM can tell us, which is not much |
| 2415 | * and certainly not enough if more than one volume hotkey was pressed |
| 2416 | * since the last poll cycle. |
| 2417 | * |
| 2418 | * Just to make our life interesting, some newer Lenovo ThinkPads have |
| 2419 | * bugs in the BIOS and may fail to update volume_toggle properly. |
| 2420 | */ |
| 2421 | if (newn->mute) { |
| 2422 | /* muted */ |
| 2423 | if (!oldn->mute || |
| 2424 | oldn->volume_toggle != newn->volume_toggle || |
| 2425 | oldn->volume_level != newn->volume_level) { |
| 2426 | /* recently muted, or repeated mute keypress, or |
| 2427 | * multiple presses ending in mute */ |
Behan Webster | a4d44ba | 2014-02-12 21:58:46 +0100 | [diff] [blame] | 2428 | issue_volchange(oldn->volume_level, newn->volume_level, |
| 2429 | event_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2430 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2431 | } |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2432 | } else { |
| 2433 | /* unmute */ |
| 2434 | if (oldn->mute) { |
| 2435 | /* recently unmuted, issue 'unmute' keypress */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2436 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2437 | } |
| 2438 | if (oldn->volume_level != newn->volume_level) { |
Behan Webster | a4d44ba | 2014-02-12 21:58:46 +0100 | [diff] [blame] | 2439 | issue_volchange(oldn->volume_level, newn->volume_level, |
| 2440 | event_mask); |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2441 | } else if (oldn->volume_toggle != newn->volume_toggle) { |
| 2442 | /* repeated vol up/down keypress at end of scale ? */ |
| 2443 | if (newn->volume_level == 0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2444 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2445 | else if (newn->volume_level >= TP_NVRAM_LEVEL_VOLUME_MAX) |
| 2446 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | /* handle brightness */ |
Henrique de Moraes Holschuh | 2899902 | 2010-05-16 19:45:36 -0300 | [diff] [blame] | 2451 | if (oldn->brightness_level != newn->brightness_level) { |
| 2452 | issue_brightnesschange(oldn->brightness_level, |
Behan Webster | a4d44ba | 2014-02-12 21:58:46 +0100 | [diff] [blame] | 2453 | newn->brightness_level, event_mask); |
Henrique de Moraes Holschuh | 2899902 | 2010-05-16 19:45:36 -0300 | [diff] [blame] | 2454 | } else if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 2455 | /* repeated key presses that didn't change state */ |
| 2456 | if (newn->brightness_level == 0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2457 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | 2899902 | 2010-05-16 19:45:36 -0300 | [diff] [blame] | 2458 | else if (newn->brightness_level >= bright_maxlvl |
| 2459 | && !tp_features.bright_unkfw) |
| 2460 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2461 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2462 | |
| 2463 | #undef TPACPI_COMPARE_KEY |
| 2464 | #undef TPACPI_MAY_SEND_KEY |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2465 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2466 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2467 | /* |
| 2468 | * Polling driver |
| 2469 | * |
| 2470 | * We track all events in hotkey_source_mask all the time, since |
| 2471 | * most of them are edge-based. We only issue those requested by |
| 2472 | * hotkey_user_mask or hotkey_driver_mask, though. |
| 2473 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2474 | static int hotkey_kthread(void *data) |
| 2475 | { |
| 2476 | struct tp_nvram_state s[2]; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2477 | u32 poll_mask, event_mask; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2478 | unsigned int si, so; |
| 2479 | unsigned long t; |
Tejun Heo | 8a32c44 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 2480 | unsigned int change_detector; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2481 | unsigned int poll_freq; |
Tejun Heo | 8a32c44 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 2482 | bool was_frozen; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2483 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2484 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 2485 | goto exit; |
| 2486 | |
| 2487 | set_freezable(); |
| 2488 | |
| 2489 | so = 0; |
| 2490 | si = 1; |
| 2491 | t = 0; |
| 2492 | |
| 2493 | /* Initial state for compares */ |
| 2494 | mutex_lock(&hotkey_thread_data_mutex); |
| 2495 | change_detector = hotkey_config_change; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2496 | poll_mask = hotkey_source_mask; |
| 2497 | event_mask = hotkey_source_mask & |
| 2498 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2499 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2500 | mutex_unlock(&hotkey_thread_data_mutex); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2501 | hotkey_read_nvram(&s[so], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2502 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2503 | while (!kthread_should_stop()) { |
| 2504 | if (t == 0) { |
| 2505 | if (likely(poll_freq)) |
| 2506 | t = 1000/poll_freq; |
| 2507 | else |
| 2508 | t = 100; /* should never happen... */ |
| 2509 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2510 | t = msleep_interruptible(t); |
Tejun Heo | 8a32c44 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 2511 | if (unlikely(kthread_freezable_should_stop(&was_frozen))) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2512 | break; |
Tejun Heo | 8a32c44 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 2513 | |
| 2514 | if (t > 0 && !was_frozen) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2515 | continue; |
| 2516 | |
| 2517 | mutex_lock(&hotkey_thread_data_mutex); |
Tejun Heo | 8a32c44 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 2518 | if (was_frozen || hotkey_config_change != change_detector) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2519 | /* forget old state on thaw or config change */ |
| 2520 | si = so; |
| 2521 | t = 0; |
| 2522 | change_detector = hotkey_config_change; |
| 2523 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2524 | poll_mask = hotkey_source_mask; |
| 2525 | event_mask = hotkey_source_mask & |
| 2526 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2527 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2528 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2529 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2530 | if (likely(poll_mask)) { |
| 2531 | hotkey_read_nvram(&s[si], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2532 | if (likely(si != so)) { |
| 2533 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2534 | event_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2535 | } |
| 2536 | } |
| 2537 | |
| 2538 | so = si; |
| 2539 | si ^= 1; |
| 2540 | } |
| 2541 | |
| 2542 | exit: |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2543 | return 0; |
| 2544 | } |
| 2545 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2546 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2547 | static void hotkey_poll_stop_sync(void) |
| 2548 | { |
| 2549 | if (tpacpi_hotkey_task) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2550 | kthread_stop(tpacpi_hotkey_task); |
| 2551 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2552 | } |
| 2553 | } |
| 2554 | |
| 2555 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2556 | static void hotkey_poll_setup(const bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2557 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2558 | const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask; |
| 2559 | const u32 poll_user_mask = hotkey_user_mask & hotkey_source_mask; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2560 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2561 | if (hotkey_poll_freq > 0 && |
| 2562 | (poll_driver_mask || |
| 2563 | (poll_user_mask && tpacpi_inputdev->users > 0))) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2564 | if (!tpacpi_hotkey_task) { |
| 2565 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 2566 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2567 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 2568 | tpacpi_hotkey_task = NULL; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2569 | pr_err("could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2570 | "for hotkey polling\n"); |
| 2571 | } |
| 2572 | } |
| 2573 | } else { |
| 2574 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2575 | if (may_warn && (poll_driver_mask || poll_user_mask) && |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2576 | hotkey_poll_freq == 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2577 | pr_notice("hot keys 0x%08x and/or events 0x%08x " |
| 2578 | "require polling, which is currently " |
| 2579 | "disabled\n", |
| 2580 | poll_user_mask, poll_driver_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2581 | } |
| 2582 | } |
| 2583 | } |
| 2584 | |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2585 | static void hotkey_poll_setup_safe(const bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2586 | { |
| 2587 | mutex_lock(&hotkey_mutex); |
| 2588 | hotkey_poll_setup(may_warn); |
| 2589 | mutex_unlock(&hotkey_mutex); |
| 2590 | } |
| 2591 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2592 | /* call with hotkey_mutex held */ |
| 2593 | static void hotkey_poll_set_freq(unsigned int freq) |
| 2594 | { |
| 2595 | if (!freq) |
| 2596 | hotkey_poll_stop_sync(); |
| 2597 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2598 | hotkey_poll_freq = freq; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2599 | } |
| 2600 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2601 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2602 | |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2603 | static void hotkey_poll_setup(const bool __unused) |
| 2604 | { |
| 2605 | } |
| 2606 | |
| 2607 | static void hotkey_poll_setup_safe(const bool __unused) |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2608 | { |
| 2609 | } |
| 2610 | |
| 2611 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2612 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2613 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 2614 | { |
| 2615 | switch (tpacpi_lifecycle) { |
| 2616 | case TPACPI_LIFE_INIT: |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2617 | case TPACPI_LIFE_RUNNING: |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2618 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2619 | return 0; |
Henrique de Moraes Holschuh | b589ea4 | 2010-02-25 21:28:58 -0300 | [diff] [blame] | 2620 | case TPACPI_LIFE_EXITING: |
| 2621 | return -EBUSY; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 2625 | BUG(); |
| 2626 | return -EBUSY; |
| 2627 | } |
| 2628 | |
| 2629 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 2630 | { |
| 2631 | /* disable hotkey polling when possible */ |
Henrique de Moraes Holschuh | b589ea4 | 2010-02-25 21:28:58 -0300 | [diff] [blame] | 2632 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING && |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2633 | !(hotkey_source_mask & hotkey_driver_mask)) |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2634 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2635 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2636 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2637 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 2638 | static ssize_t hotkey_enable_show(struct device *dev, |
| 2639 | struct device_attribute *attr, |
| 2640 | char *buf) |
| 2641 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2642 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2643 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2644 | printk_deprecated_attribute("hotkey_enable", |
| 2645 | "Hotkey reporting is always enabled"); |
| 2646 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2647 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2648 | if (res) |
| 2649 | return res; |
| 2650 | |
| 2651 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 2652 | } |
| 2653 | |
| 2654 | static ssize_t hotkey_enable_store(struct device *dev, |
| 2655 | struct device_attribute *attr, |
| 2656 | const char *buf, size_t count) |
| 2657 | { |
| 2658 | unsigned long t; |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2659 | |
| 2660 | printk_deprecated_attribute("hotkey_enable", |
| 2661 | "Hotkeys can be disabled through hotkey_mask"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2662 | |
| 2663 | if (parse_strtoul(buf, 1, &t)) |
| 2664 | return -EINVAL; |
| 2665 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2666 | if (t == 0) |
| 2667 | return -EPERM; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2668 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2669 | return count; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2670 | } |
| 2671 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 2672 | static DEVICE_ATTR_RW(hotkey_enable); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2673 | |
| 2674 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 2675 | static ssize_t hotkey_mask_show(struct device *dev, |
| 2676 | struct device_attribute *attr, |
| 2677 | char *buf) |
| 2678 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2679 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_user_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | static ssize_t hotkey_mask_store(struct device *dev, |
| 2683 | struct device_attribute *attr, |
| 2684 | const char *buf, size_t count) |
| 2685 | { |
| 2686 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2687 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2688 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2689 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2690 | return -EINVAL; |
| 2691 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2692 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2693 | return -ERESTARTSYS; |
| 2694 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2695 | res = hotkey_user_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2696 | |
| 2697 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2698 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2699 | #endif |
| 2700 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2701 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2702 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2703 | tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t); |
| 2704 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2705 | return (res) ? res : count; |
| 2706 | } |
| 2707 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 2708 | static DEVICE_ATTR_RW(hotkey_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2709 | |
| 2710 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 2711 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 2712 | struct device_attribute *attr, |
| 2713 | char *buf) |
| 2714 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2715 | return sprintf(buf, "0\n"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2716 | } |
| 2717 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 2718 | static DEVICE_ATTR_RO(hotkey_bios_enabled); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2719 | |
| 2720 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 2721 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 2722 | struct device_attribute *attr, |
| 2723 | char *buf) |
| 2724 | { |
Henrique de Moraes Holschuh | 06777be | 2009-09-12 15:22:15 -0300 | [diff] [blame] | 2725 | printk_deprecated_attribute("hotkey_bios_mask", |
| 2726 | "This attribute is useless."); |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2727 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2728 | } |
| 2729 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 2730 | static DEVICE_ATTR_RO(hotkey_bios_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2731 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2732 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 2733 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 2734 | struct device_attribute *attr, |
| 2735 | char *buf) |
| 2736 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2737 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 2738 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2739 | } |
| 2740 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 2741 | static DEVICE_ATTR_RO(hotkey_all_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2742 | |
| 2743 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 2744 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 2745 | struct device_attribute *attr, |
| 2746 | char *buf) |
| 2747 | { |
| 2748 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2749 | (hotkey_all_mask | hotkey_source_mask) |
| 2750 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2751 | } |
| 2752 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 2753 | static DEVICE_ATTR_RO(hotkey_recommended_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2754 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2755 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2756 | |
| 2757 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 2758 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 2759 | struct device_attribute *attr, |
| 2760 | char *buf) |
| 2761 | { |
| 2762 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 2763 | } |
| 2764 | |
| 2765 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 2766 | struct device_attribute *attr, |
| 2767 | const char *buf, size_t count) |
| 2768 | { |
| 2769 | unsigned long t; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2770 | u32 r_ev; |
| 2771 | int rc; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2772 | |
| 2773 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 2774 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 2775 | return -EINVAL; |
| 2776 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2777 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2778 | return -ERESTARTSYS; |
| 2779 | |
| 2780 | HOTKEY_CONFIG_CRITICAL_START |
| 2781 | hotkey_source_mask = t; |
| 2782 | HOTKEY_CONFIG_CRITICAL_END |
| 2783 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2784 | rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) & |
| 2785 | ~hotkey_source_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2786 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2787 | |
| 2788 | /* check if events needed by the driver got disabled */ |
| 2789 | r_ev = hotkey_driver_mask & ~(hotkey_acpi_mask & hotkey_all_mask) |
| 2790 | & ~hotkey_source_mask & TPACPI_HKEY_NVRAM_KNOWN_MASK; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2791 | |
| 2792 | mutex_unlock(&hotkey_mutex); |
| 2793 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2794 | if (rc < 0) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2795 | pr_err("hotkey_source_mask: " |
| 2796 | "failed to update the firmware event mask!\n"); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2797 | |
| 2798 | if (r_ev) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2799 | pr_notice("hotkey_source_mask: " |
| 2800 | "some important events were disabled: 0x%04x\n", |
| 2801 | r_ev); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2802 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2803 | tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); |
| 2804 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2805 | return (rc < 0) ? rc : count; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2806 | } |
| 2807 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 2808 | static DEVICE_ATTR_RW(hotkey_source_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2809 | |
| 2810 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 2811 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 2812 | struct device_attribute *attr, |
| 2813 | char *buf) |
| 2814 | { |
| 2815 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 2816 | } |
| 2817 | |
| 2818 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 2819 | struct device_attribute *attr, |
| 2820 | const char *buf, size_t count) |
| 2821 | { |
| 2822 | unsigned long t; |
| 2823 | |
| 2824 | if (parse_strtoul(buf, 25, &t)) |
| 2825 | return -EINVAL; |
| 2826 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2827 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2828 | return -ERESTARTSYS; |
| 2829 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2830 | hotkey_poll_set_freq(t); |
| 2831 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2832 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2833 | mutex_unlock(&hotkey_mutex); |
| 2834 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2835 | tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t); |
| 2836 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2837 | return count; |
| 2838 | } |
| 2839 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 2840 | static DEVICE_ATTR_RW(hotkey_poll_freq); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2841 | |
| 2842 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2843 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2844 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2845 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 2846 | struct device_attribute *attr, |
| 2847 | char *buf) |
| 2848 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2849 | int res; |
| 2850 | res = hotkey_get_wlsw(); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2851 | if (res < 0) |
| 2852 | return res; |
| 2853 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2854 | /* Opportunistic update */ |
| 2855 | tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF)); |
| 2856 | |
| 2857 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2858 | (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2859 | } |
| 2860 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 2861 | static DEVICE_ATTR_RO(hotkey_radio_sw); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2862 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2863 | static void hotkey_radio_sw_notify_change(void) |
| 2864 | { |
| 2865 | if (tp_features.hotkey_wlsw) |
| 2866 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2867 | "hotkey_radio_sw"); |
| 2868 | } |
| 2869 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2870 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 2871 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 2872 | struct device_attribute *attr, |
| 2873 | char *buf) |
| 2874 | { |
| 2875 | int res, s; |
| 2876 | res = hotkey_get_tablet_mode(&s); |
| 2877 | if (res < 0) |
| 2878 | return res; |
| 2879 | |
| 2880 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 2881 | } |
| 2882 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 2883 | static DEVICE_ATTR_RO(hotkey_tablet_mode); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2884 | |
| 2885 | static void hotkey_tablet_mode_notify_change(void) |
| 2886 | { |
| 2887 | if (tp_features.hotkey_tablet) |
| 2888 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2889 | "hotkey_tablet_mode"); |
| 2890 | } |
| 2891 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2892 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2893 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 2894 | struct device_attribute *attr, |
| 2895 | char *buf) |
| 2896 | { |
| 2897 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 2898 | } |
| 2899 | |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 2900 | static DEVICE_ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2901 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2902 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2903 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2904 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2905 | "wakeup_reason"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2909 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 2910 | struct device_attribute *attr, |
| 2911 | char *buf) |
| 2912 | { |
| 2913 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 2914 | } |
| 2915 | |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 2916 | static DEVICE_ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 2917 | hotkey_wakeup_hotunplug_complete_show, NULL); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2918 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2919 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2920 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2921 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2922 | "wakeup_hotunplug_complete"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2923 | } |
| 2924 | |
Bastien Nocera | b790cee | 2015-03-02 14:45:27 +0100 | [diff] [blame] | 2925 | /* sysfs adaptive kbd mode --------------------------------------------- */ |
| 2926 | |
| 2927 | static int adaptive_keyboard_get_mode(void); |
| 2928 | static int adaptive_keyboard_set_mode(int new_mode); |
| 2929 | |
| 2930 | enum ADAPTIVE_KEY_MODE { |
| 2931 | HOME_MODE, |
| 2932 | WEB_BROWSER_MODE, |
| 2933 | WEB_CONFERENCE_MODE, |
| 2934 | FUNCTION_MODE, |
| 2935 | LAYFLAT_MODE |
| 2936 | }; |
| 2937 | |
| 2938 | static ssize_t adaptive_kbd_mode_show(struct device *dev, |
| 2939 | struct device_attribute *attr, |
| 2940 | char *buf) |
| 2941 | { |
Dan Carpenter | abf9dc0 | 2015-03-11 12:34:50 +0300 | [diff] [blame] | 2942 | int current_mode; |
Bastien Nocera | b790cee | 2015-03-02 14:45:27 +0100 | [diff] [blame] | 2943 | |
| 2944 | current_mode = adaptive_keyboard_get_mode(); |
| 2945 | if (current_mode < 0) |
| 2946 | return current_mode; |
| 2947 | |
| 2948 | return snprintf(buf, PAGE_SIZE, "%d\n", current_mode); |
| 2949 | } |
| 2950 | |
| 2951 | static ssize_t adaptive_kbd_mode_store(struct device *dev, |
| 2952 | struct device_attribute *attr, |
| 2953 | const char *buf, size_t count) |
| 2954 | { |
| 2955 | unsigned long t; |
| 2956 | int res; |
| 2957 | |
| 2958 | if (parse_strtoul(buf, LAYFLAT_MODE, &t)) |
| 2959 | return -EINVAL; |
| 2960 | |
| 2961 | res = adaptive_keyboard_set_mode(t); |
| 2962 | return (res < 0) ? res : count; |
| 2963 | } |
| 2964 | |
| 2965 | static DEVICE_ATTR_RW(adaptive_kbd_mode); |
| 2966 | |
| 2967 | static struct attribute *adaptive_kbd_attributes[] = { |
| 2968 | &dev_attr_adaptive_kbd_mode.attr, |
| 2969 | NULL |
| 2970 | }; |
| 2971 | |
| 2972 | static const struct attribute_group adaptive_kbd_attr_group = { |
| 2973 | .attrs = adaptive_kbd_attributes, |
| 2974 | }; |
| 2975 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2976 | /* --------------------------------------------------------------------- */ |
| 2977 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2978 | static struct attribute *hotkey_attributes[] __initdata = { |
| 2979 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2980 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2981 | &dev_attr_hotkey_bios_mask.attr, |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 2982 | &dev_attr_wakeup_reason.attr, |
| 2983 | &dev_attr_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2984 | &dev_attr_hotkey_mask.attr, |
| 2985 | &dev_attr_hotkey_all_mask.attr, |
| 2986 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2987 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2988 | &dev_attr_hotkey_source_mask.attr, |
| 2989 | &dev_attr_hotkey_poll_freq.attr, |
| 2990 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2991 | }; |
| 2992 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2993 | /* |
| 2994 | * Sync both the hw and sw blocking state of all switches |
| 2995 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2996 | static void tpacpi_send_radiosw_update(void) |
| 2997 | { |
| 2998 | int wlsw; |
| 2999 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3000 | /* |
| 3001 | * We must sync all rfkill controllers *before* issuing any |
| 3002 | * rfkill input events, or we will race the rfkill core input |
| 3003 | * handler. |
| 3004 | * |
Lucas De Marchi | c844033 | 2011-03-17 17:18:22 -0300 | [diff] [blame] | 3005 | * tpacpi_inputdev_send_mutex works as a synchronization point |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3006 | * for the above. |
| 3007 | * |
| 3008 | * We optimize to avoid numerous calls to hotkey_get_wlsw. |
| 3009 | */ |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3010 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3011 | wlsw = hotkey_get_wlsw(); |
| 3012 | |
| 3013 | /* Sync hw blocking state first if it is hw-blocked */ |
| 3014 | if (wlsw == TPACPI_RFK_RADIO_OFF) |
| 3015 | tpacpi_rfk_update_hwblock_state(true); |
| 3016 | |
| 3017 | /* Sync sw blocking state */ |
| 3018 | tpacpi_rfk_update_swstate_all(); |
| 3019 | |
| 3020 | /* Sync hw blocking state last if it is hw-unblocked */ |
| 3021 | if (wlsw == TPACPI_RFK_RADIO_ON) |
| 3022 | tpacpi_rfk_update_hwblock_state(false); |
| 3023 | |
| 3024 | /* Issue rfkill input event for WLSW switch */ |
| 3025 | if (!(wlsw < 0)) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3026 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 3027 | |
| 3028 | input_report_switch(tpacpi_inputdev, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3029 | SW_RFKILL_ALL, (wlsw > 0)); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3030 | input_sync(tpacpi_inputdev); |
| 3031 | |
| 3032 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 3033 | } |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3034 | |
| 3035 | /* |
| 3036 | * this can be unconditional, as we will poll state again |
| 3037 | * if userspace uses the notify to read data |
| 3038 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3039 | hotkey_radio_sw_notify_change(); |
| 3040 | } |
| 3041 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3042 | static void hotkey_exit(void) |
| 3043 | { |
| 3044 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3045 | mutex_lock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3046 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3047 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3048 | #endif |
| 3049 | |
| 3050 | if (hotkey_dev_attributes) |
| 3051 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3052 | |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3053 | dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3054 | "restoring original HKEY status and mask\n"); |
| 3055 | /* yes, there is a bitwise or below, we want the |
| 3056 | * functions to be called even if one of them fail */ |
| 3057 | if (((tp_features.hotkey_mask && |
| 3058 | hotkey_mask_set(hotkey_orig_mask)) | |
| 3059 | hotkey_status_set(false)) != 0) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3060 | pr_err("failed to restore hot key mask " |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3061 | "to BIOS defaults\n"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3062 | } |
| 3063 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3064 | static void __init hotkey_unmap(const unsigned int scancode) |
| 3065 | { |
| 3066 | if (hotkey_keycode_map[scancode] != KEY_RESERVED) { |
| 3067 | clear_bit(hotkey_keycode_map[scancode], |
| 3068 | tpacpi_inputdev->keybit); |
| 3069 | hotkey_keycode_map[scancode] = KEY_RESERVED; |
| 3070 | } |
| 3071 | } |
| 3072 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3073 | /* |
| 3074 | * HKEY quirks: |
| 3075 | * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12 |
| 3076 | */ |
| 3077 | |
| 3078 | #define TPACPI_HK_Q_INIMASK 0x0001 |
| 3079 | |
| 3080 | static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = { |
| 3081 | TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3082 | TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3083 | TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK), /* 770, 770E, 770ED */ |
| 3084 | TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK), /* A20m */ |
| 3085 | TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK), /* A20p */ |
| 3086 | TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK), /* A21e, A22e */ |
| 3087 | TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK), /* A21e */ |
| 3088 | TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK), /* A21m, A22m */ |
| 3089 | TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK), /* A21p, A22p */ |
| 3090 | TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK), /* A22e */ |
| 3091 | TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK), /* A22m */ |
| 3092 | TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK), /* A30/p (0) */ |
| 3093 | TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK), /* R30 */ |
| 3094 | TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK), /* R31 */ |
| 3095 | TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK), /* T20 */ |
| 3096 | TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK), /* T21 */ |
| 3097 | TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK), /* T22 */ |
| 3098 | TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK), /* X20, X21 */ |
| 3099 | TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */ |
| 3100 | }; |
| 3101 | |
Henrique de Moraes Holschuh | fc6e756 | 2010-09-17 21:53:41 -0300 | [diff] [blame] | 3102 | typedef u16 tpacpi_keymap_entry_t; |
| 3103 | typedef tpacpi_keymap_entry_t tpacpi_keymap_t[TPACPI_HOTKEY_MAP_LEN]; |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3104 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3105 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3106 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3107 | /* Requirements for changing the default keymaps: |
| 3108 | * |
| 3109 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 3110 | * good reasons. Do not change them unless you have deep |
| 3111 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 3112 | * the various ThinkPad models. The driver behaves |
| 3113 | * differently for KEY_RESERVED: such keys have their |
| 3114 | * hot key mask *unset* in mask_recommended, and also |
| 3115 | * in the initial hot key mask programmed into the |
| 3116 | * firmware at driver load time, which means the firm- |
| 3117 | * ware may react very differently if you change them to |
| 3118 | * something else; |
| 3119 | * |
| 3120 | * 2. You must be subscribed to the linux-thinkpad and |
| 3121 | * ibm-acpi-devel mailing lists, and you should read the |
| 3122 | * list archives since 2007 if you want to change the |
| 3123 | * keymaps. This requirement exists so that you will |
| 3124 | * know the past history of problems with the thinkpad- |
| 3125 | * acpi driver keymaps, and also that you will be |
| 3126 | * listening to any bug reports; |
| 3127 | * |
| 3128 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 3129 | * for merging, *ever*. Send them to the linux-acpi |
| 3130 | * mailinglist for comments. Merging is to be done only |
| 3131 | * through acpi-test and the ACPI maintainer. |
| 3132 | * |
| 3133 | * If the above is too much to ask, don't change the keymap. |
| 3134 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 3135 | */ |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3136 | |
| 3137 | enum keymap_index { |
| 3138 | TPACPI_KEYMAP_IBM_GENERIC = 0, |
| 3139 | TPACPI_KEYMAP_LENOVO_GENERIC, |
| 3140 | }; |
| 3141 | |
| 3142 | static const tpacpi_keymap_t tpacpi_keymaps[] __initconst = { |
| 3143 | /* Generic keymap for IBM ThinkPads */ |
| 3144 | [TPACPI_KEYMAP_IBM_GENERIC] = { |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3145 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3146 | KEY_FN_F1, KEY_BATTERY, KEY_COFFEE, KEY_SLEEP, |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3147 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 3148 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3149 | |
| 3150 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3151 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3152 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3153 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3154 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3155 | /* brightness: firmware always reacts to them */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3156 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3157 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3158 | |
| 3159 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3160 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3161 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3162 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3163 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3164 | |
| 3165 | /* Volume: firmware always react to it and reprograms |
| 3166 | * the built-in *extra* mixer. Never map it to control |
| 3167 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3168 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3169 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3170 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3171 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3172 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3173 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3174 | /* (assignments unknown, please report if found) */ |
| 3175 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3176 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
Bastien Nocera | 6a68d85 | 2015-03-02 14:45:31 +0100 | [diff] [blame] | 3177 | |
| 3178 | /* No assignments, only used for Adaptive keyboards. */ |
| 3179 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3180 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3181 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3182 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3183 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3184 | }, |
| 3185 | |
| 3186 | /* Generic keymap for Lenovo ThinkPads */ |
| 3187 | [TPACPI_KEYMAP_LENOVO_GENERIC] = { |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3188 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 3189 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
Jens Taprogge | 2b75426 | 2010-08-09 23:48:22 -0300 | [diff] [blame] | 3190 | KEY_WLAN, KEY_CAMERA, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3191 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3192 | |
| 3193 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3194 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3195 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3196 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3197 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3198 | /* These should be enabled --only-- when ACPI video |
| 3199 | * is disabled (i.e. in "vendor" mode), and are handled |
| 3200 | * in a special way by the init code */ |
| 3201 | KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ |
| 3202 | KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3203 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3204 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3205 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3206 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3207 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3208 | |
| 3209 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 3210 | * react to it and reprograms the built-in *extra* mixer. |
| 3211 | * Never map it to control another mixer by default. |
| 3212 | * |
| 3213 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 3214 | * these over the regular keyboard, so these are no-ops, |
| 3215 | * but there are still weird bugs re. MUTE, so do not |
| 3216 | * change unless you get test reports from all Lenovo |
| 3217 | * models. May cause the BIOS to interfere with the |
| 3218 | * HDA mixer. |
| 3219 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3220 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3221 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3222 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3223 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3224 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3225 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3226 | /* (assignments unknown, please report if found) */ |
Andy Lutomirski | 3300955 | 2011-05-24 15:16:43 -0400 | [diff] [blame] | 3227 | KEY_UNKNOWN, KEY_UNKNOWN, |
| 3228 | |
| 3229 | /* |
| 3230 | * The mic mute button only sends 0x1a. It does not |
| 3231 | * automatically mute the mic or change the mute light. |
| 3232 | */ |
| 3233 | KEY_MICMUTE, /* 0x1a: Mic mute (since ?400 or so) */ |
| 3234 | |
| 3235 | /* (assignments unknown, please report if found) */ |
Andy Lutomirski | 3300955 | 2011-05-24 15:16:43 -0400 | [diff] [blame] | 3236 | KEY_UNKNOWN, |
Hans de Goede | 8b9dd4f | 2014-04-09 11:46:46 +0200 | [diff] [blame] | 3237 | |
| 3238 | /* Extra keys in use since the X240 / T440 / T540 */ |
Hans de Goede | 4beb81d | 2014-06-23 13:38:23 +0200 | [diff] [blame] | 3239 | KEY_CONFIG, KEY_SEARCH, KEY_SCALE, KEY_FILE, |
Bastien Nocera | 6a68d85 | 2015-03-02 14:45:31 +0100 | [diff] [blame] | 3240 | |
| 3241 | /* |
| 3242 | * These are the adaptive keyboard keycodes for Carbon X1 2014. |
| 3243 | * The first item in this list is the Mute button which is |
| 3244 | * emitted with 0x103 through |
| 3245 | * adaptive_keyboard_hotkey_notify_hotkey() when the sound |
| 3246 | * symbol is held. |
| 3247 | * We'll need to offset those by 0x20. |
| 3248 | */ |
| 3249 | KEY_RESERVED, /* Mute held, 0x103 */ |
| 3250 | KEY_BRIGHTNESS_MIN, /* Backlight off */ |
| 3251 | KEY_RESERVED, /* Clipping tool */ |
| 3252 | KEY_RESERVED, /* Cloud */ |
| 3253 | KEY_RESERVED, |
| 3254 | KEY_VOICECOMMAND, /* Voice */ |
| 3255 | KEY_RESERVED, |
| 3256 | KEY_RESERVED, /* Gestures */ |
| 3257 | KEY_RESERVED, |
| 3258 | KEY_RESERVED, |
| 3259 | KEY_RESERVED, |
| 3260 | KEY_CONFIG, /* Settings */ |
| 3261 | KEY_RESERVED, /* New tab */ |
| 3262 | KEY_REFRESH, /* Reload */ |
| 3263 | KEY_BACK, /* Back */ |
| 3264 | KEY_RESERVED, /* Microphone down */ |
| 3265 | KEY_RESERVED, /* Microphone up */ |
| 3266 | KEY_RESERVED, /* Microphone cancellation */ |
| 3267 | KEY_RESERVED, /* Camera mode */ |
| 3268 | KEY_RESERVED, /* Rotate display, 0x116 */ |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3269 | }, |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3270 | }; |
| 3271 | |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3272 | static const struct tpacpi_quirk tpacpi_keymap_qtable[] __initconst = { |
| 3273 | /* Generic maps (fallback) */ |
| 3274 | { |
| 3275 | .vendor = PCI_VENDOR_ID_IBM, |
| 3276 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 3277 | .quirks = TPACPI_KEYMAP_IBM_GENERIC, |
| 3278 | }, |
| 3279 | { |
| 3280 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 3281 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 3282 | .quirks = TPACPI_KEYMAP_LENOVO_GENERIC, |
| 3283 | }, |
| 3284 | }; |
| 3285 | |
| 3286 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(tpacpi_keymap_t) |
Henrique de Moraes Holschuh | fc6e756 | 2010-09-17 21:53:41 -0300 | [diff] [blame] | 3287 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(tpacpi_keymap_entry_t) |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3288 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3289 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3290 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 3291 | int hkeyv; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3292 | bool radiosw_state = false; |
| 3293 | bool tabletsw_state = false; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3294 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3295 | unsigned long quirks; |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3296 | unsigned long keymap_id; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3297 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3298 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3299 | "initializing hotkey subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3300 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3301 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3302 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 3303 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3304 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3305 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3306 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3307 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3308 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3309 | mutex_init(&hotkey_thread_data_mutex); |
| 3310 | #endif |
| 3311 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3312 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3313 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3314 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3315 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3316 | "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3317 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3318 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3319 | if (!tp_features.hotkey) |
| 3320 | return 1; |
| 3321 | |
Bastien Nocera | f23a5bc | 2015-03-02 14:45:16 +0100 | [diff] [blame] | 3322 | /* |
| 3323 | * Check if we have an adaptive keyboard, like on the |
| 3324 | * Lenovo Carbon X1 2014 (2nd Gen). |
| 3325 | */ |
| 3326 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
Bastien Nocera | b790cee | 2015-03-02 14:45:27 +0100 | [diff] [blame] | 3327 | if ((hkeyv >> 8) == 2) { |
Bastien Nocera | f23a5bc | 2015-03-02 14:45:16 +0100 | [diff] [blame] | 3328 | tp_features.has_adaptive_kbd = true; |
Bastien Nocera | b790cee | 2015-03-02 14:45:27 +0100 | [diff] [blame] | 3329 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 3330 | &adaptive_kbd_attr_group); |
| 3331 | if (res) |
| 3332 | goto err_exit; |
| 3333 | } |
Bastien Nocera | f23a5bc | 2015-03-02 14:45:16 +0100 | [diff] [blame] | 3334 | } |
| 3335 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3336 | quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, |
| 3337 | ARRAY_SIZE(tpacpi_hotkey_qtable)); |
| 3338 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3339 | tpacpi_disable_brightness_delay(); |
| 3340 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3341 | /* MUST have enough space for all attributes to be added to |
| 3342 | * hotkey_dev_attributes */ |
| 3343 | hotkey_dev_attributes = create_attr_set( |
| 3344 | ARRAY_SIZE(hotkey_attributes) + 2, |
| 3345 | NULL); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3346 | if (!hotkey_dev_attributes) |
| 3347 | return -ENOMEM; |
| 3348 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 3349 | hotkey_attributes, |
| 3350 | ARRAY_SIZE(hotkey_attributes)); |
| 3351 | if (res) |
| 3352 | goto err_exit; |
| 3353 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3354 | /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3355 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 3356 | for HKEY interface version 0x100 */ |
| 3357 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 3358 | if ((hkeyv >> 8) != 1) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3359 | pr_err("unknown version of the HKEY interface: 0x%x\n", |
| 3360 | hkeyv); |
| 3361 | pr_err("please report this to %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3362 | } else { |
| 3363 | /* |
| 3364 | * MHKV 0x100 in A31, R40, R40e, |
| 3365 | * T4x, X31, and later |
| 3366 | */ |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3367 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3368 | "firmware HKEY interface version: 0x%x\n", |
| 3369 | hkeyv); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3370 | |
| 3371 | /* Paranoia check AND init hotkey_all_mask */ |
| 3372 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
| 3373 | "MHKA", "qd")) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3374 | pr_err("missing MHKA handler, " |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3375 | "please report this to %s\n", |
| 3376 | TPACPI_MAIL); |
| 3377 | /* Fallback: pre-init for FN+F3,F4,F12 */ |
| 3378 | hotkey_all_mask = 0x080cU; |
| 3379 | } else { |
| 3380 | tp_features.hotkey_mask = 1; |
| 3381 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3382 | } |
| 3383 | } |
| 3384 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3385 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3386 | "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3387 | str_supported(tp_features.hotkey_mask)); |
| 3388 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3389 | /* Init hotkey_all_mask if not initialized yet */ |
| 3390 | if (!tp_features.hotkey_mask && !hotkey_all_mask && |
| 3391 | (quirks & TPACPI_HK_Q_INIMASK)) |
| 3392 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3393 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3394 | /* Init hotkey_acpi_mask and hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3395 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3396 | /* hotkey_source_mask *must* be zero for |
| 3397 | * the first hotkey_mask_get to return hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3398 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3399 | if (res) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3400 | goto err_exit; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3401 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3402 | hotkey_orig_mask = hotkey_acpi_mask; |
| 3403 | } else { |
| 3404 | hotkey_orig_mask = hotkey_all_mask; |
| 3405 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3406 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3407 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3408 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3409 | if (dbg_wlswemul) { |
| 3410 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3411 | radiosw_state = !!tpacpi_wlsw_emulstate; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3412 | pr_info("radio switch emulation enabled\n"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3413 | } else |
| 3414 | #endif |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3415 | /* Not all thinkpads have a hardware radio switch */ |
| 3416 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 3417 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3418 | radiosw_state = !!status; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3419 | pr_info("radio switch found; radios are %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3420 | enabled(status, 0)); |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3421 | } |
| 3422 | if (tp_features.hotkey_wlsw) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3423 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3424 | &dev_attr_hotkey_radio_sw.attr); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3425 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3426 | /* For X41t, X60t, X61t Tablets... */ |
| 3427 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 3428 | tp_features.hotkey_tablet = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3429 | tabletsw_state = !!(status & TP_HOTKEY_TABLET_MASK); |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3430 | pr_info("possible tablet mode switch found; " |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3431 | "ThinkPad in %s mode\n", |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3432 | (tabletsw_state) ? "tablet" : "laptop"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3433 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3434 | &dev_attr_hotkey_tablet_mode.attr); |
| 3435 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3436 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3437 | if (!res) |
| 3438 | res = register_attr_set_with_sysfs( |
| 3439 | hotkey_dev_attributes, |
| 3440 | &tpacpi_pdev->dev.kobj); |
| 3441 | if (res) |
| 3442 | goto err_exit; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3443 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3444 | /* Set up key map */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3445 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 3446 | GFP_KERNEL); |
| 3447 | if (!hotkey_keycode_map) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3448 | pr_err("failed to allocate memory for key map\n"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3449 | res = -ENOMEM; |
| 3450 | goto err_exit; |
| 3451 | } |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3452 | |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3453 | keymap_id = tpacpi_check_quirks(tpacpi_keymap_qtable, |
| 3454 | ARRAY_SIZE(tpacpi_keymap_qtable)); |
| 3455 | BUG_ON(keymap_id >= ARRAY_SIZE(tpacpi_keymaps)); |
| 3456 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3457 | "using keymap number %lu\n", keymap_id); |
| 3458 | |
| 3459 | memcpy(hotkey_keycode_map, &tpacpi_keymaps[keymap_id], |
| 3460 | TPACPI_HOTKEY_MAP_SIZE); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3461 | |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3462 | input_set_capability(tpacpi_inputdev, EV_MSC, MSC_SCAN); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3463 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 3464 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 3465 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 3466 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
| 3467 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3468 | input_set_capability(tpacpi_inputdev, EV_KEY, |
| 3469 | hotkey_keycode_map[i]); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3470 | } else { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3471 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 3472 | hotkey_reserved_mask |= 1 << i; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3473 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3474 | } |
| 3475 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3476 | if (tp_features.hotkey_wlsw) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3477 | input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL); |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3478 | input_report_switch(tpacpi_inputdev, |
| 3479 | SW_RFKILL_ALL, radiosw_state); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3480 | } |
| 3481 | if (tp_features.hotkey_tablet) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3482 | input_set_capability(tpacpi_inputdev, EV_SW, SW_TABLET_MODE); |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3483 | input_report_switch(tpacpi_inputdev, |
| 3484 | SW_TABLET_MODE, tabletsw_state); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3485 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3486 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3487 | /* Do not issue duplicate brightness change events to |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 3488 | * userspace. tpacpi_detect_brightness_capabilities() must have |
| 3489 | * been called before this point */ |
Alex Hung | ff41319 | 2012-04-24 16:40:52 +0800 | [diff] [blame] | 3490 | if (acpi_video_backlight_support()) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3491 | pr_info("This ThinkPad has standard ACPI backlight " |
| 3492 | "brightness control, supported by the ACPI " |
| 3493 | "video driver\n"); |
| 3494 | pr_notice("Disabling thinkpad-acpi brightness events " |
| 3495 | "by default...\n"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3496 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3497 | /* Disable brightness up/down on Lenovo thinkpads when |
| 3498 | * ACPI is handling them, otherwise it is plain impossible |
| 3499 | * for userspace to do something even remotely sane */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3500 | hotkey_reserved_mask |= |
| 3501 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 3502 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3503 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 3504 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3505 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3506 | |
Henrique de Moraes Holschuh | 230d8cf25 | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3507 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3508 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 3509 | & ~hotkey_all_mask |
| 3510 | & ~hotkey_reserved_mask; |
Henrique de Moraes Holschuh | 230d8cf25 | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3511 | |
| 3512 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3513 | "hotkey source mask 0x%08x, polling freq %u\n", |
| 3514 | hotkey_source_mask, hotkey_poll_freq); |
| 3515 | #endif |
| 3516 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3517 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3518 | "enabling firmware HKEY event interface...\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3519 | res = hotkey_status_set(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3520 | if (res) { |
| 3521 | hotkey_exit(); |
| 3522 | return res; |
| 3523 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3524 | res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask) |
| 3525 | | hotkey_driver_mask) |
| 3526 | & ~hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3527 | if (res < 0 && res != -ENXIO) { |
| 3528 | hotkey_exit(); |
| 3529 | return res; |
| 3530 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3531 | hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask) |
| 3532 | & ~hotkey_reserved_mask; |
| 3533 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3534 | "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n", |
| 3535 | hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3536 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3537 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 3538 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 3539 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3540 | hotkey_poll_setup_safe(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3541 | |
| 3542 | return 0; |
| 3543 | |
| 3544 | err_exit: |
| 3545 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
Bastien Nocera | b790cee | 2015-03-02 14:45:27 +0100 | [diff] [blame] | 3546 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 3547 | &adaptive_kbd_attr_group); |
| 3548 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3549 | hotkey_dev_attributes = NULL; |
| 3550 | |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 3551 | return (res < 0) ? res : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3552 | } |
| 3553 | |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3554 | /* Thinkpad X1 Carbon support 5 modes including Home mode, Web browser |
| 3555 | * mode, Web conference mode, Function mode and Lay-flat mode. |
| 3556 | * We support Home mode and Function mode currently. |
| 3557 | * |
| 3558 | * Will consider support rest of modes in future. |
| 3559 | * |
| 3560 | */ |
Lad, Prabhakar | b201a47 | 2015-02-05 14:45:38 +0000 | [diff] [blame] | 3561 | static const int adaptive_keyboard_modes[] = { |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3562 | HOME_MODE, |
| 3563 | /* WEB_BROWSER_MODE = 2, |
| 3564 | WEB_CONFERENCE_MODE = 3, */ |
| 3565 | FUNCTION_MODE |
| 3566 | }; |
| 3567 | |
| 3568 | #define DFR_CHANGE_ROW 0x101 |
| 3569 | #define DFR_SHOW_QUICKVIEW_ROW 0x102 |
Bastien Nocera | 6a68d85 | 2015-03-02 14:45:31 +0100 | [diff] [blame] | 3570 | #define FIRST_ADAPTIVE_KEY 0x103 |
| 3571 | #define ADAPTIVE_KEY_OFFSET 0x020 |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3572 | |
| 3573 | /* press Fn key a while second, it will switch to Function Mode. Then |
| 3574 | * release Fn key, previous mode be restored. |
| 3575 | */ |
| 3576 | static bool adaptive_keyboard_mode_is_saved; |
| 3577 | static int adaptive_keyboard_prev_mode; |
| 3578 | |
Bastien Nocera | f74587f | 2015-03-02 14:45:22 +0100 | [diff] [blame] | 3579 | static int adaptive_keyboard_get_mode(void) |
| 3580 | { |
| 3581 | int mode = 0; |
| 3582 | |
| 3583 | if (!acpi_evalf(hkey_handle, &mode, "GTRW", "dd", 0)) { |
| 3584 | pr_err("Cannot read adaptive keyboard mode\n"); |
| 3585 | return -EIO; |
| 3586 | } |
| 3587 | |
| 3588 | return mode; |
| 3589 | } |
| 3590 | |
| 3591 | static int adaptive_keyboard_set_mode(int new_mode) |
| 3592 | { |
| 3593 | if (new_mode < 0 || |
| 3594 | new_mode > LAYFLAT_MODE) |
| 3595 | return -EINVAL; |
| 3596 | |
| 3597 | if (!acpi_evalf(hkey_handle, NULL, "STRW", "vd", new_mode)) { |
| 3598 | pr_err("Cannot set adaptive keyboard mode\n"); |
| 3599 | return -EIO; |
| 3600 | } |
| 3601 | |
| 3602 | return 0; |
| 3603 | } |
| 3604 | |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3605 | static int adaptive_keyboard_get_next_mode(int mode) |
| 3606 | { |
| 3607 | size_t i; |
| 3608 | size_t max_mode = ARRAY_SIZE(adaptive_keyboard_modes) - 1; |
| 3609 | |
| 3610 | for (i = 0; i <= max_mode; i++) { |
| 3611 | if (adaptive_keyboard_modes[i] == mode) |
| 3612 | break; |
| 3613 | } |
| 3614 | |
| 3615 | if (i >= max_mode) |
| 3616 | i = 0; |
| 3617 | else |
| 3618 | i++; |
| 3619 | |
| 3620 | return adaptive_keyboard_modes[i]; |
| 3621 | } |
| 3622 | |
| 3623 | static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode) |
| 3624 | { |
Dan Carpenter | abf9dc0 | 2015-03-11 12:34:50 +0300 | [diff] [blame] | 3625 | int current_mode = 0; |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3626 | int new_mode = 0; |
Bastien Nocera | 6a68d85 | 2015-03-02 14:45:31 +0100 | [diff] [blame] | 3627 | int keycode; |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3628 | |
| 3629 | switch (scancode) { |
| 3630 | case DFR_CHANGE_ROW: |
| 3631 | if (adaptive_keyboard_mode_is_saved) { |
| 3632 | new_mode = adaptive_keyboard_prev_mode; |
| 3633 | adaptive_keyboard_mode_is_saved = false; |
| 3634 | } else { |
Bastien Nocera | f74587f | 2015-03-02 14:45:22 +0100 | [diff] [blame] | 3635 | current_mode = adaptive_keyboard_get_mode(); |
| 3636 | if (current_mode < 0) |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3637 | return false; |
Bastien Nocera | f74587f | 2015-03-02 14:45:22 +0100 | [diff] [blame] | 3638 | new_mode = adaptive_keyboard_get_next_mode( |
| 3639 | current_mode); |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3640 | } |
| 3641 | |
Bastien Nocera | f74587f | 2015-03-02 14:45:22 +0100 | [diff] [blame] | 3642 | if (adaptive_keyboard_set_mode(new_mode) < 0) |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3643 | return false; |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3644 | |
| 3645 | return true; |
| 3646 | |
| 3647 | case DFR_SHOW_QUICKVIEW_ROW: |
Bastien Nocera | f74587f | 2015-03-02 14:45:22 +0100 | [diff] [blame] | 3648 | current_mode = adaptive_keyboard_get_mode(); |
| 3649 | if (current_mode < 0) |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3650 | return false; |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3651 | |
Bastien Nocera | f74587f | 2015-03-02 14:45:22 +0100 | [diff] [blame] | 3652 | adaptive_keyboard_prev_mode = current_mode; |
| 3653 | adaptive_keyboard_mode_is_saved = true; |
| 3654 | |
| 3655 | if (adaptive_keyboard_set_mode (FUNCTION_MODE) < 0) |
| 3656 | return false; |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3657 | return true; |
| 3658 | |
| 3659 | default: |
Dan Carpenter | 741d98c | 2015-03-11 12:36:07 +0300 | [diff] [blame] | 3660 | if (scancode < FIRST_ADAPTIVE_KEY || |
| 3661 | scancode >= FIRST_ADAPTIVE_KEY + TPACPI_HOTKEY_MAP_LEN - |
| 3662 | ADAPTIVE_KEY_OFFSET) { |
Bastien Nocera | 6a68d85 | 2015-03-02 14:45:31 +0100 | [diff] [blame] | 3663 | pr_info("Unhandled adaptive keyboard key: 0x%x\n", |
| 3664 | scancode); |
| 3665 | return false; |
| 3666 | } |
| 3667 | keycode = hotkey_keycode_map[scancode - FIRST_ADAPTIVE_KEY + ADAPTIVE_KEY_OFFSET]; |
| 3668 | if (keycode != KEY_RESERVED) { |
| 3669 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 3670 | |
| 3671 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 3672 | input_sync(tpacpi_inputdev); |
| 3673 | |
| 3674 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 3675 | input_sync(tpacpi_inputdev); |
| 3676 | |
| 3677 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 3678 | } |
| 3679 | return true; |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3680 | } |
| 3681 | } |
| 3682 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3683 | static bool hotkey_notify_hotkey(const u32 hkey, |
| 3684 | bool *send_acpi_ev, |
| 3685 | bool *ignore_acpi_ev) |
| 3686 | { |
| 3687 | /* 0x1000-0x1FFF: key presses */ |
| 3688 | unsigned int scancode = hkey & 0xfff; |
| 3689 | *send_acpi_ev = true; |
| 3690 | *ignore_acpi_ev = false; |
| 3691 | |
Henrique de Moraes Holschuh | 34a656d2 | 2010-08-09 23:48:20 -0300 | [diff] [blame] | 3692 | /* HKEY event 0x1001 is scancode 0x00 */ |
| 3693 | if (scancode > 0 && scancode <= TPACPI_HOTKEY_MAP_LEN) { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3694 | scancode--; |
| 3695 | if (!(hotkey_source_mask & (1 << scancode))) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3696 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3697 | *send_acpi_ev = false; |
| 3698 | } else { |
| 3699 | *ignore_acpi_ev = true; |
| 3700 | } |
| 3701 | return true; |
Shuduo Sang | 3a9d20b | 2014-03-06 18:20:46 +0800 | [diff] [blame] | 3702 | } else { |
| 3703 | return adaptive_keyboard_hotkey_notify_hotkey(scancode); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3704 | } |
| 3705 | return false; |
| 3706 | } |
| 3707 | |
| 3708 | static bool hotkey_notify_wakeup(const u32 hkey, |
| 3709 | bool *send_acpi_ev, |
| 3710 | bool *ignore_acpi_ev) |
| 3711 | { |
| 3712 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3713 | *send_acpi_ev = true; |
| 3714 | *ignore_acpi_ev = false; |
| 3715 | |
| 3716 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3717 | case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */ |
| 3718 | case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3719 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 3720 | *ignore_acpi_ev = true; |
| 3721 | break; |
| 3722 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3723 | case TP_HKEY_EV_WKUP_S3_BAYEJ: /* suspend, bay eject */ |
| 3724 | case TP_HKEY_EV_WKUP_S4_BAYEJ: /* hibernation, bay eject */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3725 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 3726 | *ignore_acpi_ev = true; |
| 3727 | break; |
| 3728 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3729 | case TP_HKEY_EV_WKUP_S3_BATLOW: /* Battery on critical low level/S3 */ |
| 3730 | case TP_HKEY_EV_WKUP_S4_BATLOW: /* Battery on critical low level/S4 */ |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3731 | pr_alert("EMERGENCY WAKEUP: battery almost empty\n"); |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3732 | /* how to auto-heal: */ |
| 3733 | /* 2313: woke up from S3, go to S4/S5 */ |
| 3734 | /* 2413: woke up from S4, go to S5 */ |
| 3735 | break; |
| 3736 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3737 | default: |
| 3738 | return false; |
| 3739 | } |
| 3740 | |
| 3741 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3742 | pr_info("woke up due to a hot-unplug request...\n"); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3743 | hotkey_wakeup_reason_notify_change(); |
| 3744 | } |
| 3745 | return true; |
| 3746 | } |
| 3747 | |
Henrique de Moraes Holschuh | a50245a | 2011-06-05 16:22:35 -0300 | [diff] [blame] | 3748 | static bool hotkey_notify_dockevent(const u32 hkey, |
| 3749 | bool *send_acpi_ev, |
| 3750 | bool *ignore_acpi_ev) |
| 3751 | { |
| 3752 | /* 0x4000-0x4FFF: dock-related events */ |
| 3753 | *send_acpi_ev = true; |
| 3754 | *ignore_acpi_ev = false; |
| 3755 | |
| 3756 | switch (hkey) { |
| 3757 | case TP_HKEY_EV_UNDOCK_ACK: |
| 3758 | /* ACPI undock operation completed after wakeup */ |
| 3759 | hotkey_autosleep_ack = 1; |
| 3760 | pr_info("undocked\n"); |
| 3761 | hotkey_wakeup_hotunplug_complete_notify_change(); |
| 3762 | return true; |
| 3763 | |
| 3764 | case TP_HKEY_EV_HOTPLUG_DOCK: /* docked to port replicator */ |
| 3765 | pr_info("docked into hotplug port replicator\n"); |
| 3766 | return true; |
| 3767 | case TP_HKEY_EV_HOTPLUG_UNDOCK: /* undocked from port replicator */ |
| 3768 | pr_info("undocked from hotplug port replicator\n"); |
| 3769 | return true; |
| 3770 | |
| 3771 | default: |
| 3772 | return false; |
| 3773 | } |
| 3774 | } |
| 3775 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3776 | static bool hotkey_notify_usrevent(const u32 hkey, |
| 3777 | bool *send_acpi_ev, |
| 3778 | bool *ignore_acpi_ev) |
| 3779 | { |
| 3780 | /* 0x5000-0x5FFF: human interface helpers */ |
| 3781 | *send_acpi_ev = true; |
| 3782 | *ignore_acpi_ev = false; |
| 3783 | |
| 3784 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3785 | case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */ |
| 3786 | case TP_HKEY_EV_PEN_REMOVED: /* X61t: tablet pen removed from bay */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3787 | return true; |
| 3788 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3789 | case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */ |
| 3790 | case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3791 | tpacpi_input_send_tabletsw(); |
| 3792 | hotkey_tablet_mode_notify_change(); |
| 3793 | *send_acpi_ev = false; |
| 3794 | return true; |
| 3795 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3796 | case TP_HKEY_EV_LID_CLOSE: /* Lid closed */ |
| 3797 | case TP_HKEY_EV_LID_OPEN: /* Lid opened */ |
| 3798 | case TP_HKEY_EV_BRGHT_CHANGED: /* brightness changed */ |
Henrique de Moraes Holschuh | 176dd98 | 2009-09-20 14:09:24 -0300 | [diff] [blame] | 3799 | /* do not propagate these events */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3800 | *ignore_acpi_ev = true; |
| 3801 | return true; |
| 3802 | |
| 3803 | default: |
| 3804 | return false; |
| 3805 | } |
| 3806 | } |
| 3807 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3808 | static void thermal_dump_all_sensors(void); |
| 3809 | |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3810 | static bool hotkey_notify_6xxx(const u32 hkey, |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3811 | bool *send_acpi_ev, |
| 3812 | bool *ignore_acpi_ev) |
| 3813 | { |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3814 | bool known = true; |
| 3815 | |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3816 | /* 0x6000-0x6FFF: thermal alarms/notices and keyboard events */ |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3817 | *send_acpi_ev = true; |
| 3818 | *ignore_acpi_ev = false; |
| 3819 | |
| 3820 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3821 | case TP_HKEY_EV_THM_TABLE_CHANGED: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3822 | pr_info("EC reports that Thermal Table has changed\n"); |
Henrique de Moraes Holschuh | 54926ce | 2009-01-11 03:01:09 -0200 | [diff] [blame] | 3823 | /* recommended action: do nothing, we don't have |
| 3824 | * Lenovo ATM information */ |
| 3825 | return true; |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3826 | case TP_HKEY_EV_ALARM_BAT_HOT: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3827 | pr_crit("THERMAL ALARM: battery is too hot!\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3828 | /* recommended action: warn user through gui */ |
| 3829 | break; |
| 3830 | case TP_HKEY_EV_ALARM_BAT_XHOT: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3831 | pr_alert("THERMAL EMERGENCY: battery is extremely hot!\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3832 | /* recommended action: immediate sleep/hibernate */ |
| 3833 | break; |
| 3834 | case TP_HKEY_EV_ALARM_SENSOR_HOT: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3835 | pr_crit("THERMAL ALARM: " |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3836 | "a sensor reports something is too hot!\n"); |
| 3837 | /* recommended action: warn user through gui, that */ |
| 3838 | /* some internal component is too hot */ |
| 3839 | break; |
| 3840 | case TP_HKEY_EV_ALARM_SENSOR_XHOT: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3841 | pr_alert("THERMAL EMERGENCY: " |
| 3842 | "a sensor reports something is extremely hot!\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3843 | /* recommended action: immediate sleep/hibernate */ |
| 3844 | break; |
Richard Hartmann | 6f62bc3 | 2012-12-29 22:51:49 +0100 | [diff] [blame] | 3845 | case TP_HKEY_EV_AC_CHANGED: |
| 3846 | /* X120e, X121e, X220, X220i, X220t, X230, T420, T420s, W520: |
| 3847 | * AC status changed; can be triggered by plugging or |
| 3848 | * unplugging AC adapter, docking or undocking. */ |
| 3849 | |
| 3850 | /* fallthrough */ |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3851 | |
| 3852 | case TP_HKEY_EV_KEY_NUMLOCK: |
| 3853 | case TP_HKEY_EV_KEY_FN: |
Xavier Naveira | 67ab624 | 2015-02-10 08:45:18 +0100 | [diff] [blame] | 3854 | case TP_HKEY_EV_KEY_FN_ESC: |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3855 | /* key press events, we just ignore them as long as the EC |
| 3856 | * is still reporting them in the normal keyboard stream */ |
| 3857 | *send_acpi_ev = false; |
| 3858 | *ignore_acpi_ev = true; |
| 3859 | return true; |
| 3860 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3861 | default: |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3862 | pr_warn("unknown possible thermal alarm or keyboard event received\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3863 | known = false; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3864 | } |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3865 | |
| 3866 | thermal_dump_all_sensors(); |
| 3867 | |
| 3868 | return known; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3869 | } |
| 3870 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3871 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 3872 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3873 | u32 hkey; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3874 | bool send_acpi_ev; |
| 3875 | bool ignore_acpi_ev; |
| 3876 | bool known_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3877 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3878 | if (event != 0x80) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3879 | pr_err("unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3880 | /* forward it to userspace, maybe it knows how to handle it */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3881 | acpi_bus_generate_netlink_event( |
| 3882 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3883 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3884 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3885 | return; |
| 3886 | } |
| 3887 | |
| 3888 | while (1) { |
| 3889 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3890 | pr_err("failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3891 | return; |
| 3892 | } |
| 3893 | |
| 3894 | if (hkey == 0) { |
| 3895 | /* queue empty */ |
| 3896 | return; |
| 3897 | } |
| 3898 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3899 | send_acpi_ev = true; |
| 3900 | ignore_acpi_ev = false; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3901 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3902 | switch (hkey >> 12) { |
| 3903 | case 1: |
| 3904 | /* 0x1000-0x1FFF: key presses */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3905 | known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev, |
| 3906 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3907 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3908 | case 2: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3909 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3910 | known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev, |
| 3911 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3912 | break; |
| 3913 | case 3: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3914 | /* 0x3000-0x3FFF: bay-related wakeups */ |
Henrique de Moraes Holschuh | bf8b29c | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 3915 | switch (hkey) { |
| 3916 | case TP_HKEY_EV_BAYEJ_ACK: |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3917 | hotkey_autosleep_ack = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3918 | pr_info("bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3919 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3920 | known_ev = true; |
Henrique de Moraes Holschuh | bf8b29c | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 3921 | break; |
| 3922 | case TP_HKEY_EV_OPTDRV_EJ: |
| 3923 | /* FIXME: kick libata if SATA link offline */ |
| 3924 | known_ev = true; |
| 3925 | break; |
| 3926 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3927 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3928 | } |
| 3929 | break; |
| 3930 | case 4: |
Henrique de Moraes Holschuh | a50245a | 2011-06-05 16:22:35 -0300 | [diff] [blame] | 3931 | /* 0x4000-0x4FFF: dock-related events */ |
| 3932 | known_ev = hotkey_notify_dockevent(hkey, &send_acpi_ev, |
| 3933 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3934 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3935 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 3936 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3937 | known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev, |
| 3938 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3939 | break; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3940 | case 6: |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3941 | /* 0x6000-0x6FFF: thermal alarms/notices and |
| 3942 | * keyboard events */ |
| 3943 | known_ev = hotkey_notify_6xxx(hkey, &send_acpi_ev, |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3944 | &ignore_acpi_ev); |
| 3945 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3946 | case 7: |
| 3947 | /* 0x7000-0x7FFF: misc */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3948 | if (tp_features.hotkey_wlsw && |
| 3949 | hkey == TP_HKEY_EV_RFKILL_CHANGED) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3950 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3951 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3952 | known_ev = true; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3953 | break; |
| 3954 | } |
| 3955 | /* fallthrough to default */ |
| 3956 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3957 | known_ev = false; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3958 | } |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3959 | if (!known_ev) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3960 | pr_notice("unhandled HKEY event 0x%04x\n", hkey); |
| 3961 | pr_notice("please report the conditions when this " |
| 3962 | "event happened to %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3963 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3964 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3965 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3966 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3967 | acpi_bus_generate_netlink_event( |
| 3968 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3969 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3970 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3971 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3972 | } |
| 3973 | } |
| 3974 | |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 3975 | static void hotkey_suspend(void) |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3976 | { |
| 3977 | /* Do these on suspend, we get the events on early resume! */ |
| 3978 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 3979 | hotkey_autosleep_ack = 0; |
Shuduo Sang | 330947b | 2014-03-27 18:06:25 +0800 | [diff] [blame] | 3980 | |
| 3981 | /* save previous mode of adaptive keyboard of X1 Carbon */ |
Bastien Nocera | f23a5bc | 2015-03-02 14:45:16 +0100 | [diff] [blame] | 3982 | if (tp_features.has_adaptive_kbd) { |
| 3983 | if (!acpi_evalf(hkey_handle, &adaptive_keyboard_prev_mode, |
| 3984 | "GTRW", "dd", 0)) { |
| 3985 | pr_err("Cannot read adaptive keyboard mode.\n"); |
Shuduo Sang | 330947b | 2014-03-27 18:06:25 +0800 | [diff] [blame] | 3986 | } |
| 3987 | } |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3988 | } |
| 3989 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3990 | static void hotkey_resume(void) |
| 3991 | { |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3992 | tpacpi_disable_brightness_delay(); |
| 3993 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3994 | if (hotkey_status_set(true) < 0 || |
| 3995 | hotkey_mask_set(hotkey_acpi_mask) < 0) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3996 | pr_err("error while attempting to reset the event " |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3997 | "firmware interface\n"); |
| 3998 | |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3999 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 4000 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 4001 | hotkey_wakeup_reason_notify_change(); |
| 4002 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 4003 | hotkey_poll_setup_safe(false); |
Shuduo Sang | 330947b | 2014-03-27 18:06:25 +0800 | [diff] [blame] | 4004 | |
| 4005 | /* restore previous mode of adapive keyboard of X1 Carbon */ |
Bastien Nocera | f23a5bc | 2015-03-02 14:45:16 +0100 | [diff] [blame] | 4006 | if (tp_features.has_adaptive_kbd) { |
| 4007 | if (!acpi_evalf(hkey_handle, NULL, "STRW", "vd", |
| 4008 | adaptive_keyboard_prev_mode)) { |
| 4009 | pr_err("Cannot set adaptive keyboard mode.\n"); |
Shuduo Sang | 330947b | 2014-03-27 18:06:25 +0800 | [diff] [blame] | 4010 | } |
| 4011 | } |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 4012 | } |
| 4013 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 4014 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4015 | static int hotkey_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 4017 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4019 | if (!tp_features.hotkey) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4020 | seq_printf(m, "status:\t\tnot supported\n"); |
| 4021 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4022 | } |
| 4023 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 4024 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 4025 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 4026 | res = hotkey_status_get(&status); |
| 4027 | if (!res) |
| 4028 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 4029 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 4030 | if (res) |
| 4031 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4033 | seq_printf(m, "status:\t\t%s\n", enabled(status, 0)); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 4034 | if (hotkey_all_mask) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4035 | seq_printf(m, "mask:\t\t0x%08x\n", hotkey_user_mask); |
| 4036 | seq_printf(m, "commands:\tenable, disable, reset, <mask>\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | } else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4038 | seq_printf(m, "mask:\t\tnot supported\n"); |
| 4039 | seq_printf(m, "commands:\tenable, disable, reset\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | } |
| 4041 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4042 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | } |
| 4044 | |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 4045 | static void hotkey_enabledisable_warn(bool enable) |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 4046 | { |
| 4047 | tpacpi_log_usertask("procfs hotkey enable/disable"); |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 4048 | if (!WARN((tpacpi_lifecycle == TPACPI_LIFE_RUNNING || !enable), |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4049 | pr_fmt("hotkey enable/disable functionality has been " |
| 4050 | "removed from the driver. " |
| 4051 | "Hotkeys are always enabled.\n"))) |
| 4052 | pr_err("Please remove the hotkey=enable module " |
| 4053 | "parameter, it is deprecated. " |
| 4054 | "Hotkeys are always enabled.\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 4055 | } |
| 4056 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4057 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 4059 | int res; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 4060 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4063 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | return -ENODEV; |
| 4065 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 4066 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 4067 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4068 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 4069 | mask = hotkey_user_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 4070 | |
| 4071 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | while ((cmd = next_cmd(&buf))) { |
| 4073 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 4074 | hotkey_enabledisable_warn(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 4076 | hotkey_enabledisable_warn(0); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 4077 | res = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | } else if (strlencmp(cmd, "reset") == 0) { |
Henrique de Moraes Holschuh | 20c9aa4 | 2009-09-12 15:22:16 -0300 | [diff] [blame] | 4079 | mask = (hotkey_all_mask | hotkey_source_mask) |
| 4080 | & ~hotkey_reserved_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 4082 | /* mask set */ |
| 4083 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 4084 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 4085 | } else { |
| 4086 | res = -EINVAL; |
| 4087 | goto errexit; |
| 4088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | } |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 4090 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 4091 | if (!res) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 4092 | tpacpi_disclose_usertask("procfs hotkey", |
| 4093 | "set mask to 0x%08x\n", mask); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 4094 | res = hotkey_user_mask_set(mask); |
| 4095 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 4097 | errexit: |
| 4098 | mutex_unlock(&hotkey_mutex); |
| 4099 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 4102 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Manoj Iyer | 9fbdaeb | 2011-05-08 18:04:29 -0400 | [diff] [blame] | 4103 | {TPACPI_ACPI_IBM_HKEY_HID, 0}, |
| 4104 | {TPACPI_ACPI_LENOVO_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 4105 | {"", 0}, |
| 4106 | }; |
| 4107 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 4108 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 4109 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4110 | .notify = hotkey_notify, |
| 4111 | .handle = &hkey_handle, |
| 4112 | .type = ACPI_DEVICE_NOTIFY, |
| 4113 | }; |
| 4114 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 4115 | static struct ibm_struct hotkey_driver_data = { |
| 4116 | .name = "hotkey", |
| 4117 | .read = hotkey_read, |
| 4118 | .write = hotkey_write, |
| 4119 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 4120 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 4121 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 4122 | .acpi = &ibm_hotkey_acpidriver, |
| 4123 | }; |
| 4124 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4125 | /************************************************************************* |
| 4126 | * Bluetooth subdriver |
| 4127 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4129 | enum { |
| 4130 | /* ACPI GBDC/SBDC bits */ |
| 4131 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 4132 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4133 | TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 4134 | 0 = disable, 1 = enable */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4135 | }; |
| 4136 | |
| 4137 | enum { |
| 4138 | /* ACPI \BLTH commands */ |
| 4139 | TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */ |
| 4140 | TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */ |
| 4141 | TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */ |
| 4142 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */ |
| 4143 | TP_ACPI_BLTH_SAVE_STATE = 0x05, /* Save state for S4/S5 */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4144 | }; |
| 4145 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4146 | #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" |
| 4147 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4148 | static int bluetooth_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4149 | { |
| 4150 | int status; |
| 4151 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4152 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4153 | if (dbg_bluetoothemul) |
| 4154 | return (tpacpi_bluetooth_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4155 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4156 | #endif |
| 4157 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4158 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 4159 | return -EIO; |
| 4160 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4161 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4162 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4163 | } |
| 4164 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4165 | static int bluetooth_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4166 | { |
| 4167 | int status; |
| 4168 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4169 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4170 | "will attempt to %s bluetooth\n", |
| 4171 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4172 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4173 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4174 | if (dbg_bluetoothemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4175 | tpacpi_bluetooth_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4176 | return 0; |
| 4177 | } |
| 4178 | #endif |
| 4179 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4180 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 4181 | status = TP_ACPI_BLUETOOTH_RADIOSSW |
| 4182 | | TP_ACPI_BLUETOOTH_RESUMECTRL; |
| 4183 | else |
| 4184 | status = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4185 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4186 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 4187 | return -EIO; |
| 4188 | |
| 4189 | return 0; |
| 4190 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4191 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4192 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 4193 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 4194 | struct device_attribute *attr, |
| 4195 | char *buf) |
| 4196 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4197 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 4198 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 4202 | struct device_attribute *attr, |
| 4203 | const char *buf, size_t count) |
| 4204 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4205 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 4206 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4207 | } |
| 4208 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 4209 | static DEVICE_ATTR_RW(bluetooth_enable); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4210 | |
| 4211 | /* --------------------------------------------------------------------- */ |
| 4212 | |
| 4213 | static struct attribute *bluetooth_attributes[] = { |
| 4214 | &dev_attr_bluetooth_enable.attr, |
| 4215 | NULL |
| 4216 | }; |
| 4217 | |
| 4218 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4219 | .attrs = bluetooth_attributes, |
| 4220 | }; |
| 4221 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4222 | static const struct tpacpi_rfk_ops bluetooth_tprfk_ops = { |
| 4223 | .get_status = bluetooth_get_status, |
| 4224 | .set_status = bluetooth_set_status, |
| 4225 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4226 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4227 | static void bluetooth_shutdown(void) |
| 4228 | { |
| 4229 | /* Order firmware to save current state to NVRAM */ |
| 4230 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 4231 | TP_ACPI_BLTH_SAVE_STATE)) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4232 | pr_notice("failed to save bluetooth state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4233 | else |
| 4234 | vdbg_printk(TPACPI_DBG_RFKILL, |
Paul Bolle | 1f01358 | 2011-10-06 22:57:56 +0200 | [diff] [blame] | 4235 | "bluetooth state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4236 | } |
| 4237 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4238 | static void bluetooth_exit(void) |
| 4239 | { |
| 4240 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 4241 | &bluetooth_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4242 | |
| 4243 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
| 4244 | |
| 4245 | bluetooth_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4246 | } |
| 4247 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4248 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4250 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4251 | int status = 0; |
| 4252 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4253 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4254 | "initializing bluetooth subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4255 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4256 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4257 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4258 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4259 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4260 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4261 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4263 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4264 | "bluetooth is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4265 | str_supported(tp_features.bluetooth), |
| 4266 | status); |
| 4267 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4268 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4269 | if (dbg_bluetoothemul) { |
| 4270 | tp_features.bluetooth = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4271 | pr_info("bluetooth switch emulation enabled\n"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4272 | } else |
| 4273 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4274 | if (tp_features.bluetooth && |
| 4275 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 4276 | /* no bluetooth hardware present in system */ |
| 4277 | tp_features.bluetooth = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4278 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4279 | "bluetooth hardware not installed\n"); |
| 4280 | } |
| 4281 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4282 | if (!tp_features.bluetooth) |
| 4283 | return 1; |
| 4284 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4285 | res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 4286 | &bluetooth_tprfk_ops, |
| 4287 | RFKILL_TYPE_BLUETOOTH, |
| 4288 | TPACPI_RFK_BLUETOOTH_SW_NAME, |
| 4289 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4290 | if (res) |
| 4291 | return res; |
| 4292 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4293 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4294 | &bluetooth_attr_group); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4295 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4296 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4297 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4298 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4299 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4300 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | } |
| 4302 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4303 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4304 | static int bluetooth_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4306 | return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID, m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | } |
| 4308 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4309 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4311 | return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | } |
| 4313 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4314 | static struct ibm_struct bluetooth_driver_data = { |
| 4315 | .name = "bluetooth", |
| 4316 | .read = bluetooth_read, |
| 4317 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4318 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4319 | .shutdown = bluetooth_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4320 | }; |
| 4321 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4322 | /************************************************************************* |
| 4323 | * Wan subdriver |
| 4324 | */ |
| 4325 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4326 | enum { |
| 4327 | /* ACPI GWAN/SWAN bits */ |
| 4328 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 4329 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4330 | TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 4331 | 0 = disable, 1 = enable */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4332 | }; |
| 4333 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4334 | #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" |
| 4335 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4336 | static int wan_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4337 | { |
| 4338 | int status; |
| 4339 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4340 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4341 | if (dbg_wwanemul) |
| 4342 | return (tpacpi_wwan_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4343 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4344 | #endif |
| 4345 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4346 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 4347 | return -EIO; |
| 4348 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4349 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4350 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4351 | } |
| 4352 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4353 | static int wan_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4354 | { |
| 4355 | int status; |
| 4356 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4357 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4358 | "will attempt to %s wwan\n", |
| 4359 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4360 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4361 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4362 | if (dbg_wwanemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4363 | tpacpi_wwan_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4364 | return 0; |
| 4365 | } |
| 4366 | #endif |
| 4367 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4368 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 4369 | status = TP_ACPI_WANCARD_RADIOSSW |
| 4370 | | TP_ACPI_WANCARD_RESUMECTRL; |
| 4371 | else |
| 4372 | status = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4373 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4374 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 4375 | return -EIO; |
| 4376 | |
| 4377 | return 0; |
| 4378 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4379 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4380 | /* sysfs wan enable ---------------------------------------------------- */ |
| 4381 | static ssize_t wan_enable_show(struct device *dev, |
| 4382 | struct device_attribute *attr, |
| 4383 | char *buf) |
| 4384 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4385 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID, |
| 4386 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4387 | } |
| 4388 | |
| 4389 | static ssize_t wan_enable_store(struct device *dev, |
| 4390 | struct device_attribute *attr, |
| 4391 | const char *buf, size_t count) |
| 4392 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4393 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID, |
| 4394 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4395 | } |
| 4396 | |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 4397 | static DEVICE_ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
| 4398 | wan_enable_show, wan_enable_store); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4399 | |
| 4400 | /* --------------------------------------------------------------------- */ |
| 4401 | |
| 4402 | static struct attribute *wan_attributes[] = { |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 4403 | &dev_attr_wwan_enable.attr, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4404 | NULL |
| 4405 | }; |
| 4406 | |
| 4407 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4408 | .attrs = wan_attributes, |
| 4409 | }; |
| 4410 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4411 | static const struct tpacpi_rfk_ops wan_tprfk_ops = { |
| 4412 | .get_status = wan_get_status, |
| 4413 | .set_status = wan_set_status, |
| 4414 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4415 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4416 | static void wan_shutdown(void) |
| 4417 | { |
| 4418 | /* Order firmware to save current state to NVRAM */ |
| 4419 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd", |
| 4420 | TP_ACPI_WGSV_SAVE_STATE)) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4421 | pr_notice("failed to save WWAN state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4422 | else |
| 4423 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 4424 | "WWAN state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4425 | } |
| 4426 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4427 | static void wan_exit(void) |
| 4428 | { |
| 4429 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 4430 | &wan_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4431 | |
| 4432 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
| 4433 | |
| 4434 | wan_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4435 | } |
| 4436 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4437 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4438 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4439 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4440 | int status = 0; |
| 4441 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4442 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4443 | "initializing wan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4444 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4445 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4446 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4447 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4448 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4449 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4450 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4451 | "wan is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4452 | str_supported(tp_features.wan), |
| 4453 | status); |
| 4454 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4455 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4456 | if (dbg_wwanemul) { |
| 4457 | tp_features.wan = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4458 | pr_info("wwan switch emulation enabled\n"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4459 | } else |
| 4460 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4461 | if (tp_features.wan && |
| 4462 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 4463 | /* no wan hardware present in system */ |
| 4464 | tp_features.wan = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4465 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4466 | "wan hardware not installed\n"); |
| 4467 | } |
| 4468 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4469 | if (!tp_features.wan) |
| 4470 | return 1; |
| 4471 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4472 | res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, |
| 4473 | &wan_tprfk_ops, |
| 4474 | RFKILL_TYPE_WWAN, |
| 4475 | TPACPI_RFK_WWAN_SW_NAME, |
| 4476 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4477 | if (res) |
| 4478 | return res; |
| 4479 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4480 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4481 | &wan_attr_group); |
| 4482 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4483 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4484 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4485 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4486 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4487 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4488 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4489 | } |
| 4490 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4491 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4492 | static int wan_read(struct seq_file *m) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4493 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4494 | return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID, m); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | static int wan_write(char *buf) |
| 4498 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4499 | return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID, buf); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4500 | } |
| 4501 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4502 | static struct ibm_struct wan_driver_data = { |
| 4503 | .name = "wan", |
| 4504 | .read = wan_read, |
| 4505 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4506 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4507 | .shutdown = wan_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4508 | }; |
| 4509 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4510 | /************************************************************************* |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4511 | * UWB subdriver |
| 4512 | */ |
| 4513 | |
| 4514 | enum { |
| 4515 | /* ACPI GUWB/SUWB bits */ |
| 4516 | TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */ |
| 4517 | TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */ |
| 4518 | }; |
| 4519 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4520 | #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" |
| 4521 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4522 | static int uwb_get_status(void) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4523 | { |
| 4524 | int status; |
| 4525 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4526 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4527 | if (dbg_uwbemul) |
| 4528 | return (tpacpi_uwb_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4529 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4530 | #endif |
| 4531 | |
| 4532 | if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) |
| 4533 | return -EIO; |
| 4534 | |
| 4535 | return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4536 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4537 | } |
| 4538 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4539 | static int uwb_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4540 | { |
| 4541 | int status; |
| 4542 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4543 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4544 | "will attempt to %s UWB\n", |
| 4545 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4546 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4547 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4548 | if (dbg_uwbemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4549 | tpacpi_uwb_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4550 | return 0; |
| 4551 | } |
| 4552 | #endif |
| 4553 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4554 | if (state == TPACPI_RFK_RADIO_ON) |
| 4555 | status = TP_ACPI_UWB_RADIOSSW; |
| 4556 | else |
| 4557 | status = 0; |
| 4558 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4559 | if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) |
| 4560 | return -EIO; |
| 4561 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4562 | return 0; |
| 4563 | } |
| 4564 | |
| 4565 | /* --------------------------------------------------------------------- */ |
| 4566 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4567 | static const struct tpacpi_rfk_ops uwb_tprfk_ops = { |
| 4568 | .get_status = uwb_get_status, |
| 4569 | .set_status = uwb_set_status, |
| 4570 | }; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4571 | |
| 4572 | static void uwb_exit(void) |
| 4573 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4574 | tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4575 | } |
| 4576 | |
| 4577 | static int __init uwb_init(struct ibm_init_struct *iibm) |
| 4578 | { |
| 4579 | int res; |
| 4580 | int status = 0; |
| 4581 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4582 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4583 | "initializing uwb subdriver\n"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4584 | |
| 4585 | TPACPI_ACPIHANDLE_INIT(hkey); |
| 4586 | |
| 4587 | tp_features.uwb = hkey_handle && |
| 4588 | acpi_evalf(hkey_handle, &status, "GUWB", "qd"); |
| 4589 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4590 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4591 | "uwb is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4592 | str_supported(tp_features.uwb), |
| 4593 | status); |
| 4594 | |
| 4595 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4596 | if (dbg_uwbemul) { |
| 4597 | tp_features.uwb = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4598 | pr_info("uwb switch emulation enabled\n"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4599 | } else |
| 4600 | #endif |
| 4601 | if (tp_features.uwb && |
| 4602 | !(status & TP_ACPI_UWB_HWPRESENT)) { |
| 4603 | /* no uwb hardware present in system */ |
| 4604 | tp_features.uwb = 0; |
| 4605 | dbg_printk(TPACPI_DBG_INIT, |
| 4606 | "uwb hardware not installed\n"); |
| 4607 | } |
| 4608 | |
| 4609 | if (!tp_features.uwb) |
| 4610 | return 1; |
| 4611 | |
| 4612 | res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4613 | &uwb_tprfk_ops, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4614 | RFKILL_TYPE_UWB, |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4615 | TPACPI_RFK_UWB_SW_NAME, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4616 | false); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4617 | return res; |
| 4618 | } |
| 4619 | |
| 4620 | static struct ibm_struct uwb_driver_data = { |
| 4621 | .name = "uwb", |
| 4622 | .exit = uwb_exit, |
| 4623 | .flags.experimental = 1, |
| 4624 | }; |
| 4625 | |
| 4626 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4627 | * Video subdriver |
| 4628 | */ |
| 4629 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4630 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 4631 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4632 | enum video_access_mode { |
| 4633 | TPACPI_VIDEO_NONE = 0, |
| 4634 | TPACPI_VIDEO_570, /* 570 */ |
| 4635 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 4636 | TPACPI_VIDEO_NEW, /* all others */ |
| 4637 | }; |
| 4638 | |
| 4639 | enum { /* video status flags, based on VIDEO_570 */ |
| 4640 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 4641 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 4642 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 4643 | }; |
| 4644 | |
| 4645 | enum { /* TPACPI_VIDEO_570 constants */ |
| 4646 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 4647 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 4648 | * video_status_flags */ |
| 4649 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 4650 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 4651 | }; |
| 4652 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4653 | static enum video_access_mode video_supported; |
| 4654 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4655 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4656 | static int video_autosw_get(void); |
| 4657 | static int video_autosw_set(int enable); |
| 4658 | |
Joe Perches | 112a6ee | 2011-04-04 10:06:24 -0700 | [diff] [blame] | 4659 | TPACPI_HANDLE(vid, root, |
| 4660 | "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 4661 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 4662 | "\\_SB.PCI0.VID0", /* 770e */ |
| 4663 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 4664 | "\\_SB.PCI0.AGP.VGA", /* X100e and a few others */ |
| 4665 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 4666 | ); /* R30, R31 */ |
| 4667 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4668 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4669 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4670 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4672 | int ivga; |
| 4673 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4674 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 4675 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4676 | TPACPI_ACPIHANDLE_INIT(vid); |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4677 | if (tpacpi_is_ibm()) |
| 4678 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4679 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4680 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 4681 | /* G41, assume IVGA doesn't change */ |
| 4682 | vid_handle = vid2_handle; |
| 4683 | |
| 4684 | if (!vid_handle) |
| 4685 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4686 | video_supported = TPACPI_VIDEO_NONE; |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4687 | else if (tpacpi_is_ibm() && |
| 4688 | acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4689 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4690 | video_supported = TPACPI_VIDEO_570; |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4691 | else if (tpacpi_is_ibm() && |
| 4692 | acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4693 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4694 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4695 | else |
| 4696 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4697 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4699 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 4700 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 4701 | video_supported); |
| 4702 | |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 4703 | return (video_supported != TPACPI_VIDEO_NONE) ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | } |
| 4705 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4706 | static void video_exit(void) |
| 4707 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4708 | dbg_printk(TPACPI_DBG_EXIT, |
| 4709 | "restoring original video autoswitch mode\n"); |
| 4710 | if (video_autosw_set(video_orig_autosw)) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4711 | pr_err("error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4712 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4713 | } |
| 4714 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4715 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4716 | { |
| 4717 | int status = 0; |
| 4718 | int i; |
| 4719 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4720 | switch (video_supported) { |
| 4721 | case TPACPI_VIDEO_570: |
| 4722 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 4723 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 4724 | return -EIO; |
| 4725 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 4726 | break; |
| 4727 | case TPACPI_VIDEO_770: |
| 4728 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4729 | return -EIO; |
| 4730 | if (i) |
| 4731 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4732 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4733 | return -EIO; |
| 4734 | if (i) |
| 4735 | status |= TP_ACPI_VIDEO_S_CRT; |
| 4736 | break; |
| 4737 | case TPACPI_VIDEO_NEW: |
| 4738 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 4739 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4740 | return -EIO; |
| 4741 | if (i) |
| 4742 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4744 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 4745 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4746 | return -EIO; |
| 4747 | if (i) |
| 4748 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4749 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 4750 | return -EIO; |
| 4751 | if (i) |
| 4752 | status |= TP_ACPI_VIDEO_S_DVI; |
| 4753 | break; |
| 4754 | default: |
| 4755 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4756 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | |
| 4758 | return status; |
| 4759 | } |
| 4760 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4761 | static int video_outputsw_set(int status) |
| 4762 | { |
| 4763 | int autosw; |
| 4764 | int res = 0; |
| 4765 | |
| 4766 | switch (video_supported) { |
| 4767 | case TPACPI_VIDEO_570: |
| 4768 | res = acpi_evalf(NULL, NULL, |
| 4769 | "\\_SB.PHS2", "vdd", |
| 4770 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 4771 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 4772 | break; |
| 4773 | case TPACPI_VIDEO_770: |
| 4774 | autosw = video_autosw_get(); |
| 4775 | if (autosw < 0) |
| 4776 | return autosw; |
| 4777 | |
| 4778 | res = video_autosw_set(1); |
| 4779 | if (res) |
| 4780 | return res; |
| 4781 | res = acpi_evalf(vid_handle, NULL, |
| 4782 | "ASWT", "vdd", status * 0x100, 0); |
| 4783 | if (!autosw && video_autosw_set(autosw)) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4784 | pr_err("video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4785 | return -EIO; |
| 4786 | } |
| 4787 | break; |
| 4788 | case TPACPI_VIDEO_NEW: |
| 4789 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4790 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4791 | break; |
| 4792 | default: |
| 4793 | return -ENOSYS; |
| 4794 | } |
| 4795 | |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 4796 | return (res) ? 0 : -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4797 | } |
| 4798 | |
| 4799 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4801 | int autosw = 0; |
| 4802 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4803 | switch (video_supported) { |
| 4804 | case TPACPI_VIDEO_570: |
| 4805 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 4806 | return -EIO; |
| 4807 | break; |
| 4808 | case TPACPI_VIDEO_770: |
| 4809 | case TPACPI_VIDEO_NEW: |
| 4810 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 4811 | return -EIO; |
| 4812 | break; |
| 4813 | default: |
| 4814 | return -ENOSYS; |
| 4815 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4816 | |
| 4817 | return autosw & 1; |
| 4818 | } |
| 4819 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4820 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4821 | { |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 4822 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable) ? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4823 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4824 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4825 | } |
| 4826 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4827 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4828 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4829 | int autosw = video_autosw_get(); |
| 4830 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4831 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4832 | if (autosw < 0) |
| 4833 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4834 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4835 | switch (video_supported) { |
| 4836 | case TPACPI_VIDEO_570: |
| 4837 | res = video_autosw_set(1); |
| 4838 | if (res) |
| 4839 | return res; |
| 4840 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 4841 | break; |
| 4842 | case TPACPI_VIDEO_770: |
| 4843 | case TPACPI_VIDEO_NEW: |
| 4844 | res = video_autosw_set(1); |
| 4845 | if (res) |
| 4846 | return res; |
| 4847 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 4848 | break; |
| 4849 | default: |
| 4850 | return -ENOSYS; |
| 4851 | } |
| 4852 | if (!autosw && video_autosw_set(autosw)) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4853 | pr_err("video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4854 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4855 | } |
| 4856 | |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 4857 | return (res) ? 0 : -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | static int video_expand_toggle(void) |
| 4861 | { |
| 4862 | switch (video_supported) { |
| 4863 | case TPACPI_VIDEO_570: |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 4864 | return acpi_evalf(ec_handle, NULL, "_Q17", "v") ? |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4865 | 0 : -EIO; |
| 4866 | case TPACPI_VIDEO_770: |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 4867 | return acpi_evalf(vid_handle, NULL, "VEXP", "v") ? |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4868 | 0 : -EIO; |
| 4869 | case TPACPI_VIDEO_NEW: |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 4870 | return acpi_evalf(NULL, NULL, "\\VEXP", "v") ? |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4871 | 0 : -EIO; |
| 4872 | default: |
| 4873 | return -ENOSYS; |
| 4874 | } |
| 4875 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4876 | } |
| 4877 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4878 | static int video_read(struct seq_file *m) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4879 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4880 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4881 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4882 | if (video_supported == TPACPI_VIDEO_NONE) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4883 | seq_printf(m, "status:\t\tnot supported\n"); |
| 4884 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4885 | } |
| 4886 | |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 4887 | /* Even reads can crash X.org, so... */ |
| 4888 | if (!capable(CAP_SYS_ADMIN)) |
| 4889 | return -EPERM; |
| 4890 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4891 | status = video_outputsw_get(); |
| 4892 | if (status < 0) |
| 4893 | return status; |
| 4894 | |
| 4895 | autosw = video_autosw_get(); |
| 4896 | if (autosw < 0) |
| 4897 | return autosw; |
| 4898 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4899 | seq_printf(m, "status:\t\tsupported\n"); |
| 4900 | seq_printf(m, "lcd:\t\t%s\n", enabled(status, 0)); |
| 4901 | seq_printf(m, "crt:\t\t%s\n", enabled(status, 1)); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4902 | if (video_supported == TPACPI_VIDEO_NEW) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4903 | seq_printf(m, "dvi:\t\t%s\n", enabled(status, 3)); |
| 4904 | seq_printf(m, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 4905 | seq_printf(m, "commands:\tlcd_enable, lcd_disable\n"); |
| 4906 | seq_printf(m, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4907 | if (video_supported == TPACPI_VIDEO_NEW) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4908 | seq_printf(m, "commands:\tdvi_enable, dvi_disable\n"); |
| 4909 | seq_printf(m, "commands:\tauto_enable, auto_disable\n"); |
| 4910 | seq_printf(m, "commands:\tvideo_switch, expand_toggle\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4911 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4912 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4913 | } |
| 4914 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4915 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | { |
| 4917 | char *cmd; |
| 4918 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4919 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4921 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4922 | return -ENODEV; |
| 4923 | |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 4924 | /* Even reads can crash X.org, let alone writes... */ |
| 4925 | if (!capable(CAP_SYS_ADMIN)) |
| 4926 | return -EPERM; |
| 4927 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4928 | enable = 0; |
| 4929 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | |
| 4931 | while ((cmd = next_cmd(&buf))) { |
| 4932 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4933 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4935 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4936 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4937 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4939 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4940 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4941 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4942 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4943 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4944 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4945 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4947 | res = video_autosw_set(1); |
| 4948 | if (res) |
| 4949 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4951 | res = video_autosw_set(0); |
| 4952 | if (res) |
| 4953 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4955 | res = video_outputsw_cycle(); |
| 4956 | if (res) |
| 4957 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4959 | res = video_expand_toggle(); |
| 4960 | if (res) |
| 4961 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | } else |
| 4963 | return -EINVAL; |
| 4964 | } |
| 4965 | |
| 4966 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4967 | status = video_outputsw_get(); |
| 4968 | if (status < 0) |
| 4969 | return status; |
| 4970 | res = video_outputsw_set((status & ~disable) | enable); |
| 4971 | if (res) |
| 4972 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | return 0; |
| 4976 | } |
| 4977 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4978 | static struct ibm_struct video_driver_data = { |
| 4979 | .name = "video", |
| 4980 | .read = video_read, |
| 4981 | .write = video_write, |
| 4982 | .exit = video_exit, |
| 4983 | }; |
| 4984 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4985 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 4986 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4987 | /************************************************************************* |
| 4988 | * Light (thinklight) subdriver |
| 4989 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4991 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 4992 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4993 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4994 | static int light_get_status(void) |
| 4995 | { |
| 4996 | int status = 0; |
| 4997 | |
| 4998 | if (tp_features.light_status) { |
| 4999 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 5000 | return -EIO; |
| 5001 | return (!!status); |
| 5002 | } |
| 5003 | |
| 5004 | return -ENXIO; |
| 5005 | } |
| 5006 | |
| 5007 | static int light_set_status(int status) |
| 5008 | { |
| 5009 | int rc; |
| 5010 | |
| 5011 | if (tp_features.light) { |
| 5012 | if (cmos_handle) { |
| 5013 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 5014 | (status) ? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5015 | TP_CMOS_THINKLIGHT_ON : |
| 5016 | TP_CMOS_THINKLIGHT_OFF); |
| 5017 | } else { |
| 5018 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 5019 | (status) ? 1 : 0); |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5020 | } |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 5021 | return (rc) ? 0 : -EIO; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5022 | } |
| 5023 | |
| 5024 | return -ENXIO; |
| 5025 | } |
| 5026 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 5027 | static void light_set_status_worker(struct work_struct *work) |
| 5028 | { |
| 5029 | struct tpacpi_led_classdev *data = |
| 5030 | container_of(work, struct tpacpi_led_classdev, work); |
| 5031 | |
| 5032 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5033 | light_set_status((data->new_state != TPACPI_LED_OFF)); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 5034 | } |
| 5035 | |
| 5036 | static void light_sysfs_set(struct led_classdev *led_cdev, |
| 5037 | enum led_brightness brightness) |
| 5038 | { |
| 5039 | struct tpacpi_led_classdev *data = |
| 5040 | container_of(led_cdev, |
| 5041 | struct tpacpi_led_classdev, |
| 5042 | led_classdev); |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5043 | data->new_state = (brightness != LED_OFF) ? |
| 5044 | TPACPI_LED_ON : TPACPI_LED_OFF; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5045 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) |
| 5049 | { |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 5050 | return (light_get_status() == 1) ? LED_FULL : LED_OFF; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { |
| 5054 | .led_classdev = { |
| 5055 | .name = "tpacpi::thinklight", |
| 5056 | .brightness_set = &light_sysfs_set, |
| 5057 | .brightness_get = &light_sysfs_get, |
| 5058 | } |
| 5059 | }; |
| 5060 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5061 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 5063 | int rc; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 5064 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5065 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 5066 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 5067 | if (tpacpi_is_ibm()) { |
| 5068 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 5069 | TPACPI_ACPIHANDLE_INIT(lght); |
| 5070 | } |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5071 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 5072 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5073 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5074 | /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5075 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5076 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5077 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5078 | /* light status not supported on |
| 5079 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5080 | tp_features.light_status = |
| 5081 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 5083 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
| 5084 | str_supported(tp_features.light), |
| 5085 | str_supported(tp_features.light_status)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5086 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 5087 | if (!tp_features.light) |
| 5088 | return 1; |
| 5089 | |
| 5090 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 5091 | &tpacpi_led_thinklight.led_classdev); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 5092 | |
| 5093 | if (rc < 0) { |
| 5094 | tp_features.light = 0; |
| 5095 | tp_features.light_status = 0; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 5096 | } else { |
| 5097 | rc = 0; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 5098 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 5099 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 5100 | return rc; |
| 5101 | } |
| 5102 | |
| 5103 | static void light_exit(void) |
| 5104 | { |
| 5105 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); |
Tejun Heo | 6d394e1 | 2012-12-21 17:56:58 -0800 | [diff] [blame] | 5106 | flush_workqueue(tpacpi_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5107 | } |
| 5108 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5109 | static int light_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5111 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5112 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5113 | if (!tp_features.light) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5114 | seq_printf(m, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5115 | } else if (!tp_features.light_status) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5116 | seq_printf(m, "status:\t\tunknown\n"); |
| 5117 | seq_printf(m, "commands:\ton, off\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5118 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5119 | status = light_get_status(); |
| 5120 | if (status < 0) |
| 5121 | return status; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5122 | seq_printf(m, "status:\t\t%s\n", onoff(status, 0)); |
| 5123 | seq_printf(m, "commands:\ton, off\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5124 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5126 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | } |
| 5128 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5129 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5132 | int newstatus = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5133 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5134 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5135 | return -ENODEV; |
| 5136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5137 | while ((cmd = next_cmd(&buf))) { |
| 5138 | if (strlencmp(cmd, "on") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5139 | newstatus = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5140 | } else if (strlencmp(cmd, "off") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5141 | newstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5142 | } else |
| 5143 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5144 | } |
| 5145 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5146 | return light_set_status(newstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | } |
| 5148 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5149 | static struct ibm_struct light_driver_data = { |
| 5150 | .name = "light", |
| 5151 | .read = light_read, |
| 5152 | .write = light_write, |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 5153 | .exit = light_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5154 | }; |
| 5155 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5156 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5157 | * CMOS subdriver |
| 5158 | */ |
| 5159 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 5160 | /* sysfs cmos_command -------------------------------------------------- */ |
| 5161 | static ssize_t cmos_command_store(struct device *dev, |
| 5162 | struct device_attribute *attr, |
| 5163 | const char *buf, size_t count) |
| 5164 | { |
| 5165 | unsigned long cmos_cmd; |
| 5166 | int res; |
| 5167 | |
| 5168 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 5169 | return -EINVAL; |
| 5170 | |
| 5171 | res = issue_thinkpad_cmos_command(cmos_cmd); |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 5172 | return (res) ? res : count; |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 5173 | } |
| 5174 | |
Bastien Nocera | b4dd04a | 2015-03-02 18:40:50 +0100 | [diff] [blame] | 5175 | static DEVICE_ATTR_WO(cmos_command); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 5176 | |
| 5177 | /* --------------------------------------------------------------------- */ |
| 5178 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5179 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5180 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 5181 | int res; |
| 5182 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5183 | vdbg_printk(TPACPI_DBG_INIT, |
| 5184 | "initializing cmos commands subdriver\n"); |
| 5185 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5186 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5187 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5188 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 5189 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 5190 | |
| 5191 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 5192 | if (res) |
| 5193 | return res; |
| 5194 | |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 5195 | return (cmos_handle) ? 0 : 1; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5196 | } |
| 5197 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 5198 | static void cmos_exit(void) |
| 5199 | { |
| 5200 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 5201 | } |
| 5202 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5203 | static int cmos_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5204 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5205 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 5206 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5207 | if (!cmos_handle) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5208 | seq_printf(m, "status:\t\tnot supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5209 | else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5210 | seq_printf(m, "status:\t\tsupported\n"); |
| 5211 | seq_printf(m, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5212 | } |
| 5213 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5214 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5215 | } |
| 5216 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5217 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5218 | { |
| 5219 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 5220 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5221 | |
| 5222 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5223 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 5224 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5225 | /* cmos_cmd set */ |
| 5226 | } else |
| 5227 | return -EINVAL; |
| 5228 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 5229 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 5230 | if (res) |
| 5231 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5235 | } |
| 5236 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5237 | static struct ibm_struct cmos_driver_data = { |
| 5238 | .name = "cmos", |
| 5239 | .read = cmos_read, |
| 5240 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 5241 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5242 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5243 | |
| 5244 | /************************************************************************* |
| 5245 | * LED subdriver |
| 5246 | */ |
| 5247 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5248 | enum led_access_mode { |
| 5249 | TPACPI_LED_NONE = 0, |
| 5250 | TPACPI_LED_570, /* 570 */ |
| 5251 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 5252 | TPACPI_LED_NEW, /* all others */ |
| 5253 | }; |
| 5254 | |
| 5255 | enum { /* For TPACPI_LED_OLD */ |
| 5256 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 5257 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 5258 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 5259 | }; |
| 5260 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 5261 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5262 | |
Henrique de Moraes Holschuh | 2cbb5c8 | 2010-05-16 19:45:50 -0300 | [diff] [blame] | 5263 | static acpi_handle led_handle; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5264 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5265 | #define TPACPI_LED_NUMLEDS 16 |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5266 | static struct tpacpi_led_classdev *tpacpi_leds; |
| 5267 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; |
Harvey Harrison | e3aa51f | 2008-05-29 17:51:57 -0700 | [diff] [blame] | 5268 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5269 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
| 5270 | "tpacpi::power", |
| 5271 | "tpacpi:orange:batt", |
| 5272 | "tpacpi:green:batt", |
| 5273 | "tpacpi::dock_active", |
| 5274 | "tpacpi::bay_active", |
| 5275 | "tpacpi::dock_batt", |
| 5276 | "tpacpi::unknown_led", |
| 5277 | "tpacpi::standby", |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5278 | "tpacpi::dock_status1", |
| 5279 | "tpacpi::dock_status2", |
| 5280 | "tpacpi::unknown_led2", |
| 5281 | "tpacpi::unknown_led3", |
| 5282 | "tpacpi::thinkvantage", |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5283 | }; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5284 | #define TPACPI_SAFE_LEDS 0x1081U |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5285 | |
| 5286 | static inline bool tpacpi_is_led_restricted(const unsigned int led) |
| 5287 | { |
| 5288 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
| 5289 | return false; |
| 5290 | #else |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5291 | return (1U & (TPACPI_SAFE_LEDS >> led)) == 0; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5292 | #endif |
| 5293 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5294 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5295 | static int led_get_status(const unsigned int led) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5296 | { |
| 5297 | int status; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5298 | enum led_status_t led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5299 | |
| 5300 | switch (led_supported) { |
| 5301 | case TPACPI_LED_570: |
| 5302 | if (!acpi_evalf(ec_handle, |
| 5303 | &status, "GLED", "dd", 1 << led)) |
| 5304 | return -EIO; |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 5305 | led_s = (status == 0) ? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5306 | TPACPI_LED_OFF : |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 5307 | ((status == 1) ? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5308 | TPACPI_LED_ON : |
| 5309 | TPACPI_LED_BLINK); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5310 | tpacpi_led_state_cache[led] = led_s; |
| 5311 | return led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5312 | default: |
| 5313 | return -ENXIO; |
| 5314 | } |
| 5315 | |
| 5316 | /* not reached */ |
| 5317 | } |
| 5318 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5319 | static int led_set_status(const unsigned int led, |
| 5320 | const enum led_status_t ledstatus) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5321 | { |
| 5322 | /* off, on, blink. Index is led_status_t */ |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5323 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
| 5324 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5325 | |
| 5326 | int rc = 0; |
| 5327 | |
| 5328 | switch (led_supported) { |
| 5329 | case TPACPI_LED_570: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5330 | /* 570 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5331 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5332 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5333 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5334 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5335 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5336 | (1 << led), led_sled_arg1[ledstatus])) |
| 5337 | rc = -EIO; |
| 5338 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5339 | case TPACPI_LED_OLD: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5340 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5341 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5342 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5343 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5344 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5345 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
| 5346 | if (rc >= 0) |
| 5347 | rc = ec_write(TPACPI_LED_EC_HLBL, |
| 5348 | (ledstatus == TPACPI_LED_BLINK) << led); |
| 5349 | if (rc >= 0) |
| 5350 | rc = ec_write(TPACPI_LED_EC_HLCL, |
| 5351 | (ledstatus != TPACPI_LED_OFF) << led); |
| 5352 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5353 | case TPACPI_LED_NEW: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5354 | /* all others */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5355 | if (unlikely(led >= TPACPI_LED_NUMLEDS)) |
| 5356 | return -EINVAL; |
| 5357 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5358 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5359 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5360 | led, led_led_arg1[ledstatus])) |
| 5361 | rc = -EIO; |
| 5362 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5363 | default: |
| 5364 | rc = -ENXIO; |
| 5365 | } |
| 5366 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5367 | if (!rc) |
| 5368 | tpacpi_led_state_cache[led] = ledstatus; |
| 5369 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5370 | return rc; |
| 5371 | } |
| 5372 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5373 | static void led_set_status_worker(struct work_struct *work) |
| 5374 | { |
| 5375 | struct tpacpi_led_classdev *data = |
| 5376 | container_of(work, struct tpacpi_led_classdev, work); |
| 5377 | |
| 5378 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5379 | led_set_status(data->led, data->new_state); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | static void led_sysfs_set(struct led_classdev *led_cdev, |
| 5383 | enum led_brightness brightness) |
| 5384 | { |
| 5385 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5386 | struct tpacpi_led_classdev, led_classdev); |
| 5387 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5388 | if (brightness == LED_OFF) |
| 5389 | data->new_state = TPACPI_LED_OFF; |
| 5390 | else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) |
| 5391 | data->new_state = TPACPI_LED_ON; |
| 5392 | else |
| 5393 | data->new_state = TPACPI_LED_BLINK; |
| 5394 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5395 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, |
| 5399 | unsigned long *delay_on, unsigned long *delay_off) |
| 5400 | { |
| 5401 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5402 | struct tpacpi_led_classdev, led_classdev); |
| 5403 | |
| 5404 | /* Can we choose the flash rate? */ |
| 5405 | if (*delay_on == 0 && *delay_off == 0) { |
| 5406 | /* yes. set them to the hardware blink rate (1 Hz) */ |
| 5407 | *delay_on = 500; /* ms */ |
| 5408 | *delay_off = 500; /* ms */ |
| 5409 | } else if ((*delay_on != 500) || (*delay_off != 500)) |
| 5410 | return -EINVAL; |
| 5411 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5412 | data->new_state = TPACPI_LED_BLINK; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5413 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5414 | |
| 5415 | return 0; |
| 5416 | } |
| 5417 | |
| 5418 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) |
| 5419 | { |
| 5420 | int rc; |
| 5421 | |
| 5422 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5423 | struct tpacpi_led_classdev, led_classdev); |
| 5424 | |
| 5425 | rc = led_get_status(data->led); |
| 5426 | |
| 5427 | if (rc == TPACPI_LED_OFF || rc < 0) |
| 5428 | rc = LED_OFF; /* no error handling in led class :( */ |
| 5429 | else |
| 5430 | rc = LED_FULL; |
| 5431 | |
| 5432 | return rc; |
| 5433 | } |
| 5434 | |
| 5435 | static void led_exit(void) |
| 5436 | { |
| 5437 | unsigned int i; |
| 5438 | |
| 5439 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 5440 | if (tpacpi_leds[i].led_classdev.name) |
| 5441 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); |
| 5442 | } |
| 5443 | |
Li Dongyang | e03e389 | 2012-07-25 10:45:07 +1000 | [diff] [blame] | 5444 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5445 | kfree(tpacpi_leds); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5446 | } |
| 5447 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5448 | static int __init tpacpi_init_led(unsigned int led) |
| 5449 | { |
| 5450 | int rc; |
| 5451 | |
| 5452 | tpacpi_leds[led].led = led; |
| 5453 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5454 | /* LEDs with no name don't get registered */ |
| 5455 | if (!tpacpi_led_names[led]) |
| 5456 | return 0; |
| 5457 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5458 | tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set; |
| 5459 | tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set; |
| 5460 | if (led_supported == TPACPI_LED_570) |
| 5461 | tpacpi_leds[led].led_classdev.brightness_get = |
| 5462 | &led_sysfs_get; |
| 5463 | |
| 5464 | tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led]; |
| 5465 | |
| 5466 | INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker); |
| 5467 | |
| 5468 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 5469 | &tpacpi_leds[led].led_classdev); |
| 5470 | if (rc < 0) |
| 5471 | tpacpi_leds[led].led_classdev.name = NULL; |
| 5472 | |
| 5473 | return rc; |
| 5474 | } |
| 5475 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5476 | static const struct tpacpi_quirk led_useful_qtable[] __initconst = { |
| 5477 | TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */ |
| 5478 | TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */ |
| 5479 | TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */ |
| 5480 | |
| 5481 | TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */ |
| 5482 | TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */ |
| 5483 | TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */ |
| 5484 | TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */ |
| 5485 | TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */ |
| 5486 | TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */ |
| 5487 | TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */ |
| 5488 | TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */ |
| 5489 | |
| 5490 | TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */ |
| 5491 | TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */ |
| 5492 | TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */ |
| 5493 | TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */ |
| 5494 | TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */ |
| 5495 | |
| 5496 | TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */ |
| 5497 | TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */ |
| 5498 | TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */ |
| 5499 | TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */ |
| 5500 | |
| 5501 | /* (1) - may have excess leds enabled on MSB */ |
| 5502 | |
| 5503 | /* Defaults (order matters, keep last, don't reorder!) */ |
| 5504 | { /* Lenovo */ |
| 5505 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 5506 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5507 | .quirks = 0x1fffU, |
| 5508 | }, |
| 5509 | { /* IBM ThinkPads with no EC version string */ |
| 5510 | .vendor = PCI_VENDOR_ID_IBM, |
| 5511 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_UNKNOWN, |
| 5512 | .quirks = 0x00ffU, |
| 5513 | }, |
| 5514 | { /* IBM ThinkPads with EC version string */ |
| 5515 | .vendor = PCI_VENDOR_ID_IBM, |
| 5516 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5517 | .quirks = 0x00bfU, |
| 5518 | }, |
| 5519 | }; |
| 5520 | |
| 5521 | #undef TPACPI_LEDQ_IBM |
| 5522 | #undef TPACPI_LEDQ_LNV |
| 5523 | |
Henrique de Moraes Holschuh | 2cbb5c8 | 2010-05-16 19:45:50 -0300 | [diff] [blame] | 5524 | static enum led_access_mode __init led_init_detect_mode(void) |
| 5525 | { |
| 5526 | acpi_status status; |
| 5527 | |
| 5528 | if (tpacpi_is_ibm()) { |
| 5529 | /* 570 */ |
| 5530 | status = acpi_get_handle(ec_handle, "SLED", &led_handle); |
| 5531 | if (ACPI_SUCCESS(status)) |
| 5532 | return TPACPI_LED_570; |
| 5533 | |
| 5534 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 5535 | status = acpi_get_handle(ec_handle, "SYSL", &led_handle); |
| 5536 | if (ACPI_SUCCESS(status)) |
| 5537 | return TPACPI_LED_OLD; |
| 5538 | } |
| 5539 | |
| 5540 | /* most others */ |
| 5541 | status = acpi_get_handle(ec_handle, "LED", &led_handle); |
| 5542 | if (ACPI_SUCCESS(status)) |
| 5543 | return TPACPI_LED_NEW; |
| 5544 | |
| 5545 | /* R30, R31, and unknown firmwares */ |
| 5546 | led_handle = NULL; |
| 5547 | return TPACPI_LED_NONE; |
| 5548 | } |
| 5549 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5550 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5551 | { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5552 | unsigned int i; |
| 5553 | int rc; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5554 | unsigned long useful_leds; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5555 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5556 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 5557 | |
Henrique de Moraes Holschuh | 2cbb5c8 | 2010-05-16 19:45:50 -0300 | [diff] [blame] | 5558 | led_supported = led_init_detect_mode(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5559 | |
Adam Lee | fcb44e1 | 2013-06-07 16:20:08 +0800 | [diff] [blame] | 5560 | if (led_supported != TPACPI_LED_NONE) { |
| 5561 | useful_leds = tpacpi_check_quirks(led_useful_qtable, |
| 5562 | ARRAY_SIZE(led_useful_qtable)); |
| 5563 | |
| 5564 | if (!useful_leds) { |
| 5565 | led_handle = NULL; |
| 5566 | led_supported = TPACPI_LED_NONE; |
| 5567 | } |
| 5568 | } |
| 5569 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5570 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 5571 | str_supported(led_supported), led_supported); |
| 5572 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5573 | if (led_supported == TPACPI_LED_NONE) |
| 5574 | return 1; |
| 5575 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5576 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
| 5577 | GFP_KERNEL); |
| 5578 | if (!tpacpi_leds) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5579 | pr_err("Out of memory for LED data\n"); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5580 | return -ENOMEM; |
| 5581 | } |
| 5582 | |
| 5583 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
Adam Lee | edf2d77 | 2013-06-08 16:51:15 +0800 | [diff] [blame] | 5584 | tpacpi_leds[i].led = -1; |
| 5585 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5586 | if (!tpacpi_is_led_restricted(i) && |
| 5587 | test_bit(i, &useful_leds)) { |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5588 | rc = tpacpi_init_led(i); |
| 5589 | if (rc < 0) { |
| 5590 | led_exit(); |
| 5591 | return rc; |
| 5592 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5593 | } |
| 5594 | } |
| 5595 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5596 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5597 | pr_notice("warning: userspace override of important " |
| 5598 | "firmware LEDs is enabled\n"); |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5599 | #endif |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5600 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5601 | } |
| 5602 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5603 | #define str_led_status(s) \ |
| 5604 | ((s) == TPACPI_LED_OFF ? "off" : \ |
| 5605 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5606 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5607 | static int led_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5608 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5609 | if (!led_supported) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5610 | seq_printf(m, "status:\t\tnot supported\n"); |
| 5611 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5612 | } |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5613 | seq_printf(m, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5614 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5615 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5616 | /* 570 */ |
| 5617 | int i, status; |
| 5618 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5619 | status = led_get_status(i); |
| 5620 | if (status < 0) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5621 | return -EIO; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5622 | seq_printf(m, "%d:\t\t%s\n", |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5623 | i, str_led_status(status)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5624 | } |
| 5625 | } |
| 5626 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5627 | seq_printf(m, "commands:\t" |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5628 | "<led> on, <led> off, <led> blink (<led> is 0-15)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5629 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5630 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5631 | } |
| 5632 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5633 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | { |
| 5635 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5636 | int led, rc; |
| 5637 | enum led_status_t s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5638 | |
| 5639 | if (!led_supported) |
| 5640 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5641 | |
| 5642 | while ((cmd = next_cmd(&buf))) { |
Adam Lee | edf2d77 | 2013-06-08 16:51:15 +0800 | [diff] [blame] | 5643 | if (sscanf(cmd, "%d", &led) != 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | return -EINVAL; |
| 5645 | |
Adam Lee | edf2d77 | 2013-06-08 16:51:15 +0800 | [diff] [blame] | 5646 | if (led < 0 || led > (TPACPI_LED_NUMLEDS - 1) || |
| 5647 | tpacpi_leds[led].led < 0) |
| 5648 | return -ENODEV; |
| 5649 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5650 | if (strstr(cmd, "off")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5651 | s = TPACPI_LED_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5652 | } else if (strstr(cmd, "on")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5653 | s = TPACPI_LED_ON; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5654 | } else if (strstr(cmd, "blink")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5655 | s = TPACPI_LED_BLINK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5656 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5657 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5658 | } |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5659 | |
| 5660 | rc = led_set_status(led, s); |
| 5661 | if (rc < 0) |
| 5662 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5663 | } |
| 5664 | |
| 5665 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5666 | } |
| 5667 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5668 | static struct ibm_struct led_driver_data = { |
| 5669 | .name = "led", |
| 5670 | .read = led_read, |
| 5671 | .write = led_write, |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5672 | .exit = led_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5673 | }; |
| 5674 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5675 | /************************************************************************* |
| 5676 | * Beep subdriver |
| 5677 | */ |
| 5678 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5679 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5680 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5681 | #define TPACPI_BEEP_Q1 0x0001 |
| 5682 | |
| 5683 | static const struct tpacpi_quirk beep_quirk_table[] __initconst = { |
| 5684 | TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1), /* 570 */ |
| 5685 | TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */ |
| 5686 | }; |
| 5687 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5688 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5689 | { |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5690 | unsigned long quirks; |
| 5691 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5692 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 5693 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5694 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5695 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5696 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 5697 | str_supported(beep_handle != NULL)); |
| 5698 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5699 | quirks = tpacpi_check_quirks(beep_quirk_table, |
| 5700 | ARRAY_SIZE(beep_quirk_table)); |
| 5701 | |
| 5702 | tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); |
| 5703 | |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 5704 | return (beep_handle) ? 0 : 1; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5705 | } |
| 5706 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5707 | static int beep_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5708 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5709 | if (!beep_handle) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5710 | seq_printf(m, "status:\t\tnot supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5711 | else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5712 | seq_printf(m, "status:\t\tsupported\n"); |
| 5713 | seq_printf(m, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5714 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5716 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | } |
| 5718 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5719 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5720 | { |
| 5721 | char *cmd; |
| 5722 | int beep_cmd; |
| 5723 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5724 | if (!beep_handle) |
| 5725 | return -ENODEV; |
| 5726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5727 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5728 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 5729 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5730 | /* beep_cmd set */ |
| 5731 | } else |
| 5732 | return -EINVAL; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5733 | if (tp_features.beep_needs_two_args) { |
| 5734 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", |
| 5735 | beep_cmd, 0)) |
| 5736 | return -EIO; |
| 5737 | } else { |
| 5738 | if (!acpi_evalf(beep_handle, NULL, NULL, "vd", |
| 5739 | beep_cmd)) |
| 5740 | return -EIO; |
| 5741 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | } |
| 5743 | |
| 5744 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5745 | } |
| 5746 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5747 | static struct ibm_struct beep_driver_data = { |
| 5748 | .name = "beep", |
| 5749 | .read = beep_read, |
| 5750 | .write = beep_write, |
| 5751 | }; |
| 5752 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5753 | /************************************************************************* |
| 5754 | * Thermal subdriver |
| 5755 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5756 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5757 | enum thermal_access_mode { |
| 5758 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 5759 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 5760 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 5761 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 5762 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 5763 | }; |
| 5764 | |
| 5765 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 5766 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 5767 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 5768 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5769 | |
| 5770 | TPACPI_THERMAL_SENSOR_NA = -128000, /* Sensor not available */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5771 | }; |
| 5772 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5773 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5774 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 5775 | struct ibm_thermal_sensors_struct { |
| 5776 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 5777 | }; |
| 5778 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5779 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5780 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5781 | /* idx is zero-based */ |
| 5782 | static int thermal_get_sensor(int idx, s32 *value) |
| 5783 | { |
| 5784 | int t; |
| 5785 | s8 tmp; |
| 5786 | char tmpi[5]; |
| 5787 | |
| 5788 | t = TP_EC_THERMAL_TMP0; |
| 5789 | |
| 5790 | switch (thermal_read_mode) { |
| 5791 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 5792 | case TPACPI_THERMAL_TPEC_16: |
| 5793 | if (idx >= 8 && idx <= 15) { |
| 5794 | t = TP_EC_THERMAL_TMP8; |
| 5795 | idx -= 8; |
| 5796 | } |
| 5797 | /* fallthrough */ |
| 5798 | #endif |
| 5799 | case TPACPI_THERMAL_TPEC_8: |
| 5800 | if (idx <= 7) { |
| 5801 | if (!acpi_ec_read(t + idx, &tmp)) |
| 5802 | return -EIO; |
| 5803 | *value = tmp * 1000; |
| 5804 | return 0; |
| 5805 | } |
| 5806 | break; |
| 5807 | |
| 5808 | case TPACPI_THERMAL_ACPI_UPDT: |
| 5809 | if (idx <= 7) { |
| 5810 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5811 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 5812 | return -EIO; |
| 5813 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5814 | return -EIO; |
| 5815 | *value = (t - 2732) * 100; |
| 5816 | return 0; |
| 5817 | } |
| 5818 | break; |
| 5819 | |
| 5820 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5821 | if (idx <= 7) { |
| 5822 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5823 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5824 | return -EIO; |
| 5825 | if (t > 127 || t < -127) |
| 5826 | t = TP_EC_THERMAL_TMP_NA; |
| 5827 | *value = t * 1000; |
| 5828 | return 0; |
| 5829 | } |
| 5830 | break; |
| 5831 | |
| 5832 | case TPACPI_THERMAL_NONE: |
| 5833 | default: |
| 5834 | return -ENOSYS; |
| 5835 | } |
| 5836 | |
| 5837 | return -EINVAL; |
| 5838 | } |
| 5839 | |
| 5840 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 5841 | { |
| 5842 | int res, i; |
| 5843 | int n; |
| 5844 | |
| 5845 | n = 8; |
| 5846 | i = 0; |
| 5847 | |
| 5848 | if (!s) |
| 5849 | return -EINVAL; |
| 5850 | |
| 5851 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 5852 | n = 16; |
| 5853 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5854 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5855 | res = thermal_get_sensor(i, &s->temp[i]); |
| 5856 | if (res) |
| 5857 | return res; |
| 5858 | } |
| 5859 | |
| 5860 | return n; |
| 5861 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5862 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5863 | static void thermal_dump_all_sensors(void) |
| 5864 | { |
| 5865 | int n, i; |
| 5866 | struct ibm_thermal_sensors_struct t; |
| 5867 | |
| 5868 | n = thermal_get_sensors(&t); |
| 5869 | if (n <= 0) |
| 5870 | return; |
| 5871 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5872 | pr_notice("temperatures (Celsius):"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5873 | |
| 5874 | for (i = 0; i < n; i++) { |
| 5875 | if (t.temp[i] != TPACPI_THERMAL_SENSOR_NA) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5876 | pr_cont(" %d", (int)(t.temp[i] / 1000)); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5877 | else |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5878 | pr_cont(" N/A"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5879 | } |
| 5880 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5881 | pr_cont("\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5882 | } |
| 5883 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5884 | /* sysfs temp##_input -------------------------------------------------- */ |
| 5885 | |
| 5886 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 5887 | struct device_attribute *attr, |
| 5888 | char *buf) |
| 5889 | { |
| 5890 | struct sensor_device_attribute *sensor_attr = |
| 5891 | to_sensor_dev_attr(attr); |
| 5892 | int idx = sensor_attr->index; |
| 5893 | s32 value; |
| 5894 | int res; |
| 5895 | |
| 5896 | res = thermal_get_sensor(idx, &value); |
| 5897 | if (res) |
| 5898 | return res; |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5899 | if (value == TPACPI_THERMAL_SENSOR_NA) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5900 | return -ENXIO; |
| 5901 | |
| 5902 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 5903 | } |
| 5904 | |
| 5905 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5906 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 5907 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5908 | |
| 5909 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 5910 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 5911 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 5912 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 5913 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 5914 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 5915 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 5916 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 5917 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 5918 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 5919 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 5920 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 5921 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 5922 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 5923 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 5924 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 5925 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 5926 | }; |
| 5927 | |
| 5928 | #define THERMAL_ATTRS(X) \ |
| 5929 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 5930 | |
| 5931 | static struct attribute *thermal_temp_input_attr[] = { |
| 5932 | THERMAL_ATTRS(8), |
| 5933 | THERMAL_ATTRS(9), |
| 5934 | THERMAL_ATTRS(10), |
| 5935 | THERMAL_ATTRS(11), |
| 5936 | THERMAL_ATTRS(12), |
| 5937 | THERMAL_ATTRS(13), |
| 5938 | THERMAL_ATTRS(14), |
| 5939 | THERMAL_ATTRS(15), |
| 5940 | THERMAL_ATTRS(0), |
| 5941 | THERMAL_ATTRS(1), |
| 5942 | THERMAL_ATTRS(2), |
| 5943 | THERMAL_ATTRS(3), |
| 5944 | THERMAL_ATTRS(4), |
| 5945 | THERMAL_ATTRS(5), |
| 5946 | THERMAL_ATTRS(6), |
| 5947 | THERMAL_ATTRS(7), |
| 5948 | NULL |
| 5949 | }; |
| 5950 | |
| 5951 | static const struct attribute_group thermal_temp_input16_group = { |
| 5952 | .attrs = thermal_temp_input_attr |
| 5953 | }; |
| 5954 | |
| 5955 | static const struct attribute_group thermal_temp_input8_group = { |
| 5956 | .attrs = &thermal_temp_input_attr[8] |
| 5957 | }; |
| 5958 | |
| 5959 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 5960 | #undef THERMAL_ATTRS |
| 5961 | |
| 5962 | /* --------------------------------------------------------------------- */ |
| 5963 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5964 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5965 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5966 | u8 t, ta1, ta2; |
| 5967 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5968 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5969 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5970 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5971 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 5972 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5973 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5974 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 5975 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5976 | /* |
| 5977 | * Direct EC access mode: sensors at registers |
| 5978 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 5979 | * non-implemented, thermal sensors return 0x80 when |
| 5980 | * not available |
| 5981 | */ |
| 5982 | |
| 5983 | ta1 = ta2 = 0; |
| 5984 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5985 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5986 | ta1 |= t; |
| 5987 | } else { |
| 5988 | ta1 = 0; |
| 5989 | break; |
| 5990 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5991 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5992 | ta2 |= t; |
| 5993 | } else { |
| 5994 | ta1 = 0; |
| 5995 | break; |
| 5996 | } |
| 5997 | } |
| 5998 | if (ta1 == 0) { |
| 5999 | /* This is sheer paranoia, but we handle it anyway */ |
| 6000 | if (acpi_tmp7) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6001 | pr_err("ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6002 | "falling back to ACPI TMPx access " |
| 6003 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6004 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6005 | } else { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6006 | pr_err("ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6007 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6008 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6009 | } |
| 6010 | } else { |
| 6011 | thermal_read_mode = |
| 6012 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6013 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6014 | } |
| 6015 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 6016 | if (tpacpi_is_ibm() && |
| 6017 | acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6018 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6019 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6020 | } else { |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 6021 | /* IBM/LENOVO DSDT EC.TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6022 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6023 | } |
| 6024 | } else { |
| 6025 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6026 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6027 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6028 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6029 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 6030 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 6031 | thermal_read_mode); |
| 6032 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6033 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 6034 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6035 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 6036 | &thermal_temp_input16_group); |
| 6037 | if (res) |
| 6038 | return res; |
| 6039 | break; |
| 6040 | case TPACPI_THERMAL_TPEC_8: |
| 6041 | case TPACPI_THERMAL_ACPI_TMP07: |
| 6042 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6043 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 6044 | &thermal_temp_input8_group); |
| 6045 | if (res) |
| 6046 | return res; |
| 6047 | break; |
| 6048 | case TPACPI_THERMAL_NONE: |
| 6049 | default: |
| 6050 | return 1; |
| 6051 | } |
| 6052 | |
| 6053 | return 0; |
| 6054 | } |
| 6055 | |
| 6056 | static void thermal_exit(void) |
| 6057 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6058 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 6059 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6060 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 6061 | &thermal_temp_input16_group); |
| 6062 | break; |
| 6063 | case TPACPI_THERMAL_TPEC_8: |
| 6064 | case TPACPI_THERMAL_ACPI_TMP07: |
| 6065 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6066 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Roel Kluin | f04d5e0 | 2010-02-02 14:37:58 -0800 | [diff] [blame] | 6067 | &thermal_temp_input8_group); |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 6068 | break; |
| 6069 | case TPACPI_THERMAL_NONE: |
| 6070 | default: |
| 6071 | break; |
| 6072 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6073 | } |
| 6074 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6075 | static int thermal_read(struct seq_file *m) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6076 | { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6077 | int n, i; |
| 6078 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6079 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6080 | n = thermal_get_sensors(&t); |
| 6081 | if (unlikely(n < 0)) |
| 6082 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6083 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6084 | seq_printf(m, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6085 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6086 | if (n > 0) { |
| 6087 | for (i = 0; i < (n - 1); i++) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6088 | seq_printf(m, "%d ", t.temp[i] / 1000); |
| 6089 | seq_printf(m, "%d\n", t.temp[i] / 1000); |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6090 | } else |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6091 | seq_printf(m, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6092 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6093 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6094 | } |
| 6095 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6096 | static struct ibm_struct thermal_driver_data = { |
| 6097 | .name = "thermal", |
| 6098 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 6099 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6100 | }; |
| 6101 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6102 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6103 | * Backlight/brightness subdriver |
| 6104 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 6105 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6106 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 6107 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6108 | /* |
| 6109 | * ThinkPads can read brightness from two places: EC HBRV (0x31), or |
| 6110 | * CMOS NVRAM byte 0x5E, bits 0-3. |
| 6111 | * |
| 6112 | * EC HBRV (0x31) has the following layout |
| 6113 | * Bit 7: unknown function |
| 6114 | * Bit 6: unknown function |
| 6115 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 6116 | * Bit 4: must be set to zero to avoid problems |
| 6117 | * Bit 3-0: backlight brightness level |
| 6118 | * |
| 6119 | * brightness_get_raw returns status data in the HBRV layout |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 6120 | * |
| 6121 | * WARNING: The X61 has been verified to use HBRV for something else, so |
| 6122 | * this should be used _only_ on IBM ThinkPads, and maybe with some careful |
| 6123 | * testing on the very early *60 Lenovo models... |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6124 | */ |
| 6125 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6126 | enum { |
| 6127 | TP_EC_BACKLIGHT = 0x31, |
| 6128 | |
| 6129 | /* TP_EC_BACKLIGHT bitmasks */ |
| 6130 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 6131 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 6132 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 6133 | }; |
| 6134 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6135 | enum tpacpi_brightness_access_mode { |
| 6136 | TPACPI_BRGHT_MODE_AUTO = 0, /* Not implemented yet */ |
| 6137 | TPACPI_BRGHT_MODE_EC, /* EC control */ |
| 6138 | TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */ |
| 6139 | TPACPI_BRGHT_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 6140 | TPACPI_BRGHT_MODE_MAX |
| 6141 | }; |
| 6142 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 6143 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6144 | |
| 6145 | static enum tpacpi_brightness_access_mode brightness_mode = |
| 6146 | TPACPI_BRGHT_MODE_MAX; |
| 6147 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6148 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 6149 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6150 | static struct mutex brightness_mutex; |
| 6151 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6152 | /* NVRAM brightness access, |
| 6153 | * call with brightness_mutex held! */ |
| 6154 | static unsigned int tpacpi_brightness_nvram_get(void) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6155 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6156 | u8 lnvram; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6157 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6158 | lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 6159 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 6160 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6161 | lnvram &= bright_maxlvl; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6162 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6163 | return lnvram; |
| 6164 | } |
| 6165 | |
| 6166 | static void tpacpi_brightness_checkpoint_nvram(void) |
| 6167 | { |
| 6168 | u8 lec = 0; |
| 6169 | u8 b_nvram; |
| 6170 | |
| 6171 | if (brightness_mode != TPACPI_BRGHT_MODE_ECNVRAM) |
| 6172 | return; |
| 6173 | |
| 6174 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 6175 | "trying to checkpoint backlight level to NVRAM...\n"); |
| 6176 | |
| 6177 | if (mutex_lock_killable(&brightness_mutex) < 0) |
| 6178 | return; |
| 6179 | |
| 6180 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 6181 | goto unlock; |
| 6182 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
| 6183 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 6184 | |
| 6185 | if (lec != ((b_nvram & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 6186 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS)) { |
| 6187 | /* NVRAM needs update */ |
| 6188 | b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS << |
| 6189 | TP_NVRAM_POS_LEVEL_BRIGHTNESS); |
| 6190 | b_nvram |= lec; |
| 6191 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_BRIGHTNESS); |
| 6192 | dbg_printk(TPACPI_DBG_BRGHT, |
| 6193 | "updated NVRAM backlight level to %u (0x%02x)\n", |
| 6194 | (unsigned int) lec, (unsigned int) b_nvram); |
| 6195 | } else |
| 6196 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 6197 | "NVRAM backlight level already is %u (0x%02x)\n", |
| 6198 | (unsigned int) lec, (unsigned int) b_nvram); |
| 6199 | |
| 6200 | unlock: |
| 6201 | mutex_unlock(&brightness_mutex); |
| 6202 | } |
| 6203 | |
| 6204 | |
| 6205 | /* call with brightness_mutex held! */ |
| 6206 | static int tpacpi_brightness_get_raw(int *status) |
| 6207 | { |
| 6208 | u8 lec = 0; |
| 6209 | |
| 6210 | switch (brightness_mode) { |
| 6211 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 6212 | *status = tpacpi_brightness_nvram_get(); |
| 6213 | return 0; |
| 6214 | case TPACPI_BRGHT_MODE_EC: |
| 6215 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 6216 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 6217 | return -EIO; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6218 | *status = lec; |
| 6219 | return 0; |
| 6220 | default: |
| 6221 | return -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6222 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | /* call with brightness_mutex held! */ |
| 6226 | /* do NOT call with illegal backlight level value */ |
| 6227 | static int tpacpi_brightness_set_ec(unsigned int value) |
| 6228 | { |
| 6229 | u8 lec = 0; |
| 6230 | |
| 6231 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 6232 | return -EIO; |
| 6233 | |
| 6234 | if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT, |
| 6235 | (lec & TP_EC_BACKLIGHT_CMDMSK) | |
| 6236 | (value & TP_EC_BACKLIGHT_LVLMSK)))) |
| 6237 | return -EIO; |
| 6238 | |
| 6239 | return 0; |
| 6240 | } |
| 6241 | |
| 6242 | /* call with brightness_mutex held! */ |
| 6243 | static int tpacpi_brightness_set_ucmsstep(unsigned int value) |
| 6244 | { |
| 6245 | int cmos_cmd, inc; |
| 6246 | unsigned int current_value, i; |
| 6247 | |
| 6248 | current_value = tpacpi_brightness_nvram_get(); |
| 6249 | |
| 6250 | if (value == current_value) |
| 6251 | return 0; |
| 6252 | |
| 6253 | cmos_cmd = (value > current_value) ? |
| 6254 | TP_CMOS_BRIGHTNESS_UP : |
| 6255 | TP_CMOS_BRIGHTNESS_DOWN; |
| 6256 | inc = (value > current_value) ? 1 : -1; |
| 6257 | |
| 6258 | for (i = current_value; i != value; i += inc) |
| 6259 | if (issue_thinkpad_cmos_command(cmos_cmd)) |
| 6260 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6261 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6262 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6266 | static int brightness_set(unsigned int value) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6267 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6268 | int res; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6269 | |
Andrey Utkin | bd3c7b9e | 2014-07-15 01:56:21 +0300 | [diff] [blame] | 6270 | if (value > bright_maxlvl) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6271 | return -EINVAL; |
| 6272 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6273 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 6274 | "set backlight level to %d\n", value); |
| 6275 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6276 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6277 | if (res < 0) |
| 6278 | return res; |
| 6279 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6280 | switch (brightness_mode) { |
| 6281 | case TPACPI_BRGHT_MODE_EC: |
| 6282 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 6283 | res = tpacpi_brightness_set_ec(value); |
| 6284 | break; |
| 6285 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 6286 | res = tpacpi_brightness_set_ucmsstep(value); |
| 6287 | break; |
| 6288 | default: |
| 6289 | res = -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6290 | } |
| 6291 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6292 | mutex_unlock(&brightness_mutex); |
| 6293 | return res; |
| 6294 | } |
| 6295 | |
| 6296 | /* sysfs backlight class ----------------------------------------------- */ |
| 6297 | |
| 6298 | static int brightness_update_status(struct backlight_device *bd) |
| 6299 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6300 | unsigned int level = |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6301 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 6302 | bd->props.power == FB_BLANK_UNBLANK) ? |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6303 | bd->props.brightness : 0; |
| 6304 | |
| 6305 | dbg_printk(TPACPI_DBG_BRGHT, |
| 6306 | "backlight: attempt to set level to %d\n", |
| 6307 | level); |
| 6308 | |
| 6309 | /* it is the backlight class's job (caller) to handle |
| 6310 | * EINTR and other errors properly */ |
| 6311 | return brightness_set(level); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6312 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 6313 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6314 | static int brightness_get(struct backlight_device *bd) |
| 6315 | { |
| 6316 | int status, res; |
| 6317 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6318 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6319 | if (res < 0) |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6320 | return 0; |
| 6321 | |
| 6322 | res = tpacpi_brightness_get_raw(&status); |
| 6323 | |
| 6324 | mutex_unlock(&brightness_mutex); |
| 6325 | |
| 6326 | if (res < 0) |
| 6327 | return 0; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6328 | |
| 6329 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 6330 | } |
| 6331 | |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6332 | static void tpacpi_brightness_notify_change(void) |
| 6333 | { |
| 6334 | backlight_force_update(ibm_backlight_device, |
| 6335 | BACKLIGHT_UPDATE_HOTKEY); |
| 6336 | } |
| 6337 | |
Lionel Debroux | acc2472 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 6338 | static const struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6339 | .get_brightness = brightness_get, |
| 6340 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6341 | }; |
| 6342 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6343 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6344 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6345 | /* |
| 6346 | * Call _BCL method of video device. On some ThinkPads this will |
| 6347 | * switch the firmware to the ACPI brightness control mode. |
| 6348 | */ |
| 6349 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6350 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 6351 | { |
| 6352 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 6353 | union acpi_object *obj; |
Aaron Lu | 46445b6 | 2013-10-11 21:27:46 +0800 | [diff] [blame] | 6354 | struct acpi_device *device, *child; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6355 | int rc; |
| 6356 | |
Aaron Lu | 46445b6 | 2013-10-11 21:27:46 +0800 | [diff] [blame] | 6357 | if (acpi_bus_get_device(handle, &device)) |
| 6358 | return 0; |
| 6359 | |
| 6360 | rc = 0; |
| 6361 | list_for_each_entry(child, &device->children, node) { |
| 6362 | acpi_status status = acpi_evaluate_object(child->handle, "_BCL", |
| 6363 | NULL, &buffer); |
| 6364 | if (ACPI_FAILURE(status)) |
| 6365 | continue; |
| 6366 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6367 | obj = (union acpi_object *)buffer.pointer; |
| 6368 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6369 | pr_err("Unknown _BCL data, please report this to %s\n", |
Aaron Lu | 46445b6 | 2013-10-11 21:27:46 +0800 | [diff] [blame] | 6370 | TPACPI_MAIL); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6371 | rc = 0; |
| 6372 | } else { |
| 6373 | rc = obj->package.count; |
| 6374 | } |
Aaron Lu | 46445b6 | 2013-10-11 21:27:46 +0800 | [diff] [blame] | 6375 | break; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6376 | } |
| 6377 | |
| 6378 | kfree(buffer.pointer); |
| 6379 | return rc; |
| 6380 | } |
| 6381 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6382 | |
| 6383 | /* |
| 6384 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 6385 | */ |
| 6386 | static unsigned int __init tpacpi_check_std_acpi_brightness_support(void) |
| 6387 | { |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6388 | acpi_handle video_device; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6389 | int bcl_levels = 0; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6390 | |
Aaron Lu | 46445b6 | 2013-10-11 21:27:46 +0800 | [diff] [blame] | 6391 | tpacpi_acpi_handle_locate("video", NULL, &video_device); |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6392 | if (video_device) |
| 6393 | bcl_levels = tpacpi_query_bcl_levels(video_device); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6394 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6395 | tp_features.bright_acpimode = (bcl_levels > 0); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6396 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6397 | return (bcl_levels > 2) ? (bcl_levels - 2) : 0; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6398 | } |
| 6399 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6400 | /* |
| 6401 | * These are only useful for models that have only one possibility |
| 6402 | * of GPU. If the BIOS model handles both ATI and Intel, don't use |
| 6403 | * these quirks. |
| 6404 | */ |
| 6405 | #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */ |
| 6406 | #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */ |
| 6407 | #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */ |
| 6408 | |
| 6409 | static const struct tpacpi_quirk brightness_quirk_table[] __initconst = { |
| 6410 | /* Models with ATI GPUs known to require ECNVRAM mode */ |
| 6411 | TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */ |
| 6412 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6413 | /* Models with ATI GPUs that can use ECNVRAM */ |
Henrique de Moraes Holschuh | 7d1894d | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 6414 | TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), /* R50,51 T40-42 */ |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6415 | TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
Henrique de Moraes Holschuh | 7d1894d | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 6416 | TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC), /* R52 */ |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6417 | TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6418 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6419 | /* Models with Intel Extreme Graphics 2 */ |
Henrique de Moraes Holschuh | 7d1894d | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 6420 | TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), /* X40 */ |
Henrique de Moraes Holschuh | a9f8eac | 2009-12-09 01:36:21 +0000 | [diff] [blame] | 6421 | TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6422 | TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6423 | |
| 6424 | /* Models with Intel GMA900 */ |
| 6425 | TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC), /* T43, R52 */ |
| 6426 | TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC), /* X41 */ |
| 6427 | TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC), /* X41 Tablet */ |
| 6428 | }; |
| 6429 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6430 | /* |
| 6431 | * Returns < 0 for error, otherwise sets tp_features.bright_* |
| 6432 | * and bright_maxlvl. |
| 6433 | */ |
| 6434 | static void __init tpacpi_detect_brightness_capabilities(void) |
| 6435 | { |
| 6436 | unsigned int b; |
| 6437 | |
| 6438 | vdbg_printk(TPACPI_DBG_INIT, |
| 6439 | "detecting firmware brightness interface capabilities\n"); |
| 6440 | |
| 6441 | /* we could run a quirks check here (same table used by |
| 6442 | * brightness_init) if needed */ |
| 6443 | |
| 6444 | /* |
| 6445 | * We always attempt to detect acpi support, so as to switch |
| 6446 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 6447 | * going to publish a backlight interface |
| 6448 | */ |
| 6449 | b = tpacpi_check_std_acpi_brightness_support(); |
| 6450 | switch (b) { |
| 6451 | case 16: |
| 6452 | bright_maxlvl = 15; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6453 | pr_info("detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6454 | break; |
| 6455 | case 8: |
| 6456 | case 0: |
| 6457 | bright_maxlvl = 7; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6458 | pr_info("detected a 8-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6459 | break; |
| 6460 | default: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6461 | pr_err("Unsupported brightness interface, " |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6462 | "please contact %s\n", TPACPI_MAIL); |
| 6463 | tp_features.bright_unkfw = 1; |
| 6464 | bright_maxlvl = b - 1; |
| 6465 | } |
| 6466 | } |
| 6467 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6468 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6469 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 6470 | struct backlight_properties props; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6471 | int b; |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6472 | unsigned long quirks; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6473 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6474 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 6475 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6476 | mutex_init(&brightness_mutex); |
| 6477 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6478 | quirks = tpacpi_check_quirks(brightness_quirk_table, |
| 6479 | ARRAY_SIZE(brightness_quirk_table)); |
| 6480 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6481 | /* tpacpi_detect_brightness_capabilities() must have run already */ |
Thomas Renninger | 2dba1b5 | 2008-08-01 17:38:03 +0200 | [diff] [blame] | 6482 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6483 | /* if it is unknown, we don't handle it: it wouldn't be safe */ |
| 6484 | if (tp_features.bright_unkfw) |
| 6485 | return 1; |
| 6486 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6487 | if (!brightness_enable) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6488 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6489 | "brightness support disabled by " |
| 6490 | "module parameter\n"); |
| 6491 | return 1; |
| 6492 | } |
| 6493 | |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6494 | if (acpi_video_backlight_support()) { |
| 6495 | if (brightness_enable > 1) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6496 | pr_info("Standard ACPI backlight interface " |
| 6497 | "available, not loading native one\n"); |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6498 | return 1; |
| 6499 | } else if (brightness_enable == 1) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6500 | pr_warn("Cannot enable backlight brightness support, " |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6501 | "ACPI is already handling it. Refer to the " |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6502 | "acpi_backlight kernel parameter.\n"); |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6503 | return 1; |
| 6504 | } |
| 6505 | } else if (tp_features.bright_acpimode && brightness_enable > 1) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6506 | pr_notice("Standard ACPI backlight interface not " |
| 6507 | "available, thinkpad_acpi native " |
| 6508 | "brightness control enabled\n"); |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6509 | } |
| 6510 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6511 | /* |
| 6512 | * Check for module parameter bogosity, note that we |
| 6513 | * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be |
| 6514 | * able to detect "unspecified" |
| 6515 | */ |
| 6516 | if (brightness_mode > TPACPI_BRGHT_MODE_MAX) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6517 | return -EINVAL; |
| 6518 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6519 | /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */ |
| 6520 | if (brightness_mode == TPACPI_BRGHT_MODE_AUTO || |
| 6521 | brightness_mode == TPACPI_BRGHT_MODE_MAX) { |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6522 | if (quirks & TPACPI_BRGHT_Q_EC) |
| 6523 | brightness_mode = TPACPI_BRGHT_MODE_ECNVRAM; |
| 6524 | else |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6525 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
| 6526 | |
| 6527 | dbg_printk(TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6528 | "driver auto-selected brightness_mode=%d\n", |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6529 | brightness_mode); |
| 6530 | } |
| 6531 | |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 6532 | /* Safety */ |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 6533 | if (!tpacpi_is_ibm() && |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 6534 | (brightness_mode == TPACPI_BRGHT_MODE_ECNVRAM || |
| 6535 | brightness_mode == TPACPI_BRGHT_MODE_EC)) |
| 6536 | return -EINVAL; |
| 6537 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6538 | if (tpacpi_brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6539 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6540 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 6541 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 6542 | props.type = BACKLIGHT_PLATFORM; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6543 | props.max_brightness = bright_maxlvl; |
| 6544 | props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 6545 | ibm_backlight_device = backlight_device_register(TPACPI_BACKLIGHT_DEV_NAME, |
| 6546 | NULL, NULL, |
| 6547 | &ibm_backlight_data, |
| 6548 | &props); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6549 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6550 | int rc = PTR_ERR(ibm_backlight_device); |
| 6551 | ibm_backlight_device = NULL; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6552 | pr_err("Could not register backlight device\n"); |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6553 | return rc; |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6554 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6555 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6556 | "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6557 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6558 | if (quirks & TPACPI_BRGHT_Q_ASK) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6559 | pr_notice("brightness: will use unverified default: " |
| 6560 | "brightness_mode=%d\n", brightness_mode); |
| 6561 | pr_notice("brightness: please report to %s whether it works well " |
| 6562 | "or not on your ThinkPad\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6563 | } |
| 6564 | |
Henrique de Moraes Holschuh | 7d9745c | 2010-05-16 19:45:57 -0300 | [diff] [blame] | 6565 | /* Added by mistake in early 2007. Probably useless, but it could |
| 6566 | * be working around some unknown firmware problem where the value |
| 6567 | * read at startup doesn't match the real hardware state... so leave |
| 6568 | * it in place just in case */ |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6569 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6570 | |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6571 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6572 | "brightness: registering brightness hotkeys " |
| 6573 | "as change notification\n"); |
| 6574 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
| 6575 | | TP_ACPI_HKEY_BRGHTUP_MASK |
Joe Perches | 3098064 | 2010-11-14 19:04:38 -0800 | [diff] [blame] | 6576 | | TP_ACPI_HKEY_BRGHTDWN_MASK); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6577 | return 0; |
| 6578 | } |
| 6579 | |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 6580 | static void brightness_suspend(void) |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6581 | { |
| 6582 | tpacpi_brightness_checkpoint_nvram(); |
| 6583 | } |
| 6584 | |
| 6585 | static void brightness_shutdown(void) |
| 6586 | { |
| 6587 | tpacpi_brightness_checkpoint_nvram(); |
| 6588 | } |
| 6589 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6590 | static void brightness_exit(void) |
| 6591 | { |
| 6592 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6593 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6594 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6595 | backlight_device_unregister(ibm_backlight_device); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6596 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6597 | |
| 6598 | tpacpi_brightness_checkpoint_nvram(); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6599 | } |
| 6600 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6601 | static int brightness_read(struct seq_file *m) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6602 | { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6603 | int level; |
| 6604 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6605 | level = brightness_get(NULL); |
| 6606 | if (level < 0) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6607 | seq_printf(m, "level:\t\tunreadable\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6608 | } else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6609 | seq_printf(m, "level:\t\t%d\n", level); |
| 6610 | seq_printf(m, "commands:\tup, down\n"); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6611 | seq_printf(m, "commands:\tlevel <level> (<level> is 0-%d)\n", |
| 6612 | bright_maxlvl); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6613 | } |
| 6614 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6615 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6616 | } |
| 6617 | |
| 6618 | static int brightness_write(char *buf) |
| 6619 | { |
| 6620 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6621 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6622 | char *cmd; |
| 6623 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6624 | level = brightness_get(NULL); |
| 6625 | if (level < 0) |
| 6626 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6627 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6628 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6629 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6630 | if (level < bright_maxlvl) |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6631 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6632 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6633 | if (level > 0) |
| 6634 | level--; |
| 6635 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6636 | level >= 0 && level <= bright_maxlvl) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6637 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6638 | } else |
| 6639 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6640 | } |
| 6641 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6642 | tpacpi_disclose_usertask("procfs brightness", |
| 6643 | "set level to %d\n", level); |
| 6644 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6645 | /* |
| 6646 | * Now we know what the final level should be, so we try to set it. |
| 6647 | * Doing it this way makes the syscall restartable in case of EINTR |
| 6648 | */ |
| 6649 | rc = brightness_set(level); |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6650 | if (!rc && ibm_backlight_device) |
| 6651 | backlight_force_update(ibm_backlight_device, |
| 6652 | BACKLIGHT_UPDATE_SYSFS); |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 6653 | return (rc == -EINTR) ? -ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6654 | } |
| 6655 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6656 | static struct ibm_struct brightness_driver_data = { |
| 6657 | .name = "brightness", |
| 6658 | .read = brightness_read, |
| 6659 | .write = brightness_write, |
| 6660 | .exit = brightness_exit, |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6661 | .suspend = brightness_suspend, |
| 6662 | .shutdown = brightness_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6663 | }; |
| 6664 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6665 | /************************************************************************* |
| 6666 | * Volume subdriver |
| 6667 | */ |
| 6668 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6669 | /* |
| 6670 | * IBM ThinkPads have a simple volume controller with MUTE gating. |
| 6671 | * Very early Lenovo ThinkPads follow the IBM ThinkPad spec. |
| 6672 | * |
| 6673 | * Since the *61 series (and probably also the later *60 series), Lenovo |
| 6674 | * ThinkPads only implement the MUTE gate. |
| 6675 | * |
| 6676 | * EC register 0x30 |
| 6677 | * Bit 6: MUTE (1 mutes sound) |
| 6678 | * Bit 3-0: Volume |
| 6679 | * Other bits should be zero as far as we know. |
| 6680 | * |
| 6681 | * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and |
| 6682 | * bits 3-0 (volume). Other bits in NVRAM may have other functions, |
| 6683 | * such as bit 7 which is used to detect repeated presses of MUTE, |
| 6684 | * and we leave them unchanged. |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 6685 | * |
| 6686 | * On newer Lenovo ThinkPads, the EC can automatically change the volume |
| 6687 | * in response to user input. Unfortunately, this rarely works well. |
| 6688 | * The laptop changes the state of its internal MUTE gate and, on some |
| 6689 | * models, sends KEY_MUTE, causing any user code that responds to the |
| 6690 | * mute button to get confused. The hardware MUTE gate is also |
| 6691 | * unnecessary, since user code can handle the mute button without |
| 6692 | * kernel or EC help. |
| 6693 | * |
| 6694 | * To avoid confusing userspace, we simply disable all EC-based mute |
| 6695 | * and volume controls when possible. |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6696 | */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6697 | |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 6698 | #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT |
| 6699 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6700 | #define TPACPI_ALSA_DRVNAME "ThinkPad EC" |
| 6701 | #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control" |
| 6702 | #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME |
| 6703 | |
Takashi Iwai | cab6661 | 2013-10-24 16:06:32 +0200 | [diff] [blame] | 6704 | #if SNDRV_CARDS <= 32 |
| 6705 | #define DEFAULT_ALSA_IDX ~((1 << (SNDRV_CARDS - 3)) - 1) |
| 6706 | #else |
| 6707 | #define DEFAULT_ALSA_IDX ~((1 << (32 - 3)) - 1) |
| 6708 | #endif |
| 6709 | static int alsa_index = DEFAULT_ALSA_IDX; /* last three slots */ |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6710 | static char *alsa_id = "ThinkPadEC"; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 6711 | static bool alsa_enable = SNDRV_DEFAULT_ENABLE1; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6712 | |
| 6713 | struct tpacpi_alsa_data { |
| 6714 | struct snd_card *card; |
| 6715 | struct snd_ctl_elem_id *ctl_mute_id; |
| 6716 | struct snd_ctl_elem_id *ctl_vol_id; |
| 6717 | }; |
| 6718 | |
| 6719 | static struct snd_card *alsa_card; |
| 6720 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6721 | enum { |
| 6722 | TP_EC_AUDIO = 0x30, |
| 6723 | |
| 6724 | /* TP_EC_AUDIO bits */ |
| 6725 | TP_EC_AUDIO_MUTESW = 6, |
| 6726 | |
| 6727 | /* TP_EC_AUDIO bitmasks */ |
| 6728 | TP_EC_AUDIO_LVL_MSK = 0x0F, |
| 6729 | TP_EC_AUDIO_MUTESW_MSK = (1 << TP_EC_AUDIO_MUTESW), |
| 6730 | |
| 6731 | /* Maximum volume */ |
| 6732 | TP_EC_VOLUME_MAX = 14, |
| 6733 | }; |
| 6734 | |
| 6735 | enum tpacpi_volume_access_mode { |
| 6736 | TPACPI_VOL_MODE_AUTO = 0, /* Not implemented yet */ |
| 6737 | TPACPI_VOL_MODE_EC, /* Pure EC control */ |
| 6738 | TPACPI_VOL_MODE_UCMS_STEP, /* UCMS step-based control: N/A */ |
| 6739 | TPACPI_VOL_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 6740 | TPACPI_VOL_MODE_MAX |
| 6741 | }; |
| 6742 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6743 | enum tpacpi_volume_capabilities { |
| 6744 | TPACPI_VOL_CAP_AUTO = 0, /* Use white/blacklist */ |
| 6745 | TPACPI_VOL_CAP_VOLMUTE, /* Output vol and mute */ |
| 6746 | TPACPI_VOL_CAP_MUTEONLY, /* Output mute only */ |
| 6747 | TPACPI_VOL_CAP_MAX |
| 6748 | }; |
| 6749 | |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 6750 | enum tpacpi_mute_btn_mode { |
| 6751 | TP_EC_MUTE_BTN_LATCH = 0, /* Mute mutes; up/down unmutes */ |
| 6752 | /* We don't know what mode 1 is. */ |
| 6753 | TP_EC_MUTE_BTN_NONE = 2, /* Mute and up/down are just keys */ |
| 6754 | TP_EC_MUTE_BTN_TOGGLE = 3, /* Mute toggles; up/down unmutes */ |
| 6755 | }; |
| 6756 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6757 | static enum tpacpi_volume_access_mode volume_mode = |
| 6758 | TPACPI_VOL_MODE_MAX; |
| 6759 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6760 | static enum tpacpi_volume_capabilities volume_capabilities; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 6761 | static bool volume_control_allowed; |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 6762 | static bool software_mute_requested = true; |
| 6763 | static bool software_mute_active; |
| 6764 | static int software_mute_orig_mode; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6765 | |
| 6766 | /* |
| 6767 | * Used to syncronize writers to TP_EC_AUDIO and |
| 6768 | * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write |
| 6769 | */ |
| 6770 | static struct mutex volume_mutex; |
| 6771 | |
| 6772 | static void tpacpi_volume_checkpoint_nvram(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6773 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6774 | u8 lec = 0; |
| 6775 | u8 b_nvram; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6776 | u8 ec_mask; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6777 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6778 | if (volume_mode != TPACPI_VOL_MODE_ECNVRAM) |
| 6779 | return; |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 6780 | if (!volume_control_allowed) |
| 6781 | return; |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 6782 | if (software_mute_active) |
| 6783 | return; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6784 | |
| 6785 | vdbg_printk(TPACPI_DBG_MIXER, |
| 6786 | "trying to checkpoint mixer state to NVRAM...\n"); |
| 6787 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6788 | if (tp_features.mixer_no_level_control) |
| 6789 | ec_mask = TP_EC_AUDIO_MUTESW_MSK; |
| 6790 | else |
| 6791 | ec_mask = TP_EC_AUDIO_MUTESW_MSK | TP_EC_AUDIO_LVL_MSK; |
| 6792 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6793 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6794 | return; |
| 6795 | |
| 6796 | if (unlikely(!acpi_ec_read(TP_EC_AUDIO, &lec))) |
| 6797 | goto unlock; |
| 6798 | lec &= ec_mask; |
| 6799 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 6800 | |
| 6801 | if (lec != (b_nvram & ec_mask)) { |
| 6802 | /* NVRAM needs update */ |
| 6803 | b_nvram &= ~ec_mask; |
| 6804 | b_nvram |= lec; |
| 6805 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_MIXER); |
| 6806 | dbg_printk(TPACPI_DBG_MIXER, |
| 6807 | "updated NVRAM mixer status to 0x%02x (0x%02x)\n", |
| 6808 | (unsigned int) lec, (unsigned int) b_nvram); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6809 | } else { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6810 | vdbg_printk(TPACPI_DBG_MIXER, |
| 6811 | "NVRAM mixer status already is 0x%02x (0x%02x)\n", |
| 6812 | (unsigned int) lec, (unsigned int) b_nvram); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6813 | } |
| 6814 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6815 | unlock: |
| 6816 | mutex_unlock(&volume_mutex); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6817 | } |
| 6818 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6819 | static int volume_get_status_ec(u8 *status) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6820 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6821 | u8 s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6822 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6823 | if (!acpi_ec_read(TP_EC_AUDIO, &s)) |
| 6824 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6825 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6826 | *status = s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6827 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6828 | dbg_printk(TPACPI_DBG_MIXER, "status 0x%02x\n", s); |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6829 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6830 | return 0; |
| 6831 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6832 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6833 | static int volume_get_status(u8 *status) |
| 6834 | { |
| 6835 | return volume_get_status_ec(status); |
| 6836 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6837 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6838 | static int volume_set_status_ec(const u8 status) |
| 6839 | { |
| 6840 | if (!acpi_ec_write(TP_EC_AUDIO, status)) |
| 6841 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6842 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6843 | dbg_printk(TPACPI_DBG_MIXER, "set EC mixer to 0x%02x\n", status); |
| 6844 | |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 6845 | /* |
| 6846 | * On X200s, and possibly on others, it can take a while for |
| 6847 | * reads to become correct. |
| 6848 | */ |
| 6849 | msleep(1); |
| 6850 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6851 | return 0; |
| 6852 | } |
| 6853 | |
| 6854 | static int volume_set_status(const u8 status) |
| 6855 | { |
| 6856 | return volume_set_status_ec(status); |
| 6857 | } |
| 6858 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6859 | /* returns < 0 on error, 0 on no change, 1 on change */ |
| 6860 | static int __volume_set_mute_ec(const bool mute) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6861 | { |
| 6862 | int rc; |
| 6863 | u8 s, n; |
| 6864 | |
| 6865 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6866 | return -EINTR; |
| 6867 | |
| 6868 | rc = volume_get_status_ec(&s); |
| 6869 | if (rc) |
| 6870 | goto unlock; |
| 6871 | |
| 6872 | n = (mute) ? s | TP_EC_AUDIO_MUTESW_MSK : |
| 6873 | s & ~TP_EC_AUDIO_MUTESW_MSK; |
| 6874 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6875 | if (n != s) { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6876 | rc = volume_set_status_ec(n); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6877 | if (!rc) |
| 6878 | rc = 1; |
| 6879 | } |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6880 | |
| 6881 | unlock: |
| 6882 | mutex_unlock(&volume_mutex); |
| 6883 | return rc; |
| 6884 | } |
| 6885 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6886 | static int volume_alsa_set_mute(const bool mute) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6887 | { |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6888 | dbg_printk(TPACPI_DBG_MIXER, "ALSA: trying to %smute\n", |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6889 | (mute) ? "" : "un"); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6890 | return __volume_set_mute_ec(mute); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6891 | } |
| 6892 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6893 | static int volume_set_mute(const bool mute) |
| 6894 | { |
| 6895 | int rc; |
| 6896 | |
| 6897 | dbg_printk(TPACPI_DBG_MIXER, "trying to %smute\n", |
| 6898 | (mute) ? "" : "un"); |
| 6899 | |
| 6900 | rc = __volume_set_mute_ec(mute); |
| 6901 | return (rc < 0) ? rc : 0; |
| 6902 | } |
| 6903 | |
| 6904 | /* returns < 0 on error, 0 on no change, 1 on change */ |
| 6905 | static int __volume_set_volume_ec(const u8 vol) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6906 | { |
| 6907 | int rc; |
| 6908 | u8 s, n; |
| 6909 | |
| 6910 | if (vol > TP_EC_VOLUME_MAX) |
| 6911 | return -EINVAL; |
| 6912 | |
| 6913 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6914 | return -EINTR; |
| 6915 | |
| 6916 | rc = volume_get_status_ec(&s); |
| 6917 | if (rc) |
| 6918 | goto unlock; |
| 6919 | |
| 6920 | n = (s & ~TP_EC_AUDIO_LVL_MSK) | vol; |
| 6921 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6922 | if (n != s) { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6923 | rc = volume_set_status_ec(n); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6924 | if (!rc) |
| 6925 | rc = 1; |
| 6926 | } |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6927 | |
| 6928 | unlock: |
| 6929 | mutex_unlock(&volume_mutex); |
| 6930 | return rc; |
| 6931 | } |
| 6932 | |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 6933 | static int volume_set_software_mute(bool startup) |
| 6934 | { |
| 6935 | int result; |
| 6936 | |
| 6937 | if (!tpacpi_is_lenovo()) |
| 6938 | return -ENODEV; |
| 6939 | |
| 6940 | if (startup) { |
| 6941 | if (!acpi_evalf(ec_handle, &software_mute_orig_mode, |
| 6942 | "HAUM", "qd")) |
| 6943 | return -EIO; |
| 6944 | |
| 6945 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6946 | "Initial HAUM setting was %d\n", |
| 6947 | software_mute_orig_mode); |
| 6948 | } |
| 6949 | |
| 6950 | if (!acpi_evalf(ec_handle, &result, "SAUM", "qdd", |
| 6951 | (int)TP_EC_MUTE_BTN_NONE)) |
| 6952 | return -EIO; |
| 6953 | |
| 6954 | if (result != TP_EC_MUTE_BTN_NONE) |
| 6955 | pr_warn("Unexpected SAUM result %d\n", |
| 6956 | result); |
| 6957 | |
| 6958 | /* |
| 6959 | * In software mute mode, the standard codec controls take |
| 6960 | * precendence, so we unmute the ThinkPad HW switch at |
| 6961 | * startup. Just on case there are SAUM-capable ThinkPads |
| 6962 | * with level controls, set max HW volume as well. |
| 6963 | */ |
| 6964 | if (tp_features.mixer_no_level_control) |
| 6965 | result = volume_set_mute(false); |
| 6966 | else |
| 6967 | result = volume_set_status(TP_EC_VOLUME_MAX); |
| 6968 | |
| 6969 | if (result != 0) |
| 6970 | pr_warn("Failed to unmute the HW mute switch\n"); |
| 6971 | |
| 6972 | return 0; |
| 6973 | } |
| 6974 | |
| 6975 | static void volume_exit_software_mute(void) |
| 6976 | { |
| 6977 | int r; |
| 6978 | |
| 6979 | if (!acpi_evalf(ec_handle, &r, "SAUM", "qdd", software_mute_orig_mode) |
| 6980 | || r != software_mute_orig_mode) |
| 6981 | pr_warn("Failed to restore mute mode\n"); |
| 6982 | } |
| 6983 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6984 | static int volume_alsa_set_volume(const u8 vol) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6985 | { |
| 6986 | dbg_printk(TPACPI_DBG_MIXER, |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6987 | "ALSA: trying to set volume level to %hu\n", vol); |
| 6988 | return __volume_set_volume_ec(vol); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6989 | } |
| 6990 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6991 | static void volume_alsa_notify_change(void) |
| 6992 | { |
| 6993 | struct tpacpi_alsa_data *d; |
| 6994 | |
| 6995 | if (alsa_card && alsa_card->private_data) { |
| 6996 | d = alsa_card->private_data; |
| 6997 | if (d->ctl_mute_id) |
| 6998 | snd_ctl_notify(alsa_card, |
| 6999 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 7000 | d->ctl_mute_id); |
| 7001 | if (d->ctl_vol_id) |
| 7002 | snd_ctl_notify(alsa_card, |
| 7003 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 7004 | d->ctl_vol_id); |
| 7005 | } |
| 7006 | } |
| 7007 | |
| 7008 | static int volume_alsa_vol_info(struct snd_kcontrol *kcontrol, |
| 7009 | struct snd_ctl_elem_info *uinfo) |
| 7010 | { |
| 7011 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 7012 | uinfo->count = 1; |
| 7013 | uinfo->value.integer.min = 0; |
| 7014 | uinfo->value.integer.max = TP_EC_VOLUME_MAX; |
| 7015 | return 0; |
| 7016 | } |
| 7017 | |
| 7018 | static int volume_alsa_vol_get(struct snd_kcontrol *kcontrol, |
| 7019 | struct snd_ctl_elem_value *ucontrol) |
| 7020 | { |
| 7021 | u8 s; |
| 7022 | int rc; |
| 7023 | |
| 7024 | rc = volume_get_status(&s); |
| 7025 | if (rc < 0) |
| 7026 | return rc; |
| 7027 | |
| 7028 | ucontrol->value.integer.value[0] = s & TP_EC_AUDIO_LVL_MSK; |
| 7029 | return 0; |
| 7030 | } |
| 7031 | |
| 7032 | static int volume_alsa_vol_put(struct snd_kcontrol *kcontrol, |
| 7033 | struct snd_ctl_elem_value *ucontrol) |
| 7034 | { |
Henrique de Moraes Holschuh | 38e11cd | 2010-05-16 19:45:40 -0300 | [diff] [blame] | 7035 | tpacpi_disclose_usertask("ALSA", "set volume to %ld\n", |
| 7036 | ucontrol->value.integer.value[0]); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 7037 | return volume_alsa_set_volume(ucontrol->value.integer.value[0]); |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7038 | } |
| 7039 | |
| 7040 | #define volume_alsa_mute_info snd_ctl_boolean_mono_info |
| 7041 | |
| 7042 | static int volume_alsa_mute_get(struct snd_kcontrol *kcontrol, |
| 7043 | struct snd_ctl_elem_value *ucontrol) |
| 7044 | { |
| 7045 | u8 s; |
| 7046 | int rc; |
| 7047 | |
| 7048 | rc = volume_get_status(&s); |
| 7049 | if (rc < 0) |
| 7050 | return rc; |
| 7051 | |
| 7052 | ucontrol->value.integer.value[0] = |
| 7053 | (s & TP_EC_AUDIO_MUTESW_MSK) ? 0 : 1; |
| 7054 | return 0; |
| 7055 | } |
| 7056 | |
| 7057 | static int volume_alsa_mute_put(struct snd_kcontrol *kcontrol, |
| 7058 | struct snd_ctl_elem_value *ucontrol) |
| 7059 | { |
Henrique de Moraes Holschuh | 38e11cd | 2010-05-16 19:45:40 -0300 | [diff] [blame] | 7060 | tpacpi_disclose_usertask("ALSA", "%smute\n", |
| 7061 | ucontrol->value.integer.value[0] ? |
| 7062 | "un" : ""); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 7063 | return volume_alsa_set_mute(!ucontrol->value.integer.value[0]); |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7064 | } |
| 7065 | |
Mathias Krause | c3aa472 | 2014-07-16 19:43:17 +0200 | [diff] [blame] | 7066 | static struct snd_kcontrol_new volume_alsa_control_vol __initdata = { |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7067 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 7068 | .name = "Console Playback Volume", |
| 7069 | .index = 0, |
| 7070 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 7071 | .info = volume_alsa_vol_info, |
| 7072 | .get = volume_alsa_vol_get, |
| 7073 | }; |
| 7074 | |
Mathias Krause | c3aa472 | 2014-07-16 19:43:17 +0200 | [diff] [blame] | 7075 | static struct snd_kcontrol_new volume_alsa_control_mute __initdata = { |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7076 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 7077 | .name = "Console Playback Switch", |
| 7078 | .index = 0, |
| 7079 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 7080 | .info = volume_alsa_mute_info, |
| 7081 | .get = volume_alsa_mute_get, |
| 7082 | }; |
| 7083 | |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 7084 | static void volume_suspend(void) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7085 | { |
| 7086 | tpacpi_volume_checkpoint_nvram(); |
| 7087 | } |
| 7088 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7089 | static void volume_resume(void) |
| 7090 | { |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 7091 | if (software_mute_active) { |
| 7092 | if (volume_set_software_mute(false) < 0) |
| 7093 | pr_warn("Failed to restore software mute\n"); |
| 7094 | } else { |
| 7095 | volume_alsa_notify_change(); |
| 7096 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7097 | } |
| 7098 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7099 | static void volume_shutdown(void) |
| 7100 | { |
| 7101 | tpacpi_volume_checkpoint_nvram(); |
| 7102 | } |
| 7103 | |
| 7104 | static void volume_exit(void) |
| 7105 | { |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7106 | if (alsa_card) { |
| 7107 | snd_card_free(alsa_card); |
| 7108 | alsa_card = NULL; |
| 7109 | } |
| 7110 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7111 | tpacpi_volume_checkpoint_nvram(); |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 7112 | |
| 7113 | if (software_mute_active) |
| 7114 | volume_exit_software_mute(); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7115 | } |
| 7116 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7117 | static int __init volume_create_alsa_mixer(void) |
| 7118 | { |
| 7119 | struct snd_card *card; |
| 7120 | struct tpacpi_alsa_data *data; |
| 7121 | struct snd_kcontrol *ctl_vol; |
| 7122 | struct snd_kcontrol *ctl_mute; |
| 7123 | int rc; |
| 7124 | |
Takashi Iwai | 89235e5 | 2014-01-29 15:01:27 +0100 | [diff] [blame] | 7125 | rc = snd_card_new(&tpacpi_pdev->dev, |
| 7126 | alsa_index, alsa_id, THIS_MODULE, |
| 7127 | sizeof(struct tpacpi_alsa_data), &card); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 7128 | if (rc < 0 || !card) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7129 | pr_err("Failed to create ALSA card structures: %d\n", rc); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 7130 | return 1; |
| 7131 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7132 | |
| 7133 | BUG_ON(!card->private_data); |
| 7134 | data = card->private_data; |
| 7135 | data->card = card; |
| 7136 | |
| 7137 | strlcpy(card->driver, TPACPI_ALSA_DRVNAME, |
| 7138 | sizeof(card->driver)); |
| 7139 | strlcpy(card->shortname, TPACPI_ALSA_SHRTNAME, |
| 7140 | sizeof(card->shortname)); |
| 7141 | snprintf(card->mixername, sizeof(card->mixername), "ThinkPad EC %s", |
| 7142 | (thinkpad_id.ec_version_str) ? |
| 7143 | thinkpad_id.ec_version_str : "(unknown)"); |
| 7144 | snprintf(card->longname, sizeof(card->longname), |
| 7145 | "%s at EC reg 0x%02x, fw %s", card->shortname, TP_EC_AUDIO, |
| 7146 | (thinkpad_id.ec_version_str) ? |
| 7147 | thinkpad_id.ec_version_str : "unknown"); |
| 7148 | |
| 7149 | if (volume_control_allowed) { |
| 7150 | volume_alsa_control_vol.put = volume_alsa_vol_put; |
| 7151 | volume_alsa_control_vol.access = |
| 7152 | SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 7153 | |
| 7154 | volume_alsa_control_mute.put = volume_alsa_mute_put; |
| 7155 | volume_alsa_control_mute.access = |
| 7156 | SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 7157 | } |
| 7158 | |
| 7159 | if (!tp_features.mixer_no_level_control) { |
| 7160 | ctl_vol = snd_ctl_new1(&volume_alsa_control_vol, NULL); |
| 7161 | rc = snd_ctl_add(card, ctl_vol); |
| 7162 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7163 | pr_err("Failed to create ALSA volume control: %d\n", |
| 7164 | rc); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 7165 | goto err_exit; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7166 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7167 | data->ctl_vol_id = &ctl_vol->id; |
| 7168 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7169 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7170 | ctl_mute = snd_ctl_new1(&volume_alsa_control_mute, NULL); |
| 7171 | rc = snd_ctl_add(card, ctl_mute); |
| 7172 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7173 | pr_err("Failed to create ALSA mute control: %d\n", rc); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 7174 | goto err_exit; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7175 | } |
| 7176 | data->ctl_mute_id = &ctl_mute->id; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7177 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7178 | rc = snd_card_register(card); |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7179 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7180 | pr_err("Failed to register ALSA card: %d\n", rc); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 7181 | goto err_exit; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7182 | } |
| 7183 | |
| 7184 | alsa_card = card; |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 7185 | return 0; |
| 7186 | |
| 7187 | err_exit: |
| 7188 | snd_card_free(card); |
| 7189 | return 1; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7190 | } |
| 7191 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7192 | #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */ |
| 7193 | #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */ |
| 7194 | |
| 7195 | static const struct tpacpi_quirk volume_quirk_table[] __initconst = { |
| 7196 | /* Whitelist volume level on all IBM by default */ |
| 7197 | { .vendor = PCI_VENDOR_ID_IBM, |
| 7198 | .bios = TPACPI_MATCH_ANY, |
| 7199 | .ec = TPACPI_MATCH_ANY, |
| 7200 | .quirks = TPACPI_VOL_Q_LEVEL }, |
| 7201 | |
| 7202 | /* Lenovo models with volume control (needs confirmation) */ |
| 7203 | TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL), /* R60/i */ |
| 7204 | TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL), /* R60e/i */ |
| 7205 | TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL), /* T60/p */ |
| 7206 | TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL), /* X60/s */ |
| 7207 | TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL), /* X60t */ |
| 7208 | TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL), /* Z60 */ |
| 7209 | TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL), /* Z61 */ |
| 7210 | |
| 7211 | /* Whitelist mute-only on all Lenovo by default */ |
| 7212 | { .vendor = PCI_VENDOR_ID_LENOVO, |
| 7213 | .bios = TPACPI_MATCH_ANY, |
| 7214 | .ec = TPACPI_MATCH_ANY, |
| 7215 | .quirks = TPACPI_VOL_Q_MUTEONLY } |
| 7216 | }; |
| 7217 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7218 | static int __init volume_init(struct ibm_init_struct *iibm) |
| 7219 | { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7220 | unsigned long quirks; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7221 | int rc; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7222 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7223 | vdbg_printk(TPACPI_DBG_INIT, "initializing volume subdriver\n"); |
| 7224 | |
| 7225 | mutex_init(&volume_mutex); |
| 7226 | |
| 7227 | /* |
| 7228 | * Check for module parameter bogosity, note that we |
| 7229 | * init volume_mode to TPACPI_VOL_MODE_MAX in order to be |
| 7230 | * able to detect "unspecified" |
| 7231 | */ |
| 7232 | if (volume_mode > TPACPI_VOL_MODE_MAX) |
| 7233 | return -EINVAL; |
| 7234 | |
| 7235 | if (volume_mode == TPACPI_VOL_MODE_UCMS_STEP) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7236 | pr_err("UCMS step volume mode not implemented, " |
| 7237 | "please contact %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7238 | return 1; |
| 7239 | } |
| 7240 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7241 | if (volume_capabilities >= TPACPI_VOL_CAP_MAX) |
| 7242 | return -EINVAL; |
| 7243 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7244 | /* |
| 7245 | * The ALSA mixer is our primary interface. |
| 7246 | * When disabled, don't install the subdriver at all |
| 7247 | */ |
| 7248 | if (!alsa_enable) { |
| 7249 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 7250 | "ALSA mixer disabled by parameter, " |
| 7251 | "not loading volume subdriver...\n"); |
| 7252 | return 1; |
| 7253 | } |
| 7254 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7255 | quirks = tpacpi_check_quirks(volume_quirk_table, |
| 7256 | ARRAY_SIZE(volume_quirk_table)); |
| 7257 | |
| 7258 | switch (volume_capabilities) { |
| 7259 | case TPACPI_VOL_CAP_AUTO: |
| 7260 | if (quirks & TPACPI_VOL_Q_MUTEONLY) |
| 7261 | tp_features.mixer_no_level_control = 1; |
| 7262 | else if (quirks & TPACPI_VOL_Q_LEVEL) |
| 7263 | tp_features.mixer_no_level_control = 0; |
| 7264 | else |
| 7265 | return 1; /* no mixer */ |
| 7266 | break; |
| 7267 | case TPACPI_VOL_CAP_VOLMUTE: |
| 7268 | tp_features.mixer_no_level_control = 0; |
| 7269 | break; |
| 7270 | case TPACPI_VOL_CAP_MUTEONLY: |
| 7271 | tp_features.mixer_no_level_control = 1; |
| 7272 | break; |
| 7273 | default: |
| 7274 | return 1; |
| 7275 | } |
| 7276 | |
| 7277 | if (volume_capabilities != TPACPI_VOL_CAP_AUTO) |
| 7278 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 7279 | "using user-supplied volume_capabilities=%d\n", |
| 7280 | volume_capabilities); |
| 7281 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7282 | if (volume_mode == TPACPI_VOL_MODE_AUTO || |
| 7283 | volume_mode == TPACPI_VOL_MODE_MAX) { |
| 7284 | volume_mode = TPACPI_VOL_MODE_ECNVRAM; |
| 7285 | |
| 7286 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 7287 | "driver auto-selected volume_mode=%d\n", |
| 7288 | volume_mode); |
| 7289 | } else { |
| 7290 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 7291 | "using user-supplied volume_mode=%d\n", |
| 7292 | volume_mode); |
| 7293 | } |
| 7294 | |
| 7295 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7296 | "mute is supported, volume control is %s\n", |
| 7297 | str_supported(!tp_features.mixer_no_level_control)); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7298 | |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 7299 | if (software_mute_requested && volume_set_software_mute(true) == 0) { |
| 7300 | software_mute_active = true; |
| 7301 | } else { |
| 7302 | rc = volume_create_alsa_mixer(); |
| 7303 | if (rc) { |
| 7304 | pr_err("Could not create the ALSA mixer interface\n"); |
| 7305 | return rc; |
| 7306 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7307 | |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 7308 | pr_info("Console audio control enabled, mode: %s\n", |
| 7309 | (volume_control_allowed) ? |
| 7310 | "override (read/write)" : |
| 7311 | "monitor (read only)"); |
| 7312 | } |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7313 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7314 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 7315 | "registering volume hotkeys as change notification\n"); |
| 7316 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
| 7317 | | TP_ACPI_HKEY_VOLUP_MASK |
| 7318 | | TP_ACPI_HKEY_VOLDWN_MASK |
| 7319 | | TP_ACPI_HKEY_MUTE_MASK); |
| 7320 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7321 | return 0; |
| 7322 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7323 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7324 | static int volume_read(struct seq_file *m) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7325 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7326 | u8 status; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7327 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7328 | if (volume_get_status(&status) < 0) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7329 | seq_printf(m, "level:\t\tunreadable\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7330 | } else { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7331 | if (tp_features.mixer_no_level_control) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7332 | seq_printf(m, "level:\t\tunsupported\n"); |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7333 | else |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7334 | seq_printf(m, "level:\t\t%d\n", |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7335 | status & TP_EC_AUDIO_LVL_MSK); |
| 7336 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7337 | seq_printf(m, "mute:\t\t%s\n", |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7338 | onoff(status, TP_EC_AUDIO_MUTESW)); |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7339 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7340 | if (volume_control_allowed) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7341 | seq_printf(m, "commands:\tunmute, mute\n"); |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7342 | if (!tp_features.mixer_no_level_control) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7343 | seq_printf(m, |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7344 | "commands:\tup, down\n"); |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7345 | seq_printf(m, |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7346 | "commands:\tlevel <level>" |
| 7347 | " (<level> is 0-%d)\n", |
| 7348 | TP_EC_VOLUME_MAX); |
| 7349 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7350 | } |
| 7351 | } |
| 7352 | |
| 7353 | return 0; |
| 7354 | } |
| 7355 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7356 | static int volume_write(char *buf) |
| 7357 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7358 | u8 s; |
| 7359 | u8 new_level, new_mute; |
| 7360 | int l; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7361 | char *cmd; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7362 | int rc; |
| 7363 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7364 | /* |
| 7365 | * We do allow volume control at driver startup, so that the |
| 7366 | * user can set initial state through the volume=... parameter hack. |
| 7367 | */ |
| 7368 | if (!volume_control_allowed && tpacpi_lifecycle != TPACPI_LIFE_INIT) { |
| 7369 | if (unlikely(!tp_warned.volume_ctrl_forbidden)) { |
| 7370 | tp_warned.volume_ctrl_forbidden = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7371 | pr_notice("Console audio control in monitor mode, " |
| 7372 | "changes are not allowed\n"); |
| 7373 | pr_notice("Use the volume_control=1 module parameter " |
| 7374 | "to enable volume control\n"); |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7375 | } |
| 7376 | return -EPERM; |
| 7377 | } |
| 7378 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7379 | rc = volume_get_status(&s); |
| 7380 | if (rc < 0) |
| 7381 | return rc; |
| 7382 | |
| 7383 | new_level = s & TP_EC_AUDIO_LVL_MSK; |
| 7384 | new_mute = s & TP_EC_AUDIO_MUTESW_MSK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7385 | |
| 7386 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7387 | if (!tp_features.mixer_no_level_control) { |
| 7388 | if (strlencmp(cmd, "up") == 0) { |
| 7389 | if (new_mute) |
| 7390 | new_mute = 0; |
| 7391 | else if (new_level < TP_EC_VOLUME_MAX) |
| 7392 | new_level++; |
| 7393 | continue; |
| 7394 | } else if (strlencmp(cmd, "down") == 0) { |
| 7395 | if (new_mute) |
| 7396 | new_mute = 0; |
| 7397 | else if (new_level > 0) |
| 7398 | new_level--; |
| 7399 | continue; |
| 7400 | } else if (sscanf(cmd, "level %u", &l) == 1 && |
| 7401 | l >= 0 && l <= TP_EC_VOLUME_MAX) { |
| 7402 | new_level = l; |
| 7403 | continue; |
| 7404 | } |
| 7405 | } |
| 7406 | if (strlencmp(cmd, "mute") == 0) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7407 | new_mute = TP_EC_AUDIO_MUTESW_MSK; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7408 | else if (strlencmp(cmd, "unmute") == 0) |
| 7409 | new_mute = 0; |
| 7410 | else |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7411 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7412 | } |
| 7413 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7414 | if (tp_features.mixer_no_level_control) { |
| 7415 | tpacpi_disclose_usertask("procfs volume", "%smute\n", |
| 7416 | new_mute ? "" : "un"); |
| 7417 | rc = volume_set_mute(!!new_mute); |
| 7418 | } else { |
| 7419 | tpacpi_disclose_usertask("procfs volume", |
| 7420 | "%smute and set level to %d\n", |
| 7421 | new_mute ? "" : "un", new_level); |
| 7422 | rc = volume_set_status(new_mute | new_level); |
| 7423 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7424 | volume_alsa_notify_change(); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7425 | |
| 7426 | return (rc == -EINTR) ? -ERESTARTSYS : rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7427 | } |
| 7428 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7429 | static struct ibm_struct volume_driver_data = { |
| 7430 | .name = "volume", |
| 7431 | .read = volume_read, |
| 7432 | .write = volume_write, |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7433 | .exit = volume_exit, |
| 7434 | .suspend = volume_suspend, |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7435 | .resume = volume_resume, |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7436 | .shutdown = volume_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7437 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7438 | |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 7439 | #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
| 7440 | |
| 7441 | #define alsa_card NULL |
| 7442 | |
| 7443 | static void inline volume_alsa_notify_change(void) |
| 7444 | { |
| 7445 | } |
| 7446 | |
| 7447 | static int __init volume_init(struct ibm_init_struct *iibm) |
| 7448 | { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7449 | pr_info("volume: disabled as there is no ALSA support in this kernel\n"); |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 7450 | |
| 7451 | return 1; |
| 7452 | } |
| 7453 | |
| 7454 | static struct ibm_struct volume_driver_data = { |
| 7455 | .name = "volume", |
| 7456 | }; |
| 7457 | |
| 7458 | #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
| 7459 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7460 | /************************************************************************* |
| 7461 | * Fan subdriver |
| 7462 | */ |
| 7463 | |
| 7464 | /* |
| 7465 | * FAN ACCESS MODES |
| 7466 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7467 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7468 | * ACPI GFAN method: returns fan level |
| 7469 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7470 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7471 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7472 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7473 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7474 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 7475 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7476 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 7477 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7478 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7479 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7480 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 7481 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7482 | * |
| 7483 | * Fan speed changes of any sort (including those caused by the |
| 7484 | * disengaged mode) are usually done slowly by the firmware as the |
Uwe Kleine-König | 9ddc5b6 | 2010-01-20 17:02:24 +0100 | [diff] [blame] | 7485 | * maximum amount of fan duty cycle change per second seems to be |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7486 | * limited. |
| 7487 | * |
| 7488 | * Reading is not available if GFAN exists. |
| 7489 | * Writing is not available if SFAN exists. |
| 7490 | * |
| 7491 | * Bits |
| 7492 | * 7 automatic mode engaged; |
| 7493 | * (default operation mode of the ThinkPad) |
| 7494 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7495 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7496 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7497 | * the tachometer while the fan controller ramps up |
| 7498 | * the speed (which can take up to a few *minutes*). |
| 7499 | * Speeds up fan to 100% duty-cycle, which is far above |
| 7500 | * the standard RPM levels. It is not impossible that |
| 7501 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7502 | * 5-3 unused in some models. Extra bits for fan level |
| 7503 | * in others, but still useless as all values above |
| 7504 | * 7 map to the same speed as level 7 in these models. |
| 7505 | * 2-0 fan level (0..7 usually) |
| 7506 | * 0x00 = stop |
| 7507 | * 0x07 = max (set when temperatures critical) |
| 7508 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7509 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7510 | * |
| 7511 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 7512 | * boot. Apparently the EC does not initialize it, so unless ACPI DSDT |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7513 | * does so, its initial value is meaningless (0x07). |
| 7514 | * |
| 7515 | * For firmware bugs, refer to: |
| 7516 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 7517 | * |
| 7518 | * ---- |
| 7519 | * |
| 7520 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 7521 | * Main fan tachometer reading (in RPM) |
| 7522 | * |
| 7523 | * This register is present on all ThinkPads with a new-style EC, and |
| 7524 | * it is known not to be present on the A21m/e, and T22, as there is |
| 7525 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 7526 | * ThinkPads from this same time period (and earlier) probably lack the |
| 7527 | * tachometer as well. |
| 7528 | * |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 7529 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7530 | * was never fixed by IBM to report the EC firmware version string |
| 7531 | * probably support the tachometer (like the early X models), so |
| 7532 | * detecting it is quite hard. We need more data to know for sure. |
| 7533 | * |
| 7534 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 7535 | * might result. |
| 7536 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7537 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 7538 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7539 | * |
| 7540 | * For firmware bugs, refer to: |
| 7541 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 7542 | * |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7543 | * ---- |
| 7544 | * |
| 7545 | * ThinkPad EC register 0x31 bit 0 (only on select models) |
| 7546 | * |
| 7547 | * When bit 0 of EC register 0x31 is zero, the tachometer registers |
| 7548 | * show the speed of the main fan. When bit 0 of EC register 0x31 |
| 7549 | * is one, the tachometer registers show the speed of the auxiliary |
| 7550 | * fan. |
| 7551 | * |
| 7552 | * Fan control seems to affect both fans, regardless of the state |
| 7553 | * of this bit. |
| 7554 | * |
| 7555 | * So far, only the firmware for the X60/X61 non-tablet versions |
| 7556 | * seem to support this (firmware TP-7M). |
| 7557 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7558 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7559 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 7560 | * |
| 7561 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 7562 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 7563 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 7564 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 7565 | * |
| 7566 | * The speeds are stored on handles |
| 7567 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 7568 | * |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7569 | * There are three default speed sets, accessible as handles: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7570 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 7571 | * |
| 7572 | * ACPI DSDT switches which set is in use depending on various |
| 7573 | * factors. |
| 7574 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7575 | * TPACPI_FAN_WR_TPEC is also available and should be used to |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7576 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 7577 | * but the ACPI tables just mention level 7. |
| 7578 | */ |
| 7579 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7580 | enum { /* Fan control constants */ |
| 7581 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 7582 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 7583 | * 0x84 must be read before 0x85 */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7584 | fan_select_offset = 0x31, /* EC register 0x31 (Firmware 7M) |
| 7585 | bit 0 selects which fan is active */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7586 | |
| 7587 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 7588 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 7589 | |
| 7590 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 7591 | }; |
| 7592 | |
| 7593 | enum fan_status_access_mode { |
| 7594 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 7595 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 7596 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 7597 | }; |
| 7598 | |
| 7599 | enum fan_control_access_mode { |
| 7600 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 7601 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 7602 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 7603 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 7604 | }; |
| 7605 | |
| 7606 | enum fan_control_commands { |
| 7607 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 7608 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 7609 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 7610 | * and also watchdog cmd */ |
| 7611 | }; |
| 7612 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 7613 | static bool fan_control_allowed; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7614 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7615 | static enum fan_status_access_mode fan_status_access_mode; |
| 7616 | static enum fan_control_access_mode fan_control_access_mode; |
| 7617 | static enum fan_control_commands fan_control_commands; |
| 7618 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7619 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7620 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7621 | static u8 fan_control_resume_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7622 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7623 | |
| 7624 | static struct mutex fan_mutex; |
| 7625 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7626 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 7627 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7628 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7629 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 7630 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7631 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 7632 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7633 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7634 | "JFNS", /* 770x-JL */ |
| 7635 | ); /* all others */ |
| 7636 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7637 | /* |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7638 | * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the |
| 7639 | * HFSP register at boot, so it contains 0x07 but the Thinkpad could |
| 7640 | * be in auto mode (0x80). |
| 7641 | * |
| 7642 | * This is corrected by any write to HFSP either by the driver, or |
| 7643 | * by the firmware. |
| 7644 | * |
| 7645 | * We assume 0x07 really means auto mode while this quirk is active, |
| 7646 | * as this is far more likely than the ThinkPad being in level 7, |
| 7647 | * which is only used by the firmware during thermal emergencies. |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7648 | * |
| 7649 | * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52), |
| 7650 | * TP-70 (T43, R52), which are known to be buggy. |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7651 | */ |
| 7652 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7653 | static void fan_quirk1_setup(void) |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7654 | { |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7655 | if (fan_control_initial_status == 0x07) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7656 | pr_notice("fan_init: initial fan status is unknown, " |
| 7657 | "assuming it is in auto mode\n"); |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7658 | tp_features.fan_ctrl_status_undef = 1; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7659 | } |
| 7660 | } |
| 7661 | |
| 7662 | static void fan_quirk1_handle(u8 *fan_status) |
| 7663 | { |
| 7664 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 7665 | if (*fan_status != fan_control_initial_status) { |
| 7666 | /* something changed the HFSP regisnter since |
| 7667 | * driver init time, so it is not undefined |
| 7668 | * anymore */ |
| 7669 | tp_features.fan_ctrl_status_undef = 0; |
| 7670 | } else { |
| 7671 | /* Return most likely status. In fact, it |
| 7672 | * might be the only possible status */ |
| 7673 | *fan_status = TP_EC_FAN_AUTO; |
| 7674 | } |
| 7675 | } |
| 7676 | } |
| 7677 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7678 | /* Select main fan on X60/X61, NOOP on others */ |
| 7679 | static bool fan_select_fan1(void) |
| 7680 | { |
| 7681 | if (tp_features.second_fan) { |
| 7682 | u8 val; |
| 7683 | |
| 7684 | if (ec_read(fan_select_offset, &val) < 0) |
| 7685 | return false; |
| 7686 | val &= 0xFEU; |
| 7687 | if (ec_write(fan_select_offset, val) < 0) |
| 7688 | return false; |
| 7689 | } |
| 7690 | return true; |
| 7691 | } |
| 7692 | |
| 7693 | /* Select secondary fan on X60/X61 */ |
| 7694 | static bool fan_select_fan2(void) |
| 7695 | { |
| 7696 | u8 val; |
| 7697 | |
| 7698 | if (!tp_features.second_fan) |
| 7699 | return false; |
| 7700 | |
| 7701 | if (ec_read(fan_select_offset, &val) < 0) |
| 7702 | return false; |
| 7703 | val |= 0x01U; |
| 7704 | if (ec_write(fan_select_offset, val) < 0) |
| 7705 | return false; |
| 7706 | |
| 7707 | return true; |
| 7708 | } |
| 7709 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7710 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7711 | * Call with fan_mutex held |
| 7712 | */ |
| 7713 | static void fan_update_desired_level(u8 status) |
| 7714 | { |
| 7715 | if ((status & |
| 7716 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 7717 | if (status > 7) |
| 7718 | fan_control_desired_level = 7; |
| 7719 | else |
| 7720 | fan_control_desired_level = status; |
| 7721 | } |
| 7722 | } |
| 7723 | |
| 7724 | static int fan_get_status(u8 *status) |
| 7725 | { |
| 7726 | u8 s; |
| 7727 | |
| 7728 | /* TODO: |
| 7729 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 7730 | |
| 7731 | switch (fan_status_access_mode) { |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 7732 | case TPACPI_FAN_RD_ACPI_GFAN: { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7733 | /* 570, 600e/x, 770e, 770x */ |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 7734 | int res; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7735 | |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 7736 | if (unlikely(!acpi_evalf(gfan_handle, &res, NULL, "d"))) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7737 | return -EIO; |
| 7738 | |
| 7739 | if (likely(status)) |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 7740 | *status = res & 0x07; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7741 | |
| 7742 | break; |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 7743 | } |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7744 | case TPACPI_FAN_RD_TPEC: |
| 7745 | /* all except 570, 600e/x, 770e, 770x */ |
| 7746 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 7747 | return -EIO; |
| 7748 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7749 | if (likely(status)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7750 | *status = s; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7751 | fan_quirk1_handle(status); |
| 7752 | } |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7753 | |
| 7754 | break; |
| 7755 | |
| 7756 | default: |
| 7757 | return -ENXIO; |
| 7758 | } |
| 7759 | |
| 7760 | return 0; |
| 7761 | } |
| 7762 | |
| 7763 | static int fan_get_status_safe(u8 *status) |
| 7764 | { |
| 7765 | int rc; |
| 7766 | u8 s; |
| 7767 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7768 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7769 | return -ERESTARTSYS; |
| 7770 | rc = fan_get_status(&s); |
| 7771 | if (!rc) |
| 7772 | fan_update_desired_level(s); |
| 7773 | mutex_unlock(&fan_mutex); |
| 7774 | |
| 7775 | if (status) |
| 7776 | *status = s; |
| 7777 | |
| 7778 | return rc; |
| 7779 | } |
| 7780 | |
| 7781 | static int fan_get_speed(unsigned int *speed) |
| 7782 | { |
| 7783 | u8 hi, lo; |
| 7784 | |
| 7785 | switch (fan_status_access_mode) { |
| 7786 | case TPACPI_FAN_RD_TPEC: |
| 7787 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7788 | if (unlikely(!fan_select_fan1())) |
| 7789 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7790 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 7791 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 7792 | return -EIO; |
| 7793 | |
| 7794 | if (likely(speed)) |
| 7795 | *speed = (hi << 8) | lo; |
| 7796 | |
| 7797 | break; |
| 7798 | |
| 7799 | default: |
| 7800 | return -ENXIO; |
| 7801 | } |
| 7802 | |
| 7803 | return 0; |
| 7804 | } |
| 7805 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7806 | static int fan2_get_speed(unsigned int *speed) |
| 7807 | { |
| 7808 | u8 hi, lo; |
| 7809 | bool rc; |
| 7810 | |
| 7811 | switch (fan_status_access_mode) { |
| 7812 | case TPACPI_FAN_RD_TPEC: |
| 7813 | /* all except 570, 600e/x, 770e, 770x */ |
| 7814 | if (unlikely(!fan_select_fan2())) |
| 7815 | return -EIO; |
| 7816 | rc = !acpi_ec_read(fan_rpm_offset, &lo) || |
| 7817 | !acpi_ec_read(fan_rpm_offset + 1, &hi); |
| 7818 | fan_select_fan1(); /* play it safe */ |
| 7819 | if (rc) |
| 7820 | return -EIO; |
| 7821 | |
| 7822 | if (likely(speed)) |
| 7823 | *speed = (hi << 8) | lo; |
| 7824 | |
| 7825 | break; |
| 7826 | |
| 7827 | default: |
| 7828 | return -ENXIO; |
| 7829 | } |
| 7830 | |
| 7831 | return 0; |
| 7832 | } |
| 7833 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7834 | static int fan_set_level(int level) |
| 7835 | { |
| 7836 | if (!fan_control_allowed) |
| 7837 | return -EPERM; |
| 7838 | |
| 7839 | switch (fan_control_access_mode) { |
| 7840 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7841 | if (level >= 0 && level <= 7) { |
| 7842 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 7843 | return -EIO; |
| 7844 | } else |
| 7845 | return -EINVAL; |
| 7846 | break; |
| 7847 | |
| 7848 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7849 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7850 | if (!(level & TP_EC_FAN_AUTO) && |
| 7851 | !(level & TP_EC_FAN_FULLSPEED) && |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7852 | ((level < 0) || (level > 7))) |
| 7853 | return -EINVAL; |
| 7854 | |
| 7855 | /* safety net should the EC not support AUTO |
| 7856 | * or FULLSPEED mode bits and just ignore them */ |
| 7857 | if (level & TP_EC_FAN_FULLSPEED) |
| 7858 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 7859 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7860 | level |= 4; /* safety min speed 4 */ |
| 7861 | |
| 7862 | if (!acpi_ec_write(fan_status_offset, level)) |
| 7863 | return -EIO; |
| 7864 | else |
| 7865 | tp_features.fan_ctrl_status_undef = 0; |
| 7866 | break; |
| 7867 | |
| 7868 | default: |
| 7869 | return -ENXIO; |
| 7870 | } |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7871 | |
| 7872 | vdbg_printk(TPACPI_DBG_FAN, |
| 7873 | "fan control: set fan control register to 0x%02x\n", level); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7874 | return 0; |
| 7875 | } |
| 7876 | |
| 7877 | static int fan_set_level_safe(int level) |
| 7878 | { |
| 7879 | int rc; |
| 7880 | |
| 7881 | if (!fan_control_allowed) |
| 7882 | return -EPERM; |
| 7883 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7884 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7885 | return -ERESTARTSYS; |
| 7886 | |
| 7887 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 7888 | level = fan_control_desired_level; |
| 7889 | |
| 7890 | rc = fan_set_level(level); |
| 7891 | if (!rc) |
| 7892 | fan_update_desired_level(level); |
| 7893 | |
| 7894 | mutex_unlock(&fan_mutex); |
| 7895 | return rc; |
| 7896 | } |
| 7897 | |
| 7898 | static int fan_set_enable(void) |
| 7899 | { |
| 7900 | u8 s; |
| 7901 | int rc; |
| 7902 | |
| 7903 | if (!fan_control_allowed) |
| 7904 | return -EPERM; |
| 7905 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7906 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7907 | return -ERESTARTSYS; |
| 7908 | |
| 7909 | switch (fan_control_access_mode) { |
| 7910 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7911 | case TPACPI_FAN_WR_TPEC: |
| 7912 | rc = fan_get_status(&s); |
| 7913 | if (rc < 0) |
| 7914 | break; |
| 7915 | |
| 7916 | /* Don't go out of emergency fan mode */ |
| 7917 | if (s != 7) { |
| 7918 | s &= 0x07; |
| 7919 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 7920 | } |
| 7921 | |
| 7922 | if (!acpi_ec_write(fan_status_offset, s)) |
| 7923 | rc = -EIO; |
| 7924 | else { |
| 7925 | tp_features.fan_ctrl_status_undef = 0; |
| 7926 | rc = 0; |
| 7927 | } |
| 7928 | break; |
| 7929 | |
| 7930 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7931 | rc = fan_get_status(&s); |
| 7932 | if (rc < 0) |
| 7933 | break; |
| 7934 | |
| 7935 | s &= 0x07; |
| 7936 | |
| 7937 | /* Set fan to at least level 4 */ |
| 7938 | s |= 4; |
| 7939 | |
| 7940 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7941 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7942 | else |
| 7943 | rc = 0; |
| 7944 | break; |
| 7945 | |
| 7946 | default: |
| 7947 | rc = -ENXIO; |
| 7948 | } |
| 7949 | |
| 7950 | mutex_unlock(&fan_mutex); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7951 | |
| 7952 | if (!rc) |
| 7953 | vdbg_printk(TPACPI_DBG_FAN, |
| 7954 | "fan control: set fan control register to 0x%02x\n", |
| 7955 | s); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7956 | return rc; |
| 7957 | } |
| 7958 | |
| 7959 | static int fan_set_disable(void) |
| 7960 | { |
| 7961 | int rc; |
| 7962 | |
| 7963 | if (!fan_control_allowed) |
| 7964 | return -EPERM; |
| 7965 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7966 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7967 | return -ERESTARTSYS; |
| 7968 | |
| 7969 | rc = 0; |
| 7970 | switch (fan_control_access_mode) { |
| 7971 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7972 | case TPACPI_FAN_WR_TPEC: |
| 7973 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 7974 | rc = -EIO; |
| 7975 | else { |
| 7976 | fan_control_desired_level = 0; |
| 7977 | tp_features.fan_ctrl_status_undef = 0; |
| 7978 | } |
| 7979 | break; |
| 7980 | |
| 7981 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7982 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 7983 | rc = -EIO; |
| 7984 | else |
| 7985 | fan_control_desired_level = 0; |
| 7986 | break; |
| 7987 | |
| 7988 | default: |
| 7989 | rc = -ENXIO; |
| 7990 | } |
| 7991 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7992 | if (!rc) |
| 7993 | vdbg_printk(TPACPI_DBG_FAN, |
| 7994 | "fan control: set fan control register to 0\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7995 | |
| 7996 | mutex_unlock(&fan_mutex); |
| 7997 | return rc; |
| 7998 | } |
| 7999 | |
| 8000 | static int fan_set_speed(int speed) |
| 8001 | { |
| 8002 | int rc; |
| 8003 | |
| 8004 | if (!fan_control_allowed) |
| 8005 | return -EPERM; |
| 8006 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 8007 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8008 | return -ERESTARTSYS; |
| 8009 | |
| 8010 | rc = 0; |
| 8011 | switch (fan_control_access_mode) { |
| 8012 | case TPACPI_FAN_WR_ACPI_FANS: |
| 8013 | if (speed >= 0 && speed <= 65535) { |
| 8014 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 8015 | speed, speed, speed)) |
| 8016 | rc = -EIO; |
| 8017 | } else |
| 8018 | rc = -EINVAL; |
| 8019 | break; |
| 8020 | |
| 8021 | default: |
| 8022 | rc = -ENXIO; |
| 8023 | } |
| 8024 | |
| 8025 | mutex_unlock(&fan_mutex); |
| 8026 | return rc; |
| 8027 | } |
| 8028 | |
| 8029 | static void fan_watchdog_reset(void) |
| 8030 | { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8031 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 8032 | return; |
| 8033 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8034 | if (fan_watchdog_maxinterval > 0 && |
Tejun Heo | 41f63c5 | 2012-08-03 10:30:47 -0700 | [diff] [blame] | 8035 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) |
| 8036 | mod_delayed_work(tpacpi_wq, &fan_watchdog_task, |
| 8037 | msecs_to_jiffies(fan_watchdog_maxinterval * 1000)); |
| 8038 | else |
| 8039 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8040 | } |
| 8041 | |
| 8042 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 8043 | { |
| 8044 | int rc; |
| 8045 | |
| 8046 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 8047 | return; |
| 8048 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8049 | pr_notice("fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8050 | rc = fan_set_enable(); |
| 8051 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8052 | pr_err("fan watchdog: error %d while enabling fan, " |
| 8053 | "will try again later...\n", -rc); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8054 | /* reschedule for later */ |
| 8055 | fan_watchdog_reset(); |
| 8056 | } |
| 8057 | } |
| 8058 | |
| 8059 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8060 | * SYSFS fan layout: hwmon compatible (device) |
| 8061 | * |
| 8062 | * pwm*_enable: |
| 8063 | * 0: "disengaged" mode |
| 8064 | * 1: manual mode |
| 8065 | * 2: native EC "auto" mode (recommended, hardware default) |
| 8066 | * |
| 8067 | * pwm*: set speed in manual mode, ignored otherwise. |
| 8068 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 8069 | * interpolation. |
| 8070 | * |
| 8071 | * fan*_input: tachometer reading, RPM |
| 8072 | * |
| 8073 | * |
| 8074 | * SYSFS fan layout: extensions |
| 8075 | * |
| 8076 | * fan_watchdog (driver): |
| 8077 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 8078 | */ |
| 8079 | |
| 8080 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 8081 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 8082 | struct device_attribute *attr, |
| 8083 | char *buf) |
| 8084 | { |
| 8085 | int res, mode; |
| 8086 | u8 status; |
| 8087 | |
| 8088 | res = fan_get_status_safe(&status); |
| 8089 | if (res) |
| 8090 | return res; |
| 8091 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8092 | if (status & TP_EC_FAN_FULLSPEED) { |
| 8093 | mode = 0; |
| 8094 | } else if (status & TP_EC_FAN_AUTO) { |
| 8095 | mode = 2; |
| 8096 | } else |
| 8097 | mode = 1; |
| 8098 | |
| 8099 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 8100 | } |
| 8101 | |
| 8102 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 8103 | struct device_attribute *attr, |
| 8104 | const char *buf, size_t count) |
| 8105 | { |
| 8106 | unsigned long t; |
| 8107 | int res, level; |
| 8108 | |
| 8109 | if (parse_strtoul(buf, 2, &t)) |
| 8110 | return -EINVAL; |
| 8111 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8112 | tpacpi_disclose_usertask("hwmon pwm1_enable", |
| 8113 | "set fan mode to %lu\n", t); |
| 8114 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8115 | switch (t) { |
| 8116 | case 0: |
| 8117 | level = TP_EC_FAN_FULLSPEED; |
| 8118 | break; |
| 8119 | case 1: |
| 8120 | level = TPACPI_FAN_LAST_LEVEL; |
| 8121 | break; |
| 8122 | case 2: |
| 8123 | level = TP_EC_FAN_AUTO; |
| 8124 | break; |
| 8125 | case 3: |
| 8126 | /* reserved for software-controlled auto mode */ |
| 8127 | return -ENOSYS; |
| 8128 | default: |
| 8129 | return -EINVAL; |
| 8130 | } |
| 8131 | |
| 8132 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 8133 | if (res == -ENXIO) |
| 8134 | return -EINVAL; |
| 8135 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8136 | return res; |
| 8137 | |
| 8138 | fan_watchdog_reset(); |
| 8139 | |
| 8140 | return count; |
| 8141 | } |
| 8142 | |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 8143 | static DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 8144 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8145 | |
| 8146 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 8147 | static ssize_t fan_pwm1_show(struct device *dev, |
| 8148 | struct device_attribute *attr, |
| 8149 | char *buf) |
| 8150 | { |
| 8151 | int res; |
| 8152 | u8 status; |
| 8153 | |
| 8154 | res = fan_get_status_safe(&status); |
| 8155 | if (res) |
| 8156 | return res; |
| 8157 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8158 | if ((status & |
| 8159 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 8160 | status = fan_control_desired_level; |
| 8161 | |
| 8162 | if (status > 7) |
| 8163 | status = 7; |
| 8164 | |
| 8165 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 8166 | } |
| 8167 | |
| 8168 | static ssize_t fan_pwm1_store(struct device *dev, |
| 8169 | struct device_attribute *attr, |
| 8170 | const char *buf, size_t count) |
| 8171 | { |
| 8172 | unsigned long s; |
| 8173 | int rc; |
| 8174 | u8 status, newlevel; |
| 8175 | |
| 8176 | if (parse_strtoul(buf, 255, &s)) |
| 8177 | return -EINVAL; |
| 8178 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8179 | tpacpi_disclose_usertask("hwmon pwm1", |
| 8180 | "set fan speed to %lu\n", s); |
| 8181 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8182 | /* scale down from 0-255 to 0-7 */ |
| 8183 | newlevel = (s >> 5) & 0x07; |
| 8184 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 8185 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 8186 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8187 | |
| 8188 | rc = fan_get_status(&status); |
| 8189 | if (!rc && (status & |
| 8190 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 8191 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 8192 | if (rc == -ENXIO) |
| 8193 | rc = -EINVAL; |
| 8194 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8195 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 8196 | fan_watchdog_reset(); |
| 8197 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8198 | } |
| 8199 | |
| 8200 | mutex_unlock(&fan_mutex); |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 8201 | return (rc) ? rc : count; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8202 | } |
| 8203 | |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 8204 | static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, fan_pwm1_show, fan_pwm1_store); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8205 | |
| 8206 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 8207 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 8208 | struct device_attribute *attr, |
| 8209 | char *buf) |
| 8210 | { |
| 8211 | int res; |
| 8212 | unsigned int speed; |
| 8213 | |
| 8214 | res = fan_get_speed(&speed); |
| 8215 | if (res < 0) |
| 8216 | return res; |
| 8217 | |
| 8218 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 8219 | } |
| 8220 | |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 8221 | static DEVICE_ATTR(fan1_input, S_IRUGO, fan_fan1_input_show, NULL); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8222 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8223 | /* sysfs fan fan2_input ------------------------------------------------ */ |
| 8224 | static ssize_t fan_fan2_input_show(struct device *dev, |
| 8225 | struct device_attribute *attr, |
| 8226 | char *buf) |
| 8227 | { |
| 8228 | int res; |
| 8229 | unsigned int speed; |
| 8230 | |
| 8231 | res = fan2_get_speed(&speed); |
| 8232 | if (res < 0) |
| 8233 | return res; |
| 8234 | |
| 8235 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 8236 | } |
| 8237 | |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 8238 | static DEVICE_ATTR(fan2_input, S_IRUGO, fan_fan2_input_show, NULL); |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8239 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8240 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8241 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 8242 | char *buf) |
| 8243 | { |
| 8244 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 8245 | } |
| 8246 | |
| 8247 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 8248 | const char *buf, size_t count) |
| 8249 | { |
| 8250 | unsigned long t; |
| 8251 | |
| 8252 | if (parse_strtoul(buf, 120, &t)) |
| 8253 | return -EINVAL; |
| 8254 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8255 | if (!fan_control_allowed) |
| 8256 | return -EPERM; |
| 8257 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8258 | fan_watchdog_maxinterval = t; |
| 8259 | fan_watchdog_reset(); |
| 8260 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8261 | tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t); |
| 8262 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8263 | return count; |
| 8264 | } |
| 8265 | |
| 8266 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 8267 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 8268 | |
| 8269 | /* --------------------------------------------------------------------- */ |
| 8270 | static struct attribute *fan_attributes[] = { |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 8271 | &dev_attr_pwm1_enable.attr, &dev_attr_pwm1.attr, |
| 8272 | &dev_attr_fan1_input.attr, |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8273 | NULL, /* for fan2_input */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8274 | NULL |
| 8275 | }; |
| 8276 | |
| 8277 | static const struct attribute_group fan_attr_group = { |
| 8278 | .attrs = fan_attributes, |
| 8279 | }; |
| 8280 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8281 | #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */ |
| 8282 | #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */ |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8283 | |
| 8284 | #define TPACPI_FAN_QI(__id1, __id2, __quirks) \ |
| 8285 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 8286 | .bios = TPACPI_MATCH_ANY, \ |
| 8287 | .ec = TPID(__id1, __id2), \ |
| 8288 | .quirks = __quirks } |
| 8289 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8290 | #define TPACPI_FAN_QL(__id1, __id2, __quirks) \ |
| 8291 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 8292 | .bios = TPACPI_MATCH_ANY, \ |
| 8293 | .ec = TPID(__id1, __id2), \ |
| 8294 | .quirks = __quirks } |
| 8295 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8296 | static const struct tpacpi_quirk fan_quirk_table[] __initconst = { |
| 8297 | TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1), |
| 8298 | TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1), |
| 8299 | TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1), |
| 8300 | TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1), |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8301 | TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN), |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8302 | }; |
| 8303 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8304 | #undef TPACPI_FAN_QL |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8305 | #undef TPACPI_FAN_QI |
| 8306 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8307 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8308 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8309 | int rc; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8310 | unsigned long quirks; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8311 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8312 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 8313 | "initializing fan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8314 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 8315 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8316 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 8317 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8318 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8319 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 8320 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8321 | tp_features.second_fan = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8322 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8323 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 8324 | if (tpacpi_is_ibm()) { |
| 8325 | TPACPI_ACPIHANDLE_INIT(fans); |
| 8326 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 8327 | TPACPI_ACPIHANDLE_INIT(sfan); |
| 8328 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8329 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8330 | quirks = tpacpi_check_quirks(fan_quirk_table, |
| 8331 | ARRAY_SIZE(fan_quirk_table)); |
| 8332 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8333 | if (gfan_handle) { |
| 8334 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8335 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8336 | } else { |
| 8337 | /* all other ThinkPads: note that even old-style |
| 8338 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8339 | if (likely(acpi_ec_read(fan_status_offset, |
| 8340 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8341 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8342 | if (quirks & TPACPI_FAN_Q1) |
| 8343 | fan_quirk1_setup(); |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8344 | if (quirks & TPACPI_FAN_2FAN) { |
| 8345 | tp_features.second_fan = 1; |
| 8346 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 8347 | "secondary fan support enabled\n"); |
| 8348 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8349 | } else { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8350 | pr_err("ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8351 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8352 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8353 | } |
| 8354 | } |
| 8355 | |
| 8356 | if (sfan_handle) { |
| 8357 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8358 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 8359 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8360 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8361 | } else { |
| 8362 | if (!gfan_handle) { |
| 8363 | /* gfan without sfan means no fan control */ |
| 8364 | /* all other models implement TP EC 0x2f control */ |
| 8365 | |
| 8366 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8367 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8368 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8369 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8370 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8371 | TPACPI_FAN_CMD_SPEED | |
| 8372 | TPACPI_FAN_CMD_LEVEL | |
| 8373 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8374 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8375 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8376 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8377 | TPACPI_FAN_CMD_LEVEL | |
| 8378 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8379 | } |
| 8380 | } |
| 8381 | } |
| 8382 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8383 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 8384 | "fan is %s, modes %d, %d\n", |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8385 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 8386 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 8387 | fan_status_access_mode, fan_control_access_mode); |
| 8388 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8389 | /* fan control master switch */ |
| 8390 | if (!fan_control_allowed) { |
| 8391 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 8392 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8393 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8394 | "fan control features disabled by parameter\n"); |
| 8395 | } |
| 8396 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8397 | /* update fan_control_desired_level */ |
| 8398 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 8399 | fan_get_status_safe(NULL); |
| 8400 | |
| 8401 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 8402 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8403 | if (tp_features.second_fan) { |
| 8404 | /* attach second fan tachometer */ |
| 8405 | fan_attributes[ARRAY_SIZE(fan_attributes)-2] = |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 8406 | &dev_attr_fan2_input.attr; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8407 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8408 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8409 | &fan_attr_group); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8410 | if (rc < 0) |
| 8411 | return rc; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 8412 | |
| 8413 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
| 8414 | &driver_attr_fan_watchdog); |
| 8415 | if (rc < 0) { |
| 8416 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
| 8417 | &fan_attr_group); |
| 8418 | return rc; |
| 8419 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8420 | return 0; |
| 8421 | } else |
| 8422 | return 1; |
| 8423 | } |
| 8424 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8425 | static void fan_exit(void) |
| 8426 | { |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8427 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8428 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8429 | |
| 8430 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8431 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group); |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8432 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 8433 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8434 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8435 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8436 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8437 | } |
| 8438 | |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 8439 | static void fan_suspend(void) |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8440 | { |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8441 | int rc; |
| 8442 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8443 | if (!fan_control_allowed) |
| 8444 | return; |
| 8445 | |
| 8446 | /* Store fan status in cache */ |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8447 | fan_control_resume_level = 0; |
| 8448 | rc = fan_get_status_safe(&fan_control_resume_level); |
| 8449 | if (rc < 0) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8450 | pr_notice("failed to read fan level for later " |
| 8451 | "restore during resume: %d\n", rc); |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8452 | |
| 8453 | /* if it is undefined, don't attempt to restore it. |
| 8454 | * KEEP THIS LAST */ |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8455 | if (tp_features.fan_ctrl_status_undef) |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8456 | fan_control_resume_level = 0; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8457 | } |
| 8458 | |
| 8459 | static void fan_resume(void) |
| 8460 | { |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8461 | u8 current_level = 7; |
| 8462 | bool do_set = false; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8463 | int rc; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8464 | |
| 8465 | /* DSDT *always* updates status on resume */ |
| 8466 | tp_features.fan_ctrl_status_undef = 0; |
| 8467 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8468 | if (!fan_control_allowed || |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8469 | !fan_control_resume_level || |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8470 | (fan_get_status_safe(¤t_level) < 0)) |
| 8471 | return; |
| 8472 | |
| 8473 | switch (fan_control_access_mode) { |
| 8474 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8475 | /* never decrease fan level */ |
| 8476 | do_set = (fan_control_resume_level > current_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8477 | break; |
| 8478 | case TPACPI_FAN_WR_ACPI_FANS: |
| 8479 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8480 | /* never decrease fan level, scale is: |
| 8481 | * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO |
| 8482 | * |
| 8483 | * We expect the firmware to set either 7 or AUTO, but we |
| 8484 | * handle FULLSPEED out of paranoia. |
| 8485 | * |
| 8486 | * So, we can safely only restore FULLSPEED or 7, anything |
| 8487 | * else could slow the fan. Restoring AUTO is useless, at |
| 8488 | * best that's exactly what the DSDT already set (it is the |
| 8489 | * slower it uses). |
| 8490 | * |
| 8491 | * Always keep in mind that the DSDT *will* have set the |
| 8492 | * fans to what the vendor supposes is the best level. We |
| 8493 | * muck with it only to speed the fan up. |
| 8494 | */ |
| 8495 | if (fan_control_resume_level != 7 && |
| 8496 | !(fan_control_resume_level & TP_EC_FAN_FULLSPEED)) |
| 8497 | return; |
| 8498 | else |
| 8499 | do_set = !(current_level & TP_EC_FAN_FULLSPEED) && |
| 8500 | (current_level != fan_control_resume_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8501 | break; |
| 8502 | default: |
| 8503 | return; |
| 8504 | } |
| 8505 | if (do_set) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8506 | pr_notice("restoring fan level to 0x%02x\n", |
| 8507 | fan_control_resume_level); |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8508 | rc = fan_set_level_safe(fan_control_resume_level); |
| 8509 | if (rc < 0) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8510 | pr_notice("failed to restore fan level: %d\n", rc); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8511 | } |
| 8512 | } |
| 8513 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8514 | static int fan_read(struct seq_file *m) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8515 | { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8516 | int rc; |
| 8517 | u8 status; |
| 8518 | unsigned int speed = 0; |
| 8519 | |
| 8520 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8521 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8522 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8523 | rc = fan_get_status_safe(&status); |
| 8524 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8525 | return rc; |
| 8526 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8527 | seq_printf(m, "status:\t\t%s\n" |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8528 | "level:\t\t%d\n", |
| 8529 | (status != 0) ? "enabled" : "disabled", status); |
| 8530 | break; |
| 8531 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8532 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8533 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8534 | rc = fan_get_status_safe(&status); |
| 8535 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8536 | return rc; |
| 8537 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8538 | seq_printf(m, "status:\t\t%s\n", |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8539 | (status != 0) ? "enabled" : "disabled"); |
| 8540 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8541 | rc = fan_get_speed(&speed); |
| 8542 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8543 | return rc; |
| 8544 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8545 | seq_printf(m, "speed:\t\t%d\n", speed); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8546 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8547 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8548 | /* Disengaged mode takes precedence */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8549 | seq_printf(m, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8550 | else if (status & TP_EC_FAN_AUTO) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8551 | seq_printf(m, "level:\t\tauto\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8552 | else |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8553 | seq_printf(m, "level:\t\t%d\n", status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8554 | break; |
| 8555 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8556 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8557 | default: |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8558 | seq_printf(m, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8559 | } |
| 8560 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8561 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8562 | seq_printf(m, "commands:\tlevel <level>"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8563 | |
| 8564 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8565 | case TPACPI_FAN_WR_ACPI_SFAN: |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8566 | seq_printf(m, " (<level> is 0-7)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8567 | break; |
| 8568 | |
| 8569 | default: |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8570 | seq_printf(m, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8571 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8572 | break; |
| 8573 | } |
| 8574 | } |
| 8575 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8576 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8577 | seq_printf(m, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8578 | "commands:\twatchdog <timeout> (<timeout> " |
| 8579 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8580 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8581 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8582 | seq_printf(m, "commands:\tspeed <speed>" |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8583 | " (<speed> is 0-65535)\n"); |
| 8584 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8585 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8586 | } |
| 8587 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8588 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 8589 | { |
| 8590 | int level; |
| 8591 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8592 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8593 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8594 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8595 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8596 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8597 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8598 | return 0; |
| 8599 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8600 | *rc = fan_set_level_safe(level); |
| 8601 | if (*rc == -ENXIO) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8602 | pr_err("level command accepted for unsupported access mode %d\n", |
| 8603 | fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8604 | else if (!*rc) |
| 8605 | tpacpi_disclose_usertask("procfs fan", |
| 8606 | "set level to %d\n", level); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8607 | |
| 8608 | return 1; |
| 8609 | } |
| 8610 | |
| 8611 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 8612 | { |
| 8613 | if (strlencmp(cmd, "enable") != 0) |
| 8614 | return 0; |
| 8615 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8616 | *rc = fan_set_enable(); |
| 8617 | if (*rc == -ENXIO) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8618 | pr_err("enable command accepted for unsupported access mode %d\n", |
| 8619 | fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8620 | else if (!*rc) |
| 8621 | tpacpi_disclose_usertask("procfs fan", "enable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8622 | |
| 8623 | return 1; |
| 8624 | } |
| 8625 | |
| 8626 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 8627 | { |
| 8628 | if (strlencmp(cmd, "disable") != 0) |
| 8629 | return 0; |
| 8630 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8631 | *rc = fan_set_disable(); |
| 8632 | if (*rc == -ENXIO) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8633 | pr_err("disable command accepted for unsupported access mode %d\n", |
| 8634 | fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8635 | else if (!*rc) |
| 8636 | tpacpi_disclose_usertask("procfs fan", "disable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8637 | |
| 8638 | return 1; |
| 8639 | } |
| 8640 | |
| 8641 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 8642 | { |
| 8643 | int speed; |
| 8644 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8645 | /* TODO: |
| 8646 | * Support speed <low> <medium> <high> ? */ |
| 8647 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8648 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 8649 | return 0; |
| 8650 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8651 | *rc = fan_set_speed(speed); |
| 8652 | if (*rc == -ENXIO) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8653 | pr_err("speed command accepted for unsupported access mode %d\n", |
| 8654 | fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8655 | else if (!*rc) |
| 8656 | tpacpi_disclose_usertask("procfs fan", |
| 8657 | "set speed to %d\n", speed); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8658 | |
| 8659 | return 1; |
| 8660 | } |
| 8661 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8662 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 8663 | { |
| 8664 | int interval; |
| 8665 | |
| 8666 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 8667 | return 0; |
| 8668 | |
| 8669 | if (interval < 0 || interval > 120) |
| 8670 | *rc = -EINVAL; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8671 | else { |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8672 | fan_watchdog_maxinterval = interval; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8673 | tpacpi_disclose_usertask("procfs fan", |
| 8674 | "set watchdog timer to %d\n", |
| 8675 | interval); |
| 8676 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8677 | |
| 8678 | return 1; |
| 8679 | } |
| 8680 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8681 | static int fan_write(char *buf) |
| 8682 | { |
| 8683 | char *cmd; |
| 8684 | int rc = 0; |
| 8685 | |
| 8686 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8687 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8688 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8689 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8690 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8691 | fan_write_cmd_disable(cmd, &rc) || |
| 8692 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8693 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8694 | fan_write_cmd_speed(cmd, &rc)) |
| 8695 | ) |
| 8696 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8697 | else if (!rc) |
| 8698 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8699 | } |
| 8700 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8701 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8702 | } |
| 8703 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8704 | static struct ibm_struct fan_driver_data = { |
| 8705 | .name = "fan", |
| 8706 | .read = fan_read, |
| 8707 | .write = fan_write, |
| 8708 | .exit = fan_exit, |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8709 | .suspend = fan_suspend, |
| 8710 | .resume = fan_resume, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8711 | }; |
| 8712 | |
David Henningsson | 420f973 | 2013-10-16 23:10:31 +0200 | [diff] [blame] | 8713 | /************************************************************************* |
| 8714 | * Mute LED subdriver |
| 8715 | */ |
| 8716 | |
| 8717 | |
| 8718 | struct tp_led_table { |
| 8719 | acpi_string name; |
| 8720 | int on_value; |
| 8721 | int off_value; |
| 8722 | int state; |
| 8723 | }; |
| 8724 | |
| 8725 | static struct tp_led_table led_tables[] = { |
| 8726 | [TPACPI_LED_MUTE] = { |
| 8727 | .name = "SSMS", |
| 8728 | .on_value = 1, |
| 8729 | .off_value = 0, |
| 8730 | }, |
| 8731 | [TPACPI_LED_MICMUTE] = { |
| 8732 | .name = "MMTS", |
| 8733 | .on_value = 2, |
| 8734 | .off_value = 0, |
| 8735 | }, |
| 8736 | }; |
| 8737 | |
| 8738 | static int mute_led_on_off(struct tp_led_table *t, bool state) |
| 8739 | { |
| 8740 | acpi_handle temp; |
| 8741 | int output; |
| 8742 | |
| 8743 | if (!ACPI_SUCCESS(acpi_get_handle(hkey_handle, t->name, &temp))) { |
| 8744 | pr_warn("Thinkpad ACPI has no %s interface.\n", t->name); |
| 8745 | return -EIO; |
| 8746 | } |
| 8747 | |
| 8748 | if (!acpi_evalf(hkey_handle, &output, t->name, "dd", |
| 8749 | state ? t->on_value : t->off_value)) |
| 8750 | return -EIO; |
| 8751 | |
| 8752 | t->state = state; |
| 8753 | return state; |
| 8754 | } |
| 8755 | |
| 8756 | int tpacpi_led_set(int whichled, bool on) |
| 8757 | { |
| 8758 | struct tp_led_table *t; |
| 8759 | |
| 8760 | if (whichled < 0 || whichled >= TPACPI_LED_MAX) |
| 8761 | return -EINVAL; |
| 8762 | |
| 8763 | t = &led_tables[whichled]; |
| 8764 | if (t->state < 0 || t->state == on) |
| 8765 | return t->state; |
| 8766 | return mute_led_on_off(t, on); |
| 8767 | } |
| 8768 | EXPORT_SYMBOL_GPL(tpacpi_led_set); |
| 8769 | |
| 8770 | static int mute_led_init(struct ibm_init_struct *iibm) |
| 8771 | { |
| 8772 | acpi_handle temp; |
| 8773 | int i; |
| 8774 | |
| 8775 | for (i = 0; i < TPACPI_LED_MAX; i++) { |
| 8776 | struct tp_led_table *t = &led_tables[i]; |
| 8777 | if (ACPI_SUCCESS(acpi_get_handle(hkey_handle, t->name, &temp))) |
| 8778 | mute_led_on_off(t, false); |
| 8779 | else |
| 8780 | t->state = -ENODEV; |
| 8781 | } |
| 8782 | return 0; |
| 8783 | } |
| 8784 | |
| 8785 | static void mute_led_exit(void) |
| 8786 | { |
| 8787 | int i; |
| 8788 | |
| 8789 | for (i = 0; i < TPACPI_LED_MAX; i++) |
| 8790 | tpacpi_led_set(i, false); |
| 8791 | } |
| 8792 | |
Takashi Iwai | 119f449 | 2014-02-12 16:32:45 +0100 | [diff] [blame] | 8793 | static void mute_led_resume(void) |
| 8794 | { |
| 8795 | int i; |
| 8796 | |
| 8797 | for (i = 0; i < TPACPI_LED_MAX; i++) { |
| 8798 | struct tp_led_table *t = &led_tables[i]; |
| 8799 | if (t->state >= 0) |
| 8800 | mute_led_on_off(t, t->state); |
| 8801 | } |
| 8802 | } |
| 8803 | |
David Henningsson | 420f973 | 2013-10-16 23:10:31 +0200 | [diff] [blame] | 8804 | static struct ibm_struct mute_led_driver_data = { |
| 8805 | .name = "mute_led", |
| 8806 | .exit = mute_led_exit, |
Takashi Iwai | 119f449 | 2014-02-12 16:32:45 +0100 | [diff] [blame] | 8807 | .resume = mute_led_resume, |
David Henningsson | 420f973 | 2013-10-16 23:10:31 +0200 | [diff] [blame] | 8808 | }; |
| 8809 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8810 | /**************************************************************************** |
| 8811 | **************************************************************************** |
| 8812 | * |
| 8813 | * Infrastructure |
| 8814 | * |
| 8815 | **************************************************************************** |
| 8816 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8817 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8818 | /* |
| 8819 | * HKEY event callout for other subdrivers go here |
| 8820 | * (yes, it is ugly, but it is quick, safe, and gets the job done |
| 8821 | */ |
| 8822 | static void tpacpi_driver_event(const unsigned int hkey_event) |
| 8823 | { |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 8824 | if (ibm_backlight_device) { |
| 8825 | switch (hkey_event) { |
| 8826 | case TP_HKEY_EV_BRGHT_UP: |
| 8827 | case TP_HKEY_EV_BRGHT_DOWN: |
| 8828 | tpacpi_brightness_notify_change(); |
| 8829 | } |
| 8830 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 8831 | if (alsa_card) { |
| 8832 | switch (hkey_event) { |
| 8833 | case TP_HKEY_EV_VOL_UP: |
| 8834 | case TP_HKEY_EV_VOL_DOWN: |
| 8835 | case TP_HKEY_EV_VOL_MUTE: |
| 8836 | volume_alsa_notify_change(); |
| 8837 | } |
| 8838 | } |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8839 | } |
| 8840 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8841 | static void hotkey_driver_event(const unsigned int scancode) |
| 8842 | { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 8843 | tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8844 | } |
| 8845 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8846 | /* sysfs name ---------------------------------------------------------- */ |
| 8847 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 8848 | struct device_attribute *attr, |
| 8849 | char *buf) |
| 8850 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8851 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8852 | } |
| 8853 | |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 8854 | static DEVICE_ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8855 | |
| 8856 | /* --------------------------------------------------------------------- */ |
| 8857 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8858 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 8859 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8860 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8861 | /* |
| 8862 | * Module and infrastructure proble, init and exit handling |
| 8863 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8864 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 8865 | static bool force_load; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8866 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8867 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8868 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8869 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8870 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8871 | |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 8872 | return (is_supported) ? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8873 | } |
| 8874 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 8875 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8876 | static void ibm_exit(struct ibm_struct *ibm) |
| 8877 | { |
| 8878 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 8879 | |
| 8880 | list_del_init(&ibm->all_drivers); |
| 8881 | |
| 8882 | if (ibm->flags.acpi_notify_installed) { |
| 8883 | dbg_printk(TPACPI_DBG_EXIT, |
| 8884 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 8885 | BUG_ON(!ibm->acpi); |
| 8886 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 8887 | ibm->acpi->type, |
| 8888 | dispatch_acpi_notify); |
| 8889 | ibm->flags.acpi_notify_installed = 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8890 | } |
| 8891 | |
| 8892 | if (ibm->flags.proc_created) { |
| 8893 | dbg_printk(TPACPI_DBG_EXIT, |
| 8894 | "%s: remove_proc_entry\n", ibm->name); |
| 8895 | remove_proc_entry(ibm->name, proc_dir); |
| 8896 | ibm->flags.proc_created = 0; |
| 8897 | } |
| 8898 | |
| 8899 | if (ibm->flags.acpi_driver_registered) { |
| 8900 | dbg_printk(TPACPI_DBG_EXIT, |
| 8901 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 8902 | BUG_ON(!ibm->acpi); |
| 8903 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 8904 | kfree(ibm->acpi->driver); |
| 8905 | ibm->acpi->driver = NULL; |
| 8906 | ibm->flags.acpi_driver_registered = 0; |
| 8907 | } |
| 8908 | |
| 8909 | if (ibm->flags.init_called && ibm->exit) { |
| 8910 | ibm->exit(); |
| 8911 | ibm->flags.init_called = 0; |
| 8912 | } |
| 8913 | |
| 8914 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 8915 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 8916 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8917 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8918 | { |
| 8919 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8920 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8921 | struct proc_dir_entry *entry; |
| 8922 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8923 | BUG_ON(ibm == NULL); |
| 8924 | |
| 8925 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 8926 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8927 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8928 | return 0; |
| 8929 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8930 | dbg_printk(TPACPI_DBG_INIT, |
| 8931 | "probing for %s\n", ibm->name); |
| 8932 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8933 | if (iibm->init) { |
| 8934 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8935 | if (ret > 0) |
| 8936 | return 0; /* probe failed */ |
| 8937 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8938 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8939 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8940 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8941 | } |
| 8942 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8943 | if (ibm->acpi) { |
| 8944 | if (ibm->acpi->hid) { |
| 8945 | ret = register_tpacpi_subdriver(ibm); |
| 8946 | if (ret) |
| 8947 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8948 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8949 | |
| 8950 | if (ibm->acpi->notify) { |
| 8951 | ret = setup_acpi_notify(ibm); |
| 8952 | if (ret == -ENODEV) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8953 | pr_notice("disabling subdriver %s\n", |
| 8954 | ibm->name); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8955 | ret = 0; |
| 8956 | goto err_out; |
| 8957 | } |
| 8958 | if (ret < 0) |
| 8959 | goto err_out; |
| 8960 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8961 | } |
| 8962 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8963 | dbg_printk(TPACPI_DBG_INIT, |
| 8964 | "%s installed\n", ibm->name); |
| 8965 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8966 | if (ibm->read) { |
Al Viro | d161a13 | 2011-07-24 03:36:29 -0400 | [diff] [blame] | 8967 | umode_t mode = iibm->base_procfs_mode; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8968 | |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 8969 | if (!mode) |
| 8970 | mode = S_IRUGO; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8971 | if (ibm->write) |
| 8972 | mode |= S_IWUSR; |
| 8973 | entry = proc_create_data(ibm->name, mode, proc_dir, |
| 8974 | &dispatch_proc_fops, ibm); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8975 | if (!entry) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8976 | pr_err("unable to create proc entry %s\n", ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8977 | ret = -ENODEV; |
| 8978 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8979 | } |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8980 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8981 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8982 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8983 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 8984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8985 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8986 | |
| 8987 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8988 | dbg_printk(TPACPI_DBG_INIT, |
| 8989 | "%s: at error exit path with result %d\n", |
| 8990 | ibm->name, ret); |
| 8991 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8992 | ibm_exit(ibm); |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 8993 | return (ret < 0) ? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8994 | } |
| 8995 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8996 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8997 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8998 | static bool __pure __init tpacpi_is_fw_digit(const char c) |
| 8999 | { |
| 9000 | return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); |
| 9001 | } |
| 9002 | |
Jan van den Berg | 72a979f | 2014-09-17 00:01:08 +0200 | [diff] [blame] | 9003 | static bool __pure __init tpacpi_is_valid_fw_id(const char * const s, |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 9004 | const char t) |
| 9005 | { |
Adam Lee | 1b0eb5bc | 2015-02-11 13:43:10 +0800 | [diff] [blame] | 9006 | /* |
| 9007 | * Most models: xxyTkkWW (#.##c) |
| 9008 | * Ancient 570/600 and -SL lacks (#.##c) |
| 9009 | */ |
| 9010 | if (s && strlen(s) >= 8 && |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 9011 | tpacpi_is_fw_digit(s[0]) && |
| 9012 | tpacpi_is_fw_digit(s[1]) && |
Manoj Iyer | 16a3d9f | 2012-09-24 11:57:40 -0500 | [diff] [blame] | 9013 | s[2] == t && |
| 9014 | (s[3] == 'T' || s[3] == 'N') && |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 9015 | tpacpi_is_fw_digit(s[4]) && |
Adam Lee | 1b0eb5bc | 2015-02-11 13:43:10 +0800 | [diff] [blame] | 9016 | tpacpi_is_fw_digit(s[5])) |
| 9017 | return true; |
| 9018 | |
| 9019 | /* New models: xxxyTkkW (#.##c); T550 and some others */ |
| 9020 | return s && strlen(s) >= 8 && |
| 9021 | tpacpi_is_fw_digit(s[0]) && |
| 9022 | tpacpi_is_fw_digit(s[1]) && |
| 9023 | tpacpi_is_fw_digit(s[2]) && |
| 9024 | s[3] == t && |
| 9025 | (s[4] == 'T' || s[4] == 'N') && |
| 9026 | tpacpi_is_fw_digit(s[5]) && |
| 9027 | tpacpi_is_fw_digit(s[6]); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 9028 | } |
| 9029 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9030 | /* returns 0 - probe ok, or < 0 - probe error. |
| 9031 | * Probe ok doesn't mean thinkpad found. |
| 9032 | * On error, kfree() cleanup on tp->* is not performed, caller must do it */ |
| 9033 | static int __must_check __init get_thinkpad_model_data( |
| 9034 | struct thinkpad_id_data *tp) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 9035 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 9036 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 9037 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9038 | char const *s; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 9039 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9040 | if (!tp) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9041 | return -EINVAL; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9042 | |
| 9043 | memset(tp, 0, sizeof(*tp)); |
| 9044 | |
| 9045 | if (dmi_name_in_vendors("IBM")) |
| 9046 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 9047 | else if (dmi_name_in_vendors("LENOVO")) |
| 9048 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 9049 | else |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9050 | return 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9051 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9052 | s = dmi_get_system_info(DMI_BIOS_VERSION); |
| 9053 | tp->bios_version_str = kstrdup(s, GFP_KERNEL); |
| 9054 | if (s && !tp->bios_version_str) |
| 9055 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 9056 | |
| 9057 | /* Really ancient ThinkPad 240X will fail this, which is fine */ |
Manoj Iyer | 16a3d9f | 2012-09-24 11:57:40 -0500 | [diff] [blame] | 9058 | if (!(tpacpi_is_valid_fw_id(tp->bios_version_str, 'E') || |
| 9059 | tpacpi_is_valid_fw_id(tp->bios_version_str, 'C'))) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9060 | return 0; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 9061 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9062 | tp->bios_model = tp->bios_version_str[0] |
| 9063 | | (tp->bios_version_str[1] << 8); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 9064 | tp->bios_release = (tp->bios_version_str[4] << 8) |
| 9065 | | tp->bios_version_str[5]; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9066 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 9067 | /* |
| 9068 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 9069 | * X32 or newer, all Z series; Some models must have an |
| 9070 | * up-to-date BIOS or they will not be detected. |
| 9071 | * |
| 9072 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 9073 | */ |
| 9074 | while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) { |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 9075 | if (sscanf(dev->name, |
| 9076 | "IBM ThinkPad Embedded Controller -[%17c", |
| 9077 | ec_fw_string) == 1) { |
| 9078 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 9079 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9080 | |
| 9081 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9082 | if (!tp->ec_version_str) |
| 9083 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 9084 | |
| 9085 | if (tpacpi_is_valid_fw_id(ec_fw_string, 'H')) { |
| 9086 | tp->ec_model = ec_fw_string[0] |
| 9087 | | (ec_fw_string[1] << 8); |
| 9088 | tp->ec_release = (ec_fw_string[4] << 8) |
| 9089 | | ec_fw_string[5]; |
| 9090 | } else { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9091 | pr_notice("ThinkPad firmware release %s " |
| 9092 | "doesn't match the known patterns\n", |
| 9093 | ec_fw_string); |
| 9094 | pr_notice("please report this to %s\n", |
| 9095 | TPACPI_MAIL); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 9096 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9097 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 9098 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 9099 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9100 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9101 | s = dmi_get_system_info(DMI_PRODUCT_VERSION); |
Rasmus Villemoes | 40f5c77 | 2014-10-13 15:54:52 -0700 | [diff] [blame] | 9102 | if (s && !(strncasecmp(s, "ThinkPad", 8) && strncasecmp(s, "Lenovo", 6))) { |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9103 | tp->model_str = kstrdup(s, GFP_KERNEL); |
| 9104 | if (!tp->model_str) |
| 9105 | return -ENOMEM; |
Manoj Iyer | a4f46bb | 2012-08-06 18:15:37 -0500 | [diff] [blame] | 9106 | } else { |
| 9107 | s = dmi_get_system_info(DMI_BIOS_VENDOR); |
Rasmus Villemoes | 40f5c77 | 2014-10-13 15:54:52 -0700 | [diff] [blame] | 9108 | if (s && !(strncasecmp(s, "Lenovo", 6))) { |
Manoj Iyer | a4f46bb | 2012-08-06 18:15:37 -0500 | [diff] [blame] | 9109 | tp->model_str = kstrdup(s, GFP_KERNEL); |
| 9110 | if (!tp->model_str) |
| 9111 | return -ENOMEM; |
| 9112 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9113 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 9114 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9115 | s = dmi_get_system_info(DMI_PRODUCT_NAME); |
| 9116 | tp->nummodel_str = kstrdup(s, GFP_KERNEL); |
| 9117 | if (s && !tp->nummodel_str) |
| 9118 | return -ENOMEM; |
| 9119 | |
| 9120 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9121 | } |
| 9122 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9123 | static int __init probe_for_thinkpad(void) |
| 9124 | { |
| 9125 | int is_thinkpad; |
| 9126 | |
| 9127 | if (acpi_disabled) |
| 9128 | return -ENODEV; |
| 9129 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 9130 | /* It would be dangerous to run the driver in this case */ |
| 9131 | if (!tpacpi_is_ibm() && !tpacpi_is_lenovo()) |
| 9132 | return -ENODEV; |
| 9133 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9134 | /* |
| 9135 | * Non-ancient models have better DMI tagging, but very old models |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 9136 | * don't. tpacpi_is_fw_known() is a cheat to help in that case. |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9137 | */ |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 9138 | is_thinkpad = (thinkpad_id.model_str != NULL) || |
| 9139 | (thinkpad_id.ec_model != 0) || |
| 9140 | tpacpi_is_fw_known(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9141 | |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 9142 | /* The EC handler is required */ |
| 9143 | tpacpi_acpi_handle_locate("ec", TPACPI_ACPI_EC_HID, &ec_handle); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9144 | if (!ec_handle) { |
| 9145 | if (is_thinkpad) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9146 | pr_err("Not yet supported ThinkPad detected!\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9147 | return -ENODEV; |
| 9148 | } |
| 9149 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 9150 | if (!is_thinkpad && !force_load) |
| 9151 | return -ENODEV; |
| 9152 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9153 | return 0; |
| 9154 | } |
| 9155 | |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 9156 | static void __init thinkpad_acpi_init_banner(void) |
| 9157 | { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9158 | pr_info("%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 9159 | pr_info("%s\n", TPACPI_URL); |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 9160 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9161 | pr_info("ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 9162 | (thinkpad_id.bios_version_str) ? |
| 9163 | thinkpad_id.bios_version_str : "unknown", |
| 9164 | (thinkpad_id.ec_version_str) ? |
| 9165 | thinkpad_id.ec_version_str : "unknown"); |
| 9166 | |
| 9167 | BUG_ON(!thinkpad_id.vendor); |
| 9168 | |
| 9169 | if (thinkpad_id.model_str) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9170 | pr_info("%s %s, model %s\n", |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 9171 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 9172 | "IBM" : ((thinkpad_id.vendor == |
| 9173 | PCI_VENDOR_ID_LENOVO) ? |
| 9174 | "Lenovo" : "Unknown vendor"), |
| 9175 | thinkpad_id.model_str, |
| 9176 | (thinkpad_id.nummodel_str) ? |
| 9177 | thinkpad_id.nummodel_str : "unknown"); |
| 9178 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9179 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 9180 | /* Module init, exit, parameters */ |
| 9181 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9182 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 9183 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9184 | .data = &thinkpad_acpi_driver_data, |
| 9185 | }, |
| 9186 | { |
| 9187 | .init = hotkey_init, |
| 9188 | .data = &hotkey_driver_data, |
| 9189 | }, |
| 9190 | { |
| 9191 | .init = bluetooth_init, |
| 9192 | .data = &bluetooth_driver_data, |
| 9193 | }, |
| 9194 | { |
| 9195 | .init = wan_init, |
| 9196 | .data = &wan_driver_data, |
| 9197 | }, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 9198 | { |
| 9199 | .init = uwb_init, |
| 9200 | .data = &uwb_driver_data, |
| 9201 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 9202 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9203 | { |
| 9204 | .init = video_init, |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 9205 | .base_procfs_mode = S_IRUSR, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9206 | .data = &video_driver_data, |
| 9207 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 9208 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9209 | { |
| 9210 | .init = light_init, |
| 9211 | .data = &light_driver_data, |
| 9212 | }, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9213 | { |
| 9214 | .init = cmos_init, |
| 9215 | .data = &cmos_driver_data, |
| 9216 | }, |
| 9217 | { |
| 9218 | .init = led_init, |
| 9219 | .data = &led_driver_data, |
| 9220 | }, |
| 9221 | { |
| 9222 | .init = beep_init, |
| 9223 | .data = &beep_driver_data, |
| 9224 | }, |
| 9225 | { |
| 9226 | .init = thermal_init, |
| 9227 | .data = &thermal_driver_data, |
| 9228 | }, |
| 9229 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9230 | .init = brightness_init, |
| 9231 | .data = &brightness_driver_data, |
| 9232 | }, |
| 9233 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 9234 | .init = volume_init, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9235 | .data = &volume_driver_data, |
| 9236 | }, |
| 9237 | { |
| 9238 | .init = fan_init, |
| 9239 | .data = &fan_driver_data, |
| 9240 | }, |
David Henningsson | 420f973 | 2013-10-16 23:10:31 +0200 | [diff] [blame] | 9241 | { |
| 9242 | .init = mute_led_init, |
| 9243 | .data = &mute_led_driver_data, |
| 9244 | }, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9245 | }; |
| 9246 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 9247 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 9248 | { |
| 9249 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9250 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 9251 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 9252 | if (!kp || !kp->name || !val) |
| 9253 | return -EINVAL; |
| 9254 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9255 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 9256 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 9257 | WARN_ON(ibm == NULL); |
| 9258 | |
| 9259 | if (!ibm || !ibm->name) |
| 9260 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9261 | |
| 9262 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 9263 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 9264 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9265 | strcpy(ibms_init[i].param, val); |
| 9266 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 9267 | return 0; |
| 9268 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9269 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 9270 | |
| 9271 | return -EINVAL; |
| 9272 | } |
| 9273 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 9274 | module_param(experimental, int, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9275 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9276 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 9277 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 9278 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9279 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 9280 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 9281 | module_param(force_load, bool, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9282 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9283 | "Attempts to load the driver even on a " |
| 9284 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 9285 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 9286 | module_param_named(fan_control, fan_control_allowed, bool, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9287 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9288 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 9289 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 9290 | module_param_named(brightness_mode, brightness_mode, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9291 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9292 | "Selects brightness control strategy: " |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 9293 | "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 9294 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 9295 | module_param(brightness_enable, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9296 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9297 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 9298 | |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 9299 | #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 9300 | module_param_named(volume_mode, volume_mode, uint, 0444); |
| 9301 | MODULE_PARM_DESC(volume_mode, |
| 9302 | "Selects volume control strategy: " |
| 9303 | "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM"); |
| 9304 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 9305 | module_param_named(volume_capabilities, volume_capabilities, uint, 0444); |
| 9306 | MODULE_PARM_DESC(volume_capabilities, |
| 9307 | "Selects the mixer capabilites: " |
| 9308 | "0=auto, 1=volume and mute, 2=mute only"); |
| 9309 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 9310 | module_param_named(volume_control, volume_control_allowed, bool, 0444); |
| 9311 | MODULE_PARM_DESC(volume_control, |
| 9312 | "Enables software override for the console audio " |
| 9313 | "control when true"); |
| 9314 | |
Andy Lutomirski | 9a417ec | 2014-10-17 17:04:29 -0700 | [diff] [blame] | 9315 | module_param_named(software_mute, software_mute_requested, bool, 0444); |
| 9316 | MODULE_PARM_DESC(software_mute, |
| 9317 | "Request full software mute control"); |
| 9318 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 9319 | /* ALSA module API parameters */ |
| 9320 | module_param_named(index, alsa_index, int, 0444); |
| 9321 | MODULE_PARM_DESC(index, "ALSA index for the ACPI EC Mixer"); |
| 9322 | module_param_named(id, alsa_id, charp, 0444); |
| 9323 | MODULE_PARM_DESC(id, "ALSA id for the ACPI EC Mixer"); |
| 9324 | module_param_named(enable, alsa_enable, bool, 0444); |
| 9325 | MODULE_PARM_DESC(enable, "Enable the ALSA interface for the ACPI EC Mixer"); |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 9326 | #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 9327 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9328 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9329 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 9330 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9331 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 9332 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9333 | TPACPI_PARAM(hotkey); |
| 9334 | TPACPI_PARAM(bluetooth); |
| 9335 | TPACPI_PARAM(video); |
| 9336 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9337 | TPACPI_PARAM(cmos); |
| 9338 | TPACPI_PARAM(led); |
| 9339 | TPACPI_PARAM(beep); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9340 | TPACPI_PARAM(brightness); |
| 9341 | TPACPI_PARAM(volume); |
| 9342 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 9343 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 9344 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 9345 | module_param(dbg_wlswemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 9346 | MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation"); |
| 9347 | module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0); |
| 9348 | MODULE_PARM_DESC(wlsw_state, |
| 9349 | "Initial state of the emulated WLSW switch"); |
| 9350 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 9351 | module_param(dbg_bluetoothemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 9352 | MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation"); |
| 9353 | module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0); |
| 9354 | MODULE_PARM_DESC(bluetooth_state, |
| 9355 | "Initial state of the emulated bluetooth switch"); |
| 9356 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 9357 | module_param(dbg_wwanemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 9358 | MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation"); |
| 9359 | module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0); |
| 9360 | MODULE_PARM_DESC(wwan_state, |
| 9361 | "Initial state of the emulated WWAN switch"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 9362 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 9363 | module_param(dbg_uwbemul, uint, 0444); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 9364 | MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation"); |
| 9365 | module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0); |
| 9366 | MODULE_PARM_DESC(uwb_state, |
| 9367 | "Initial state of the emulated UWB switch"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 9368 | #endif |
| 9369 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 9370 | static void thinkpad_acpi_module_exit(void) |
| 9371 | { |
| 9372 | struct ibm_struct *ibm, *itmp; |
| 9373 | |
| 9374 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 9375 | |
| 9376 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 9377 | &tpacpi_all_drivers, |
| 9378 | all_drivers) { |
| 9379 | ibm_exit(ibm); |
| 9380 | } |
| 9381 | |
| 9382 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 9383 | |
| 9384 | if (tpacpi_inputdev) { |
| 9385 | if (tp_features.input_device_registered) |
| 9386 | input_unregister_device(tpacpi_inputdev); |
| 9387 | else |
| 9388 | input_free_device(tpacpi_inputdev); |
Li Dongyang | 00d3959 | 2012-07-25 10:45:09 +1000 | [diff] [blame] | 9389 | kfree(hotkey_keycode_map); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 9390 | } |
| 9391 | |
| 9392 | if (tpacpi_hwmon) |
| 9393 | hwmon_device_unregister(tpacpi_hwmon); |
| 9394 | |
| 9395 | if (tp_features.sensors_pdev_attrs_registered) |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 9396 | device_remove_file(&tpacpi_sensors_pdev->dev, &dev_attr_name); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 9397 | if (tpacpi_sensors_pdev) |
| 9398 | platform_device_unregister(tpacpi_sensors_pdev); |
| 9399 | if (tpacpi_pdev) |
| 9400 | platform_device_unregister(tpacpi_pdev); |
| 9401 | |
| 9402 | if (tp_features.sensors_pdrv_attrs_registered) |
| 9403 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 9404 | if (tp_features.platform_drv_attrs_registered) |
| 9405 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 9406 | |
| 9407 | if (tp_features.sensors_pdrv_registered) |
| 9408 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 9409 | |
| 9410 | if (tp_features.platform_drv_registered) |
| 9411 | platform_driver_unregister(&tpacpi_pdriver); |
| 9412 | |
| 9413 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9414 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 9415 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 9416 | if (tpacpi_wq) |
| 9417 | destroy_workqueue(tpacpi_wq); |
| 9418 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 9419 | kfree(thinkpad_id.bios_version_str); |
| 9420 | kfree(thinkpad_id.ec_version_str); |
| 9421 | kfree(thinkpad_id.model_str); |
Li Dongyang | d2be15b | 2012-07-25 10:45:08 +1000 | [diff] [blame] | 9422 | kfree(thinkpad_id.nummodel_str); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 9423 | } |
| 9424 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 9425 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9426 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9427 | { |
| 9428 | int ret, i; |
| 9429 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 9430 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 9431 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9432 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9433 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9434 | ret = get_thinkpad_model_data(&thinkpad_id); |
| 9435 | if (ret) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9436 | pr_err("unable to get DMI data: %d\n", ret); |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9437 | thinkpad_acpi_module_exit(); |
| 9438 | return ret; |
| 9439 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9440 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9441 | if (ret) { |
| 9442 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9443 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9444 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9445 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9446 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9447 | |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 9448 | thinkpad_acpi_init_banner(); |
| 9449 | tpacpi_check_outdated_fw(); |
| 9450 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9451 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 9452 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9453 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 9454 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
| 9455 | if (!tpacpi_wq) { |
| 9456 | thinkpad_acpi_module_exit(); |
| 9457 | return -ENOMEM; |
| 9458 | } |
| 9459 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9460 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9461 | if (!proc_dir) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9462 | pr_err("unable to create proc dir " TPACPI_PROC_DIR "\n"); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9463 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9464 | return -ENODEV; |
| 9465 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 9466 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9467 | ret = platform_driver_register(&tpacpi_pdriver); |
| 9468 | if (ret) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9469 | pr_err("unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9470 | thinkpad_acpi_module_exit(); |
| 9471 | return ret; |
| 9472 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 9473 | tp_features.platform_drv_registered = 1; |
| 9474 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9475 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 9476 | if (ret) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9477 | pr_err("unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9478 | thinkpad_acpi_module_exit(); |
| 9479 | return ret; |
| 9480 | } |
| 9481 | tp_features.sensors_pdrv_registered = 1; |
| 9482 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9483 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 9484 | if (!ret) { |
| 9485 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9486 | ret = tpacpi_create_driver_attributes( |
| 9487 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 9488 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9489 | if (ret) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9490 | pr_err("unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9491 | thinkpad_acpi_module_exit(); |
| 9492 | return ret; |
| 9493 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 9494 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9495 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9496 | |
| 9497 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9498 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9499 | NULL, 0); |
| 9500 | if (IS_ERR(tpacpi_pdev)) { |
| 9501 | ret = PTR_ERR(tpacpi_pdev); |
| 9502 | tpacpi_pdev = NULL; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9503 | pr_err("unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9504 | thinkpad_acpi_module_exit(); |
| 9505 | return ret; |
| 9506 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9507 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9508 | TPACPI_HWMON_DRVR_NAME, |
| 9509 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9510 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 9511 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 9512 | tpacpi_sensors_pdev = NULL; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9513 | pr_err("unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9514 | thinkpad_acpi_module_exit(); |
| 9515 | return ret; |
| 9516 | } |
Bjørn Mork | 5fb73bc | 2015-05-19 19:45:03 +0200 | [diff] [blame] | 9517 | ret = device_create_file(&tpacpi_sensors_pdev->dev, &dev_attr_name); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9518 | if (ret) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9519 | pr_err("unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9520 | thinkpad_acpi_module_exit(); |
| 9521 | return ret; |
| 9522 | } |
| 9523 | tp_features.sensors_pdev_attrs_registered = 1; |
| 9524 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9525 | if (IS_ERR(tpacpi_hwmon)) { |
| 9526 | ret = PTR_ERR(tpacpi_hwmon); |
| 9527 | tpacpi_hwmon = NULL; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9528 | pr_err("unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9529 | thinkpad_acpi_module_exit(); |
| 9530 | return ret; |
| 9531 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 9532 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9533 | tpacpi_inputdev = input_allocate_device(); |
| 9534 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9535 | thinkpad_acpi_module_exit(); |
| 9536 | return -ENOMEM; |
| 9537 | } else { |
| 9538 | /* Prepare input device, but don't register */ |
| 9539 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9540 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9541 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 9542 | tpacpi_inputdev->id.vendor = thinkpad_id.vendor; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9543 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 9544 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
Henrique de Moraes Holschuh | d112ef9 | 2009-12-09 01:36:26 +0000 | [diff] [blame] | 9545 | tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9546 | } |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 9547 | |
| 9548 | /* Init subdriver dependencies */ |
| 9549 | tpacpi_detect_brightness_capabilities(); |
| 9550 | |
| 9551 | /* Init subdrivers */ |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9552 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 9553 | ret = ibm_init(&ibms_init[i]); |
| 9554 | if (ret >= 0 && *ibms_init[i].param) |
| 9555 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9556 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9557 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9558 | return ret; |
| 9559 | } |
| 9560 | } |
Henrique de Moraes Holschuh | b589ea4 | 2010-02-25 21:28:58 -0300 | [diff] [blame] | 9561 | |
| 9562 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
| 9563 | |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9564 | ret = input_register_device(tpacpi_inputdev); |
| 9565 | if (ret < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9566 | pr_err("unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9567 | thinkpad_acpi_module_exit(); |
| 9568 | return ret; |
| 9569 | } else { |
| 9570 | tp_features.input_device_registered = 1; |
| 9571 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9572 | |
| 9573 | return 0; |
| 9574 | } |
| 9575 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 9576 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 9577 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9578 | /* |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 9579 | * This will autoload the driver in almost every ThinkPad |
| 9580 | * in widespread use. |
| 9581 | * |
| 9582 | * Only _VERY_ old models, like the 240, 240x and 570 lack |
| 9583 | * the HKEY event interface. |
| 9584 | */ |
| 9585 | MODULE_DEVICE_TABLE(acpi, ibm_htk_device_ids); |
| 9586 | |
| 9587 | /* |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9588 | * DMI matching for module autoloading |
| 9589 | * |
| 9590 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 9591 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 9592 | * |
| 9593 | * Only models listed in thinkwiki will be supported, so add yours |
| 9594 | * if it is not there yet. |
| 9595 | */ |
| 9596 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
Mathieu Chouquet-Stringer | b36a50f | 2009-03-14 16:35:26 +0100 | [diff] [blame] | 9597 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*") |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9598 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9599 | /* Ancient thinkpad BIOSes have to be identified by |
| 9600 | * BIOS type or model number, and there are far less |
| 9601 | * BIOS types than model numbers... */ |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 9602 | IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9603 | |
Henrique de Moraes Holschuh | f68f53a | 2009-04-14 02:44:12 +0000 | [diff] [blame] | 9604 | MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>"); |
| 9605 | MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9606 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 9607 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9608 | MODULE_LICENSE("GPL"); |
| 9609 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9610 | module_init(thinkpad_acpi_module_init); |
| 9611 | module_exit(thinkpad_acpi_module_exit); |