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 | |
Henrique de Moraes Holschuh | 5d2eb14 | 2009-12-15 21:51:13 -0200 | [diff] [blame] | 24 | #define TPACPI_VERSION "0.24" |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 25 | #define TPACPI_SYSFS_VERSION 0x020700 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 26 | |
| 27 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * Changelog: |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 29 | * 2007-10-20 changelog trimmed down |
| 30 | * |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 31 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
| 32 | * drivers/misc. |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 33 | * |
| 34 | * 2006-11-22 0.13 new maintainer |
| 35 | * changelog now lives in git commit history, and will |
| 36 | * not be updated further in-file. |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 37 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 38 | * 2005-03-17 0.11 support for 600e, 770x |
| 39 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 40 | * |
| 41 | * 2005-01-16 0.9 use MODULE_VERSION |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 42 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
| 43 | * fix parameter passing on module loading |
| 44 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
| 45 | * thanks to Jim Radford <radford@blackbean.org> |
| 46 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
| 47 | * thanks to Chris Wright <chrisw@osdl.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | */ |
| 49 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 50 | #include <linux/kernel.h> |
| 51 | #include <linux/module.h> |
| 52 | #include <linux/init.h> |
| 53 | #include <linux/types.h> |
| 54 | #include <linux/string.h> |
| 55 | #include <linux/list.h> |
| 56 | #include <linux/mutex.h> |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 57 | #include <linux/sched.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 58 | #include <linux/kthread.h> |
| 59 | #include <linux/freezer.h> |
| 60 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 61 | #include <linux/slab.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 62 | |
| 63 | #include <linux/nvram.h> |
| 64 | #include <linux/proc_fs.h> |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 65 | #include <linux/seq_file.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 66 | #include <linux/sysfs.h> |
| 67 | #include <linux/backlight.h> |
| 68 | #include <linux/fb.h> |
| 69 | #include <linux/platform_device.h> |
| 70 | #include <linux/hwmon.h> |
| 71 | #include <linux/hwmon-sysfs.h> |
| 72 | #include <linux/input.h> |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 73 | #include <linux/leds.h> |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 74 | #include <linux/rfkill.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 75 | #include <asm/uaccess.h> |
| 76 | |
| 77 | #include <linux/dmi.h> |
| 78 | #include <linux/jiffies.h> |
| 79 | #include <linux/workqueue.h> |
| 80 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 81 | #include <sound/core.h> |
| 82 | #include <sound/control.h> |
| 83 | #include <sound/initval.h> |
| 84 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 85 | #include <acpi/acpi_drivers.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 86 | |
| 87 | #include <linux/pci_ids.h> |
| 88 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 89 | |
| 90 | /* ThinkPad CMOS commands */ |
| 91 | #define TP_CMOS_VOLUME_DOWN 0 |
| 92 | #define TP_CMOS_VOLUME_UP 1 |
| 93 | #define TP_CMOS_VOLUME_MUTE 2 |
| 94 | #define TP_CMOS_BRIGHTNESS_UP 4 |
| 95 | #define TP_CMOS_BRIGHTNESS_DOWN 5 |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 96 | #define TP_CMOS_THINKLIGHT_ON 12 |
| 97 | #define TP_CMOS_THINKLIGHT_OFF 13 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 98 | |
| 99 | /* NVRAM Addresses */ |
| 100 | enum tp_nvram_addr { |
| 101 | TP_NVRAM_ADDR_HK2 = 0x57, |
| 102 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, |
| 103 | TP_NVRAM_ADDR_VIDEO = 0x59, |
| 104 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, |
| 105 | TP_NVRAM_ADDR_MIXER = 0x60, |
| 106 | }; |
| 107 | |
| 108 | /* NVRAM bit masks */ |
| 109 | enum { |
| 110 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, |
| 111 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, |
| 112 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, |
| 113 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, |
| 114 | TP_NVRAM_MASK_THINKLIGHT = 0x10, |
| 115 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, |
| 116 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, |
| 117 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, |
| 118 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, |
| 119 | TP_NVRAM_MASK_MUTE = 0x40, |
| 120 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, |
| 121 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, |
| 122 | TP_NVRAM_POS_LEVEL_VOLUME = 0, |
| 123 | }; |
| 124 | |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 125 | /* Misc NVRAM-related */ |
| 126 | enum { |
| 127 | TP_NVRAM_LEVEL_VOLUME_MAX = 14, |
| 128 | }; |
| 129 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 130 | /* ACPI HIDs */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 131 | #define TPACPI_ACPI_HKEY_HID "IBM0068" |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 132 | #define TPACPI_ACPI_EC_HID "PNP0C09" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 133 | |
| 134 | /* Input IDs */ |
| 135 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ |
| 136 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 |
| 137 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 138 | /* ACPI \WGSV commands */ |
| 139 | enum { |
| 140 | TP_ACPI_WGSV_GET_STATE = 0x01, /* Get state information */ |
| 141 | TP_ACPI_WGSV_PWR_ON_ON_RESUME = 0x02, /* Resume WWAN powered on */ |
| 142 | TP_ACPI_WGSV_PWR_OFF_ON_RESUME = 0x03, /* Resume WWAN powered off */ |
| 143 | TP_ACPI_WGSV_SAVE_STATE = 0x04, /* Save state for S4/S5 */ |
| 144 | }; |
| 145 | |
| 146 | /* TP_ACPI_WGSV_GET_STATE bits */ |
| 147 | enum { |
| 148 | TP_ACPI_WGSV_STATE_WWANEXIST = 0x0001, /* WWAN hw available */ |
| 149 | TP_ACPI_WGSV_STATE_WWANPWR = 0x0002, /* WWAN radio enabled */ |
| 150 | TP_ACPI_WGSV_STATE_WWANPWRRES = 0x0004, /* WWAN state at resume */ |
| 151 | TP_ACPI_WGSV_STATE_WWANBIOSOFF = 0x0008, /* WWAN disabled in BIOS */ |
| 152 | TP_ACPI_WGSV_STATE_BLTHEXIST = 0x0001, /* BLTH hw available */ |
| 153 | TP_ACPI_WGSV_STATE_BLTHPWR = 0x0002, /* BLTH radio enabled */ |
| 154 | TP_ACPI_WGSV_STATE_BLTHPWRRES = 0x0004, /* BLTH state at resume */ |
| 155 | TP_ACPI_WGSV_STATE_BLTHBIOSOFF = 0x0008, /* BLTH disabled in BIOS */ |
| 156 | TP_ACPI_WGSV_STATE_UWBEXIST = 0x0010, /* UWB hw available */ |
| 157 | TP_ACPI_WGSV_STATE_UWBPWR = 0x0020, /* UWB radio enabled */ |
| 158 | }; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 159 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 160 | /* HKEY events */ |
| 161 | enum tpacpi_hkey_event_t { |
| 162 | /* Hotkey-related */ |
| 163 | TP_HKEY_EV_HOTKEY_BASE = 0x1001, /* first hotkey (FN+F1) */ |
| 164 | TP_HKEY_EV_BRGHT_UP = 0x1010, /* Brightness up */ |
| 165 | TP_HKEY_EV_BRGHT_DOWN = 0x1011, /* Brightness down */ |
| 166 | TP_HKEY_EV_VOL_UP = 0x1015, /* Volume up or unmute */ |
| 167 | TP_HKEY_EV_VOL_DOWN = 0x1016, /* Volume down or unmute */ |
| 168 | TP_HKEY_EV_VOL_MUTE = 0x1017, /* Mixer output mute */ |
| 169 | |
| 170 | /* Reasons for waking up from S3/S4 */ |
| 171 | TP_HKEY_EV_WKUP_S3_UNDOCK = 0x2304, /* undock requested, S3 */ |
| 172 | TP_HKEY_EV_WKUP_S4_UNDOCK = 0x2404, /* undock requested, S4 */ |
| 173 | TP_HKEY_EV_WKUP_S3_BAYEJ = 0x2305, /* bay ejection req, S3 */ |
| 174 | TP_HKEY_EV_WKUP_S4_BAYEJ = 0x2405, /* bay ejection req, S4 */ |
| 175 | TP_HKEY_EV_WKUP_S3_BATLOW = 0x2313, /* battery empty, S3 */ |
| 176 | TP_HKEY_EV_WKUP_S4_BATLOW = 0x2413, /* battery empty, S4 */ |
| 177 | |
| 178 | /* Auto-sleep after eject request */ |
| 179 | TP_HKEY_EV_BAYEJ_ACK = 0x3003, /* bay ejection complete */ |
| 180 | TP_HKEY_EV_UNDOCK_ACK = 0x4003, /* undock complete */ |
| 181 | |
| 182 | /* Misc bay events */ |
| 183 | TP_HKEY_EV_OPTDRV_EJ = 0x3006, /* opt. drive tray ejected */ |
| 184 | |
| 185 | /* User-interface events */ |
| 186 | TP_HKEY_EV_LID_CLOSE = 0x5001, /* laptop lid closed */ |
| 187 | TP_HKEY_EV_LID_OPEN = 0x5002, /* laptop lid opened */ |
| 188 | TP_HKEY_EV_TABLET_TABLET = 0x5009, /* tablet swivel up */ |
| 189 | TP_HKEY_EV_TABLET_NOTEBOOK = 0x500a, /* tablet swivel down */ |
| 190 | TP_HKEY_EV_PEN_INSERTED = 0x500b, /* tablet pen inserted */ |
| 191 | TP_HKEY_EV_PEN_REMOVED = 0x500c, /* tablet pen removed */ |
| 192 | TP_HKEY_EV_BRGHT_CHANGED = 0x5010, /* backlight control event */ |
| 193 | |
| 194 | /* Thermal events */ |
| 195 | TP_HKEY_EV_ALARM_BAT_HOT = 0x6011, /* battery too hot */ |
| 196 | TP_HKEY_EV_ALARM_BAT_XHOT = 0x6012, /* battery critically hot */ |
| 197 | TP_HKEY_EV_ALARM_SENSOR_HOT = 0x6021, /* sensor too hot */ |
| 198 | TP_HKEY_EV_ALARM_SENSOR_XHOT = 0x6022, /* sensor critically hot */ |
| 199 | TP_HKEY_EV_THM_TABLE_CHANGED = 0x6030, /* thermal table changed */ |
| 200 | |
| 201 | /* Misc */ |
| 202 | TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */ |
| 203 | }; |
| 204 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 205 | /**************************************************************************** |
| 206 | * Main driver |
| 207 | */ |
| 208 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 209 | #define TPACPI_NAME "thinkpad" |
| 210 | #define TPACPI_DESC "ThinkPad ACPI Extras" |
| 211 | #define TPACPI_FILE TPACPI_NAME "_acpi" |
| 212 | #define TPACPI_URL "http://ibm-acpi.sf.net/" |
| 213 | #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 214 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 215 | #define TPACPI_PROC_DIR "ibm" |
| 216 | #define TPACPI_ACPI_EVENT_PREFIX "ibm" |
| 217 | #define TPACPI_DRVR_NAME TPACPI_FILE |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 218 | #define TPACPI_DRVR_SHORTNAME "tpacpi" |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 219 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 220 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 221 | #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd" |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 222 | #define TPACPI_WORKQUEUE_NAME "ktpacpid" |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 223 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 224 | #define TPACPI_MAX_ACPI_ARGS 3 |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 225 | |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 226 | /* printk headers */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 227 | #define TPACPI_LOG TPACPI_FILE ": " |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 228 | #define TPACPI_EMERG KERN_EMERG TPACPI_LOG |
| 229 | #define TPACPI_ALERT KERN_ALERT TPACPI_LOG |
| 230 | #define TPACPI_CRIT KERN_CRIT TPACPI_LOG |
| 231 | #define TPACPI_ERR KERN_ERR TPACPI_LOG |
| 232 | #define TPACPI_WARN KERN_WARNING TPACPI_LOG |
| 233 | #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG |
| 234 | #define TPACPI_INFO KERN_INFO TPACPI_LOG |
| 235 | #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 236 | |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 237 | /* Debugging printk groups */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 238 | #define TPACPI_DBG_ALL 0xffff |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 239 | #define TPACPI_DBG_DISCLOSETASK 0x8000 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 240 | #define TPACPI_DBG_INIT 0x0001 |
| 241 | #define TPACPI_DBG_EXIT 0x0002 |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 242 | #define TPACPI_DBG_RFKILL 0x0004 |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 243 | #define TPACPI_DBG_HKEY 0x0008 |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 244 | #define TPACPI_DBG_FAN 0x0010 |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 245 | #define TPACPI_DBG_BRGHT 0x0020 |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 246 | #define TPACPI_DBG_MIXER 0x0040 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 247 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 248 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 249 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 250 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 251 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 252 | |
| 253 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 254 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 255 | */ |
| 256 | |
| 257 | struct ibm_struct; |
| 258 | |
| 259 | struct tp_acpi_drv_struct { |
| 260 | const struct acpi_device_id *hid; |
| 261 | struct acpi_driver *driver; |
| 262 | |
| 263 | void (*notify) (struct ibm_struct *, u32); |
| 264 | acpi_handle *handle; |
| 265 | u32 type; |
| 266 | struct acpi_device *device; |
| 267 | }; |
| 268 | |
| 269 | struct ibm_struct { |
| 270 | char *name; |
| 271 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 272 | int (*read) (struct seq_file *); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 273 | int (*write) (char *); |
| 274 | void (*exit) (void); |
| 275 | void (*resume) (void); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 276 | void (*suspend) (pm_message_t state); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 277 | void (*shutdown) (void); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 278 | |
| 279 | struct list_head all_drivers; |
| 280 | |
| 281 | struct tp_acpi_drv_struct *acpi; |
| 282 | |
| 283 | struct { |
| 284 | u8 acpi_driver_registered:1; |
| 285 | u8 acpi_notify_installed:1; |
| 286 | u8 proc_created:1; |
| 287 | u8 init_called:1; |
| 288 | u8 experimental:1; |
| 289 | } flags; |
| 290 | }; |
| 291 | |
| 292 | struct ibm_init_struct { |
| 293 | char param[32]; |
| 294 | |
| 295 | int (*init) (struct ibm_init_struct *); |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 296 | mode_t base_procfs_mode; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 297 | struct ibm_struct *data; |
| 298 | }; |
| 299 | |
| 300 | static struct { |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 301 | u32 bluetooth:1; |
| 302 | u32 hotkey:1; |
| 303 | u32 hotkey_mask:1; |
| 304 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 305 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 306 | u32 light:1; |
| 307 | u32 light_status:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 308 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 309 | u32 bright_unkfw:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 310 | u32 wan:1; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 311 | u32 uwb:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 312 | u32 fan_ctrl_status_undef:1; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 313 | u32 second_fan:1; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 314 | u32 beep_needs_two_args:1; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 315 | u32 mixer_no_level_control:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 316 | u32 input_device_registered:1; |
| 317 | u32 platform_drv_registered:1; |
| 318 | u32 platform_drv_attrs_registered:1; |
| 319 | u32 sensors_pdrv_registered:1; |
| 320 | u32 sensors_pdrv_attrs_registered:1; |
| 321 | u32 sensors_pdev_attrs_registered:1; |
| 322 | u32 hotkey_poll_active:1; |
| 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; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 369 | unsigned 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; |
| 377 | static int tpacpi_wlsw_emulstate; |
| 378 | static int dbg_bluetoothemul; |
| 379 | static int tpacpi_bluetooth_emulstate; |
| 380 | static int dbg_wwanemul; |
| 381 | static int tpacpi_wwan_emulstate; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 382 | static int dbg_uwbemul; |
| 383 | static int 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 | |
| 391 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 392 | do { if (dbg_level & (a_dbg_level)) \ |
| 393 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ |
| 394 | } while (0) |
| 395 | |
| 396 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 397 | #define vdbg_printk dbg_printk |
| 398 | static const char *str_supported(int is_supported); |
| 399 | #else |
| 400 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 401 | do { } while (0) |
| 402 | #endif |
| 403 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 404 | static void tpacpi_log_usertask(const char * const what) |
| 405 | { |
| 406 | printk(TPACPI_DEBUG "%s: access by process with PID %d\n", |
| 407 | what, task_tgid_vnr(current)); |
| 408 | } |
| 409 | |
| 410 | #define tpacpi_disclose_usertask(what, format, arg...) \ |
| 411 | do { \ |
| 412 | if (unlikely( \ |
| 413 | (dbg_level & TPACPI_DBG_DISCLOSETASK) && \ |
| 414 | (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \ |
| 415 | printk(TPACPI_DEBUG "%s: PID %d: " format, \ |
| 416 | what, task_tgid_vnr(current), ## arg); \ |
| 417 | } \ |
| 418 | } while (0) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 419 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 420 | /* |
| 421 | * Quirk handling helpers |
| 422 | * |
| 423 | * ThinkPad IDs and versions seen in the field so far |
| 424 | * are two-characters from the set [0-9A-Z], i.e. base 36. |
| 425 | * |
| 426 | * We use values well outside that range as specials. |
| 427 | */ |
| 428 | |
| 429 | #define TPACPI_MATCH_ANY 0xffffU |
| 430 | #define TPACPI_MATCH_UNKNOWN 0U |
| 431 | |
| 432 | /* TPID('1', 'Y') == 0x5931 */ |
| 433 | #define TPID(__c1, __c2) (((__c2) << 8) | (__c1)) |
| 434 | |
| 435 | #define TPACPI_Q_IBM(__id1, __id2, __quirk) \ |
| 436 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 437 | .bios = TPID(__id1, __id2), \ |
| 438 | .ec = TPACPI_MATCH_ANY, \ |
| 439 | .quirks = (__quirk) } |
| 440 | |
| 441 | #define TPACPI_Q_LNV(__id1, __id2, __quirk) \ |
| 442 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 443 | .bios = TPID(__id1, __id2), \ |
| 444 | .ec = TPACPI_MATCH_ANY, \ |
| 445 | .quirks = (__quirk) } |
| 446 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 447 | #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \ |
| 448 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 449 | .bios = TPACPI_MATCH_ANY, \ |
| 450 | .ec = TPID(__id1, __id2), \ |
| 451 | .quirks = (__quirk) } |
| 452 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 453 | struct tpacpi_quirk { |
| 454 | unsigned int vendor; |
| 455 | u16 bios; |
| 456 | u16 ec; |
| 457 | unsigned long quirks; |
| 458 | }; |
| 459 | |
| 460 | /** |
| 461 | * tpacpi_check_quirks() - search BIOS/EC version on a list |
| 462 | * @qlist: array of &struct tpacpi_quirk |
| 463 | * @qlist_size: number of elements in @qlist |
| 464 | * |
| 465 | * Iterates over a quirks list until one is found that matches the |
| 466 | * ThinkPad's vendor, BIOS and EC model. |
| 467 | * |
| 468 | * Returns 0 if nothing matches, otherwise returns the quirks field of |
| 469 | * the matching &struct tpacpi_quirk entry. |
| 470 | * |
| 471 | * The match criteria is: vendor, ec and bios much match. |
| 472 | */ |
| 473 | static unsigned long __init tpacpi_check_quirks( |
| 474 | const struct tpacpi_quirk *qlist, |
| 475 | unsigned int qlist_size) |
| 476 | { |
| 477 | while (qlist_size) { |
| 478 | if ((qlist->vendor == thinkpad_id.vendor || |
| 479 | qlist->vendor == TPACPI_MATCH_ANY) && |
| 480 | (qlist->bios == thinkpad_id.bios_model || |
| 481 | qlist->bios == TPACPI_MATCH_ANY) && |
| 482 | (qlist->ec == thinkpad_id.ec_model || |
| 483 | qlist->ec == TPACPI_MATCH_ANY)) |
| 484 | return qlist->quirks; |
| 485 | |
| 486 | qlist_size--; |
| 487 | qlist++; |
| 488 | } |
| 489 | return 0; |
| 490 | } |
| 491 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 492 | static inline bool __pure __init tpacpi_is_lenovo(void) |
| 493 | { |
| 494 | return thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO; |
| 495 | } |
| 496 | |
| 497 | static inline bool __pure __init tpacpi_is_ibm(void) |
| 498 | { |
| 499 | return thinkpad_id.vendor == PCI_VENDOR_ID_IBM; |
| 500 | } |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 501 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 502 | /**************************************************************************** |
| 503 | **************************************************************************** |
| 504 | * |
| 505 | * ACPI Helpers and device model |
| 506 | * |
| 507 | **************************************************************************** |
| 508 | ****************************************************************************/ |
| 509 | |
| 510 | /************************************************************************* |
| 511 | * ACPI basic handles |
| 512 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 514 | static acpi_handle root_handle; |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 515 | static acpi_handle ec_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 517 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | static acpi_handle object##_handle; \ |
Henrique de Moraes Holschuh | ef07a5a | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 519 | static const acpi_handle *object##_parent __initdata = \ |
| 520 | &parent##_handle; \ |
| 521 | static char *object##_paths[] __initdata = { paths } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 523 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 524 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 526 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 527 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 528 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 529 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 530 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 531 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 532 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 533 | "^HKEY", /* R30, R31 */ |
| 534 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 535 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 536 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 537 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 538 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 539 | "\\_SB.PCI0.VID0", /* 770e */ |
| 540 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
Henrique de Moraes Holschuh | a318930 | 2010-05-16 19:45:26 -0300 | [diff] [blame] | 541 | "\\_SB.PCI0.AGP.VGA", /* X100e and a few others */ |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 542 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 543 | ); /* R30, R31 */ |
| 544 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 545 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 546 | /************************************************************************* |
| 547 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 548 | */ |
| 549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | static int acpi_evalf(acpi_handle handle, |
| 551 | void *res, char *method, char *fmt, ...) |
| 552 | { |
| 553 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 554 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 555 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 556 | struct acpi_buffer result, *resultp; |
| 557 | union acpi_object out_obj; |
| 558 | acpi_status status; |
| 559 | va_list ap; |
| 560 | char res_type; |
| 561 | int success; |
| 562 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | if (!*fmt) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 565 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | if (*fmt == 'q') { |
| 570 | quiet = 1; |
| 571 | fmt++; |
| 572 | } else |
| 573 | quiet = 0; |
| 574 | |
| 575 | res_type = *(fmt++); |
| 576 | |
| 577 | params.count = 0; |
| 578 | params.pointer = &in_objs[0]; |
| 579 | |
| 580 | va_start(ap, fmt); |
| 581 | while (*fmt) { |
| 582 | char c = *(fmt++); |
| 583 | switch (c) { |
| 584 | case 'd': /* int */ |
| 585 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 586 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 587 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 588 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 590 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | "with invalid format character '%c'\n", c); |
Jesper Juhl | 2136585 | 2010-12-24 19:56:28 +0100 | [diff] [blame] | 592 | va_end(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | return 0; |
| 594 | } |
| 595 | } |
| 596 | va_end(ap); |
| 597 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 598 | if (res_type != 'v') { |
| 599 | result.length = sizeof(out_obj); |
| 600 | result.pointer = &out_obj; |
| 601 | resultp = &result; |
| 602 | } else |
| 603 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 605 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 608 | case 'd': /* int */ |
Henrique de Moraes Holschuh | 263f4a3 | 2010-05-16 19:45:45 -0300 | [diff] [blame] | 609 | success = (status == AE_OK && |
| 610 | out_obj.type == ACPI_TYPE_INTEGER); |
| 611 | if (success && res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | *(int *)res = out_obj.integer.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 614 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | success = status == AE_OK; |
| 616 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 617 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 619 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | "with invalid format character '%c'\n", res_type); |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | if (!success && !quiet) |
Henrique de Moraes Holschuh | 263f4a3 | 2010-05-16 19:45:45 -0300 | [diff] [blame] | 625 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %s\n", |
| 626 | method, fmt0, acpi_format_exception(status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
| 628 | return success; |
| 629 | } |
| 630 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 631 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 632 | { |
| 633 | int v; |
| 634 | |
| 635 | if (ecrd_handle) { |
| 636 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 637 | return 0; |
| 638 | *p = v; |
| 639 | } else { |
| 640 | if (ec_read(i, p) < 0) |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | return 1; |
| 645 | } |
| 646 | |
| 647 | static int acpi_ec_write(int i, u8 v) |
| 648 | { |
| 649 | if (ecwr_handle) { |
| 650 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 651 | return 0; |
| 652 | } else { |
| 653 | if (ec_write(i, v) < 0) |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | return 1; |
| 658 | } |
| 659 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 660 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 661 | { |
| 662 | if (!cmos_handle) |
| 663 | return -ENXIO; |
| 664 | |
| 665 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 666 | return -EIO; |
| 667 | |
| 668 | return 0; |
| 669 | } |
| 670 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 671 | /************************************************************************* |
| 672 | * ACPI device model |
| 673 | */ |
| 674 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 675 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 676 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | ef07a5a | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 677 | object##_paths, ARRAY_SIZE(object##_paths)) |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 678 | |
Henrique de Moraes Holschuh | ef07a5a | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 679 | static void __init drv_acpi_handle_init(const char *name, |
| 680 | acpi_handle *handle, const acpi_handle parent, |
| 681 | char **paths, const int num_paths) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 682 | { |
| 683 | int i; |
| 684 | acpi_status status; |
| 685 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 686 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 687 | name); |
| 688 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 689 | for (i = 0; i < num_paths; i++) { |
| 690 | status = acpi_get_handle(parent, paths[i], handle); |
| 691 | if (ACPI_SUCCESS(status)) { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 692 | dbg_printk(TPACPI_DBG_INIT, |
| 693 | "Found ACPI handle %s for %s\n", |
Henrique de Moraes Holschuh | ef07a5a | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 694 | paths[i], name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 695 | return; |
| 696 | } |
| 697 | } |
| 698 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 699 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 700 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 701 | *handle = NULL; |
| 702 | } |
| 703 | |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 704 | static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle, |
| 705 | u32 level, void *context, void **return_value) |
| 706 | { |
| 707 | *(acpi_handle *)return_value = handle; |
| 708 | |
| 709 | return AE_CTRL_TERMINATE; |
| 710 | } |
| 711 | |
| 712 | static void __init tpacpi_acpi_handle_locate(const char *name, |
| 713 | const char *hid, |
| 714 | acpi_handle *handle) |
| 715 | { |
| 716 | acpi_status status; |
| 717 | acpi_handle device_found; |
| 718 | |
| 719 | BUG_ON(!name || !hid || !handle); |
| 720 | vdbg_printk(TPACPI_DBG_INIT, |
| 721 | "trying to locate ACPI handle for %s, using HID %s\n", |
| 722 | name, hid); |
| 723 | |
| 724 | memset(&device_found, 0, sizeof(device_found)); |
| 725 | status = acpi_get_devices(hid, tpacpi_acpi_handle_locate_callback, |
| 726 | (void *)name, &device_found); |
| 727 | |
| 728 | *handle = NULL; |
| 729 | |
| 730 | if (ACPI_SUCCESS(status)) { |
| 731 | *handle = device_found; |
| 732 | dbg_printk(TPACPI_DBG_INIT, |
| 733 | "Found ACPI handle for %s\n", name); |
| 734 | } else { |
| 735 | vdbg_printk(TPACPI_DBG_INIT, |
| 736 | "Could not locate an ACPI handle for %s: %s\n", |
| 737 | name, acpi_format_exception(status)); |
| 738 | } |
| 739 | } |
| 740 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 741 | 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] | 742 | { |
| 743 | struct ibm_struct *ibm = data; |
| 744 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 745 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 746 | return; |
| 747 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 748 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 749 | return; |
| 750 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 751 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 752 | } |
| 753 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 754 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 755 | { |
| 756 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 757 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 758 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 759 | BUG_ON(!ibm->acpi); |
| 760 | |
| 761 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 762 | return 0; |
| 763 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 764 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 765 | "setting up ACPI notify for %s\n", ibm->name); |
| 766 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 767 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 768 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 769 | printk(TPACPI_ERR "acpi_bus_get_device(%s) failed: %d\n", |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 770 | 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) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 783 | printk(TPACPI_NOTICE |
| 784 | "another device driver is already " |
| 785 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 786 | } else { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 787 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 72f1992 | 2010-05-16 19:45:48 -0300 | [diff] [blame] | 788 | "acpi_install_notify_handler(%s) failed: %s\n", |
| 789 | ibm->name, acpi_format_exception(status)); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 790 | } |
| 791 | return -ENODEV; |
| 792 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 793 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 794 | return 0; |
| 795 | } |
| 796 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 797 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 798 | { |
| 799 | return 0; |
| 800 | } |
| 801 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 802 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 803 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 804 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 805 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 806 | dbg_printk(TPACPI_DBG_INIT, |
| 807 | "registering %s as an ACPI driver\n", ibm->name); |
| 808 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 809 | BUG_ON(!ibm->acpi); |
| 810 | |
| 811 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 812 | if (!ibm->acpi->driver) { |
Mariusz Kozlowski | 4f778b9 | 2008-10-18 14:23:53 -0300 | [diff] [blame] | 813 | printk(TPACPI_ERR |
| 814 | "failed to allocate memory for ibm->acpi->driver\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 815 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 816 | } |
| 817 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 818 | 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] | 819 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 820 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 821 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 822 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 823 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 824 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 825 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 826 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 827 | kfree(ibm->acpi->driver); |
| 828 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 829 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 830 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 831 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 832 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | |
| 836 | /**************************************************************************** |
| 837 | **************************************************************************** |
| 838 | * |
| 839 | * Procfs Helpers |
| 840 | * |
| 841 | **************************************************************************** |
| 842 | ****************************************************************************/ |
| 843 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 844 | 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] | 845 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 846 | struct ibm_struct *ibm = m->private; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 847 | |
| 848 | if (!ibm || !ibm->read) |
| 849 | return -EINVAL; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 850 | return ibm->read(m); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 851 | } |
| 852 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 853 | 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] | 854 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 855 | return single_open(file, dispatch_proc_show, PDE(inode)->data); |
| 856 | } |
| 857 | |
| 858 | static ssize_t dispatch_proc_write(struct file *file, |
| 859 | const char __user *userbuf, |
| 860 | size_t count, loff_t *pos) |
| 861 | { |
| 862 | struct ibm_struct *ibm = PDE(file->f_path.dentry->d_inode)->data; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 863 | char *kernbuf; |
| 864 | int ret; |
| 865 | |
| 866 | if (!ibm || !ibm->write) |
| 867 | return -EINVAL; |
Michael Buesch | 5b05d46 | 2009-08-01 12:04:19 -0300 | [diff] [blame] | 868 | if (count > PAGE_SIZE - 2) |
| 869 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 870 | |
| 871 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 872 | if (!kernbuf) |
| 873 | return -ENOMEM; |
| 874 | |
| 875 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 876 | kfree(kernbuf); |
| 877 | return -EFAULT; |
| 878 | } |
| 879 | |
| 880 | kernbuf[count] = 0; |
| 881 | strcat(kernbuf, ","); |
| 882 | ret = ibm->write(kernbuf); |
| 883 | if (ret == 0) |
| 884 | ret = count; |
| 885 | |
| 886 | kfree(kernbuf); |
| 887 | |
| 888 | return ret; |
| 889 | } |
| 890 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 891 | static const struct file_operations dispatch_proc_fops = { |
| 892 | .owner = THIS_MODULE, |
| 893 | .open = dispatch_proc_open, |
| 894 | .read = seq_read, |
| 895 | .llseek = seq_lseek, |
| 896 | .release = single_release, |
| 897 | .write = dispatch_proc_write, |
| 898 | }; |
| 899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | static char *next_cmd(char **cmds) |
| 901 | { |
| 902 | char *start = *cmds; |
| 903 | char *end; |
| 904 | |
| 905 | while ((end = strchr(start, ',')) && end == start) |
| 906 | start = end + 1; |
| 907 | |
| 908 | if (!end) |
| 909 | return NULL; |
| 910 | |
| 911 | *end = 0; |
| 912 | *cmds = end + 1; |
| 913 | return start; |
| 914 | } |
| 915 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 916 | |
| 917 | /**************************************************************************** |
| 918 | **************************************************************************** |
| 919 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 920 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 921 | * |
| 922 | **************************************************************************** |
| 923 | ****************************************************************************/ |
| 924 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 925 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 926 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 927 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 928 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 929 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 930 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 931 | |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 932 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
| 933 | pm_message_t state) |
| 934 | { |
| 935 | struct ibm_struct *ibm, *itmp; |
| 936 | |
| 937 | list_for_each_entry_safe(ibm, itmp, |
| 938 | &tpacpi_all_drivers, |
| 939 | all_drivers) { |
| 940 | if (ibm->suspend) |
| 941 | (ibm->suspend)(state); |
| 942 | } |
| 943 | |
| 944 | return 0; |
| 945 | } |
| 946 | |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 947 | static int tpacpi_resume_handler(struct platform_device *pdev) |
| 948 | { |
| 949 | struct ibm_struct *ibm, *itmp; |
| 950 | |
| 951 | list_for_each_entry_safe(ibm, itmp, |
| 952 | &tpacpi_all_drivers, |
| 953 | all_drivers) { |
| 954 | if (ibm->resume) |
| 955 | (ibm->resume)(); |
| 956 | } |
| 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 961 | static void tpacpi_shutdown_handler(struct platform_device *pdev) |
| 962 | { |
| 963 | struct ibm_struct *ibm, *itmp; |
| 964 | |
| 965 | list_for_each_entry_safe(ibm, itmp, |
| 966 | &tpacpi_all_drivers, |
| 967 | all_drivers) { |
| 968 | if (ibm->shutdown) |
| 969 | (ibm->shutdown)(); |
| 970 | } |
| 971 | } |
| 972 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 973 | static struct platform_driver tpacpi_pdriver = { |
| 974 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 975 | .name = TPACPI_DRVR_NAME, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 976 | .owner = THIS_MODULE, |
| 977 | }, |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 978 | .suspend = tpacpi_suspend_handler, |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 979 | .resume = tpacpi_resume_handler, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 980 | .shutdown = tpacpi_shutdown_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 981 | }; |
| 982 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 983 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 984 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 985 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 986 | .owner = THIS_MODULE, |
| 987 | }, |
| 988 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 989 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 990 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 991 | * sysfs support helpers |
| 992 | */ |
| 993 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 994 | struct attribute_set { |
| 995 | unsigned int members, max_members; |
| 996 | struct attribute_group group; |
| 997 | }; |
| 998 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 999 | struct attribute_set_obj { |
| 1000 | struct attribute_set s; |
| 1001 | struct attribute *a; |
| 1002 | } __attribute__((packed)); |
| 1003 | |
| 1004 | 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] | 1005 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1006 | { |
| 1007 | struct attribute_set_obj *sobj; |
| 1008 | |
| 1009 | if (max_members == 0) |
| 1010 | return NULL; |
| 1011 | |
| 1012 | /* Allocates space for implicit NULL at the end too */ |
| 1013 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 1014 | max_members * sizeof(struct attribute *), |
| 1015 | GFP_KERNEL); |
| 1016 | if (!sobj) |
| 1017 | return NULL; |
| 1018 | sobj->s.max_members = max_members; |
| 1019 | sobj->s.group.attrs = &sobj->a; |
| 1020 | sobj->s.group.name = name; |
| 1021 | |
| 1022 | return &sobj->s; |
| 1023 | } |
| 1024 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1025 | #define destroy_attr_set(_set) \ |
| 1026 | kfree(_set); |
| 1027 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1028 | /* 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] | 1029 | 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] | 1030 | { |
| 1031 | if (!s || !attr) |
| 1032 | return -EINVAL; |
| 1033 | |
| 1034 | if (s->members >= s->max_members) |
| 1035 | return -ENOMEM; |
| 1036 | |
| 1037 | s->group.attrs[s->members] = attr; |
| 1038 | s->members++; |
| 1039 | |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1043 | 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] | 1044 | struct attribute **attr, |
| 1045 | unsigned int count) |
| 1046 | { |
| 1047 | int i, res; |
| 1048 | |
| 1049 | for (i = 0; i < count; i++) { |
| 1050 | res = add_to_attr_set(s, attr[i]); |
| 1051 | if (res) |
| 1052 | return res; |
| 1053 | } |
| 1054 | |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1058 | 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] | 1059 | { |
| 1060 | sysfs_remove_group(kobj, &s->group); |
| 1061 | destroy_attr_set(s); |
| 1062 | } |
| 1063 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1064 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 1065 | sysfs_create_group(_kobj, &_attr_set->group) |
| 1066 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1067 | static int parse_strtoul(const char *buf, |
| 1068 | unsigned long max, unsigned long *value) |
| 1069 | { |
| 1070 | char *endp; |
| 1071 | |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 1072 | *value = simple_strtoul(skip_spaces(buf), &endp, 0); |
| 1073 | endp = skip_spaces(endp); |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1074 | if (*endp || *value > max) |
| 1075 | return -EINVAL; |
| 1076 | |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 1080 | static void tpacpi_disable_brightness_delay(void) |
| 1081 | { |
| 1082 | if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0)) |
| 1083 | printk(TPACPI_NOTICE |
| 1084 | "ACPI backlight control delay disabled\n"); |
| 1085 | } |
| 1086 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1087 | static void printk_deprecated_attribute(const char * const what, |
| 1088 | const char * const details) |
| 1089 | { |
| 1090 | tpacpi_log_usertask("deprecated sysfs attribute"); |
| 1091 | printk(TPACPI_WARN "WARNING: sysfs attribute %s is deprecated and " |
| 1092 | "will be removed. %s\n", |
| 1093 | what, details); |
| 1094 | } |
| 1095 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1096 | /************************************************************************* |
| 1097 | * rfkill and radio control support helpers |
| 1098 | */ |
| 1099 | |
| 1100 | /* |
| 1101 | * ThinkPad-ACPI firmware handling model: |
| 1102 | * |
| 1103 | * WLSW (master wireless switch) is event-driven, and is common to all |
| 1104 | * firmware-controlled radios. It cannot be controlled, just monitored, |
| 1105 | * as expected. It overrides all radio state in firmware |
| 1106 | * |
| 1107 | * The kernel, a masked-off hotkey, and WLSW can change the radio state |
| 1108 | * (TODO: verify how WLSW interacts with the returned radio state). |
| 1109 | * |
| 1110 | * The only time there are shadow radio state changes, is when |
| 1111 | * masked-off hotkeys are used. |
| 1112 | */ |
| 1113 | |
| 1114 | /* |
| 1115 | * Internal driver API for radio state: |
| 1116 | * |
| 1117 | * int: < 0 = error, otherwise enum tpacpi_rfkill_state |
| 1118 | * bool: true means radio blocked (off) |
| 1119 | */ |
| 1120 | enum tpacpi_rfkill_state { |
| 1121 | TPACPI_RFK_RADIO_OFF = 0, |
| 1122 | TPACPI_RFK_RADIO_ON |
| 1123 | }; |
| 1124 | |
| 1125 | /* rfkill switches */ |
| 1126 | enum tpacpi_rfk_id { |
| 1127 | TPACPI_RFK_BLUETOOTH_SW_ID = 0, |
| 1128 | TPACPI_RFK_WWAN_SW_ID, |
| 1129 | TPACPI_RFK_UWB_SW_ID, |
| 1130 | TPACPI_RFK_SW_MAX |
| 1131 | }; |
| 1132 | |
| 1133 | static const char *tpacpi_rfkill_names[] = { |
| 1134 | [TPACPI_RFK_BLUETOOTH_SW_ID] = "bluetooth", |
| 1135 | [TPACPI_RFK_WWAN_SW_ID] = "wwan", |
| 1136 | [TPACPI_RFK_UWB_SW_ID] = "uwb", |
| 1137 | [TPACPI_RFK_SW_MAX] = NULL |
| 1138 | }; |
| 1139 | |
| 1140 | /* ThinkPad-ACPI rfkill subdriver */ |
| 1141 | struct tpacpi_rfk { |
| 1142 | struct rfkill *rfkill; |
| 1143 | enum tpacpi_rfk_id id; |
| 1144 | const struct tpacpi_rfk_ops *ops; |
| 1145 | }; |
| 1146 | |
| 1147 | struct tpacpi_rfk_ops { |
| 1148 | /* firmware interface */ |
| 1149 | int (*get_status)(void); |
| 1150 | int (*set_status)(const enum tpacpi_rfkill_state); |
| 1151 | }; |
| 1152 | |
| 1153 | static struct tpacpi_rfk *tpacpi_rfkill_switches[TPACPI_RFK_SW_MAX]; |
| 1154 | |
| 1155 | /* Query FW and update rfkill sw state for a given rfkill switch */ |
| 1156 | static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk *tp_rfk) |
| 1157 | { |
| 1158 | int status; |
| 1159 | |
| 1160 | if (!tp_rfk) |
| 1161 | return -ENODEV; |
| 1162 | |
| 1163 | status = (tp_rfk->ops->get_status)(); |
| 1164 | if (status < 0) |
| 1165 | return status; |
| 1166 | |
| 1167 | rfkill_set_sw_state(tp_rfk->rfkill, |
| 1168 | (status == TPACPI_RFK_RADIO_OFF)); |
| 1169 | |
| 1170 | return status; |
| 1171 | } |
| 1172 | |
| 1173 | /* Query FW and update rfkill sw state for all rfkill switches */ |
| 1174 | static void tpacpi_rfk_update_swstate_all(void) |
| 1175 | { |
| 1176 | unsigned int i; |
| 1177 | |
| 1178 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) |
| 1179 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[i]); |
| 1180 | } |
| 1181 | |
| 1182 | /* |
| 1183 | * Sync the HW-blocking state of all rfkill switches, |
| 1184 | * do notice it causes the rfkill core to schedule uevents |
| 1185 | */ |
| 1186 | static void tpacpi_rfk_update_hwblock_state(bool blocked) |
| 1187 | { |
| 1188 | unsigned int i; |
| 1189 | struct tpacpi_rfk *tp_rfk; |
| 1190 | |
| 1191 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) { |
| 1192 | tp_rfk = tpacpi_rfkill_switches[i]; |
| 1193 | if (tp_rfk) { |
| 1194 | if (rfkill_set_hw_state(tp_rfk->rfkill, |
| 1195 | blocked)) { |
| 1196 | /* ignore -- we track sw block */ |
| 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | /* Call to get the WLSW state from the firmware */ |
| 1203 | static int hotkey_get_wlsw(void); |
| 1204 | |
| 1205 | /* Call to query WLSW state and update all rfkill switches */ |
| 1206 | static bool tpacpi_rfk_check_hwblock_state(void) |
| 1207 | { |
| 1208 | int res = hotkey_get_wlsw(); |
| 1209 | int hw_blocked; |
| 1210 | |
| 1211 | /* When unknown or unsupported, we have to assume it is unblocked */ |
| 1212 | if (res < 0) |
| 1213 | return false; |
| 1214 | |
| 1215 | hw_blocked = (res == TPACPI_RFK_RADIO_OFF); |
| 1216 | tpacpi_rfk_update_hwblock_state(hw_blocked); |
| 1217 | |
| 1218 | return hw_blocked; |
| 1219 | } |
| 1220 | |
| 1221 | static int tpacpi_rfk_hook_set_block(void *data, bool blocked) |
| 1222 | { |
| 1223 | struct tpacpi_rfk *tp_rfk = data; |
| 1224 | int res; |
| 1225 | |
| 1226 | dbg_printk(TPACPI_DBG_RFKILL, |
| 1227 | "request to change radio state to %s\n", |
| 1228 | blocked ? "blocked" : "unblocked"); |
| 1229 | |
| 1230 | /* try to set radio state */ |
| 1231 | res = (tp_rfk->ops->set_status)(blocked ? |
| 1232 | TPACPI_RFK_RADIO_OFF : TPACPI_RFK_RADIO_ON); |
| 1233 | |
| 1234 | /* and update the rfkill core with whatever the FW really did */ |
| 1235 | tpacpi_rfk_update_swstate(tp_rfk); |
| 1236 | |
| 1237 | return (res < 0) ? res : 0; |
| 1238 | } |
| 1239 | |
| 1240 | static const struct rfkill_ops tpacpi_rfk_rfkill_ops = { |
| 1241 | .set_block = tpacpi_rfk_hook_set_block, |
| 1242 | }; |
| 1243 | |
| 1244 | static int __init tpacpi_new_rfkill(const enum tpacpi_rfk_id id, |
| 1245 | const struct tpacpi_rfk_ops *tp_rfkops, |
| 1246 | const enum rfkill_type rfktype, |
| 1247 | const char *name, |
| 1248 | const bool set_default) |
| 1249 | { |
| 1250 | struct tpacpi_rfk *atp_rfk; |
| 1251 | int res; |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1252 | bool sw_state = false; |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1253 | bool hw_state; |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1254 | int sw_status; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1255 | |
| 1256 | BUG_ON(id >= TPACPI_RFK_SW_MAX || tpacpi_rfkill_switches[id]); |
| 1257 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1258 | atp_rfk = kzalloc(sizeof(struct tpacpi_rfk), GFP_KERNEL); |
| 1259 | if (atp_rfk) |
| 1260 | atp_rfk->rfkill = rfkill_alloc(name, |
| 1261 | &tpacpi_pdev->dev, |
| 1262 | rfktype, |
| 1263 | &tpacpi_rfk_rfkill_ops, |
| 1264 | atp_rfk); |
| 1265 | if (!atp_rfk || !atp_rfk->rfkill) { |
| 1266 | printk(TPACPI_ERR |
| 1267 | "failed to allocate memory for rfkill class\n"); |
| 1268 | kfree(atp_rfk); |
| 1269 | return -ENOMEM; |
| 1270 | } |
| 1271 | |
| 1272 | atp_rfk->id = id; |
| 1273 | atp_rfk->ops = tp_rfkops; |
| 1274 | |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1275 | sw_status = (tp_rfkops->get_status)(); |
| 1276 | if (sw_status < 0) { |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1277 | printk(TPACPI_ERR |
| 1278 | "failed to read initial state for %s, error %d\n", |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1279 | name, sw_status); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1280 | } else { |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1281 | sw_state = (sw_status == TPACPI_RFK_RADIO_OFF); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1282 | if (set_default) { |
| 1283 | /* try to keep the initial state, since we ask the |
| 1284 | * firmware to preserve it across S5 in NVRAM */ |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1285 | rfkill_init_sw_state(atp_rfk->rfkill, sw_state); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1286 | } |
| 1287 | } |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1288 | hw_state = tpacpi_rfk_check_hwblock_state(); |
| 1289 | rfkill_set_hw_state(atp_rfk->rfkill, hw_state); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1290 | |
| 1291 | res = rfkill_register(atp_rfk->rfkill); |
| 1292 | if (res < 0) { |
| 1293 | printk(TPACPI_ERR |
| 1294 | "failed to register %s rfkill switch: %d\n", |
| 1295 | name, res); |
| 1296 | rfkill_destroy(atp_rfk->rfkill); |
| 1297 | kfree(atp_rfk); |
| 1298 | return res; |
| 1299 | } |
| 1300 | |
| 1301 | tpacpi_rfkill_switches[id] = atp_rfk; |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1302 | |
| 1303 | printk(TPACPI_INFO "rfkill switch %s: radio is %sblocked\n", |
| 1304 | name, (sw_state || hw_state) ? "" : "un"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id) |
| 1309 | { |
| 1310 | struct tpacpi_rfk *tp_rfk; |
| 1311 | |
| 1312 | BUG_ON(id >= TPACPI_RFK_SW_MAX); |
| 1313 | |
| 1314 | tp_rfk = tpacpi_rfkill_switches[id]; |
| 1315 | if (tp_rfk) { |
| 1316 | rfkill_unregister(tp_rfk->rfkill); |
Corentin Chary | 5f0dadb | 2009-09-14 12:43:52 +0200 | [diff] [blame] | 1317 | rfkill_destroy(tp_rfk->rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1318 | tpacpi_rfkill_switches[id] = NULL; |
| 1319 | kfree(tp_rfk); |
| 1320 | } |
| 1321 | } |
| 1322 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1323 | static void printk_deprecated_rfkill_attribute(const char * const what) |
| 1324 | { |
| 1325 | printk_deprecated_attribute(what, |
| 1326 | "Please switch to generic rfkill before year 2010"); |
| 1327 | } |
| 1328 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1329 | /* sysfs <radio> enable ------------------------------------------------ */ |
| 1330 | static ssize_t tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id, |
| 1331 | struct device_attribute *attr, |
| 1332 | char *buf) |
| 1333 | { |
| 1334 | int status; |
| 1335 | |
| 1336 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1337 | |
| 1338 | /* This is in the ABI... */ |
| 1339 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1340 | status = TPACPI_RFK_RADIO_OFF; |
| 1341 | } else { |
| 1342 | status = tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1343 | if (status < 0) |
| 1344 | return status; |
| 1345 | } |
| 1346 | |
| 1347 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1348 | (status == TPACPI_RFK_RADIO_ON) ? 1 : 0); |
| 1349 | } |
| 1350 | |
| 1351 | static ssize_t tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id, |
| 1352 | struct device_attribute *attr, |
| 1353 | const char *buf, size_t count) |
| 1354 | { |
| 1355 | unsigned long t; |
| 1356 | int res; |
| 1357 | |
| 1358 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1359 | |
| 1360 | if (parse_strtoul(buf, 1, &t)) |
| 1361 | return -EINVAL; |
| 1362 | |
| 1363 | tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); |
| 1364 | |
| 1365 | /* This is in the ABI... */ |
| 1366 | if (tpacpi_rfk_check_hwblock_state() && !!t) |
| 1367 | return -EPERM; |
| 1368 | |
| 1369 | res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? |
| 1370 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF); |
| 1371 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1372 | |
| 1373 | return (res < 0) ? res : count; |
| 1374 | } |
| 1375 | |
| 1376 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1377 | 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] | 1378 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1379 | if (id >= TPACPI_RFK_SW_MAX) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1380 | seq_printf(m, "status:\t\tnot supported\n"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1381 | else { |
| 1382 | int status; |
| 1383 | |
| 1384 | /* This is in the ABI... */ |
| 1385 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1386 | status = TPACPI_RFK_RADIO_OFF; |
| 1387 | } else { |
| 1388 | status = tpacpi_rfk_update_swstate( |
| 1389 | tpacpi_rfkill_switches[id]); |
| 1390 | if (status < 0) |
| 1391 | return status; |
| 1392 | } |
| 1393 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1394 | seq_printf(m, "status:\t\t%s\n", |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1395 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1396 | "enabled" : "disabled"); |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1397 | seq_printf(m, "commands:\tenable, disable\n"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1400 | return 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf) |
| 1404 | { |
| 1405 | char *cmd; |
| 1406 | int status = -1; |
| 1407 | int res = 0; |
| 1408 | |
| 1409 | if (id >= TPACPI_RFK_SW_MAX) |
| 1410 | return -ENODEV; |
| 1411 | |
| 1412 | while ((cmd = next_cmd(&buf))) { |
| 1413 | if (strlencmp(cmd, "enable") == 0) |
| 1414 | status = TPACPI_RFK_RADIO_ON; |
| 1415 | else if (strlencmp(cmd, "disable") == 0) |
| 1416 | status = TPACPI_RFK_RADIO_OFF; |
| 1417 | else |
| 1418 | return -EINVAL; |
| 1419 | } |
| 1420 | |
| 1421 | if (status != -1) { |
| 1422 | tpacpi_disclose_usertask("procfs", "attempt to %s %s\n", |
| 1423 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1424 | "enable" : "disable", |
| 1425 | tpacpi_rfkill_names[id]); |
| 1426 | res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); |
| 1427 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1428 | } |
| 1429 | |
| 1430 | return res; |
| 1431 | } |
| 1432 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1433 | /************************************************************************* |
| 1434 | * thinkpad-acpi driver attributes |
| 1435 | */ |
| 1436 | |
| 1437 | /* interface_version --------------------------------------------------- */ |
| 1438 | static ssize_t tpacpi_driver_interface_version_show( |
| 1439 | struct device_driver *drv, |
| 1440 | char *buf) |
| 1441 | { |
| 1442 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 1443 | } |
| 1444 | |
| 1445 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 1446 | tpacpi_driver_interface_version_show, NULL); |
| 1447 | |
| 1448 | /* debug_level --------------------------------------------------------- */ |
| 1449 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 1450 | char *buf) |
| 1451 | { |
| 1452 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 1453 | } |
| 1454 | |
| 1455 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 1456 | const char *buf, size_t count) |
| 1457 | { |
| 1458 | unsigned long t; |
| 1459 | |
| 1460 | if (parse_strtoul(buf, 0xffff, &t)) |
| 1461 | return -EINVAL; |
| 1462 | |
| 1463 | dbg_level = t; |
| 1464 | |
| 1465 | return count; |
| 1466 | } |
| 1467 | |
| 1468 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1469 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 1470 | |
| 1471 | /* version ------------------------------------------------------------- */ |
| 1472 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 1473 | char *buf) |
| 1474 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1475 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 1476 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | static DRIVER_ATTR(version, S_IRUGO, |
| 1480 | tpacpi_driver_version_show, NULL); |
| 1481 | |
| 1482 | /* --------------------------------------------------------------------- */ |
| 1483 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1484 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1485 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1486 | /* wlsw_emulstate ------------------------------------------------------ */ |
| 1487 | static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv, |
| 1488 | char *buf) |
| 1489 | { |
| 1490 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate); |
| 1491 | } |
| 1492 | |
| 1493 | static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv, |
| 1494 | const char *buf, size_t count) |
| 1495 | { |
| 1496 | unsigned long t; |
| 1497 | |
| 1498 | if (parse_strtoul(buf, 1, &t)) |
| 1499 | return -EINVAL; |
| 1500 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1501 | if (tpacpi_wlsw_emulstate != !!t) { |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1502 | tpacpi_wlsw_emulstate = !!t; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1503 | tpacpi_rfk_update_hwblock_state(!t); /* negative logic */ |
| 1504 | } |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1505 | |
| 1506 | return count; |
| 1507 | } |
| 1508 | |
| 1509 | static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO, |
| 1510 | tpacpi_driver_wlsw_emulstate_show, |
| 1511 | tpacpi_driver_wlsw_emulstate_store); |
| 1512 | |
| 1513 | /* bluetooth_emulstate ------------------------------------------------- */ |
| 1514 | static ssize_t tpacpi_driver_bluetooth_emulstate_show( |
| 1515 | struct device_driver *drv, |
| 1516 | char *buf) |
| 1517 | { |
| 1518 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate); |
| 1519 | } |
| 1520 | |
| 1521 | static ssize_t tpacpi_driver_bluetooth_emulstate_store( |
| 1522 | struct device_driver *drv, |
| 1523 | const char *buf, size_t count) |
| 1524 | { |
| 1525 | unsigned long t; |
| 1526 | |
| 1527 | if (parse_strtoul(buf, 1, &t)) |
| 1528 | return -EINVAL; |
| 1529 | |
| 1530 | tpacpi_bluetooth_emulstate = !!t; |
| 1531 | |
| 1532 | return count; |
| 1533 | } |
| 1534 | |
| 1535 | static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO, |
| 1536 | tpacpi_driver_bluetooth_emulstate_show, |
| 1537 | tpacpi_driver_bluetooth_emulstate_store); |
| 1538 | |
| 1539 | /* wwan_emulstate ------------------------------------------------- */ |
| 1540 | static ssize_t tpacpi_driver_wwan_emulstate_show( |
| 1541 | struct device_driver *drv, |
| 1542 | char *buf) |
| 1543 | { |
| 1544 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate); |
| 1545 | } |
| 1546 | |
| 1547 | static ssize_t tpacpi_driver_wwan_emulstate_store( |
| 1548 | struct device_driver *drv, |
| 1549 | const char *buf, size_t count) |
| 1550 | { |
| 1551 | unsigned long t; |
| 1552 | |
| 1553 | if (parse_strtoul(buf, 1, &t)) |
| 1554 | return -EINVAL; |
| 1555 | |
| 1556 | tpacpi_wwan_emulstate = !!t; |
| 1557 | |
| 1558 | return count; |
| 1559 | } |
| 1560 | |
| 1561 | static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO, |
| 1562 | tpacpi_driver_wwan_emulstate_show, |
| 1563 | tpacpi_driver_wwan_emulstate_store); |
| 1564 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1565 | /* uwb_emulstate ------------------------------------------------- */ |
| 1566 | static ssize_t tpacpi_driver_uwb_emulstate_show( |
| 1567 | struct device_driver *drv, |
| 1568 | char *buf) |
| 1569 | { |
| 1570 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate); |
| 1571 | } |
| 1572 | |
| 1573 | static ssize_t tpacpi_driver_uwb_emulstate_store( |
| 1574 | struct device_driver *drv, |
| 1575 | const char *buf, size_t count) |
| 1576 | { |
| 1577 | unsigned long t; |
| 1578 | |
| 1579 | if (parse_strtoul(buf, 1, &t)) |
| 1580 | return -EINVAL; |
| 1581 | |
| 1582 | tpacpi_uwb_emulstate = !!t; |
| 1583 | |
| 1584 | return count; |
| 1585 | } |
| 1586 | |
| 1587 | static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO, |
| 1588 | tpacpi_driver_uwb_emulstate_show, |
| 1589 | tpacpi_driver_uwb_emulstate_store); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1590 | #endif |
| 1591 | |
| 1592 | /* --------------------------------------------------------------------- */ |
| 1593 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1594 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1595 | &driver_attr_debug_level, &driver_attr_version, |
| 1596 | &driver_attr_interface_version, |
| 1597 | }; |
| 1598 | |
| 1599 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 1600 | { |
| 1601 | int i, res; |
| 1602 | |
| 1603 | i = 0; |
| 1604 | res = 0; |
| 1605 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 1606 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 1607 | i++; |
| 1608 | } |
| 1609 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1610 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1611 | if (!res && dbg_wlswemul) |
| 1612 | res = driver_create_file(drv, &driver_attr_wlsw_emulstate); |
| 1613 | if (!res && dbg_bluetoothemul) |
| 1614 | res = driver_create_file(drv, &driver_attr_bluetooth_emulstate); |
| 1615 | if (!res && dbg_wwanemul) |
| 1616 | res = driver_create_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1617 | if (!res && dbg_uwbemul) |
| 1618 | res = driver_create_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1619 | #endif |
| 1620 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1621 | return res; |
| 1622 | } |
| 1623 | |
| 1624 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 1625 | { |
| 1626 | int i; |
| 1627 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1628 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1629 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1630 | |
| 1631 | #ifdef THINKPAD_ACPI_DEBUGFACILITIES |
| 1632 | driver_remove_file(drv, &driver_attr_wlsw_emulstate); |
| 1633 | driver_remove_file(drv, &driver_attr_bluetooth_emulstate); |
| 1634 | driver_remove_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1635 | driver_remove_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1636 | #endif |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1637 | } |
| 1638 | |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1639 | /************************************************************************* |
| 1640 | * Firmware Data |
| 1641 | */ |
| 1642 | |
| 1643 | /* |
| 1644 | * Table of recommended minimum BIOS versions |
| 1645 | * |
| 1646 | * Reasons for listing: |
Uwe Kleine-König | 9ddc5b6 | 2010-01-20 17:02:24 +0100 | [diff] [blame] | 1647 | * 1. Stable BIOS, listed because the unknown amount of |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1648 | * bugs and bad ACPI behaviour on older versions |
| 1649 | * |
| 1650 | * 2. BIOS or EC fw with known bugs that trigger on Linux |
| 1651 | * |
| 1652 | * 3. BIOS with known reduced functionality in older versions |
| 1653 | * |
| 1654 | * We recommend the latest BIOS and EC version. |
| 1655 | * We only support the latest BIOS and EC fw version as a rule. |
| 1656 | * |
| 1657 | * Sources: IBM ThinkPad Public Web Documents (update changelogs), |
| 1658 | * Information from users in ThinkWiki |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1659 | * |
| 1660 | * WARNING: we use this table also to detect that the machine is |
| 1661 | * 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] | 1662 | */ |
| 1663 | |
| 1664 | #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \ |
| 1665 | { .vendor = (__v), \ |
| 1666 | .bios = TPID(__id1, __id2), \ |
| 1667 | .ec = TPACPI_MATCH_ANY, \ |
| 1668 | .quirks = TPACPI_MATCH_ANY << 16 \ |
| 1669 | | (__bv1) << 8 | (__bv2) } |
| 1670 | |
| 1671 | #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1672 | __eid, __ev1, __ev2) \ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1673 | { .vendor = (__v), \ |
| 1674 | .bios = TPID(__bid1, __bid2), \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1675 | .ec = __eid, \ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1676 | .quirks = (__ev1) << 24 | (__ev2) << 16 \ |
| 1677 | | (__bv1) << 8 | (__bv2) } |
| 1678 | |
| 1679 | #define TPV_QI0(__id1, __id2, __bv1, __bv2) \ |
| 1680 | TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2) |
| 1681 | |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1682 | /* Outdated IBM BIOSes often lack the EC id string */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1683 | #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1684 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1685 | __bv1, __bv2, TPID(__id1, __id2), \ |
| 1686 | __ev1, __ev2), \ |
| 1687 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
| 1688 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ |
| 1689 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1690 | |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1691 | /* Outdated IBM BIOSes often lack the EC id string */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1692 | #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \ |
| 1693 | __eid1, __eid2, __ev1, __ev2) \ |
| 1694 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1695 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
| 1696 | __ev1, __ev2), \ |
| 1697 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
| 1698 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ |
| 1699 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1700 | |
| 1701 | #define TPV_QL0(__id1, __id2, __bv1, __bv2) \ |
| 1702 | TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2) |
| 1703 | |
| 1704 | #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1705 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1706 | __bv1, __bv2, TPID(__id1, __id2), \ |
| 1707 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1708 | |
| 1709 | #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \ |
| 1710 | __eid1, __eid2, __ev1, __ev2) \ |
| 1711 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1712 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
| 1713 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1714 | |
| 1715 | static const struct tpacpi_quirk tpacpi_bios_version_qtable[] __initconst = { |
| 1716 | /* Numeric models ------------------ */ |
| 1717 | /* FW MODEL BIOS VERS */ |
| 1718 | TPV_QI0('I', 'M', '6', '5'), /* 570 */ |
| 1719 | TPV_QI0('I', 'U', '2', '6'), /* 570E */ |
| 1720 | TPV_QI0('I', 'B', '5', '4'), /* 600 */ |
| 1721 | TPV_QI0('I', 'H', '4', '7'), /* 600E */ |
| 1722 | TPV_QI0('I', 'N', '3', '6'), /* 600E */ |
| 1723 | TPV_QI0('I', 'T', '5', '5'), /* 600X */ |
| 1724 | TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */ |
| 1725 | TPV_QI0('I', 'I', '4', '2'), /* 770X */ |
| 1726 | TPV_QI0('I', 'O', '2', '3'), /* 770Z */ |
| 1727 | |
| 1728 | /* A-series ------------------------- */ |
| 1729 | /* FW MODEL BIOS VERS EC VERS */ |
| 1730 | TPV_QI0('I', 'W', '5', '9'), /* A20m */ |
| 1731 | TPV_QI0('I', 'V', '6', '9'), /* A20p */ |
| 1732 | TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */ |
| 1733 | TPV_QI0('K', 'U', '3', '6'), /* A21e */ |
| 1734 | TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */ |
| 1735 | TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */ |
| 1736 | TPV_QI0('1', 'B', '1', '7'), /* A22e */ |
| 1737 | TPV_QI0('1', '3', '2', '0'), /* A22m */ |
| 1738 | TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */ |
| 1739 | TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */ |
| 1740 | TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */ |
| 1741 | |
| 1742 | /* G-series ------------------------- */ |
| 1743 | /* FW MODEL BIOS VERS */ |
| 1744 | TPV_QI0('1', 'T', 'A', '6'), /* G40 */ |
| 1745 | TPV_QI0('1', 'X', '5', '7'), /* G41 */ |
| 1746 | |
| 1747 | /* R-series, T-series --------------- */ |
| 1748 | /* FW MODEL BIOS VERS EC VERS */ |
| 1749 | TPV_QI0('1', 'C', 'F', '0'), /* R30 */ |
| 1750 | TPV_QI0('1', 'F', 'F', '1'), /* R31 */ |
| 1751 | TPV_QI0('1', 'M', '9', '7'), /* R32 */ |
| 1752 | TPV_QI0('1', 'O', '6', '1'), /* R40 */ |
| 1753 | TPV_QI0('1', 'P', '6', '5'), /* R40 */ |
| 1754 | TPV_QI0('1', 'S', '7', '0'), /* R40e */ |
| 1755 | TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51, |
| 1756 | T40/p, T41/p, T42/p (1) */ |
| 1757 | TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */ |
| 1758 | TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */ |
| 1759 | TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */ |
| 1760 | TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */ |
| 1761 | |
| 1762 | TPV_QI0('I', 'Y', '6', '1'), /* T20 */ |
| 1763 | TPV_QI0('K', 'Z', '3', '4'), /* T21 */ |
| 1764 | TPV_QI0('1', '6', '3', '2'), /* T22 */ |
| 1765 | TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */ |
| 1766 | TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */ |
| 1767 | TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */ |
| 1768 | |
| 1769 | TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */ |
| 1770 | TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */ |
Henrique de Moraes Holschuh | 90765c6 | 2009-12-09 01:36:23 +0000 | [diff] [blame] | 1771 | TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1772 | |
| 1773 | /* BIOS FW BIOS VERS EC FW EC VERS */ |
| 1774 | TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */ |
| 1775 | TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */ |
| 1776 | |
| 1777 | /* X-series ------------------------- */ |
| 1778 | /* FW MODEL BIOS VERS EC VERS */ |
| 1779 | TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */ |
| 1780 | TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */ |
| 1781 | TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */ |
| 1782 | TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */ |
| 1783 | TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */ |
| 1784 | TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */ |
| 1785 | TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */ |
| 1786 | |
Henrique de Moraes Holschuh | 90765c6 | 2009-12-09 01:36:23 +0000 | [diff] [blame] | 1787 | TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */ |
| 1788 | TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1789 | |
| 1790 | /* (0) - older versions lack DMI EC fw string and functionality */ |
| 1791 | /* (1) - older versions known to lack functionality */ |
| 1792 | }; |
| 1793 | |
| 1794 | #undef TPV_QL1 |
| 1795 | #undef TPV_QL0 |
| 1796 | #undef TPV_QI2 |
| 1797 | #undef TPV_QI1 |
| 1798 | #undef TPV_QI0 |
| 1799 | #undef TPV_Q_X |
| 1800 | #undef TPV_Q |
| 1801 | |
| 1802 | static void __init tpacpi_check_outdated_fw(void) |
| 1803 | { |
| 1804 | unsigned long fwvers; |
| 1805 | u16 ec_version, bios_version; |
| 1806 | |
| 1807 | fwvers = tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1808 | ARRAY_SIZE(tpacpi_bios_version_qtable)); |
| 1809 | |
| 1810 | if (!fwvers) |
| 1811 | return; |
| 1812 | |
| 1813 | bios_version = fwvers & 0xffffU; |
| 1814 | ec_version = (fwvers >> 16) & 0xffffU; |
| 1815 | |
| 1816 | /* note that unknown versions are set to 0x0000 and we use that */ |
| 1817 | if ((bios_version > thinkpad_id.bios_release) || |
| 1818 | (ec_version > thinkpad_id.ec_release && |
| 1819 | ec_version != TPACPI_MATCH_ANY)) { |
| 1820 | /* |
| 1821 | * The changelogs would let us track down the exact |
| 1822 | * reason, but it is just too much of a pain to track |
| 1823 | * it. We only list BIOSes that are either really |
| 1824 | * broken, or really stable to begin with, so it is |
| 1825 | * best if the user upgrades the firmware anyway. |
| 1826 | */ |
| 1827 | printk(TPACPI_WARN |
| 1828 | "WARNING: Outdated ThinkPad BIOS/EC firmware\n"); |
| 1829 | printk(TPACPI_WARN |
| 1830 | "WARNING: This firmware may be missing critical bug " |
| 1831 | "fixes and/or important features\n"); |
| 1832 | } |
| 1833 | } |
| 1834 | |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1835 | static bool __init tpacpi_is_fw_known(void) |
| 1836 | { |
| 1837 | return tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1838 | ARRAY_SIZE(tpacpi_bios_version_qtable)) != 0; |
| 1839 | } |
| 1840 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1841 | /**************************************************************************** |
| 1842 | **************************************************************************** |
| 1843 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1844 | * Subdrivers |
| 1845 | * |
| 1846 | **************************************************************************** |
| 1847 | ****************************************************************************/ |
| 1848 | |
| 1849 | /************************************************************************* |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 1850 | * thinkpad-acpi metadata subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1851 | */ |
| 1852 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1853 | static int thinkpad_acpi_driver_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1855 | seq_printf(m, "driver:\t\t%s\n", TPACPI_DESC); |
| 1856 | seq_printf(m, "version:\t%s\n", TPACPI_VERSION); |
| 1857 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1860 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1861 | .name = "driver", |
| 1862 | .read = thinkpad_acpi_driver_read, |
| 1863 | }; |
| 1864 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1865 | /************************************************************************* |
| 1866 | * Hotkey subdriver |
| 1867 | */ |
| 1868 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1869 | /* |
| 1870 | * ThinkPad firmware event model |
| 1871 | * |
| 1872 | * The ThinkPad firmware has two main event interfaces: normal ACPI |
| 1873 | * notifications (which follow the ACPI standard), and a private event |
| 1874 | * interface. |
| 1875 | * |
| 1876 | * The private event interface also issues events for the hotkeys. As |
| 1877 | * the driver gained features, the event handling code ended up being |
| 1878 | * built around the hotkey subdriver. This will need to be refactored |
| 1879 | * to a more formal event API eventually. |
| 1880 | * |
| 1881 | * Some "hotkeys" are actually supposed to be used as event reports, |
| 1882 | * such as "brightness has changed", "volume has changed", depending on |
| 1883 | * the ThinkPad model and how the firmware is operating. |
| 1884 | * |
| 1885 | * Unlike other classes, hotkey-class events have mask/unmask control on |
| 1886 | * non-ancient firmware. However, how it behaves changes a lot with the |
| 1887 | * firmware model and version. |
| 1888 | */ |
| 1889 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1890 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1891 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1892 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1893 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1894 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1895 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1896 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1897 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1898 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1899 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1900 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1901 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1902 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1903 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1904 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1905 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1906 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1907 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1908 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1909 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1910 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1911 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1912 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1913 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1914 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
Henrique de Moraes Holschuh | 34a656d | 2010-08-09 23:48:20 -0300 | [diff] [blame] | 1915 | TP_ACPI_HOTKEYSCAN_UNK1, |
| 1916 | TP_ACPI_HOTKEYSCAN_UNK2, |
| 1917 | TP_ACPI_HOTKEYSCAN_UNK3, |
| 1918 | TP_ACPI_HOTKEYSCAN_UNK4, |
| 1919 | TP_ACPI_HOTKEYSCAN_UNK5, |
| 1920 | TP_ACPI_HOTKEYSCAN_UNK6, |
| 1921 | TP_ACPI_HOTKEYSCAN_UNK7, |
| 1922 | TP_ACPI_HOTKEYSCAN_UNK8, |
| 1923 | |
| 1924 | /* Hotkey keymap size */ |
| 1925 | TPACPI_HOTKEY_MAP_LEN |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1926 | }; |
| 1927 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1928 | enum { /* Keys/events available through NVRAM polling */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1929 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1930 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1931 | }; |
| 1932 | |
| 1933 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1934 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1935 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1936 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1937 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1938 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1939 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1940 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1941 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1942 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1943 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1944 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1945 | }; |
| 1946 | |
| 1947 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1948 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1949 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1950 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1951 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1952 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1953 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1954 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1955 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1956 | TP_ACPI_HKEY_MUTE_MASK, |
| 1957 | }; |
| 1958 | |
| 1959 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1960 | struct tp_nvram_state { |
| 1961 | u16 thinkpad_toggle:1; |
| 1962 | u16 zoom_toggle:1; |
| 1963 | u16 display_toggle:1; |
| 1964 | u16 thinklight_toggle:1; |
| 1965 | u16 hibernate_toggle:1; |
| 1966 | u16 displayexp_toggle:1; |
| 1967 | u16 display_state:1; |
| 1968 | u16 brightness_toggle:1; |
| 1969 | u16 volume_toggle:1; |
| 1970 | u16 mute:1; |
| 1971 | |
| 1972 | u8 brightness_level; |
| 1973 | u8 volume_level; |
| 1974 | }; |
| 1975 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1976 | /* kthread for the hotkey poller */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1977 | static struct task_struct *tpacpi_hotkey_task; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1978 | |
| 1979 | /* Acquired while the poller kthread is running, use to sync start/stop */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1980 | static struct mutex hotkey_thread_mutex; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1981 | |
| 1982 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1983 | * Acquire mutex to write poller control variables as an |
| 1984 | * atomic block. |
| 1985 | * |
| 1986 | * Increment hotkey_config_change when changing them if you |
| 1987 | * want the kthread to forget old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1988 | * |
| 1989 | * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 1990 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1991 | static struct mutex hotkey_thread_data_mutex; |
| 1992 | static unsigned int hotkey_config_change; |
| 1993 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1994 | /* |
| 1995 | * hotkey poller control variables |
| 1996 | * |
| 1997 | * 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] | 1998 | * |
| 1999 | * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 2000 | * should be used only when the changes need to be taken as |
| 2001 | * a block, OR when one needs to force the kthread to forget |
| 2002 | * old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2003 | */ |
| 2004 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 2005 | static unsigned int hotkey_poll_freq = 10; /* Hz */ |
| 2006 | |
| 2007 | #define HOTKEY_CONFIG_CRITICAL_START \ |
| 2008 | do { \ |
| 2009 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 2010 | hotkey_config_change++; \ |
| 2011 | } while (0); |
| 2012 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 2013 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2014 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2015 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2016 | |
| 2017 | #define hotkey_source_mask 0U |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2018 | #define HOTKEY_CONFIG_CRITICAL_START |
| 2019 | #define HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2020 | |
| 2021 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2022 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2023 | static struct mutex hotkey_mutex; |
| 2024 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2025 | static enum { /* Reasons for waking up */ |
| 2026 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 2027 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 2028 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 2029 | } hotkey_wakeup_reason; |
| 2030 | |
| 2031 | static int hotkey_autosleep_ack; |
| 2032 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2033 | static u32 hotkey_orig_mask; /* events the BIOS had enabled */ |
| 2034 | static u32 hotkey_all_mask; /* all events supported in fw */ |
| 2035 | static u32 hotkey_reserved_mask; /* events better left disabled */ |
| 2036 | static u32 hotkey_driver_mask; /* events needed by the driver */ |
| 2037 | static u32 hotkey_user_mask; /* events visible to userspace */ |
| 2038 | static u32 hotkey_acpi_mask; /* events enabled in firmware */ |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2039 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 2040 | static unsigned int hotkey_report_mode; |
| 2041 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2042 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2043 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 2044 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2045 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2046 | static void tpacpi_driver_event(const unsigned int hkey_event); |
| 2047 | static void hotkey_driver_event(const unsigned int scancode); |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2048 | static void hotkey_poll_setup(const bool may_warn); |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2049 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2050 | /* HKEY.MHKG() return bits */ |
| 2051 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 2052 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2053 | static int hotkey_get_wlsw(void) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2054 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2055 | int status; |
| 2056 | |
| 2057 | if (!tp_features.hotkey_wlsw) |
| 2058 | return -ENODEV; |
| 2059 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2060 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2061 | if (dbg_wlswemul) |
| 2062 | return (tpacpi_wlsw_emulstate) ? |
| 2063 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2064 | #endif |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2065 | |
| 2066 | if (!acpi_evalf(hkey_handle, &status, "WLSW", "d")) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2067 | return -EIO; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2068 | |
| 2069 | return (status) ? TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2070 | } |
| 2071 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2072 | static int hotkey_get_tablet_mode(int *status) |
| 2073 | { |
| 2074 | int s; |
| 2075 | |
| 2076 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 2077 | return -EIO; |
| 2078 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 2079 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 2080 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2081 | } |
| 2082 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2083 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2084 | * Reads current event mask from firmware, and updates |
| 2085 | * hotkey_acpi_mask accordingly. Also resets any bits |
| 2086 | * from hotkey_user_mask that are unavailable to be |
| 2087 | * delivered (shadow requirement of the userspace ABI). |
| 2088 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2089 | * Call with hotkey_mutex held |
| 2090 | */ |
| 2091 | static int hotkey_mask_get(void) |
| 2092 | { |
| 2093 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2094 | u32 m = 0; |
| 2095 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2096 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2097 | return -EIO; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2098 | |
| 2099 | hotkey_acpi_mask = m; |
| 2100 | } else { |
| 2101 | /* no mask support doesn't mean no event support... */ |
| 2102 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2103 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2104 | |
| 2105 | /* sync userspace-visible mask */ |
| 2106 | hotkey_user_mask &= (hotkey_acpi_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2107 | |
| 2108 | return 0; |
| 2109 | } |
| 2110 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2111 | void static hotkey_mask_warn_incomplete_mask(void) |
| 2112 | { |
| 2113 | /* log only what the user can fix... */ |
| 2114 | const u32 wantedmask = hotkey_driver_mask & |
| 2115 | ~(hotkey_acpi_mask | hotkey_source_mask) & |
| 2116 | (hotkey_all_mask | TPACPI_HKEY_NVRAM_KNOWN_MASK); |
| 2117 | |
| 2118 | if (wantedmask) |
| 2119 | printk(TPACPI_NOTICE |
| 2120 | "required events 0x%08x not enabled!\n", |
| 2121 | wantedmask); |
| 2122 | } |
| 2123 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2124 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2125 | * Set the firmware mask when supported |
| 2126 | * |
| 2127 | * Also calls hotkey_mask_get to update hotkey_acpi_mask. |
| 2128 | * |
| 2129 | * NOTE: does not set bits in hotkey_user_mask, but may reset them. |
| 2130 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2131 | * Call with hotkey_mutex held |
| 2132 | */ |
| 2133 | static int hotkey_mask_set(u32 mask) |
| 2134 | { |
| 2135 | int i; |
| 2136 | int rc = 0; |
| 2137 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2138 | const u32 fwmask = mask & ~hotkey_source_mask; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 2139 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2140 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2141 | for (i = 0; i < 32; i++) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2142 | if (!acpi_evalf(hkey_handle, |
| 2143 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2144 | !!(mask & (1 << i)))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2145 | rc = -EIO; |
| 2146 | break; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2147 | } |
| 2148 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2149 | } |
| 2150 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2151 | /* |
| 2152 | * We *must* make an inconditional call to hotkey_mask_get to |
| 2153 | * refresh hotkey_acpi_mask and update hotkey_user_mask |
| 2154 | * |
| 2155 | * Take the opportunity to also log when we cannot _enable_ |
| 2156 | * a given event. |
| 2157 | */ |
| 2158 | if (!hotkey_mask_get() && !rc && (fwmask & ~hotkey_acpi_mask)) { |
| 2159 | printk(TPACPI_NOTICE |
| 2160 | "asked for hotkey mask 0x%08x, but " |
| 2161 | "firmware forced it to 0x%08x\n", |
| 2162 | fwmask, hotkey_acpi_mask); |
| 2163 | } |
| 2164 | |
Henrique de Moraes Holschuh | 6b30eb7 | 2009-12-09 01:36:25 +0000 | [diff] [blame] | 2165 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING) |
| 2166 | hotkey_mask_warn_incomplete_mask(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2167 | |
| 2168 | return rc; |
| 2169 | } |
| 2170 | |
| 2171 | /* |
| 2172 | * Sets hotkey_user_mask and tries to set the firmware mask |
| 2173 | * |
| 2174 | * Call with hotkey_mutex held |
| 2175 | */ |
| 2176 | static int hotkey_user_mask_set(const u32 mask) |
| 2177 | { |
| 2178 | int rc; |
| 2179 | |
| 2180 | /* Give people a chance to notice they are doing something that |
| 2181 | * is bound to go boom on their users sooner or later */ |
| 2182 | if (!tp_warned.hotkey_mask_ff && |
| 2183 | (mask == 0xffff || mask == 0xffffff || |
| 2184 | mask == 0xffffffff)) { |
| 2185 | tp_warned.hotkey_mask_ff = 1; |
| 2186 | printk(TPACPI_NOTICE |
| 2187 | "setting the hotkey mask to 0x%08x is likely " |
| 2188 | "not the best way to go about it\n", mask); |
| 2189 | printk(TPACPI_NOTICE |
| 2190 | "please consider using the driver defaults, " |
| 2191 | "and refer to up-to-date thinkpad-acpi " |
| 2192 | "documentation\n"); |
| 2193 | } |
| 2194 | |
| 2195 | /* Try to enable what the user asked for, plus whatever we need. |
| 2196 | * this syncs everything but won't enable bits in hotkey_user_mask */ |
| 2197 | rc = hotkey_mask_set((mask | hotkey_driver_mask) & ~hotkey_source_mask); |
| 2198 | |
| 2199 | /* Enable the available bits in hotkey_user_mask */ |
| 2200 | hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask); |
| 2201 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2202 | return rc; |
| 2203 | } |
| 2204 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2205 | /* |
| 2206 | * Sets the driver hotkey mask. |
| 2207 | * |
| 2208 | * Can be called even if the hotkey subdriver is inactive |
| 2209 | */ |
| 2210 | static int tpacpi_hotkey_driver_mask_set(const u32 mask) |
| 2211 | { |
| 2212 | int rc; |
| 2213 | |
| 2214 | /* Do the right thing if hotkey_init has not been called yet */ |
| 2215 | if (!tp_features.hotkey) { |
| 2216 | hotkey_driver_mask = mask; |
| 2217 | return 0; |
| 2218 | } |
| 2219 | |
| 2220 | mutex_lock(&hotkey_mutex); |
| 2221 | |
| 2222 | HOTKEY_CONFIG_CRITICAL_START |
| 2223 | hotkey_driver_mask = mask; |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2224 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2225 | hotkey_source_mask |= (mask & ~hotkey_all_mask); |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2226 | #endif |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2227 | HOTKEY_CONFIG_CRITICAL_END |
| 2228 | |
| 2229 | rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) & |
| 2230 | ~hotkey_source_mask); |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2231 | hotkey_poll_setup(true); |
| 2232 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2233 | mutex_unlock(&hotkey_mutex); |
| 2234 | |
| 2235 | return rc; |
| 2236 | } |
| 2237 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2238 | static int hotkey_status_get(int *status) |
| 2239 | { |
| 2240 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 2241 | return -EIO; |
| 2242 | |
| 2243 | return 0; |
| 2244 | } |
| 2245 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2246 | static int hotkey_status_set(bool enable) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2247 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2248 | 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] | 2249 | return -EIO; |
| 2250 | |
| 2251 | return 0; |
| 2252 | } |
| 2253 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2254 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2255 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2256 | int state; |
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 | if (tp_features.hotkey_tablet && |
| 2259 | !hotkey_get_tablet_mode(&state)) { |
| 2260 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2261 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2262 | input_report_switch(tpacpi_inputdev, |
| 2263 | SW_TABLET_MODE, !!state); |
| 2264 | input_sync(tpacpi_inputdev); |
| 2265 | |
| 2266 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2267 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2268 | } |
| 2269 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2270 | /* Do NOT call without validating scancode first */ |
| 2271 | static void tpacpi_input_send_key(const unsigned int scancode) |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2272 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2273 | const unsigned int keycode = hotkey_keycode_map[scancode]; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2274 | |
| 2275 | if (keycode != KEY_RESERVED) { |
| 2276 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2277 | |
| 2278 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 2279 | if (keycode == KEY_UNKNOWN) |
| 2280 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 2281 | scancode); |
| 2282 | input_sync(tpacpi_inputdev); |
| 2283 | |
| 2284 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 2285 | if (keycode == KEY_UNKNOWN) |
| 2286 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 2287 | scancode); |
| 2288 | input_sync(tpacpi_inputdev); |
| 2289 | |
| 2290 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2291 | } |
| 2292 | } |
| 2293 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2294 | /* Do NOT call without validating scancode first */ |
| 2295 | static void tpacpi_input_send_key_masked(const unsigned int scancode) |
| 2296 | { |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2297 | hotkey_driver_event(scancode); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2298 | if (hotkey_user_mask & (1 << scancode)) |
| 2299 | tpacpi_input_send_key(scancode); |
| 2300 | } |
| 2301 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2302 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2303 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 2304 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2305 | /* Do NOT call without validating scancode first */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2306 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 2307 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2308 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2309 | if (hotkey_report_mode < 2) { |
| 2310 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 2311 | 0x80, TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2312 | } |
| 2313 | } |
| 2314 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2315 | 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] | 2316 | { |
| 2317 | u8 d; |
| 2318 | |
| 2319 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 2320 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 2321 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 2322 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 2323 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 2324 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 2325 | } |
| 2326 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 2327 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 2328 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 2329 | } |
| 2330 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 2331 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 2332 | n->displayexp_toggle = |
| 2333 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 2334 | } |
| 2335 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 2336 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 2337 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 2338 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 2339 | n->brightness_toggle = |
| 2340 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 2341 | } |
| 2342 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 2343 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 2344 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 2345 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 2346 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 2347 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 2348 | } |
| 2349 | } |
| 2350 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2351 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
| 2352 | struct tp_nvram_state *newn, |
| 2353 | const u32 event_mask) |
| 2354 | { |
| 2355 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2356 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2357 | do { \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2358 | if ((event_mask & (1 << __scancode)) && \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2359 | oldn->__member != newn->__member) \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2360 | tpacpi_hotkey_send_key(__scancode); \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2361 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2362 | |
| 2363 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2364 | do { \ |
| 2365 | if (event_mask & (1 << __scancode)) \ |
| 2366 | tpacpi_hotkey_send_key(__scancode); \ |
| 2367 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2368 | |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2369 | void issue_volchange(const unsigned int oldvol, |
| 2370 | const unsigned int newvol) |
| 2371 | { |
| 2372 | unsigned int i = oldvol; |
| 2373 | |
| 2374 | while (i > newvol) { |
| 2375 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2376 | i--; |
| 2377 | } |
| 2378 | while (i < newvol) { |
| 2379 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2380 | i++; |
| 2381 | } |
| 2382 | } |
| 2383 | |
Henrique de Moraes Holschuh | 2899902 | 2010-05-16 19:45:36 -0300 | [diff] [blame] | 2384 | void issue_brightnesschange(const unsigned int oldbrt, |
| 2385 | const unsigned int newbrt) |
| 2386 | { |
| 2387 | unsigned int i = oldbrt; |
| 2388 | |
| 2389 | while (i > newbrt) { |
| 2390 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2391 | i--; |
| 2392 | } |
| 2393 | while (i < newbrt) { |
| 2394 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2395 | i++; |
| 2396 | } |
| 2397 | } |
| 2398 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2399 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 2400 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 2401 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 2402 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 2403 | |
| 2404 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 2405 | |
| 2406 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 2407 | |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2408 | /* |
| 2409 | * Handle volume |
| 2410 | * |
| 2411 | * This code is supposed to duplicate the IBM firmware behaviour: |
| 2412 | * - Pressing MUTE issues mute hotkey message, even when already mute |
| 2413 | * - Pressing Volume up/down issues volume up/down hotkey messages, |
| 2414 | * even when already at maximum or minumum volume |
| 2415 | * - The act of unmuting issues volume up/down notification, |
| 2416 | * depending which key was used to unmute |
| 2417 | * |
| 2418 | * We are constrained to what the NVRAM can tell us, which is not much |
| 2419 | * and certainly not enough if more than one volume hotkey was pressed |
| 2420 | * since the last poll cycle. |
| 2421 | * |
| 2422 | * Just to make our life interesting, some newer Lenovo ThinkPads have |
| 2423 | * bugs in the BIOS and may fail to update volume_toggle properly. |
| 2424 | */ |
| 2425 | if (newn->mute) { |
| 2426 | /* muted */ |
| 2427 | if (!oldn->mute || |
| 2428 | oldn->volume_toggle != newn->volume_toggle || |
| 2429 | oldn->volume_level != newn->volume_level) { |
| 2430 | /* recently muted, or repeated mute keypress, or |
| 2431 | * multiple presses ending in mute */ |
| 2432 | issue_volchange(oldn->volume_level, newn->volume_level); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2433 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2434 | } |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2435 | } else { |
| 2436 | /* unmute */ |
| 2437 | if (oldn->mute) { |
| 2438 | /* recently unmuted, issue 'unmute' keypress */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2439 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2440 | } |
| 2441 | if (oldn->volume_level != newn->volume_level) { |
| 2442 | issue_volchange(oldn->volume_level, newn->volume_level); |
| 2443 | } else if (oldn->volume_toggle != newn->volume_toggle) { |
| 2444 | /* repeated vol up/down keypress at end of scale ? */ |
| 2445 | if (newn->volume_level == 0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2446 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2447 | else if (newn->volume_level >= TP_NVRAM_LEVEL_VOLUME_MAX) |
| 2448 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2449 | } |
| 2450 | } |
| 2451 | |
| 2452 | /* handle brightness */ |
Henrique de Moraes Holschuh | 2899902 | 2010-05-16 19:45:36 -0300 | [diff] [blame] | 2453 | if (oldn->brightness_level != newn->brightness_level) { |
| 2454 | issue_brightnesschange(oldn->brightness_level, |
| 2455 | newn->brightness_level); |
| 2456 | } else if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 2457 | /* repeated key presses that didn't change state */ |
| 2458 | if (newn->brightness_level == 0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2459 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | 2899902 | 2010-05-16 19:45:36 -0300 | [diff] [blame] | 2460 | else if (newn->brightness_level >= bright_maxlvl |
| 2461 | && !tp_features.bright_unkfw) |
| 2462 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2463 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2464 | |
| 2465 | #undef TPACPI_COMPARE_KEY |
| 2466 | #undef TPACPI_MAY_SEND_KEY |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2467 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2468 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2469 | /* |
| 2470 | * Polling driver |
| 2471 | * |
| 2472 | * We track all events in hotkey_source_mask all the time, since |
| 2473 | * most of them are edge-based. We only issue those requested by |
| 2474 | * hotkey_user_mask or hotkey_driver_mask, though. |
| 2475 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2476 | static int hotkey_kthread(void *data) |
| 2477 | { |
| 2478 | struct tp_nvram_state s[2]; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2479 | u32 poll_mask, event_mask; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2480 | unsigned int si, so; |
| 2481 | unsigned long t; |
| 2482 | unsigned int change_detector, must_reset; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2483 | unsigned int poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2484 | |
| 2485 | mutex_lock(&hotkey_thread_mutex); |
| 2486 | |
| 2487 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 2488 | goto exit; |
| 2489 | |
| 2490 | set_freezable(); |
| 2491 | |
| 2492 | so = 0; |
| 2493 | si = 1; |
| 2494 | t = 0; |
| 2495 | |
| 2496 | /* Initial state for compares */ |
| 2497 | mutex_lock(&hotkey_thread_data_mutex); |
| 2498 | change_detector = hotkey_config_change; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2499 | poll_mask = hotkey_source_mask; |
| 2500 | event_mask = hotkey_source_mask & |
| 2501 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2502 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2503 | mutex_unlock(&hotkey_thread_data_mutex); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2504 | hotkey_read_nvram(&s[so], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2505 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2506 | while (!kthread_should_stop()) { |
| 2507 | if (t == 0) { |
| 2508 | if (likely(poll_freq)) |
| 2509 | t = 1000/poll_freq; |
| 2510 | else |
| 2511 | t = 100; /* should never happen... */ |
| 2512 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2513 | t = msleep_interruptible(t); |
| 2514 | if (unlikely(kthread_should_stop())) |
| 2515 | break; |
| 2516 | must_reset = try_to_freeze(); |
| 2517 | if (t > 0 && !must_reset) |
| 2518 | continue; |
| 2519 | |
| 2520 | mutex_lock(&hotkey_thread_data_mutex); |
| 2521 | if (must_reset || hotkey_config_change != change_detector) { |
| 2522 | /* forget old state on thaw or config change */ |
| 2523 | si = so; |
| 2524 | t = 0; |
| 2525 | change_detector = hotkey_config_change; |
| 2526 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2527 | poll_mask = hotkey_source_mask; |
| 2528 | event_mask = hotkey_source_mask & |
| 2529 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2530 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2531 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2532 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2533 | if (likely(poll_mask)) { |
| 2534 | hotkey_read_nvram(&s[si], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2535 | if (likely(si != so)) { |
| 2536 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2537 | event_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | so = si; |
| 2542 | si ^= 1; |
| 2543 | } |
| 2544 | |
| 2545 | exit: |
| 2546 | mutex_unlock(&hotkey_thread_mutex); |
| 2547 | return 0; |
| 2548 | } |
| 2549 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2550 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2551 | static void hotkey_poll_stop_sync(void) |
| 2552 | { |
| 2553 | if (tpacpi_hotkey_task) { |
| 2554 | if (frozen(tpacpi_hotkey_task) || |
| 2555 | freezing(tpacpi_hotkey_task)) |
| 2556 | thaw_process(tpacpi_hotkey_task); |
| 2557 | |
| 2558 | kthread_stop(tpacpi_hotkey_task); |
| 2559 | tpacpi_hotkey_task = NULL; |
| 2560 | mutex_lock(&hotkey_thread_mutex); |
| 2561 | /* at this point, the thread did exit */ |
| 2562 | mutex_unlock(&hotkey_thread_mutex); |
| 2563 | } |
| 2564 | } |
| 2565 | |
| 2566 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2567 | static void hotkey_poll_setup(const bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2568 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2569 | const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask; |
| 2570 | 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] | 2571 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2572 | if (hotkey_poll_freq > 0 && |
| 2573 | (poll_driver_mask || |
| 2574 | (poll_user_mask && tpacpi_inputdev->users > 0))) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2575 | if (!tpacpi_hotkey_task) { |
| 2576 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 2577 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2578 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 2579 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2580 | printk(TPACPI_ERR |
| 2581 | "could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2582 | "for hotkey polling\n"); |
| 2583 | } |
| 2584 | } |
| 2585 | } else { |
| 2586 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2587 | if (may_warn && (poll_driver_mask || poll_user_mask) && |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2588 | hotkey_poll_freq == 0) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2589 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2590 | "hot keys 0x%08x and/or events 0x%08x " |
| 2591 | "require polling, which is currently " |
| 2592 | "disabled\n", |
| 2593 | poll_user_mask, poll_driver_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2594 | } |
| 2595 | } |
| 2596 | } |
| 2597 | |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2598 | static void hotkey_poll_setup_safe(const bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2599 | { |
| 2600 | mutex_lock(&hotkey_mutex); |
| 2601 | hotkey_poll_setup(may_warn); |
| 2602 | mutex_unlock(&hotkey_mutex); |
| 2603 | } |
| 2604 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2605 | /* call with hotkey_mutex held */ |
| 2606 | static void hotkey_poll_set_freq(unsigned int freq) |
| 2607 | { |
| 2608 | if (!freq) |
| 2609 | hotkey_poll_stop_sync(); |
| 2610 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2611 | hotkey_poll_freq = freq; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2612 | } |
| 2613 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2614 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2615 | |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2616 | static void hotkey_poll_setup(const bool __unused) |
| 2617 | { |
| 2618 | } |
| 2619 | |
| 2620 | static void hotkey_poll_setup_safe(const bool __unused) |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2621 | { |
| 2622 | } |
| 2623 | |
| 2624 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2625 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2626 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 2627 | { |
| 2628 | switch (tpacpi_lifecycle) { |
| 2629 | case TPACPI_LIFE_INIT: |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2630 | case TPACPI_LIFE_RUNNING: |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2631 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2632 | return 0; |
Henrique de Moraes Holschuh | b589ea4 | 2010-02-25 21:28:58 -0300 | [diff] [blame] | 2633 | case TPACPI_LIFE_EXITING: |
| 2634 | return -EBUSY; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 2638 | BUG(); |
| 2639 | return -EBUSY; |
| 2640 | } |
| 2641 | |
| 2642 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 2643 | { |
| 2644 | /* disable hotkey polling when possible */ |
Henrique de Moraes Holschuh | b589ea4 | 2010-02-25 21:28:58 -0300 | [diff] [blame] | 2645 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING && |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2646 | !(hotkey_source_mask & hotkey_driver_mask)) |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2647 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2648 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2649 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2650 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 2651 | static ssize_t hotkey_enable_show(struct device *dev, |
| 2652 | struct device_attribute *attr, |
| 2653 | char *buf) |
| 2654 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2655 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2656 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2657 | printk_deprecated_attribute("hotkey_enable", |
| 2658 | "Hotkey reporting is always enabled"); |
| 2659 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2660 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2661 | if (res) |
| 2662 | return res; |
| 2663 | |
| 2664 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 2665 | } |
| 2666 | |
| 2667 | static ssize_t hotkey_enable_store(struct device *dev, |
| 2668 | struct device_attribute *attr, |
| 2669 | const char *buf, size_t count) |
| 2670 | { |
| 2671 | unsigned long t; |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2672 | |
| 2673 | printk_deprecated_attribute("hotkey_enable", |
| 2674 | "Hotkeys can be disabled through hotkey_mask"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2675 | |
| 2676 | if (parse_strtoul(buf, 1, &t)) |
| 2677 | return -EINVAL; |
| 2678 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2679 | if (t == 0) |
| 2680 | return -EPERM; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2681 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2682 | return count; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2686 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2687 | hotkey_enable_show, hotkey_enable_store); |
| 2688 | |
| 2689 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 2690 | static ssize_t hotkey_mask_show(struct device *dev, |
| 2691 | struct device_attribute *attr, |
| 2692 | char *buf) |
| 2693 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2694 | 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] | 2695 | } |
| 2696 | |
| 2697 | static ssize_t hotkey_mask_store(struct device *dev, |
| 2698 | struct device_attribute *attr, |
| 2699 | const char *buf, size_t count) |
| 2700 | { |
| 2701 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2702 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2703 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2704 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2705 | return -EINVAL; |
| 2706 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2707 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2708 | return -ERESTARTSYS; |
| 2709 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2710 | res = hotkey_user_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2711 | |
| 2712 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2713 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2714 | #endif |
| 2715 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2716 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2717 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2718 | tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t); |
| 2719 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2720 | return (res) ? res : count; |
| 2721 | } |
| 2722 | |
| 2723 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2724 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2725 | hotkey_mask_show, hotkey_mask_store); |
| 2726 | |
| 2727 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 2728 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 2729 | struct device_attribute *attr, |
| 2730 | char *buf) |
| 2731 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2732 | return sprintf(buf, "0\n"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2736 | __ATTR(hotkey_bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2737 | |
| 2738 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 2739 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 2740 | struct device_attribute *attr, |
| 2741 | char *buf) |
| 2742 | { |
Henrique de Moraes Holschuh | 06777be | 2009-09-12 15:22:15 -0300 | [diff] [blame] | 2743 | printk_deprecated_attribute("hotkey_bios_mask", |
| 2744 | "This attribute is useless."); |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2745 | 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] | 2746 | } |
| 2747 | |
| 2748 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2749 | __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2750 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2751 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 2752 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 2753 | struct device_attribute *attr, |
| 2754 | char *buf) |
| 2755 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2756 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 2757 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 2761 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 2762 | |
| 2763 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 2764 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 2765 | struct device_attribute *attr, |
| 2766 | char *buf) |
| 2767 | { |
| 2768 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2769 | (hotkey_all_mask | hotkey_source_mask) |
| 2770 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 2774 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 2775 | hotkey_recommended_mask_show, NULL); |
| 2776 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2777 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2778 | |
| 2779 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 2780 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 2781 | struct device_attribute *attr, |
| 2782 | char *buf) |
| 2783 | { |
| 2784 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 2785 | } |
| 2786 | |
| 2787 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 2788 | struct device_attribute *attr, |
| 2789 | const char *buf, size_t count) |
| 2790 | { |
| 2791 | unsigned long t; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2792 | u32 r_ev; |
| 2793 | int rc; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2794 | |
| 2795 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 2796 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 2797 | return -EINVAL; |
| 2798 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2799 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2800 | return -ERESTARTSYS; |
| 2801 | |
| 2802 | HOTKEY_CONFIG_CRITICAL_START |
| 2803 | hotkey_source_mask = t; |
| 2804 | HOTKEY_CONFIG_CRITICAL_END |
| 2805 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2806 | rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) & |
| 2807 | ~hotkey_source_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2808 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2809 | |
| 2810 | /* check if events needed by the driver got disabled */ |
| 2811 | r_ev = hotkey_driver_mask & ~(hotkey_acpi_mask & hotkey_all_mask) |
| 2812 | & ~hotkey_source_mask & TPACPI_HKEY_NVRAM_KNOWN_MASK; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2813 | |
| 2814 | mutex_unlock(&hotkey_mutex); |
| 2815 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2816 | if (rc < 0) |
| 2817 | printk(TPACPI_ERR "hotkey_source_mask: failed to update the" |
| 2818 | "firmware event mask!\n"); |
| 2819 | |
| 2820 | if (r_ev) |
| 2821 | printk(TPACPI_NOTICE "hotkey_source_mask: " |
| 2822 | "some important events were disabled: " |
| 2823 | "0x%04x\n", r_ev); |
| 2824 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2825 | tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); |
| 2826 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2827 | return (rc < 0) ? rc : count; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2828 | } |
| 2829 | |
| 2830 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 2831 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 2832 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 2833 | |
| 2834 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 2835 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 2836 | struct device_attribute *attr, |
| 2837 | char *buf) |
| 2838 | { |
| 2839 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 2840 | } |
| 2841 | |
| 2842 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 2843 | struct device_attribute *attr, |
| 2844 | const char *buf, size_t count) |
| 2845 | { |
| 2846 | unsigned long t; |
| 2847 | |
| 2848 | if (parse_strtoul(buf, 25, &t)) |
| 2849 | return -EINVAL; |
| 2850 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2851 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2852 | return -ERESTARTSYS; |
| 2853 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2854 | hotkey_poll_set_freq(t); |
| 2855 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2856 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2857 | mutex_unlock(&hotkey_mutex); |
| 2858 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2859 | tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t); |
| 2860 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2861 | return count; |
| 2862 | } |
| 2863 | |
| 2864 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 2865 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 2866 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 2867 | |
| 2868 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2869 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2870 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2871 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 2872 | struct device_attribute *attr, |
| 2873 | char *buf) |
| 2874 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2875 | int res; |
| 2876 | res = hotkey_get_wlsw(); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2877 | if (res < 0) |
| 2878 | return res; |
| 2879 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2880 | /* Opportunistic update */ |
| 2881 | tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF)); |
| 2882 | |
| 2883 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2884 | (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 2888 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 2889 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2890 | static void hotkey_radio_sw_notify_change(void) |
| 2891 | { |
| 2892 | if (tp_features.hotkey_wlsw) |
| 2893 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2894 | "hotkey_radio_sw"); |
| 2895 | } |
| 2896 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2897 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 2898 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 2899 | struct device_attribute *attr, |
| 2900 | char *buf) |
| 2901 | { |
| 2902 | int res, s; |
| 2903 | res = hotkey_get_tablet_mode(&s); |
| 2904 | if (res < 0) |
| 2905 | return res; |
| 2906 | |
| 2907 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 2908 | } |
| 2909 | |
| 2910 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 2911 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 2912 | |
| 2913 | static void hotkey_tablet_mode_notify_change(void) |
| 2914 | { |
| 2915 | if (tp_features.hotkey_tablet) |
| 2916 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2917 | "hotkey_tablet_mode"); |
| 2918 | } |
| 2919 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2920 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 2921 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 2922 | struct device_attribute *attr, |
| 2923 | char *buf) |
| 2924 | { |
| 2925 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2926 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 2927 | } |
| 2928 | |
| 2929 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 2930 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 2931 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2932 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2933 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 2934 | struct device_attribute *attr, |
| 2935 | char *buf) |
| 2936 | { |
| 2937 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 2938 | } |
| 2939 | |
| 2940 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 2941 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 2942 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2943 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2944 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2945 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2946 | "wakeup_reason"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2950 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 2951 | struct device_attribute *attr, |
| 2952 | char *buf) |
| 2953 | { |
| 2954 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 2955 | } |
| 2956 | |
| 2957 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 2958 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 2959 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 2960 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2961 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2962 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2963 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2964 | "wakeup_hotunplug_complete"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2965 | } |
| 2966 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2967 | /* --------------------------------------------------------------------- */ |
| 2968 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2969 | static struct attribute *hotkey_attributes[] __initdata = { |
| 2970 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2971 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2972 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2973 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2974 | &dev_attr_hotkey_wakeup_reason.attr, |
| 2975 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2976 | &dev_attr_hotkey_mask.attr, |
| 2977 | &dev_attr_hotkey_all_mask.attr, |
| 2978 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2979 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2980 | &dev_attr_hotkey_source_mask.attr, |
| 2981 | &dev_attr_hotkey_poll_freq.attr, |
| 2982 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2983 | }; |
| 2984 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2985 | /* |
| 2986 | * Sync both the hw and sw blocking state of all switches |
| 2987 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2988 | static void tpacpi_send_radiosw_update(void) |
| 2989 | { |
| 2990 | int wlsw; |
| 2991 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2992 | /* |
| 2993 | * We must sync all rfkill controllers *before* issuing any |
| 2994 | * rfkill input events, or we will race the rfkill core input |
| 2995 | * handler. |
| 2996 | * |
| 2997 | * tpacpi_inputdev_send_mutex works as a syncronization point |
| 2998 | * for the above. |
| 2999 | * |
| 3000 | * We optimize to avoid numerous calls to hotkey_get_wlsw. |
| 3001 | */ |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3002 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3003 | wlsw = hotkey_get_wlsw(); |
| 3004 | |
| 3005 | /* Sync hw blocking state first if it is hw-blocked */ |
| 3006 | if (wlsw == TPACPI_RFK_RADIO_OFF) |
| 3007 | tpacpi_rfk_update_hwblock_state(true); |
| 3008 | |
| 3009 | /* Sync sw blocking state */ |
| 3010 | tpacpi_rfk_update_swstate_all(); |
| 3011 | |
| 3012 | /* Sync hw blocking state last if it is hw-unblocked */ |
| 3013 | if (wlsw == TPACPI_RFK_RADIO_ON) |
| 3014 | tpacpi_rfk_update_hwblock_state(false); |
| 3015 | |
| 3016 | /* Issue rfkill input event for WLSW switch */ |
| 3017 | if (!(wlsw < 0)) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3018 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 3019 | |
| 3020 | input_report_switch(tpacpi_inputdev, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3021 | SW_RFKILL_ALL, (wlsw > 0)); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3022 | input_sync(tpacpi_inputdev); |
| 3023 | |
| 3024 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 3025 | } |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3026 | |
| 3027 | /* |
| 3028 | * this can be unconditional, as we will poll state again |
| 3029 | * if userspace uses the notify to read data |
| 3030 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3031 | hotkey_radio_sw_notify_change(); |
| 3032 | } |
| 3033 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3034 | static void hotkey_exit(void) |
| 3035 | { |
| 3036 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3037 | mutex_lock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3038 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3039 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3040 | #endif |
| 3041 | |
| 3042 | if (hotkey_dev_attributes) |
| 3043 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3044 | |
| 3045 | kfree(hotkey_keycode_map); |
| 3046 | |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3047 | dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3048 | "restoring original HKEY status and mask\n"); |
| 3049 | /* yes, there is a bitwise or below, we want the |
| 3050 | * functions to be called even if one of them fail */ |
| 3051 | if (((tp_features.hotkey_mask && |
| 3052 | hotkey_mask_set(hotkey_orig_mask)) | |
| 3053 | hotkey_status_set(false)) != 0) |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3054 | printk(TPACPI_ERR |
| 3055 | "failed to restore hot key mask " |
| 3056 | "to BIOS defaults\n"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3057 | } |
| 3058 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3059 | static void __init hotkey_unmap(const unsigned int scancode) |
| 3060 | { |
| 3061 | if (hotkey_keycode_map[scancode] != KEY_RESERVED) { |
| 3062 | clear_bit(hotkey_keycode_map[scancode], |
| 3063 | tpacpi_inputdev->keybit); |
| 3064 | hotkey_keycode_map[scancode] = KEY_RESERVED; |
| 3065 | } |
| 3066 | } |
| 3067 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3068 | /* |
| 3069 | * HKEY quirks: |
| 3070 | * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12 |
| 3071 | */ |
| 3072 | |
| 3073 | #define TPACPI_HK_Q_INIMASK 0x0001 |
| 3074 | |
| 3075 | static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = { |
| 3076 | TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3077 | TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3078 | TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK), /* 770, 770E, 770ED */ |
| 3079 | TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK), /* A20m */ |
| 3080 | TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK), /* A20p */ |
| 3081 | TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK), /* A21e, A22e */ |
| 3082 | TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK), /* A21e */ |
| 3083 | TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK), /* A21m, A22m */ |
| 3084 | TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK), /* A21p, A22p */ |
| 3085 | TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK), /* A22e */ |
| 3086 | TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK), /* A22m */ |
| 3087 | TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK), /* A30/p (0) */ |
| 3088 | TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK), /* R30 */ |
| 3089 | TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK), /* R31 */ |
| 3090 | TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK), /* T20 */ |
| 3091 | TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK), /* T21 */ |
| 3092 | TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK), /* T22 */ |
| 3093 | TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK), /* X20, X21 */ |
| 3094 | TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */ |
| 3095 | }; |
| 3096 | |
Henrique de Moraes Holschuh | fc6e756 | 2010-09-17 21:53:41 -0300 | [diff] [blame] | 3097 | typedef u16 tpacpi_keymap_entry_t; |
| 3098 | 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] | 3099 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3100 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3101 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3102 | /* Requirements for changing the default keymaps: |
| 3103 | * |
| 3104 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 3105 | * good reasons. Do not change them unless you have deep |
| 3106 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 3107 | * the various ThinkPad models. The driver behaves |
| 3108 | * differently for KEY_RESERVED: such keys have their |
| 3109 | * hot key mask *unset* in mask_recommended, and also |
| 3110 | * in the initial hot key mask programmed into the |
| 3111 | * firmware at driver load time, which means the firm- |
| 3112 | * ware may react very differently if you change them to |
| 3113 | * something else; |
| 3114 | * |
| 3115 | * 2. You must be subscribed to the linux-thinkpad and |
| 3116 | * ibm-acpi-devel mailing lists, and you should read the |
| 3117 | * list archives since 2007 if you want to change the |
| 3118 | * keymaps. This requirement exists so that you will |
| 3119 | * know the past history of problems with the thinkpad- |
| 3120 | * acpi driver keymaps, and also that you will be |
| 3121 | * listening to any bug reports; |
| 3122 | * |
| 3123 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 3124 | * for merging, *ever*. Send them to the linux-acpi |
| 3125 | * mailinglist for comments. Merging is to be done only |
| 3126 | * through acpi-test and the ACPI maintainer. |
| 3127 | * |
| 3128 | * If the above is too much to ask, don't change the keymap. |
| 3129 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 3130 | */ |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3131 | |
| 3132 | enum keymap_index { |
| 3133 | TPACPI_KEYMAP_IBM_GENERIC = 0, |
| 3134 | TPACPI_KEYMAP_LENOVO_GENERIC, |
| 3135 | }; |
| 3136 | |
| 3137 | static const tpacpi_keymap_t tpacpi_keymaps[] __initconst = { |
| 3138 | /* Generic keymap for IBM ThinkPads */ |
| 3139 | [TPACPI_KEYMAP_IBM_GENERIC] = { |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3140 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3141 | KEY_FN_F1, KEY_BATTERY, KEY_COFFEE, KEY_SLEEP, |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3142 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 3143 | 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] | 3144 | |
| 3145 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3146 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3147 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3148 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3149 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3150 | /* brightness: firmware always reacts to them */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3151 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3152 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3153 | |
| 3154 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3155 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3156 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3157 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3158 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3159 | |
| 3160 | /* Volume: firmware always react to it and reprograms |
| 3161 | * the built-in *extra* mixer. Never map it to control |
| 3162 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3163 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3164 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3165 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3166 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3167 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3168 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3169 | /* (assignments unknown, please report if found) */ |
| 3170 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3171 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3172 | }, |
| 3173 | |
| 3174 | /* Generic keymap for Lenovo ThinkPads */ |
| 3175 | [TPACPI_KEYMAP_LENOVO_GENERIC] = { |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3176 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 3177 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
Jens Taprogge | 2b75426 | 2010-08-09 23:48:22 -0300 | [diff] [blame] | 3178 | KEY_WLAN, KEY_CAMERA, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3179 | 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] | 3180 | |
| 3181 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3182 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3183 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3184 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3185 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3186 | /* These should be enabled --only-- when ACPI video |
| 3187 | * is disabled (i.e. in "vendor" mode), and are handled |
| 3188 | * in a special way by the init code */ |
| 3189 | KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ |
| 3190 | KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3191 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3192 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3193 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3194 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3195 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3196 | |
| 3197 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 3198 | * react to it and reprograms the built-in *extra* mixer. |
| 3199 | * Never map it to control another mixer by default. |
| 3200 | * |
| 3201 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 3202 | * these over the regular keyboard, so these are no-ops, |
| 3203 | * but there are still weird bugs re. MUTE, so do not |
| 3204 | * change unless you get test reports from all Lenovo |
| 3205 | * models. May cause the BIOS to interfere with the |
| 3206 | * HDA mixer. |
| 3207 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3208 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3209 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3210 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3211 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3212 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3213 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3214 | /* (assignments unknown, please report if found) */ |
| 3215 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3216 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3217 | }, |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3218 | }; |
| 3219 | |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3220 | static const struct tpacpi_quirk tpacpi_keymap_qtable[] __initconst = { |
| 3221 | /* Generic maps (fallback) */ |
| 3222 | { |
| 3223 | .vendor = PCI_VENDOR_ID_IBM, |
| 3224 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 3225 | .quirks = TPACPI_KEYMAP_IBM_GENERIC, |
| 3226 | }, |
| 3227 | { |
| 3228 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 3229 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 3230 | .quirks = TPACPI_KEYMAP_LENOVO_GENERIC, |
| 3231 | }, |
| 3232 | }; |
| 3233 | |
| 3234 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(tpacpi_keymap_t) |
Henrique de Moraes Holschuh | fc6e756 | 2010-09-17 21:53:41 -0300 | [diff] [blame] | 3235 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(tpacpi_keymap_entry_t) |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3236 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3237 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3238 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 3239 | int hkeyv; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3240 | bool radiosw_state = false; |
| 3241 | bool tabletsw_state = false; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3242 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3243 | unsigned long quirks; |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3244 | unsigned long keymap_id; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3245 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3246 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3247 | "initializing hotkey subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3248 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3249 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3250 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 3251 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3252 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3253 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3254 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3255 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3256 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 3257 | mutex_init(&hotkey_thread_mutex); |
| 3258 | mutex_init(&hotkey_thread_data_mutex); |
| 3259 | #endif |
| 3260 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3261 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3262 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3263 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3264 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3265 | "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3266 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3267 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3268 | if (!tp_features.hotkey) |
| 3269 | return 1; |
| 3270 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3271 | quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, |
| 3272 | ARRAY_SIZE(tpacpi_hotkey_qtable)); |
| 3273 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3274 | tpacpi_disable_brightness_delay(); |
| 3275 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3276 | /* MUST have enough space for all attributes to be added to |
| 3277 | * hotkey_dev_attributes */ |
| 3278 | hotkey_dev_attributes = create_attr_set( |
| 3279 | ARRAY_SIZE(hotkey_attributes) + 2, |
| 3280 | NULL); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3281 | if (!hotkey_dev_attributes) |
| 3282 | return -ENOMEM; |
| 3283 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 3284 | hotkey_attributes, |
| 3285 | ARRAY_SIZE(hotkey_attributes)); |
| 3286 | if (res) |
| 3287 | goto err_exit; |
| 3288 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3289 | /* 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] | 3290 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 3291 | for HKEY interface version 0x100 */ |
| 3292 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 3293 | if ((hkeyv >> 8) != 1) { |
| 3294 | printk(TPACPI_ERR "unknown version of the " |
| 3295 | "HKEY interface: 0x%x\n", hkeyv); |
| 3296 | printk(TPACPI_ERR "please report this to %s\n", |
| 3297 | TPACPI_MAIL); |
| 3298 | } else { |
| 3299 | /* |
| 3300 | * MHKV 0x100 in A31, R40, R40e, |
| 3301 | * T4x, X31, and later |
| 3302 | */ |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3303 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3304 | "firmware HKEY interface version: 0x%x\n", |
| 3305 | hkeyv); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3306 | |
| 3307 | /* Paranoia check AND init hotkey_all_mask */ |
| 3308 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
| 3309 | "MHKA", "qd")) { |
| 3310 | printk(TPACPI_ERR |
| 3311 | "missing MHKA handler, " |
| 3312 | "please report this to %s\n", |
| 3313 | TPACPI_MAIL); |
| 3314 | /* Fallback: pre-init for FN+F3,F4,F12 */ |
| 3315 | hotkey_all_mask = 0x080cU; |
| 3316 | } else { |
| 3317 | tp_features.hotkey_mask = 1; |
| 3318 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3319 | } |
| 3320 | } |
| 3321 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3322 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3323 | "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3324 | str_supported(tp_features.hotkey_mask)); |
| 3325 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3326 | /* Init hotkey_all_mask if not initialized yet */ |
| 3327 | if (!tp_features.hotkey_mask && !hotkey_all_mask && |
| 3328 | (quirks & TPACPI_HK_Q_INIMASK)) |
| 3329 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3330 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3331 | /* Init hotkey_acpi_mask and hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3332 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3333 | /* hotkey_source_mask *must* be zero for |
| 3334 | * the first hotkey_mask_get to return hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3335 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3336 | if (res) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3337 | goto err_exit; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3338 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3339 | hotkey_orig_mask = hotkey_acpi_mask; |
| 3340 | } else { |
| 3341 | hotkey_orig_mask = hotkey_all_mask; |
| 3342 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3343 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3344 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3345 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3346 | if (dbg_wlswemul) { |
| 3347 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3348 | radiosw_state = !!tpacpi_wlsw_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3349 | printk(TPACPI_INFO |
| 3350 | "radio switch emulation enabled\n"); |
| 3351 | } else |
| 3352 | #endif |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3353 | /* Not all thinkpads have a hardware radio switch */ |
| 3354 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 3355 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3356 | radiosw_state = !!status; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3357 | printk(TPACPI_INFO |
| 3358 | "radio switch found; radios are %s\n", |
| 3359 | enabled(status, 0)); |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3360 | } |
| 3361 | if (tp_features.hotkey_wlsw) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3362 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3363 | &dev_attr_hotkey_radio_sw.attr); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3364 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3365 | /* For X41t, X60t, X61t Tablets... */ |
| 3366 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 3367 | tp_features.hotkey_tablet = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3368 | tabletsw_state = !!(status & TP_HOTKEY_TABLET_MASK); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3369 | printk(TPACPI_INFO |
| 3370 | "possible tablet mode switch found; " |
| 3371 | "ThinkPad in %s mode\n", |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3372 | (tabletsw_state) ? "tablet" : "laptop"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3373 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3374 | &dev_attr_hotkey_tablet_mode.attr); |
| 3375 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3376 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3377 | if (!res) |
| 3378 | res = register_attr_set_with_sysfs( |
| 3379 | hotkey_dev_attributes, |
| 3380 | &tpacpi_pdev->dev.kobj); |
| 3381 | if (res) |
| 3382 | goto err_exit; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3383 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3384 | /* Set up key map */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3385 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 3386 | GFP_KERNEL); |
| 3387 | if (!hotkey_keycode_map) { |
| 3388 | printk(TPACPI_ERR |
| 3389 | "failed to allocate memory for key map\n"); |
| 3390 | res = -ENOMEM; |
| 3391 | goto err_exit; |
| 3392 | } |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3393 | |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3394 | keymap_id = tpacpi_check_quirks(tpacpi_keymap_qtable, |
| 3395 | ARRAY_SIZE(tpacpi_keymap_qtable)); |
| 3396 | BUG_ON(keymap_id >= ARRAY_SIZE(tpacpi_keymaps)); |
| 3397 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3398 | "using keymap number %lu\n", keymap_id); |
| 3399 | |
| 3400 | memcpy(hotkey_keycode_map, &tpacpi_keymaps[keymap_id], |
| 3401 | TPACPI_HOTKEY_MAP_SIZE); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3402 | |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3403 | input_set_capability(tpacpi_inputdev, EV_MSC, MSC_SCAN); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3404 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 3405 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 3406 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 3407 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
| 3408 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3409 | input_set_capability(tpacpi_inputdev, EV_KEY, |
| 3410 | hotkey_keycode_map[i]); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3411 | } else { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3412 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 3413 | hotkey_reserved_mask |= 1 << i; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3414 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3415 | } |
| 3416 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3417 | if (tp_features.hotkey_wlsw) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3418 | input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL); |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3419 | input_report_switch(tpacpi_inputdev, |
| 3420 | SW_RFKILL_ALL, radiosw_state); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3421 | } |
| 3422 | if (tp_features.hotkey_tablet) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3423 | input_set_capability(tpacpi_inputdev, EV_SW, SW_TABLET_MODE); |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3424 | input_report_switch(tpacpi_inputdev, |
| 3425 | SW_TABLET_MODE, tabletsw_state); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3426 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3427 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3428 | /* Do not issue duplicate brightness change events to |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 3429 | * userspace. tpacpi_detect_brightness_capabilities() must have |
| 3430 | * been called before this point */ |
Henrique de Moraes Holschuh | 8bf3d4c | 2009-05-30 13:25:09 -0300 | [diff] [blame] | 3431 | if (tp_features.bright_acpimode && acpi_video_backlight_support()) { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3432 | printk(TPACPI_INFO |
| 3433 | "This ThinkPad has standard ACPI backlight " |
| 3434 | "brightness control, supported by the ACPI " |
| 3435 | "video driver\n"); |
| 3436 | printk(TPACPI_NOTICE |
| 3437 | "Disabling thinkpad-acpi brightness events " |
| 3438 | "by default...\n"); |
| 3439 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3440 | /* Disable brightness up/down on Lenovo thinkpads when |
| 3441 | * ACPI is handling them, otherwise it is plain impossible |
| 3442 | * for userspace to do something even remotely sane */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3443 | hotkey_reserved_mask |= |
| 3444 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 3445 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3446 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 3447 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3448 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3449 | |
Henrique de Moraes Holschuh | 230d8cf | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3450 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3451 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 3452 | & ~hotkey_all_mask |
| 3453 | & ~hotkey_reserved_mask; |
Henrique de Moraes Holschuh | 230d8cf | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3454 | |
| 3455 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3456 | "hotkey source mask 0x%08x, polling freq %u\n", |
| 3457 | hotkey_source_mask, hotkey_poll_freq); |
| 3458 | #endif |
| 3459 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3460 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3461 | "enabling firmware HKEY event interface...\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3462 | res = hotkey_status_set(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3463 | if (res) { |
| 3464 | hotkey_exit(); |
| 3465 | return res; |
| 3466 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3467 | res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask) |
| 3468 | | hotkey_driver_mask) |
| 3469 | & ~hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3470 | if (res < 0 && res != -ENXIO) { |
| 3471 | hotkey_exit(); |
| 3472 | return res; |
| 3473 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3474 | hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask) |
| 3475 | & ~hotkey_reserved_mask; |
| 3476 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3477 | "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n", |
| 3478 | hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3479 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3480 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3481 | "legacy ibm/hotkey event reporting over procfs %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3482 | (hotkey_report_mode < 2) ? |
| 3483 | "enabled" : "disabled"); |
| 3484 | |
| 3485 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 3486 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 3487 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3488 | hotkey_poll_setup_safe(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3489 | |
| 3490 | return 0; |
| 3491 | |
| 3492 | err_exit: |
| 3493 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3494 | hotkey_dev_attributes = NULL; |
| 3495 | |
| 3496 | return (res < 0)? res : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3497 | } |
| 3498 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3499 | static bool hotkey_notify_hotkey(const u32 hkey, |
| 3500 | bool *send_acpi_ev, |
| 3501 | bool *ignore_acpi_ev) |
| 3502 | { |
| 3503 | /* 0x1000-0x1FFF: key presses */ |
| 3504 | unsigned int scancode = hkey & 0xfff; |
| 3505 | *send_acpi_ev = true; |
| 3506 | *ignore_acpi_ev = false; |
| 3507 | |
Henrique de Moraes Holschuh | 34a656d | 2010-08-09 23:48:20 -0300 | [diff] [blame] | 3508 | /* HKEY event 0x1001 is scancode 0x00 */ |
| 3509 | if (scancode > 0 && scancode <= TPACPI_HOTKEY_MAP_LEN) { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3510 | scancode--; |
| 3511 | if (!(hotkey_source_mask & (1 << scancode))) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3512 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3513 | *send_acpi_ev = false; |
| 3514 | } else { |
| 3515 | *ignore_acpi_ev = true; |
| 3516 | } |
| 3517 | return true; |
| 3518 | } |
| 3519 | return false; |
| 3520 | } |
| 3521 | |
| 3522 | static bool hotkey_notify_wakeup(const u32 hkey, |
| 3523 | bool *send_acpi_ev, |
| 3524 | bool *ignore_acpi_ev) |
| 3525 | { |
| 3526 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3527 | *send_acpi_ev = true; |
| 3528 | *ignore_acpi_ev = false; |
| 3529 | |
| 3530 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3531 | case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */ |
| 3532 | case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3533 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 3534 | *ignore_acpi_ev = true; |
| 3535 | break; |
| 3536 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3537 | case TP_HKEY_EV_WKUP_S3_BAYEJ: /* suspend, bay eject */ |
| 3538 | case TP_HKEY_EV_WKUP_S4_BAYEJ: /* hibernation, bay eject */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3539 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 3540 | *ignore_acpi_ev = true; |
| 3541 | break; |
| 3542 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3543 | case TP_HKEY_EV_WKUP_S3_BATLOW: /* Battery on critical low level/S3 */ |
| 3544 | case TP_HKEY_EV_WKUP_S4_BATLOW: /* Battery on critical low level/S4 */ |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3545 | printk(TPACPI_ALERT |
| 3546 | "EMERGENCY WAKEUP: battery almost empty\n"); |
| 3547 | /* how to auto-heal: */ |
| 3548 | /* 2313: woke up from S3, go to S4/S5 */ |
| 3549 | /* 2413: woke up from S4, go to S5 */ |
| 3550 | break; |
| 3551 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3552 | default: |
| 3553 | return false; |
| 3554 | } |
| 3555 | |
| 3556 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
| 3557 | printk(TPACPI_INFO |
| 3558 | "woke up due to a hot-unplug " |
| 3559 | "request...\n"); |
| 3560 | hotkey_wakeup_reason_notify_change(); |
| 3561 | } |
| 3562 | return true; |
| 3563 | } |
| 3564 | |
| 3565 | static bool hotkey_notify_usrevent(const u32 hkey, |
| 3566 | bool *send_acpi_ev, |
| 3567 | bool *ignore_acpi_ev) |
| 3568 | { |
| 3569 | /* 0x5000-0x5FFF: human interface helpers */ |
| 3570 | *send_acpi_ev = true; |
| 3571 | *ignore_acpi_ev = false; |
| 3572 | |
| 3573 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3574 | case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */ |
| 3575 | 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] | 3576 | return true; |
| 3577 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3578 | case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */ |
| 3579 | case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3580 | tpacpi_input_send_tabletsw(); |
| 3581 | hotkey_tablet_mode_notify_change(); |
| 3582 | *send_acpi_ev = false; |
| 3583 | return true; |
| 3584 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3585 | case TP_HKEY_EV_LID_CLOSE: /* Lid closed */ |
| 3586 | case TP_HKEY_EV_LID_OPEN: /* Lid opened */ |
| 3587 | case TP_HKEY_EV_BRGHT_CHANGED: /* brightness changed */ |
Henrique de Moraes Holschuh | 176dd98 | 2009-09-20 14:09:24 -0300 | [diff] [blame] | 3588 | /* do not propagate these events */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3589 | *ignore_acpi_ev = true; |
| 3590 | return true; |
| 3591 | |
| 3592 | default: |
| 3593 | return false; |
| 3594 | } |
| 3595 | } |
| 3596 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3597 | static void thermal_dump_all_sensors(void); |
| 3598 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3599 | static bool hotkey_notify_thermal(const u32 hkey, |
| 3600 | bool *send_acpi_ev, |
| 3601 | bool *ignore_acpi_ev) |
| 3602 | { |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3603 | bool known = true; |
| 3604 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3605 | /* 0x6000-0x6FFF: thermal alarms */ |
| 3606 | *send_acpi_ev = true; |
| 3607 | *ignore_acpi_ev = false; |
| 3608 | |
| 3609 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3610 | case TP_HKEY_EV_THM_TABLE_CHANGED: |
Henrique de Moraes Holschuh | 54926ce | 2009-01-11 03:01:09 -0200 | [diff] [blame] | 3611 | printk(TPACPI_INFO |
| 3612 | "EC reports that Thermal Table has changed\n"); |
| 3613 | /* recommended action: do nothing, we don't have |
| 3614 | * Lenovo ATM information */ |
| 3615 | return true; |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3616 | case TP_HKEY_EV_ALARM_BAT_HOT: |
| 3617 | printk(TPACPI_CRIT |
| 3618 | "THERMAL ALARM: battery is too hot!\n"); |
| 3619 | /* recommended action: warn user through gui */ |
| 3620 | break; |
| 3621 | case TP_HKEY_EV_ALARM_BAT_XHOT: |
| 3622 | printk(TPACPI_ALERT |
| 3623 | "THERMAL EMERGENCY: battery is extremely hot!\n"); |
| 3624 | /* recommended action: immediate sleep/hibernate */ |
| 3625 | break; |
| 3626 | case TP_HKEY_EV_ALARM_SENSOR_HOT: |
| 3627 | printk(TPACPI_CRIT |
| 3628 | "THERMAL ALARM: " |
| 3629 | "a sensor reports something is too hot!\n"); |
| 3630 | /* recommended action: warn user through gui, that */ |
| 3631 | /* some internal component is too hot */ |
| 3632 | break; |
| 3633 | case TP_HKEY_EV_ALARM_SENSOR_XHOT: |
| 3634 | printk(TPACPI_ALERT |
| 3635 | "THERMAL EMERGENCY: " |
| 3636 | "a sensor reports something is extremely hot!\n"); |
| 3637 | /* recommended action: immediate sleep/hibernate */ |
| 3638 | break; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3639 | default: |
| 3640 | printk(TPACPI_ALERT |
| 3641 | "THERMAL ALERT: unknown thermal alarm received\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3642 | known = false; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3643 | } |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3644 | |
| 3645 | thermal_dump_all_sensors(); |
| 3646 | |
| 3647 | return known; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3648 | } |
| 3649 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3650 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 3651 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3652 | u32 hkey; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3653 | bool send_acpi_ev; |
| 3654 | bool ignore_acpi_ev; |
| 3655 | bool known_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3656 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3657 | if (event != 0x80) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3658 | printk(TPACPI_ERR |
| 3659 | "unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3660 | /* 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] | 3661 | acpi_bus_generate_netlink_event( |
| 3662 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3663 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3664 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3665 | return; |
| 3666 | } |
| 3667 | |
| 3668 | while (1) { |
| 3669 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3670 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3671 | return; |
| 3672 | } |
| 3673 | |
| 3674 | if (hkey == 0) { |
| 3675 | /* queue empty */ |
| 3676 | return; |
| 3677 | } |
| 3678 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3679 | send_acpi_ev = true; |
| 3680 | ignore_acpi_ev = false; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3681 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3682 | switch (hkey >> 12) { |
| 3683 | case 1: |
| 3684 | /* 0x1000-0x1FFF: key presses */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3685 | known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev, |
| 3686 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3687 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3688 | case 2: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3689 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3690 | known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev, |
| 3691 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3692 | break; |
| 3693 | case 3: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3694 | /* 0x3000-0x3FFF: bay-related wakeups */ |
Henrique de Moraes Holschuh | bf8b29c | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 3695 | switch (hkey) { |
| 3696 | case TP_HKEY_EV_BAYEJ_ACK: |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3697 | hotkey_autosleep_ack = 1; |
| 3698 | printk(TPACPI_INFO |
| 3699 | "bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3700 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3701 | known_ev = true; |
Henrique de Moraes Holschuh | bf8b29c | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 3702 | break; |
| 3703 | case TP_HKEY_EV_OPTDRV_EJ: |
| 3704 | /* FIXME: kick libata if SATA link offline */ |
| 3705 | known_ev = true; |
| 3706 | break; |
| 3707 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3708 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3709 | } |
| 3710 | break; |
| 3711 | case 4: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3712 | /* 0x4000-0x4FFF: dock-related wakeups */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3713 | if (hkey == TP_HKEY_EV_UNDOCK_ACK) { |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3714 | hotkey_autosleep_ack = 1; |
| 3715 | printk(TPACPI_INFO |
| 3716 | "undocked\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3717 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3718 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3719 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3720 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3721 | } |
| 3722 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3723 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 3724 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3725 | known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev, |
| 3726 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3727 | break; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3728 | case 6: |
| 3729 | /* 0x6000-0x6FFF: thermal alarms */ |
| 3730 | known_ev = hotkey_notify_thermal(hkey, &send_acpi_ev, |
| 3731 | &ignore_acpi_ev); |
| 3732 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3733 | case 7: |
| 3734 | /* 0x7000-0x7FFF: misc */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3735 | if (tp_features.hotkey_wlsw && |
| 3736 | hkey == TP_HKEY_EV_RFKILL_CHANGED) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3737 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3738 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3739 | known_ev = true; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3740 | break; |
| 3741 | } |
| 3742 | /* fallthrough to default */ |
| 3743 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3744 | known_ev = false; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3745 | } |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3746 | if (!known_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3747 | printk(TPACPI_NOTICE |
| 3748 | "unhandled HKEY event 0x%04x\n", hkey); |
Henrique de Moraes Holschuh | cb42935 | 2009-01-11 03:01:07 -0200 | [diff] [blame] | 3749 | printk(TPACPI_NOTICE |
| 3750 | "please report the conditions when this " |
| 3751 | "event happened to %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3752 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3753 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3754 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3755 | if (!ignore_acpi_ev && |
| 3756 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 3757 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 3758 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3759 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3760 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3761 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3762 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3763 | acpi_bus_generate_netlink_event( |
| 3764 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3765 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3766 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3767 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3768 | } |
| 3769 | } |
| 3770 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3771 | static void hotkey_suspend(pm_message_t state) |
| 3772 | { |
| 3773 | /* Do these on suspend, we get the events on early resume! */ |
| 3774 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 3775 | hotkey_autosleep_ack = 0; |
| 3776 | } |
| 3777 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3778 | static void hotkey_resume(void) |
| 3779 | { |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3780 | tpacpi_disable_brightness_delay(); |
| 3781 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3782 | if (hotkey_status_set(true) < 0 || |
| 3783 | hotkey_mask_set(hotkey_acpi_mask) < 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3784 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3785 | "error while attempting to reset the event " |
| 3786 | "firmware interface\n"); |
| 3787 | |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3788 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3789 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3790 | hotkey_wakeup_reason_notify_change(); |
| 3791 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3792 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3793 | } |
| 3794 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3795 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3796 | static int hotkey_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3798 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3800 | if (!tp_features.hotkey) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3801 | seq_printf(m, "status:\t\tnot supported\n"); |
| 3802 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3803 | } |
| 3804 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3805 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3806 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3807 | res = hotkey_status_get(&status); |
| 3808 | if (!res) |
| 3809 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3810 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3811 | if (res) |
| 3812 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3814 | 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] | 3815 | if (hotkey_all_mask) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3816 | seq_printf(m, "mask:\t\t0x%08x\n", hotkey_user_mask); |
| 3817 | seq_printf(m, "commands:\tenable, disable, reset, <mask>\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | } else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3819 | seq_printf(m, "mask:\t\tnot supported\n"); |
| 3820 | seq_printf(m, "commands:\tenable, disable, reset\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3821 | } |
| 3822 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3823 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | } |
| 3825 | |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3826 | static void hotkey_enabledisable_warn(bool enable) |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3827 | { |
| 3828 | tpacpi_log_usertask("procfs hotkey enable/disable"); |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3829 | if (!WARN((tpacpi_lifecycle == TPACPI_LIFE_RUNNING || !enable), |
| 3830 | TPACPI_WARN |
| 3831 | "hotkey enable/disable functionality has been " |
| 3832 | "removed from the driver. Hotkeys are always " |
| 3833 | "enabled\n")) |
| 3834 | printk(TPACPI_ERR |
| 3835 | "Please remove the hotkey=enable module " |
| 3836 | "parameter, it is deprecated. Hotkeys are always " |
| 3837 | "enabled\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3838 | } |
| 3839 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3840 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3842 | int res; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3843 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3846 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3847 | return -ENODEV; |
| 3848 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3849 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3850 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3851 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3852 | mask = hotkey_user_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3853 | |
| 3854 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | while ((cmd = next_cmd(&buf))) { |
| 3856 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3857 | hotkey_enabledisable_warn(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3859 | hotkey_enabledisable_warn(0); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3860 | res = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | } else if (strlencmp(cmd, "reset") == 0) { |
Henrique de Moraes Holschuh | 20c9aa4 | 2009-09-12 15:22:16 -0300 | [diff] [blame] | 3862 | mask = (hotkey_all_mask | hotkey_source_mask) |
| 3863 | & ~hotkey_reserved_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 3865 | /* mask set */ |
| 3866 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 3867 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3868 | } else { |
| 3869 | res = -EINVAL; |
| 3870 | goto errexit; |
| 3871 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | } |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3873 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3874 | if (!res) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3875 | tpacpi_disclose_usertask("procfs hotkey", |
| 3876 | "set mask to 0x%08x\n", mask); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3877 | res = hotkey_user_mask_set(mask); |
| 3878 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3880 | errexit: |
| 3881 | mutex_unlock(&hotkey_mutex); |
| 3882 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3885 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3886 | {TPACPI_ACPI_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3887 | {"", 0}, |
| 3888 | }; |
| 3889 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3890 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3891 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3892 | .notify = hotkey_notify, |
| 3893 | .handle = &hkey_handle, |
| 3894 | .type = ACPI_DEVICE_NOTIFY, |
| 3895 | }; |
| 3896 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3897 | static struct ibm_struct hotkey_driver_data = { |
| 3898 | .name = "hotkey", |
| 3899 | .read = hotkey_read, |
| 3900 | .write = hotkey_write, |
| 3901 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3902 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3903 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3904 | .acpi = &ibm_hotkey_acpidriver, |
| 3905 | }; |
| 3906 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3907 | /************************************************************************* |
| 3908 | * Bluetooth subdriver |
| 3909 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3911 | enum { |
| 3912 | /* ACPI GBDC/SBDC bits */ |
| 3913 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 3914 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3915 | TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 3916 | 0 = disable, 1 = enable */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3917 | }; |
| 3918 | |
| 3919 | enum { |
| 3920 | /* ACPI \BLTH commands */ |
| 3921 | TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */ |
| 3922 | TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */ |
| 3923 | TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */ |
| 3924 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */ |
| 3925 | 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] | 3926 | }; |
| 3927 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3928 | #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" |
| 3929 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3930 | static int bluetooth_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3931 | { |
| 3932 | int status; |
| 3933 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3934 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3935 | if (dbg_bluetoothemul) |
| 3936 | return (tpacpi_bluetooth_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3937 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3938 | #endif |
| 3939 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3940 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 3941 | return -EIO; |
| 3942 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3943 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3944 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3945 | } |
| 3946 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3947 | static int bluetooth_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3948 | { |
| 3949 | int status; |
| 3950 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3951 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3952 | "will attempt to %s bluetooth\n", |
| 3953 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3954 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3955 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3956 | if (dbg_bluetoothemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3957 | tpacpi_bluetooth_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3958 | return 0; |
| 3959 | } |
| 3960 | #endif |
| 3961 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3962 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 3963 | status = TP_ACPI_BLUETOOTH_RADIOSSW |
| 3964 | | TP_ACPI_BLUETOOTH_RESUMECTRL; |
| 3965 | else |
| 3966 | status = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3967 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3968 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 3969 | return -EIO; |
| 3970 | |
| 3971 | return 0; |
| 3972 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3973 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3974 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 3975 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 3976 | struct device_attribute *attr, |
| 3977 | char *buf) |
| 3978 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3979 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3980 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 3984 | struct device_attribute *attr, |
| 3985 | const char *buf, size_t count) |
| 3986 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3987 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3988 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 3992 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3993 | bluetooth_enable_show, bluetooth_enable_store); |
| 3994 | |
| 3995 | /* --------------------------------------------------------------------- */ |
| 3996 | |
| 3997 | static struct attribute *bluetooth_attributes[] = { |
| 3998 | &dev_attr_bluetooth_enable.attr, |
| 3999 | NULL |
| 4000 | }; |
| 4001 | |
| 4002 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4003 | .attrs = bluetooth_attributes, |
| 4004 | }; |
| 4005 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4006 | static const struct tpacpi_rfk_ops bluetooth_tprfk_ops = { |
| 4007 | .get_status = bluetooth_get_status, |
| 4008 | .set_status = bluetooth_set_status, |
| 4009 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4010 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4011 | static void bluetooth_shutdown(void) |
| 4012 | { |
| 4013 | /* Order firmware to save current state to NVRAM */ |
| 4014 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 4015 | TP_ACPI_BLTH_SAVE_STATE)) |
| 4016 | printk(TPACPI_NOTICE |
| 4017 | "failed to save bluetooth state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4018 | else |
| 4019 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 4020 | "bluestooth state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4021 | } |
| 4022 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4023 | static void bluetooth_exit(void) |
| 4024 | { |
| 4025 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 4026 | &bluetooth_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4027 | |
| 4028 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
| 4029 | |
| 4030 | bluetooth_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4031 | } |
| 4032 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4033 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4035 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4036 | int status = 0; |
| 4037 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4038 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4039 | "initializing bluetooth subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4040 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4041 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4042 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4043 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4044 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4045 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4046 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4048 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4049 | "bluetooth is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4050 | str_supported(tp_features.bluetooth), |
| 4051 | status); |
| 4052 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4053 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4054 | if (dbg_bluetoothemul) { |
| 4055 | tp_features.bluetooth = 1; |
| 4056 | printk(TPACPI_INFO |
| 4057 | "bluetooth switch emulation enabled\n"); |
| 4058 | } else |
| 4059 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4060 | if (tp_features.bluetooth && |
| 4061 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 4062 | /* no bluetooth hardware present in system */ |
| 4063 | tp_features.bluetooth = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4064 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4065 | "bluetooth hardware not installed\n"); |
| 4066 | } |
| 4067 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4068 | if (!tp_features.bluetooth) |
| 4069 | return 1; |
| 4070 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4071 | res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 4072 | &bluetooth_tprfk_ops, |
| 4073 | RFKILL_TYPE_BLUETOOTH, |
| 4074 | TPACPI_RFK_BLUETOOTH_SW_NAME, |
| 4075 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4076 | if (res) |
| 4077 | return res; |
| 4078 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4079 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4080 | &bluetooth_attr_group); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4081 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4082 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4083 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4084 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4085 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4086 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | } |
| 4088 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4089 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4090 | static int bluetooth_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4092 | return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID, m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4095 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4097 | return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | } |
| 4099 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4100 | static struct ibm_struct bluetooth_driver_data = { |
| 4101 | .name = "bluetooth", |
| 4102 | .read = bluetooth_read, |
| 4103 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4104 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4105 | .shutdown = bluetooth_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4106 | }; |
| 4107 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4108 | /************************************************************************* |
| 4109 | * Wan subdriver |
| 4110 | */ |
| 4111 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4112 | enum { |
| 4113 | /* ACPI GWAN/SWAN bits */ |
| 4114 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 4115 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4116 | TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 4117 | 0 = disable, 1 = enable */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4118 | }; |
| 4119 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4120 | #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" |
| 4121 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4122 | static int wan_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4123 | { |
| 4124 | int status; |
| 4125 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4126 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4127 | if (dbg_wwanemul) |
| 4128 | return (tpacpi_wwan_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4129 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4130 | #endif |
| 4131 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4132 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 4133 | return -EIO; |
| 4134 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4135 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4136 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4137 | } |
| 4138 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4139 | static int wan_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4140 | { |
| 4141 | int status; |
| 4142 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4143 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4144 | "will attempt to %s wwan\n", |
| 4145 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4146 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4147 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4148 | if (dbg_wwanemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4149 | tpacpi_wwan_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4150 | return 0; |
| 4151 | } |
| 4152 | #endif |
| 4153 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4154 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 4155 | status = TP_ACPI_WANCARD_RADIOSSW |
| 4156 | | TP_ACPI_WANCARD_RESUMECTRL; |
| 4157 | else |
| 4158 | status = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4159 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4160 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 4161 | return -EIO; |
| 4162 | |
| 4163 | return 0; |
| 4164 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4165 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4166 | /* sysfs wan enable ---------------------------------------------------- */ |
| 4167 | static ssize_t wan_enable_show(struct device *dev, |
| 4168 | struct device_attribute *attr, |
| 4169 | char *buf) |
| 4170 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4171 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID, |
| 4172 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | static ssize_t wan_enable_store(struct device *dev, |
| 4176 | struct device_attribute *attr, |
| 4177 | const char *buf, size_t count) |
| 4178 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4179 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID, |
| 4180 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 4184 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4185 | wan_enable_show, wan_enable_store); |
| 4186 | |
| 4187 | /* --------------------------------------------------------------------- */ |
| 4188 | |
| 4189 | static struct attribute *wan_attributes[] = { |
| 4190 | &dev_attr_wan_enable.attr, |
| 4191 | NULL |
| 4192 | }; |
| 4193 | |
| 4194 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4195 | .attrs = wan_attributes, |
| 4196 | }; |
| 4197 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4198 | static const struct tpacpi_rfk_ops wan_tprfk_ops = { |
| 4199 | .get_status = wan_get_status, |
| 4200 | .set_status = wan_set_status, |
| 4201 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4202 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4203 | static void wan_shutdown(void) |
| 4204 | { |
| 4205 | /* Order firmware to save current state to NVRAM */ |
| 4206 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd", |
| 4207 | TP_ACPI_WGSV_SAVE_STATE)) |
| 4208 | printk(TPACPI_NOTICE |
| 4209 | "failed to save WWAN state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4210 | else |
| 4211 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 4212 | "WWAN state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4213 | } |
| 4214 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4215 | static void wan_exit(void) |
| 4216 | { |
| 4217 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 4218 | &wan_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4219 | |
| 4220 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
| 4221 | |
| 4222 | wan_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4223 | } |
| 4224 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4225 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4226 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4227 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4228 | int status = 0; |
| 4229 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4230 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4231 | "initializing wan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4232 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4233 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4234 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4235 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4236 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4237 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4238 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4239 | "wan is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4240 | str_supported(tp_features.wan), |
| 4241 | status); |
| 4242 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4243 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4244 | if (dbg_wwanemul) { |
| 4245 | tp_features.wan = 1; |
| 4246 | printk(TPACPI_INFO |
| 4247 | "wwan switch emulation enabled\n"); |
| 4248 | } else |
| 4249 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4250 | if (tp_features.wan && |
| 4251 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 4252 | /* no wan hardware present in system */ |
| 4253 | tp_features.wan = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4254 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4255 | "wan hardware not installed\n"); |
| 4256 | } |
| 4257 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4258 | if (!tp_features.wan) |
| 4259 | return 1; |
| 4260 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4261 | res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, |
| 4262 | &wan_tprfk_ops, |
| 4263 | RFKILL_TYPE_WWAN, |
| 4264 | TPACPI_RFK_WWAN_SW_NAME, |
| 4265 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4266 | if (res) |
| 4267 | return res; |
| 4268 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4269 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4270 | &wan_attr_group); |
| 4271 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4272 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4273 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4274 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4275 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4276 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4277 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4278 | } |
| 4279 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4280 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4281 | static int wan_read(struct seq_file *m) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4282 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4283 | return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID, m); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | static int wan_write(char *buf) |
| 4287 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4288 | return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID, buf); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4289 | } |
| 4290 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4291 | static struct ibm_struct wan_driver_data = { |
| 4292 | .name = "wan", |
| 4293 | .read = wan_read, |
| 4294 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4295 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4296 | .shutdown = wan_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4297 | }; |
| 4298 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4299 | /************************************************************************* |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4300 | * UWB subdriver |
| 4301 | */ |
| 4302 | |
| 4303 | enum { |
| 4304 | /* ACPI GUWB/SUWB bits */ |
| 4305 | TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */ |
| 4306 | TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */ |
| 4307 | }; |
| 4308 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4309 | #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" |
| 4310 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4311 | static int uwb_get_status(void) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4312 | { |
| 4313 | int status; |
| 4314 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4315 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4316 | if (dbg_uwbemul) |
| 4317 | return (tpacpi_uwb_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4318 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4319 | #endif |
| 4320 | |
| 4321 | if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) |
| 4322 | return -EIO; |
| 4323 | |
| 4324 | return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4325 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4326 | } |
| 4327 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4328 | static int uwb_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4329 | { |
| 4330 | int status; |
| 4331 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4332 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4333 | "will attempt to %s UWB\n", |
| 4334 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4335 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4336 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4337 | if (dbg_uwbemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4338 | tpacpi_uwb_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4339 | return 0; |
| 4340 | } |
| 4341 | #endif |
| 4342 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4343 | if (state == TPACPI_RFK_RADIO_ON) |
| 4344 | status = TP_ACPI_UWB_RADIOSSW; |
| 4345 | else |
| 4346 | status = 0; |
| 4347 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4348 | if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) |
| 4349 | return -EIO; |
| 4350 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4351 | return 0; |
| 4352 | } |
| 4353 | |
| 4354 | /* --------------------------------------------------------------------- */ |
| 4355 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4356 | static const struct tpacpi_rfk_ops uwb_tprfk_ops = { |
| 4357 | .get_status = uwb_get_status, |
| 4358 | .set_status = uwb_set_status, |
| 4359 | }; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4360 | |
| 4361 | static void uwb_exit(void) |
| 4362 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4363 | tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | static int __init uwb_init(struct ibm_init_struct *iibm) |
| 4367 | { |
| 4368 | int res; |
| 4369 | int status = 0; |
| 4370 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4371 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4372 | "initializing uwb subdriver\n"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4373 | |
| 4374 | TPACPI_ACPIHANDLE_INIT(hkey); |
| 4375 | |
| 4376 | tp_features.uwb = hkey_handle && |
| 4377 | acpi_evalf(hkey_handle, &status, "GUWB", "qd"); |
| 4378 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4379 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4380 | "uwb is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4381 | str_supported(tp_features.uwb), |
| 4382 | status); |
| 4383 | |
| 4384 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4385 | if (dbg_uwbemul) { |
| 4386 | tp_features.uwb = 1; |
| 4387 | printk(TPACPI_INFO |
| 4388 | "uwb switch emulation enabled\n"); |
| 4389 | } else |
| 4390 | #endif |
| 4391 | if (tp_features.uwb && |
| 4392 | !(status & TP_ACPI_UWB_HWPRESENT)) { |
| 4393 | /* no uwb hardware present in system */ |
| 4394 | tp_features.uwb = 0; |
| 4395 | dbg_printk(TPACPI_DBG_INIT, |
| 4396 | "uwb hardware not installed\n"); |
| 4397 | } |
| 4398 | |
| 4399 | if (!tp_features.uwb) |
| 4400 | return 1; |
| 4401 | |
| 4402 | res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4403 | &uwb_tprfk_ops, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4404 | RFKILL_TYPE_UWB, |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4405 | TPACPI_RFK_UWB_SW_NAME, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4406 | false); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4407 | return res; |
| 4408 | } |
| 4409 | |
| 4410 | static struct ibm_struct uwb_driver_data = { |
| 4411 | .name = "uwb", |
| 4412 | .exit = uwb_exit, |
| 4413 | .flags.experimental = 1, |
| 4414 | }; |
| 4415 | |
| 4416 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4417 | * Video subdriver |
| 4418 | */ |
| 4419 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4420 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 4421 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4422 | enum video_access_mode { |
| 4423 | TPACPI_VIDEO_NONE = 0, |
| 4424 | TPACPI_VIDEO_570, /* 570 */ |
| 4425 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 4426 | TPACPI_VIDEO_NEW, /* all others */ |
| 4427 | }; |
| 4428 | |
| 4429 | enum { /* video status flags, based on VIDEO_570 */ |
| 4430 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 4431 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 4432 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 4433 | }; |
| 4434 | |
| 4435 | enum { /* TPACPI_VIDEO_570 constants */ |
| 4436 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 4437 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 4438 | * video_status_flags */ |
| 4439 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 4440 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 4441 | }; |
| 4442 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4443 | static enum video_access_mode video_supported; |
| 4444 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4445 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4446 | static int video_autosw_get(void); |
| 4447 | static int video_autosw_set(int enable); |
| 4448 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4449 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4450 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4451 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4453 | int ivga; |
| 4454 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4455 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 4456 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4457 | TPACPI_ACPIHANDLE_INIT(vid); |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4458 | if (tpacpi_is_ibm()) |
| 4459 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4460 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4461 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 4462 | /* G41, assume IVGA doesn't change */ |
| 4463 | vid_handle = vid2_handle; |
| 4464 | |
| 4465 | if (!vid_handle) |
| 4466 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4467 | video_supported = TPACPI_VIDEO_NONE; |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4468 | else if (tpacpi_is_ibm() && |
| 4469 | acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4470 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4471 | video_supported = TPACPI_VIDEO_570; |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4472 | else if (tpacpi_is_ibm() && |
| 4473 | acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4474 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4475 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4476 | else |
| 4477 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4478 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4480 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 4481 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 4482 | video_supported); |
| 4483 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4484 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | } |
| 4486 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4487 | static void video_exit(void) |
| 4488 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4489 | dbg_printk(TPACPI_DBG_EXIT, |
| 4490 | "restoring original video autoswitch mode\n"); |
| 4491 | if (video_autosw_set(video_orig_autosw)) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4492 | printk(TPACPI_ERR "error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4493 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4494 | } |
| 4495 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4496 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | { |
| 4498 | int status = 0; |
| 4499 | int i; |
| 4500 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4501 | switch (video_supported) { |
| 4502 | case TPACPI_VIDEO_570: |
| 4503 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 4504 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 4505 | return -EIO; |
| 4506 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 4507 | break; |
| 4508 | case TPACPI_VIDEO_770: |
| 4509 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4510 | return -EIO; |
| 4511 | if (i) |
| 4512 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4513 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4514 | return -EIO; |
| 4515 | if (i) |
| 4516 | status |= TP_ACPI_VIDEO_S_CRT; |
| 4517 | break; |
| 4518 | case TPACPI_VIDEO_NEW: |
| 4519 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 4520 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4521 | return -EIO; |
| 4522 | if (i) |
| 4523 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4525 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 4526 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4527 | return -EIO; |
| 4528 | if (i) |
| 4529 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4530 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 4531 | return -EIO; |
| 4532 | if (i) |
| 4533 | status |= TP_ACPI_VIDEO_S_DVI; |
| 4534 | break; |
| 4535 | default: |
| 4536 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | |
| 4539 | return status; |
| 4540 | } |
| 4541 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4542 | static int video_outputsw_set(int status) |
| 4543 | { |
| 4544 | int autosw; |
| 4545 | int res = 0; |
| 4546 | |
| 4547 | switch (video_supported) { |
| 4548 | case TPACPI_VIDEO_570: |
| 4549 | res = acpi_evalf(NULL, NULL, |
| 4550 | "\\_SB.PHS2", "vdd", |
| 4551 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 4552 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 4553 | break; |
| 4554 | case TPACPI_VIDEO_770: |
| 4555 | autosw = video_autosw_get(); |
| 4556 | if (autosw < 0) |
| 4557 | return autosw; |
| 4558 | |
| 4559 | res = video_autosw_set(1); |
| 4560 | if (res) |
| 4561 | return res; |
| 4562 | res = acpi_evalf(vid_handle, NULL, |
| 4563 | "ASWT", "vdd", status * 0x100, 0); |
| 4564 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4565 | printk(TPACPI_ERR |
| 4566 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4567 | return -EIO; |
| 4568 | } |
| 4569 | break; |
| 4570 | case TPACPI_VIDEO_NEW: |
| 4571 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4572 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4573 | break; |
| 4574 | default: |
| 4575 | return -ENOSYS; |
| 4576 | } |
| 4577 | |
| 4578 | return (res)? 0 : -EIO; |
| 4579 | } |
| 4580 | |
| 4581 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4583 | int autosw = 0; |
| 4584 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4585 | switch (video_supported) { |
| 4586 | case TPACPI_VIDEO_570: |
| 4587 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 4588 | return -EIO; |
| 4589 | break; |
| 4590 | case TPACPI_VIDEO_770: |
| 4591 | case TPACPI_VIDEO_NEW: |
| 4592 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 4593 | return -EIO; |
| 4594 | break; |
| 4595 | default: |
| 4596 | return -ENOSYS; |
| 4597 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4598 | |
| 4599 | return autosw & 1; |
| 4600 | } |
| 4601 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4602 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4603 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4604 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4605 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4606 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4607 | } |
| 4608 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4609 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4610 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4611 | int autosw = video_autosw_get(); |
| 4612 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4613 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4614 | if (autosw < 0) |
| 4615 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4616 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4617 | switch (video_supported) { |
| 4618 | case TPACPI_VIDEO_570: |
| 4619 | res = video_autosw_set(1); |
| 4620 | if (res) |
| 4621 | return res; |
| 4622 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 4623 | break; |
| 4624 | case TPACPI_VIDEO_770: |
| 4625 | case TPACPI_VIDEO_NEW: |
| 4626 | res = video_autosw_set(1); |
| 4627 | if (res) |
| 4628 | return res; |
| 4629 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 4630 | break; |
| 4631 | default: |
| 4632 | return -ENOSYS; |
| 4633 | } |
| 4634 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4635 | printk(TPACPI_ERR |
| 4636 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4637 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4638 | } |
| 4639 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4640 | return (res)? 0 : -EIO; |
| 4641 | } |
| 4642 | |
| 4643 | static int video_expand_toggle(void) |
| 4644 | { |
| 4645 | switch (video_supported) { |
| 4646 | case TPACPI_VIDEO_570: |
| 4647 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 4648 | 0 : -EIO; |
| 4649 | case TPACPI_VIDEO_770: |
| 4650 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 4651 | 0 : -EIO; |
| 4652 | case TPACPI_VIDEO_NEW: |
| 4653 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 4654 | 0 : -EIO; |
| 4655 | default: |
| 4656 | return -ENOSYS; |
| 4657 | } |
| 4658 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4659 | } |
| 4660 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4661 | static int video_read(struct seq_file *m) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4662 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4663 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4664 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4665 | if (video_supported == TPACPI_VIDEO_NONE) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4666 | seq_printf(m, "status:\t\tnot supported\n"); |
| 4667 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4668 | } |
| 4669 | |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 4670 | /* Even reads can crash X.org, so... */ |
| 4671 | if (!capable(CAP_SYS_ADMIN)) |
| 4672 | return -EPERM; |
| 4673 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4674 | status = video_outputsw_get(); |
| 4675 | if (status < 0) |
| 4676 | return status; |
| 4677 | |
| 4678 | autosw = video_autosw_get(); |
| 4679 | if (autosw < 0) |
| 4680 | return autosw; |
| 4681 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4682 | seq_printf(m, "status:\t\tsupported\n"); |
| 4683 | seq_printf(m, "lcd:\t\t%s\n", enabled(status, 0)); |
| 4684 | 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] | 4685 | if (video_supported == TPACPI_VIDEO_NEW) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4686 | seq_printf(m, "dvi:\t\t%s\n", enabled(status, 3)); |
| 4687 | seq_printf(m, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 4688 | seq_printf(m, "commands:\tlcd_enable, lcd_disable\n"); |
| 4689 | seq_printf(m, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4690 | if (video_supported == TPACPI_VIDEO_NEW) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4691 | seq_printf(m, "commands:\tdvi_enable, dvi_disable\n"); |
| 4692 | seq_printf(m, "commands:\tauto_enable, auto_disable\n"); |
| 4693 | seq_printf(m, "commands:\tvideo_switch, expand_toggle\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4694 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4695 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4696 | } |
| 4697 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4698 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | { |
| 4700 | char *cmd; |
| 4701 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4702 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4704 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4705 | return -ENODEV; |
| 4706 | |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 4707 | /* Even reads can crash X.org, let alone writes... */ |
| 4708 | if (!capable(CAP_SYS_ADMIN)) |
| 4709 | return -EPERM; |
| 4710 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4711 | enable = 0; |
| 4712 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | |
| 4714 | while ((cmd = next_cmd(&buf))) { |
| 4715 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4716 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4717 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4718 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4720 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4722 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4723 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4724 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4725 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4726 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4727 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4728 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4729 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4730 | res = video_autosw_set(1); |
| 4731 | if (res) |
| 4732 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4734 | res = video_autosw_set(0); |
| 4735 | if (res) |
| 4736 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4737 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4738 | res = video_outputsw_cycle(); |
| 4739 | if (res) |
| 4740 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4741 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4742 | res = video_expand_toggle(); |
| 4743 | if (res) |
| 4744 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | } else |
| 4746 | return -EINVAL; |
| 4747 | } |
| 4748 | |
| 4749 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4750 | status = video_outputsw_get(); |
| 4751 | if (status < 0) |
| 4752 | return status; |
| 4753 | res = video_outputsw_set((status & ~disable) | enable); |
| 4754 | if (res) |
| 4755 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | } |
| 4757 | |
| 4758 | return 0; |
| 4759 | } |
| 4760 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4761 | static struct ibm_struct video_driver_data = { |
| 4762 | .name = "video", |
| 4763 | .read = video_read, |
| 4764 | .write = video_write, |
| 4765 | .exit = video_exit, |
| 4766 | }; |
| 4767 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4768 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 4769 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4770 | /************************************************************************* |
| 4771 | * Light (thinklight) subdriver |
| 4772 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4774 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 4775 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4776 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4777 | static int light_get_status(void) |
| 4778 | { |
| 4779 | int status = 0; |
| 4780 | |
| 4781 | if (tp_features.light_status) { |
| 4782 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 4783 | return -EIO; |
| 4784 | return (!!status); |
| 4785 | } |
| 4786 | |
| 4787 | return -ENXIO; |
| 4788 | } |
| 4789 | |
| 4790 | static int light_set_status(int status) |
| 4791 | { |
| 4792 | int rc; |
| 4793 | |
| 4794 | if (tp_features.light) { |
| 4795 | if (cmos_handle) { |
| 4796 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", |
| 4797 | (status)? |
| 4798 | TP_CMOS_THINKLIGHT_ON : |
| 4799 | TP_CMOS_THINKLIGHT_OFF); |
| 4800 | } else { |
| 4801 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", |
| 4802 | (status)? 1 : 0); |
| 4803 | } |
| 4804 | return (rc)? 0 : -EIO; |
| 4805 | } |
| 4806 | |
| 4807 | return -ENXIO; |
| 4808 | } |
| 4809 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4810 | static void light_set_status_worker(struct work_struct *work) |
| 4811 | { |
| 4812 | struct tpacpi_led_classdev *data = |
| 4813 | container_of(work, struct tpacpi_led_classdev, work); |
| 4814 | |
| 4815 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4816 | light_set_status((data->new_state != TPACPI_LED_OFF)); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4817 | } |
| 4818 | |
| 4819 | static void light_sysfs_set(struct led_classdev *led_cdev, |
| 4820 | enum led_brightness brightness) |
| 4821 | { |
| 4822 | struct tpacpi_led_classdev *data = |
| 4823 | container_of(led_cdev, |
| 4824 | struct tpacpi_led_classdev, |
| 4825 | led_classdev); |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4826 | data->new_state = (brightness != LED_OFF) ? |
| 4827 | TPACPI_LED_ON : TPACPI_LED_OFF; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4828 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4829 | } |
| 4830 | |
| 4831 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) |
| 4832 | { |
| 4833 | return (light_get_status() == 1)? LED_FULL : LED_OFF; |
| 4834 | } |
| 4835 | |
| 4836 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { |
| 4837 | .led_classdev = { |
| 4838 | .name = "tpacpi::thinklight", |
| 4839 | .brightness_set = &light_sysfs_set, |
| 4840 | .brightness_get = &light_sysfs_get, |
| 4841 | } |
| 4842 | }; |
| 4843 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4844 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4846 | int rc; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4847 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4848 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 4849 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4850 | if (tpacpi_is_ibm()) { |
| 4851 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 4852 | TPACPI_ACPIHANDLE_INIT(lght); |
| 4853 | } |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4854 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4855 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4856 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4857 | /* 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] | 4858 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4859 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4860 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4861 | /* light status not supported on |
| 4862 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4863 | tp_features.light_status = |
| 4864 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4866 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
| 4867 | str_supported(tp_features.light), |
| 4868 | str_supported(tp_features.light_status)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4869 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4870 | if (!tp_features.light) |
| 4871 | return 1; |
| 4872 | |
| 4873 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 4874 | &tpacpi_led_thinklight.led_classdev); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4875 | |
| 4876 | if (rc < 0) { |
| 4877 | tp_features.light = 0; |
| 4878 | tp_features.light_status = 0; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4879 | } else { |
| 4880 | rc = 0; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4881 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4882 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4883 | return rc; |
| 4884 | } |
| 4885 | |
| 4886 | static void light_exit(void) |
| 4887 | { |
| 4888 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); |
| 4889 | if (work_pending(&tpacpi_led_thinklight.work)) |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4890 | flush_workqueue(tpacpi_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | } |
| 4892 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4893 | static int light_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4895 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4897 | if (!tp_features.light) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4898 | seq_printf(m, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4899 | } else if (!tp_features.light_status) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4900 | seq_printf(m, "status:\t\tunknown\n"); |
| 4901 | seq_printf(m, "commands:\ton, off\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4902 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4903 | status = light_get_status(); |
| 4904 | if (status < 0) |
| 4905 | return status; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4906 | seq_printf(m, "status:\t\t%s\n", onoff(status, 0)); |
| 4907 | seq_printf(m, "commands:\ton, off\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4908 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4909 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4910 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | } |
| 4912 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4913 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4916 | int newstatus = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4917 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4918 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4919 | return -ENODEV; |
| 4920 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | while ((cmd = next_cmd(&buf))) { |
| 4922 | if (strlencmp(cmd, "on") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4923 | newstatus = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | } else if (strlencmp(cmd, "off") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4925 | newstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | } else |
| 4927 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | } |
| 4929 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4930 | return light_set_status(newstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4931 | } |
| 4932 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4933 | static struct ibm_struct light_driver_data = { |
| 4934 | .name = "light", |
| 4935 | .read = light_read, |
| 4936 | .write = light_write, |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4937 | .exit = light_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4938 | }; |
| 4939 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4940 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4941 | * CMOS subdriver |
| 4942 | */ |
| 4943 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4944 | /* sysfs cmos_command -------------------------------------------------- */ |
| 4945 | static ssize_t cmos_command_store(struct device *dev, |
| 4946 | struct device_attribute *attr, |
| 4947 | const char *buf, size_t count) |
| 4948 | { |
| 4949 | unsigned long cmos_cmd; |
| 4950 | int res; |
| 4951 | |
| 4952 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 4953 | return -EINVAL; |
| 4954 | |
| 4955 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4956 | return (res)? res : count; |
| 4957 | } |
| 4958 | |
| 4959 | static struct device_attribute dev_attr_cmos_command = |
| 4960 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 4961 | |
| 4962 | /* --------------------------------------------------------------------- */ |
| 4963 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4964 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4965 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4966 | int res; |
| 4967 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4968 | vdbg_printk(TPACPI_DBG_INIT, |
| 4969 | "initializing cmos commands subdriver\n"); |
| 4970 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4971 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4972 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4973 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 4974 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4975 | |
| 4976 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4977 | if (res) |
| 4978 | return res; |
| 4979 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4980 | return (cmos_handle)? 0 : 1; |
| 4981 | } |
| 4982 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4983 | static void cmos_exit(void) |
| 4984 | { |
| 4985 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4986 | } |
| 4987 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4988 | static int cmos_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4989 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4990 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4991 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | if (!cmos_handle) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4993 | seq_printf(m, "status:\t\tnot supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4994 | else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4995 | seq_printf(m, "status:\t\tsupported\n"); |
| 4996 | seq_printf(m, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4997 | } |
| 4998 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4999 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | } |
| 5001 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5002 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | { |
| 5004 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 5005 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | |
| 5007 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5008 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 5009 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | /* cmos_cmd set */ |
| 5011 | } else |
| 5012 | return -EINVAL; |
| 5013 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 5014 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 5015 | if (res) |
| 5016 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | } |
| 5018 | |
| 5019 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5020 | } |
| 5021 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5022 | static struct ibm_struct cmos_driver_data = { |
| 5023 | .name = "cmos", |
| 5024 | .read = cmos_read, |
| 5025 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 5026 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5027 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5028 | |
| 5029 | /************************************************************************* |
| 5030 | * LED subdriver |
| 5031 | */ |
| 5032 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5033 | enum led_access_mode { |
| 5034 | TPACPI_LED_NONE = 0, |
| 5035 | TPACPI_LED_570, /* 570 */ |
| 5036 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 5037 | TPACPI_LED_NEW, /* all others */ |
| 5038 | }; |
| 5039 | |
| 5040 | enum { /* For TPACPI_LED_OLD */ |
| 5041 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 5042 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 5043 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 5044 | }; |
| 5045 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 5046 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5047 | |
Henrique de Moraes Holschuh | 2cbb5c8 | 2010-05-16 19:45:50 -0300 | [diff] [blame] | 5048 | static acpi_handle led_handle; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5049 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5050 | #define TPACPI_LED_NUMLEDS 16 |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5051 | static struct tpacpi_led_classdev *tpacpi_leds; |
| 5052 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; |
Harvey Harrison | e3aa51f | 2008-05-29 17:51:57 -0700 | [diff] [blame] | 5053 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5054 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
| 5055 | "tpacpi::power", |
| 5056 | "tpacpi:orange:batt", |
| 5057 | "tpacpi:green:batt", |
| 5058 | "tpacpi::dock_active", |
| 5059 | "tpacpi::bay_active", |
| 5060 | "tpacpi::dock_batt", |
| 5061 | "tpacpi::unknown_led", |
| 5062 | "tpacpi::standby", |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5063 | "tpacpi::dock_status1", |
| 5064 | "tpacpi::dock_status2", |
| 5065 | "tpacpi::unknown_led2", |
| 5066 | "tpacpi::unknown_led3", |
| 5067 | "tpacpi::thinkvantage", |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5068 | }; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5069 | #define TPACPI_SAFE_LEDS 0x1081U |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5070 | |
| 5071 | static inline bool tpacpi_is_led_restricted(const unsigned int led) |
| 5072 | { |
| 5073 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
| 5074 | return false; |
| 5075 | #else |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5076 | return (1U & (TPACPI_SAFE_LEDS >> led)) == 0; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5077 | #endif |
| 5078 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5079 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5080 | static int led_get_status(const unsigned int led) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5081 | { |
| 5082 | int status; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5083 | enum led_status_t led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5084 | |
| 5085 | switch (led_supported) { |
| 5086 | case TPACPI_LED_570: |
| 5087 | if (!acpi_evalf(ec_handle, |
| 5088 | &status, "GLED", "dd", 1 << led)) |
| 5089 | return -EIO; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5090 | led_s = (status == 0)? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5091 | TPACPI_LED_OFF : |
| 5092 | ((status == 1)? |
| 5093 | TPACPI_LED_ON : |
| 5094 | TPACPI_LED_BLINK); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5095 | tpacpi_led_state_cache[led] = led_s; |
| 5096 | return led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5097 | default: |
| 5098 | return -ENXIO; |
| 5099 | } |
| 5100 | |
| 5101 | /* not reached */ |
| 5102 | } |
| 5103 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5104 | static int led_set_status(const unsigned int led, |
| 5105 | const enum led_status_t ledstatus) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5106 | { |
| 5107 | /* off, on, blink. Index is led_status_t */ |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5108 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
| 5109 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5110 | |
| 5111 | int rc = 0; |
| 5112 | |
| 5113 | switch (led_supported) { |
| 5114 | case TPACPI_LED_570: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5115 | /* 570 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5116 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5117 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5118 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5119 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5120 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5121 | (1 << led), led_sled_arg1[ledstatus])) |
| 5122 | rc = -EIO; |
| 5123 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5124 | case TPACPI_LED_OLD: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5125 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5126 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5127 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5128 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5129 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5130 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
| 5131 | if (rc >= 0) |
| 5132 | rc = ec_write(TPACPI_LED_EC_HLBL, |
| 5133 | (ledstatus == TPACPI_LED_BLINK) << led); |
| 5134 | if (rc >= 0) |
| 5135 | rc = ec_write(TPACPI_LED_EC_HLCL, |
| 5136 | (ledstatus != TPACPI_LED_OFF) << led); |
| 5137 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5138 | case TPACPI_LED_NEW: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5139 | /* all others */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5140 | if (unlikely(led >= TPACPI_LED_NUMLEDS)) |
| 5141 | return -EINVAL; |
| 5142 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5143 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5144 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5145 | led, led_led_arg1[ledstatus])) |
| 5146 | rc = -EIO; |
| 5147 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5148 | default: |
| 5149 | rc = -ENXIO; |
| 5150 | } |
| 5151 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5152 | if (!rc) |
| 5153 | tpacpi_led_state_cache[led] = ledstatus; |
| 5154 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5155 | return rc; |
| 5156 | } |
| 5157 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5158 | static void led_set_status_worker(struct work_struct *work) |
| 5159 | { |
| 5160 | struct tpacpi_led_classdev *data = |
| 5161 | container_of(work, struct tpacpi_led_classdev, work); |
| 5162 | |
| 5163 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5164 | led_set_status(data->led, data->new_state); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | static void led_sysfs_set(struct led_classdev *led_cdev, |
| 5168 | enum led_brightness brightness) |
| 5169 | { |
| 5170 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5171 | struct tpacpi_led_classdev, led_classdev); |
| 5172 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5173 | if (brightness == LED_OFF) |
| 5174 | data->new_state = TPACPI_LED_OFF; |
| 5175 | else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) |
| 5176 | data->new_state = TPACPI_LED_ON; |
| 5177 | else |
| 5178 | data->new_state = TPACPI_LED_BLINK; |
| 5179 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5180 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, |
| 5184 | unsigned long *delay_on, unsigned long *delay_off) |
| 5185 | { |
| 5186 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5187 | struct tpacpi_led_classdev, led_classdev); |
| 5188 | |
| 5189 | /* Can we choose the flash rate? */ |
| 5190 | if (*delay_on == 0 && *delay_off == 0) { |
| 5191 | /* yes. set them to the hardware blink rate (1 Hz) */ |
| 5192 | *delay_on = 500; /* ms */ |
| 5193 | *delay_off = 500; /* ms */ |
| 5194 | } else if ((*delay_on != 500) || (*delay_off != 500)) |
| 5195 | return -EINVAL; |
| 5196 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5197 | data->new_state = TPACPI_LED_BLINK; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5198 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5199 | |
| 5200 | return 0; |
| 5201 | } |
| 5202 | |
| 5203 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) |
| 5204 | { |
| 5205 | int rc; |
| 5206 | |
| 5207 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5208 | struct tpacpi_led_classdev, led_classdev); |
| 5209 | |
| 5210 | rc = led_get_status(data->led); |
| 5211 | |
| 5212 | if (rc == TPACPI_LED_OFF || rc < 0) |
| 5213 | rc = LED_OFF; /* no error handling in led class :( */ |
| 5214 | else |
| 5215 | rc = LED_FULL; |
| 5216 | |
| 5217 | return rc; |
| 5218 | } |
| 5219 | |
| 5220 | static void led_exit(void) |
| 5221 | { |
| 5222 | unsigned int i; |
| 5223 | |
| 5224 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 5225 | if (tpacpi_leds[i].led_classdev.name) |
| 5226 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); |
| 5227 | } |
| 5228 | |
| 5229 | kfree(tpacpi_leds); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5230 | } |
| 5231 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5232 | static int __init tpacpi_init_led(unsigned int led) |
| 5233 | { |
| 5234 | int rc; |
| 5235 | |
| 5236 | tpacpi_leds[led].led = led; |
| 5237 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5238 | /* LEDs with no name don't get registered */ |
| 5239 | if (!tpacpi_led_names[led]) |
| 5240 | return 0; |
| 5241 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5242 | tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set; |
| 5243 | tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set; |
| 5244 | if (led_supported == TPACPI_LED_570) |
| 5245 | tpacpi_leds[led].led_classdev.brightness_get = |
| 5246 | &led_sysfs_get; |
| 5247 | |
| 5248 | tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led]; |
| 5249 | |
| 5250 | INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker); |
| 5251 | |
| 5252 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 5253 | &tpacpi_leds[led].led_classdev); |
| 5254 | if (rc < 0) |
| 5255 | tpacpi_leds[led].led_classdev.name = NULL; |
| 5256 | |
| 5257 | return rc; |
| 5258 | } |
| 5259 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5260 | static const struct tpacpi_quirk led_useful_qtable[] __initconst = { |
| 5261 | TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */ |
| 5262 | TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */ |
| 5263 | TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */ |
| 5264 | |
| 5265 | TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */ |
| 5266 | TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */ |
| 5267 | TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */ |
| 5268 | TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */ |
| 5269 | TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */ |
| 5270 | TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */ |
| 5271 | TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */ |
| 5272 | TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */ |
| 5273 | |
| 5274 | TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */ |
| 5275 | TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */ |
| 5276 | TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */ |
| 5277 | TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */ |
| 5278 | TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */ |
| 5279 | |
| 5280 | TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */ |
| 5281 | TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */ |
| 5282 | TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */ |
| 5283 | TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */ |
| 5284 | |
| 5285 | /* (1) - may have excess leds enabled on MSB */ |
| 5286 | |
| 5287 | /* Defaults (order matters, keep last, don't reorder!) */ |
| 5288 | { /* Lenovo */ |
| 5289 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 5290 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5291 | .quirks = 0x1fffU, |
| 5292 | }, |
| 5293 | { /* IBM ThinkPads with no EC version string */ |
| 5294 | .vendor = PCI_VENDOR_ID_IBM, |
| 5295 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_UNKNOWN, |
| 5296 | .quirks = 0x00ffU, |
| 5297 | }, |
| 5298 | { /* IBM ThinkPads with EC version string */ |
| 5299 | .vendor = PCI_VENDOR_ID_IBM, |
| 5300 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5301 | .quirks = 0x00bfU, |
| 5302 | }, |
| 5303 | }; |
| 5304 | |
| 5305 | #undef TPACPI_LEDQ_IBM |
| 5306 | #undef TPACPI_LEDQ_LNV |
| 5307 | |
Henrique de Moraes Holschuh | 2cbb5c8 | 2010-05-16 19:45:50 -0300 | [diff] [blame] | 5308 | static enum led_access_mode __init led_init_detect_mode(void) |
| 5309 | { |
| 5310 | acpi_status status; |
| 5311 | |
| 5312 | if (tpacpi_is_ibm()) { |
| 5313 | /* 570 */ |
| 5314 | status = acpi_get_handle(ec_handle, "SLED", &led_handle); |
| 5315 | if (ACPI_SUCCESS(status)) |
| 5316 | return TPACPI_LED_570; |
| 5317 | |
| 5318 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 5319 | status = acpi_get_handle(ec_handle, "SYSL", &led_handle); |
| 5320 | if (ACPI_SUCCESS(status)) |
| 5321 | return TPACPI_LED_OLD; |
| 5322 | } |
| 5323 | |
| 5324 | /* most others */ |
| 5325 | status = acpi_get_handle(ec_handle, "LED", &led_handle); |
| 5326 | if (ACPI_SUCCESS(status)) |
| 5327 | return TPACPI_LED_NEW; |
| 5328 | |
| 5329 | /* R30, R31, and unknown firmwares */ |
| 5330 | led_handle = NULL; |
| 5331 | return TPACPI_LED_NONE; |
| 5332 | } |
| 5333 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5334 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5335 | { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5336 | unsigned int i; |
| 5337 | int rc; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5338 | unsigned long useful_leds; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5339 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5340 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 5341 | |
Henrique de Moraes Holschuh | 2cbb5c8 | 2010-05-16 19:45:50 -0300 | [diff] [blame] | 5342 | led_supported = led_init_detect_mode(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5343 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5344 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 5345 | str_supported(led_supported), led_supported); |
| 5346 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5347 | if (led_supported == TPACPI_LED_NONE) |
| 5348 | return 1; |
| 5349 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5350 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
| 5351 | GFP_KERNEL); |
| 5352 | if (!tpacpi_leds) { |
| 5353 | printk(TPACPI_ERR "Out of memory for LED data\n"); |
| 5354 | return -ENOMEM; |
| 5355 | } |
| 5356 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5357 | useful_leds = tpacpi_check_quirks(led_useful_qtable, |
| 5358 | ARRAY_SIZE(led_useful_qtable)); |
| 5359 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5360 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5361 | if (!tpacpi_is_led_restricted(i) && |
| 5362 | test_bit(i, &useful_leds)) { |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5363 | rc = tpacpi_init_led(i); |
| 5364 | if (rc < 0) { |
| 5365 | led_exit(); |
| 5366 | return rc; |
| 5367 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5368 | } |
| 5369 | } |
| 5370 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5371 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5372 | printk(TPACPI_NOTICE |
| 5373 | "warning: userspace override of important " |
| 5374 | "firmware LEDs is enabled\n"); |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5375 | #endif |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5376 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5377 | } |
| 5378 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5379 | #define str_led_status(s) \ |
| 5380 | ((s) == TPACPI_LED_OFF ? "off" : \ |
| 5381 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5382 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5383 | static int led_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5384 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5385 | if (!led_supported) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5386 | seq_printf(m, "status:\t\tnot supported\n"); |
| 5387 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5388 | } |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5389 | seq_printf(m, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5390 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5391 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5392 | /* 570 */ |
| 5393 | int i, status; |
| 5394 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5395 | status = led_get_status(i); |
| 5396 | if (status < 0) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5397 | return -EIO; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5398 | seq_printf(m, "%d:\t\t%s\n", |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5399 | i, str_led_status(status)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5400 | } |
| 5401 | } |
| 5402 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5403 | seq_printf(m, "commands:\t" |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5404 | "<led> on, <led> off, <led> blink (<led> is 0-15)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5405 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5406 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5407 | } |
| 5408 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5409 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5410 | { |
| 5411 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5412 | int led, rc; |
| 5413 | enum led_status_t s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5414 | |
| 5415 | if (!led_supported) |
| 5416 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5417 | |
| 5418 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5419 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5420 | return -EINVAL; |
| 5421 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5422 | if (strstr(cmd, "off")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5423 | s = TPACPI_LED_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5424 | } else if (strstr(cmd, "on")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5425 | s = TPACPI_LED_ON; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5426 | } else if (strstr(cmd, "blink")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5427 | s = TPACPI_LED_BLINK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5428 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5429 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5430 | } |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5431 | |
| 5432 | rc = led_set_status(led, s); |
| 5433 | if (rc < 0) |
| 5434 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5438 | } |
| 5439 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5440 | static struct ibm_struct led_driver_data = { |
| 5441 | .name = "led", |
| 5442 | .read = led_read, |
| 5443 | .write = led_write, |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5444 | .exit = led_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5445 | }; |
| 5446 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5447 | /************************************************************************* |
| 5448 | * Beep subdriver |
| 5449 | */ |
| 5450 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5451 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5452 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5453 | #define TPACPI_BEEP_Q1 0x0001 |
| 5454 | |
| 5455 | static const struct tpacpi_quirk beep_quirk_table[] __initconst = { |
| 5456 | TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1), /* 570 */ |
| 5457 | TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */ |
| 5458 | }; |
| 5459 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5460 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5461 | { |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5462 | unsigned long quirks; |
| 5463 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5464 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 5465 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5466 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5467 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5468 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 5469 | str_supported(beep_handle != NULL)); |
| 5470 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5471 | quirks = tpacpi_check_quirks(beep_quirk_table, |
| 5472 | ARRAY_SIZE(beep_quirk_table)); |
| 5473 | |
| 5474 | tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); |
| 5475 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5476 | return (beep_handle)? 0 : 1; |
| 5477 | } |
| 5478 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5479 | static int beep_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5481 | if (!beep_handle) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5482 | seq_printf(m, "status:\t\tnot supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5483 | else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5484 | seq_printf(m, "status:\t\tsupported\n"); |
| 5485 | seq_printf(m, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5486 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5488 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5489 | } |
| 5490 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5491 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | { |
| 5493 | char *cmd; |
| 5494 | int beep_cmd; |
| 5495 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5496 | if (!beep_handle) |
| 5497 | return -ENODEV; |
| 5498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5499 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5500 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 5501 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5502 | /* beep_cmd set */ |
| 5503 | } else |
| 5504 | return -EINVAL; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5505 | if (tp_features.beep_needs_two_args) { |
| 5506 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", |
| 5507 | beep_cmd, 0)) |
| 5508 | return -EIO; |
| 5509 | } else { |
| 5510 | if (!acpi_evalf(beep_handle, NULL, NULL, "vd", |
| 5511 | beep_cmd)) |
| 5512 | return -EIO; |
| 5513 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5517 | } |
| 5518 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5519 | static struct ibm_struct beep_driver_data = { |
| 5520 | .name = "beep", |
| 5521 | .read = beep_read, |
| 5522 | .write = beep_write, |
| 5523 | }; |
| 5524 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5525 | /************************************************************************* |
| 5526 | * Thermal subdriver |
| 5527 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5528 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5529 | enum thermal_access_mode { |
| 5530 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 5531 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 5532 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 5533 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 5534 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 5535 | }; |
| 5536 | |
| 5537 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 5538 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 5539 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 5540 | 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] | 5541 | |
| 5542 | TPACPI_THERMAL_SENSOR_NA = -128000, /* Sensor not available */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5543 | }; |
| 5544 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5545 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5546 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 5547 | struct ibm_thermal_sensors_struct { |
| 5548 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 5549 | }; |
| 5550 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5551 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5552 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5553 | /* idx is zero-based */ |
| 5554 | static int thermal_get_sensor(int idx, s32 *value) |
| 5555 | { |
| 5556 | int t; |
| 5557 | s8 tmp; |
| 5558 | char tmpi[5]; |
| 5559 | |
| 5560 | t = TP_EC_THERMAL_TMP0; |
| 5561 | |
| 5562 | switch (thermal_read_mode) { |
| 5563 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 5564 | case TPACPI_THERMAL_TPEC_16: |
| 5565 | if (idx >= 8 && idx <= 15) { |
| 5566 | t = TP_EC_THERMAL_TMP8; |
| 5567 | idx -= 8; |
| 5568 | } |
| 5569 | /* fallthrough */ |
| 5570 | #endif |
| 5571 | case TPACPI_THERMAL_TPEC_8: |
| 5572 | if (idx <= 7) { |
| 5573 | if (!acpi_ec_read(t + idx, &tmp)) |
| 5574 | return -EIO; |
| 5575 | *value = tmp * 1000; |
| 5576 | return 0; |
| 5577 | } |
| 5578 | break; |
| 5579 | |
| 5580 | case TPACPI_THERMAL_ACPI_UPDT: |
| 5581 | if (idx <= 7) { |
| 5582 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5583 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 5584 | return -EIO; |
| 5585 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5586 | return -EIO; |
| 5587 | *value = (t - 2732) * 100; |
| 5588 | return 0; |
| 5589 | } |
| 5590 | break; |
| 5591 | |
| 5592 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5593 | if (idx <= 7) { |
| 5594 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5595 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5596 | return -EIO; |
| 5597 | if (t > 127 || t < -127) |
| 5598 | t = TP_EC_THERMAL_TMP_NA; |
| 5599 | *value = t * 1000; |
| 5600 | return 0; |
| 5601 | } |
| 5602 | break; |
| 5603 | |
| 5604 | case TPACPI_THERMAL_NONE: |
| 5605 | default: |
| 5606 | return -ENOSYS; |
| 5607 | } |
| 5608 | |
| 5609 | return -EINVAL; |
| 5610 | } |
| 5611 | |
| 5612 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 5613 | { |
| 5614 | int res, i; |
| 5615 | int n; |
| 5616 | |
| 5617 | n = 8; |
| 5618 | i = 0; |
| 5619 | |
| 5620 | if (!s) |
| 5621 | return -EINVAL; |
| 5622 | |
| 5623 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 5624 | n = 16; |
| 5625 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5626 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5627 | res = thermal_get_sensor(i, &s->temp[i]); |
| 5628 | if (res) |
| 5629 | return res; |
| 5630 | } |
| 5631 | |
| 5632 | return n; |
| 5633 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5634 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5635 | static void thermal_dump_all_sensors(void) |
| 5636 | { |
| 5637 | int n, i; |
| 5638 | struct ibm_thermal_sensors_struct t; |
| 5639 | |
| 5640 | n = thermal_get_sensors(&t); |
| 5641 | if (n <= 0) |
| 5642 | return; |
| 5643 | |
| 5644 | printk(TPACPI_NOTICE |
| 5645 | "temperatures (Celsius):"); |
| 5646 | |
| 5647 | for (i = 0; i < n; i++) { |
| 5648 | if (t.temp[i] != TPACPI_THERMAL_SENSOR_NA) |
| 5649 | printk(KERN_CONT " %d", (int)(t.temp[i] / 1000)); |
| 5650 | else |
| 5651 | printk(KERN_CONT " N/A"); |
| 5652 | } |
| 5653 | |
| 5654 | printk(KERN_CONT "\n"); |
| 5655 | } |
| 5656 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5657 | /* sysfs temp##_input -------------------------------------------------- */ |
| 5658 | |
| 5659 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 5660 | struct device_attribute *attr, |
| 5661 | char *buf) |
| 5662 | { |
| 5663 | struct sensor_device_attribute *sensor_attr = |
| 5664 | to_sensor_dev_attr(attr); |
| 5665 | int idx = sensor_attr->index; |
| 5666 | s32 value; |
| 5667 | int res; |
| 5668 | |
| 5669 | res = thermal_get_sensor(idx, &value); |
| 5670 | if (res) |
| 5671 | return res; |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5672 | if (value == TPACPI_THERMAL_SENSOR_NA) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5673 | return -ENXIO; |
| 5674 | |
| 5675 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 5676 | } |
| 5677 | |
| 5678 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5679 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 5680 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5681 | |
| 5682 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 5683 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 5684 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 5685 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 5686 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 5687 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 5688 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 5689 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 5690 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 5691 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 5692 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 5693 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 5694 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 5695 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 5696 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 5697 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 5698 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 5699 | }; |
| 5700 | |
| 5701 | #define THERMAL_ATTRS(X) \ |
| 5702 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 5703 | |
| 5704 | static struct attribute *thermal_temp_input_attr[] = { |
| 5705 | THERMAL_ATTRS(8), |
| 5706 | THERMAL_ATTRS(9), |
| 5707 | THERMAL_ATTRS(10), |
| 5708 | THERMAL_ATTRS(11), |
| 5709 | THERMAL_ATTRS(12), |
| 5710 | THERMAL_ATTRS(13), |
| 5711 | THERMAL_ATTRS(14), |
| 5712 | THERMAL_ATTRS(15), |
| 5713 | THERMAL_ATTRS(0), |
| 5714 | THERMAL_ATTRS(1), |
| 5715 | THERMAL_ATTRS(2), |
| 5716 | THERMAL_ATTRS(3), |
| 5717 | THERMAL_ATTRS(4), |
| 5718 | THERMAL_ATTRS(5), |
| 5719 | THERMAL_ATTRS(6), |
| 5720 | THERMAL_ATTRS(7), |
| 5721 | NULL |
| 5722 | }; |
| 5723 | |
| 5724 | static const struct attribute_group thermal_temp_input16_group = { |
| 5725 | .attrs = thermal_temp_input_attr |
| 5726 | }; |
| 5727 | |
| 5728 | static const struct attribute_group thermal_temp_input8_group = { |
| 5729 | .attrs = &thermal_temp_input_attr[8] |
| 5730 | }; |
| 5731 | |
| 5732 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 5733 | #undef THERMAL_ATTRS |
| 5734 | |
| 5735 | /* --------------------------------------------------------------------- */ |
| 5736 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5737 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5738 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5739 | u8 t, ta1, ta2; |
| 5740 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5741 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5742 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5743 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5744 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 5745 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5746 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5747 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 5748 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5749 | /* |
| 5750 | * Direct EC access mode: sensors at registers |
| 5751 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 5752 | * non-implemented, thermal sensors return 0x80 when |
| 5753 | * not available |
| 5754 | */ |
| 5755 | |
| 5756 | ta1 = ta2 = 0; |
| 5757 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5758 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5759 | ta1 |= t; |
| 5760 | } else { |
| 5761 | ta1 = 0; |
| 5762 | break; |
| 5763 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5764 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5765 | ta2 |= t; |
| 5766 | } else { |
| 5767 | ta1 = 0; |
| 5768 | break; |
| 5769 | } |
| 5770 | } |
| 5771 | if (ta1 == 0) { |
| 5772 | /* This is sheer paranoia, but we handle it anyway */ |
| 5773 | if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5774 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5775 | "ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5776 | "falling back to ACPI TMPx access " |
| 5777 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5778 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5779 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5780 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5781 | "ThinkPad ACPI EC access misbehaving, " |
| 5782 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5783 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5784 | } |
| 5785 | } else { |
| 5786 | thermal_read_mode = |
| 5787 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5788 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5789 | } |
| 5790 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 5791 | if (tpacpi_is_ibm() && |
| 5792 | acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5793 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5794 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5795 | } else { |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 5796 | /* IBM/LENOVO DSDT EC.TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5797 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5798 | } |
| 5799 | } else { |
| 5800 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5801 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5802 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5803 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5804 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 5805 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 5806 | thermal_read_mode); |
| 5807 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5808 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5809 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5810 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5811 | &thermal_temp_input16_group); |
| 5812 | if (res) |
| 5813 | return res; |
| 5814 | break; |
| 5815 | case TPACPI_THERMAL_TPEC_8: |
| 5816 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5817 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5818 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5819 | &thermal_temp_input8_group); |
| 5820 | if (res) |
| 5821 | return res; |
| 5822 | break; |
| 5823 | case TPACPI_THERMAL_NONE: |
| 5824 | default: |
| 5825 | return 1; |
| 5826 | } |
| 5827 | |
| 5828 | return 0; |
| 5829 | } |
| 5830 | |
| 5831 | static void thermal_exit(void) |
| 5832 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5833 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5834 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5835 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5836 | &thermal_temp_input16_group); |
| 5837 | break; |
| 5838 | case TPACPI_THERMAL_TPEC_8: |
| 5839 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5840 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5841 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Roel Kluin | f04d5e0 | 2010-02-02 14:37:58 -0800 | [diff] [blame] | 5842 | &thermal_temp_input8_group); |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5843 | break; |
| 5844 | case TPACPI_THERMAL_NONE: |
| 5845 | default: |
| 5846 | break; |
| 5847 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5848 | } |
| 5849 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5850 | static int thermal_read(struct seq_file *m) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5851 | { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5852 | int n, i; |
| 5853 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5854 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5855 | n = thermal_get_sensors(&t); |
| 5856 | if (unlikely(n < 0)) |
| 5857 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5858 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5859 | seq_printf(m, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5860 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5861 | if (n > 0) { |
| 5862 | for (i = 0; i < (n - 1); i++) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5863 | seq_printf(m, "%d ", t.temp[i] / 1000); |
| 5864 | seq_printf(m, "%d\n", t.temp[i] / 1000); |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5865 | } else |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5866 | seq_printf(m, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5867 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5868 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5869 | } |
| 5870 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5871 | static struct ibm_struct thermal_driver_data = { |
| 5872 | .name = "thermal", |
| 5873 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5874 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5875 | }; |
| 5876 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5877 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5878 | * Backlight/brightness subdriver |
| 5879 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 5880 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5881 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 5882 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5883 | /* |
| 5884 | * ThinkPads can read brightness from two places: EC HBRV (0x31), or |
| 5885 | * CMOS NVRAM byte 0x5E, bits 0-3. |
| 5886 | * |
| 5887 | * EC HBRV (0x31) has the following layout |
| 5888 | * Bit 7: unknown function |
| 5889 | * Bit 6: unknown function |
| 5890 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 5891 | * Bit 4: must be set to zero to avoid problems |
| 5892 | * Bit 3-0: backlight brightness level |
| 5893 | * |
| 5894 | * brightness_get_raw returns status data in the HBRV layout |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 5895 | * |
| 5896 | * WARNING: The X61 has been verified to use HBRV for something else, so |
| 5897 | * this should be used _only_ on IBM ThinkPads, and maybe with some careful |
| 5898 | * testing on the very early *60 Lenovo models... |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5899 | */ |
| 5900 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5901 | enum { |
| 5902 | TP_EC_BACKLIGHT = 0x31, |
| 5903 | |
| 5904 | /* TP_EC_BACKLIGHT bitmasks */ |
| 5905 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 5906 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 5907 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 5908 | }; |
| 5909 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5910 | enum tpacpi_brightness_access_mode { |
| 5911 | TPACPI_BRGHT_MODE_AUTO = 0, /* Not implemented yet */ |
| 5912 | TPACPI_BRGHT_MODE_EC, /* EC control */ |
| 5913 | TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */ |
| 5914 | TPACPI_BRGHT_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 5915 | TPACPI_BRGHT_MODE_MAX |
| 5916 | }; |
| 5917 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5918 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5919 | |
| 5920 | static enum tpacpi_brightness_access_mode brightness_mode = |
| 5921 | TPACPI_BRGHT_MODE_MAX; |
| 5922 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5923 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 5924 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5925 | static struct mutex brightness_mutex; |
| 5926 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5927 | /* NVRAM brightness access, |
| 5928 | * call with brightness_mutex held! */ |
| 5929 | static unsigned int tpacpi_brightness_nvram_get(void) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5930 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5931 | u8 lnvram; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5932 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5933 | lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 5934 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5935 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 5936 | lnvram &= bright_maxlvl; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5937 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5938 | return lnvram; |
| 5939 | } |
| 5940 | |
| 5941 | static void tpacpi_brightness_checkpoint_nvram(void) |
| 5942 | { |
| 5943 | u8 lec = 0; |
| 5944 | u8 b_nvram; |
| 5945 | |
| 5946 | if (brightness_mode != TPACPI_BRGHT_MODE_ECNVRAM) |
| 5947 | return; |
| 5948 | |
| 5949 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5950 | "trying to checkpoint backlight level to NVRAM...\n"); |
| 5951 | |
| 5952 | if (mutex_lock_killable(&brightness_mutex) < 0) |
| 5953 | return; |
| 5954 | |
| 5955 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5956 | goto unlock; |
| 5957 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
| 5958 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 5959 | |
| 5960 | if (lec != ((b_nvram & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5961 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS)) { |
| 5962 | /* NVRAM needs update */ |
| 5963 | b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS << |
| 5964 | TP_NVRAM_POS_LEVEL_BRIGHTNESS); |
| 5965 | b_nvram |= lec; |
| 5966 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_BRIGHTNESS); |
| 5967 | dbg_printk(TPACPI_DBG_BRGHT, |
| 5968 | "updated NVRAM backlight level to %u (0x%02x)\n", |
| 5969 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5970 | } else |
| 5971 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5972 | "NVRAM backlight level already is %u (0x%02x)\n", |
| 5973 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5974 | |
| 5975 | unlock: |
| 5976 | mutex_unlock(&brightness_mutex); |
| 5977 | } |
| 5978 | |
| 5979 | |
| 5980 | /* call with brightness_mutex held! */ |
| 5981 | static int tpacpi_brightness_get_raw(int *status) |
| 5982 | { |
| 5983 | u8 lec = 0; |
| 5984 | |
| 5985 | switch (brightness_mode) { |
| 5986 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 5987 | *status = tpacpi_brightness_nvram_get(); |
| 5988 | return 0; |
| 5989 | case TPACPI_BRGHT_MODE_EC: |
| 5990 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 5991 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 5992 | return -EIO; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5993 | *status = lec; |
| 5994 | return 0; |
| 5995 | default: |
| 5996 | return -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5997 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5998 | } |
| 5999 | |
| 6000 | /* call with brightness_mutex held! */ |
| 6001 | /* do NOT call with illegal backlight level value */ |
| 6002 | static int tpacpi_brightness_set_ec(unsigned int value) |
| 6003 | { |
| 6004 | u8 lec = 0; |
| 6005 | |
| 6006 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 6007 | return -EIO; |
| 6008 | |
| 6009 | if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT, |
| 6010 | (lec & TP_EC_BACKLIGHT_CMDMSK) | |
| 6011 | (value & TP_EC_BACKLIGHT_LVLMSK)))) |
| 6012 | return -EIO; |
| 6013 | |
| 6014 | return 0; |
| 6015 | } |
| 6016 | |
| 6017 | /* call with brightness_mutex held! */ |
| 6018 | static int tpacpi_brightness_set_ucmsstep(unsigned int value) |
| 6019 | { |
| 6020 | int cmos_cmd, inc; |
| 6021 | unsigned int current_value, i; |
| 6022 | |
| 6023 | current_value = tpacpi_brightness_nvram_get(); |
| 6024 | |
| 6025 | if (value == current_value) |
| 6026 | return 0; |
| 6027 | |
| 6028 | cmos_cmd = (value > current_value) ? |
| 6029 | TP_CMOS_BRIGHTNESS_UP : |
| 6030 | TP_CMOS_BRIGHTNESS_DOWN; |
| 6031 | inc = (value > current_value) ? 1 : -1; |
| 6032 | |
| 6033 | for (i = current_value; i != value; i += inc) |
| 6034 | if (issue_thinkpad_cmos_command(cmos_cmd)) |
| 6035 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6036 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6037 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6038 | } |
| 6039 | |
| 6040 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6041 | static int brightness_set(unsigned int value) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6042 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6043 | int res; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6044 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6045 | if (value > bright_maxlvl || value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6046 | return -EINVAL; |
| 6047 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6048 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 6049 | "set backlight level to %d\n", value); |
| 6050 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6051 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6052 | if (res < 0) |
| 6053 | return res; |
| 6054 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6055 | switch (brightness_mode) { |
| 6056 | case TPACPI_BRGHT_MODE_EC: |
| 6057 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 6058 | res = tpacpi_brightness_set_ec(value); |
| 6059 | break; |
| 6060 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 6061 | res = tpacpi_brightness_set_ucmsstep(value); |
| 6062 | break; |
| 6063 | default: |
| 6064 | res = -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6065 | } |
| 6066 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6067 | mutex_unlock(&brightness_mutex); |
| 6068 | return res; |
| 6069 | } |
| 6070 | |
| 6071 | /* sysfs backlight class ----------------------------------------------- */ |
| 6072 | |
| 6073 | static int brightness_update_status(struct backlight_device *bd) |
| 6074 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6075 | unsigned int level = |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6076 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 6077 | bd->props.power == FB_BLANK_UNBLANK) ? |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6078 | bd->props.brightness : 0; |
| 6079 | |
| 6080 | dbg_printk(TPACPI_DBG_BRGHT, |
| 6081 | "backlight: attempt to set level to %d\n", |
| 6082 | level); |
| 6083 | |
| 6084 | /* it is the backlight class's job (caller) to handle |
| 6085 | * EINTR and other errors properly */ |
| 6086 | return brightness_set(level); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6087 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 6088 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6089 | static int brightness_get(struct backlight_device *bd) |
| 6090 | { |
| 6091 | int status, res; |
| 6092 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6093 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6094 | if (res < 0) |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6095 | return 0; |
| 6096 | |
| 6097 | res = tpacpi_brightness_get_raw(&status); |
| 6098 | |
| 6099 | mutex_unlock(&brightness_mutex); |
| 6100 | |
| 6101 | if (res < 0) |
| 6102 | return 0; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6103 | |
| 6104 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 6105 | } |
| 6106 | |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6107 | static void tpacpi_brightness_notify_change(void) |
| 6108 | { |
| 6109 | backlight_force_update(ibm_backlight_device, |
| 6110 | BACKLIGHT_UPDATE_HOTKEY); |
| 6111 | } |
| 6112 | |
Lionel Debroux | acc2472 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 6113 | static const struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6114 | .get_brightness = brightness_get, |
| 6115 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6116 | }; |
| 6117 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6118 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6119 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6120 | /* |
| 6121 | * Call _BCL method of video device. On some ThinkPads this will |
| 6122 | * switch the firmware to the ACPI brightness control mode. |
| 6123 | */ |
| 6124 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6125 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 6126 | { |
| 6127 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 6128 | union acpi_object *obj; |
| 6129 | int rc; |
| 6130 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6131 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, "_BCL", NULL, &buffer))) { |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6132 | obj = (union acpi_object *)buffer.pointer; |
| 6133 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
| 6134 | printk(TPACPI_ERR "Unknown _BCL data, " |
| 6135 | "please report this to %s\n", TPACPI_MAIL); |
| 6136 | rc = 0; |
| 6137 | } else { |
| 6138 | rc = obj->package.count; |
| 6139 | } |
| 6140 | } else { |
| 6141 | return 0; |
| 6142 | } |
| 6143 | |
| 6144 | kfree(buffer.pointer); |
| 6145 | return rc; |
| 6146 | } |
| 6147 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6148 | |
| 6149 | /* |
| 6150 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 6151 | */ |
| 6152 | static unsigned int __init tpacpi_check_std_acpi_brightness_support(void) |
| 6153 | { |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6154 | acpi_handle video_device; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6155 | int bcl_levels = 0; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6156 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6157 | tpacpi_acpi_handle_locate("video", ACPI_VIDEO_HID, &video_device); |
| 6158 | if (video_device) |
| 6159 | bcl_levels = tpacpi_query_bcl_levels(video_device); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6160 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6161 | tp_features.bright_acpimode = (bcl_levels > 0); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6162 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6163 | return (bcl_levels > 2) ? (bcl_levels - 2) : 0; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6164 | } |
| 6165 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6166 | /* |
| 6167 | * These are only useful for models that have only one possibility |
| 6168 | * of GPU. If the BIOS model handles both ATI and Intel, don't use |
| 6169 | * these quirks. |
| 6170 | */ |
| 6171 | #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */ |
| 6172 | #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */ |
| 6173 | #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */ |
| 6174 | |
| 6175 | static const struct tpacpi_quirk brightness_quirk_table[] __initconst = { |
| 6176 | /* Models with ATI GPUs known to require ECNVRAM mode */ |
| 6177 | TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */ |
| 6178 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6179 | /* Models with ATI GPUs that can use ECNVRAM */ |
Henrique de Moraes Holschuh | 7d1894d | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 6180 | 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] | 6181 | 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] | 6182 | TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC), /* R52 */ |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6183 | TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6184 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6185 | /* Models with Intel Extreme Graphics 2 */ |
Henrique de Moraes Holschuh | 7d1894d | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 6186 | TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), /* X40 */ |
Henrique de Moraes Holschuh | a9f8eac | 2009-12-09 01:36:21 +0000 | [diff] [blame] | 6187 | TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6188 | 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] | 6189 | |
| 6190 | /* Models with Intel GMA900 */ |
| 6191 | TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC), /* T43, R52 */ |
| 6192 | TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC), /* X41 */ |
| 6193 | TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC), /* X41 Tablet */ |
| 6194 | }; |
| 6195 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6196 | /* |
| 6197 | * Returns < 0 for error, otherwise sets tp_features.bright_* |
| 6198 | * and bright_maxlvl. |
| 6199 | */ |
| 6200 | static void __init tpacpi_detect_brightness_capabilities(void) |
| 6201 | { |
| 6202 | unsigned int b; |
| 6203 | |
| 6204 | vdbg_printk(TPACPI_DBG_INIT, |
| 6205 | "detecting firmware brightness interface capabilities\n"); |
| 6206 | |
| 6207 | /* we could run a quirks check here (same table used by |
| 6208 | * brightness_init) if needed */ |
| 6209 | |
| 6210 | /* |
| 6211 | * We always attempt to detect acpi support, so as to switch |
| 6212 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 6213 | * going to publish a backlight interface |
| 6214 | */ |
| 6215 | b = tpacpi_check_std_acpi_brightness_support(); |
| 6216 | switch (b) { |
| 6217 | case 16: |
| 6218 | bright_maxlvl = 15; |
| 6219 | printk(TPACPI_INFO |
| 6220 | "detected a 16-level brightness capable ThinkPad\n"); |
| 6221 | break; |
| 6222 | case 8: |
| 6223 | case 0: |
| 6224 | bright_maxlvl = 7; |
| 6225 | printk(TPACPI_INFO |
| 6226 | "detected a 8-level brightness capable ThinkPad\n"); |
| 6227 | break; |
| 6228 | default: |
| 6229 | printk(TPACPI_ERR |
| 6230 | "Unsupported brightness interface, " |
| 6231 | "please contact %s\n", TPACPI_MAIL); |
| 6232 | tp_features.bright_unkfw = 1; |
| 6233 | bright_maxlvl = b - 1; |
| 6234 | } |
| 6235 | } |
| 6236 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6237 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6238 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 6239 | struct backlight_properties props; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6240 | int b; |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6241 | unsigned long quirks; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6242 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6243 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 6244 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6245 | mutex_init(&brightness_mutex); |
| 6246 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6247 | quirks = tpacpi_check_quirks(brightness_quirk_table, |
| 6248 | ARRAY_SIZE(brightness_quirk_table)); |
| 6249 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6250 | /* tpacpi_detect_brightness_capabilities() must have run already */ |
Thomas Renninger | 2dba1b5 | 2008-08-01 17:38:03 +0200 | [diff] [blame] | 6251 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6252 | /* if it is unknown, we don't handle it: it wouldn't be safe */ |
| 6253 | if (tp_features.bright_unkfw) |
| 6254 | return 1; |
| 6255 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6256 | if (!brightness_enable) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6257 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6258 | "brightness support disabled by " |
| 6259 | "module parameter\n"); |
| 6260 | return 1; |
| 6261 | } |
| 6262 | |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6263 | if (acpi_video_backlight_support()) { |
| 6264 | if (brightness_enable > 1) { |
| 6265 | printk(TPACPI_INFO |
| 6266 | "Standard ACPI backlight interface " |
| 6267 | "available, not loading native one.\n"); |
| 6268 | return 1; |
| 6269 | } else if (brightness_enable == 1) { |
| 6270 | printk(TPACPI_WARN |
| 6271 | "Cannot enable backlight brightness support, " |
| 6272 | "ACPI is already handling it. Refer to the " |
| 6273 | "acpi_backlight kernel parameter\n"); |
| 6274 | return 1; |
| 6275 | } |
| 6276 | } else if (tp_features.bright_acpimode && brightness_enable > 1) { |
| 6277 | printk(TPACPI_NOTICE |
| 6278 | "Standard ACPI backlight interface not " |
| 6279 | "available, thinkpad_acpi native " |
| 6280 | "brightness control enabled\n"); |
| 6281 | } |
| 6282 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6283 | /* |
| 6284 | * Check for module parameter bogosity, note that we |
| 6285 | * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be |
| 6286 | * able to detect "unspecified" |
| 6287 | */ |
| 6288 | if (brightness_mode > TPACPI_BRGHT_MODE_MAX) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6289 | return -EINVAL; |
| 6290 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6291 | /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */ |
| 6292 | if (brightness_mode == TPACPI_BRGHT_MODE_AUTO || |
| 6293 | brightness_mode == TPACPI_BRGHT_MODE_MAX) { |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6294 | if (quirks & TPACPI_BRGHT_Q_EC) |
| 6295 | brightness_mode = TPACPI_BRGHT_MODE_ECNVRAM; |
| 6296 | else |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6297 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
| 6298 | |
| 6299 | dbg_printk(TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6300 | "driver auto-selected brightness_mode=%d\n", |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6301 | brightness_mode); |
| 6302 | } |
| 6303 | |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 6304 | /* Safety */ |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 6305 | if (!tpacpi_is_ibm() && |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 6306 | (brightness_mode == TPACPI_BRGHT_MODE_ECNVRAM || |
| 6307 | brightness_mode == TPACPI_BRGHT_MODE_EC)) |
| 6308 | return -EINVAL; |
| 6309 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6310 | if (tpacpi_brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6311 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6312 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 6313 | memset(&props, 0, sizeof(struct backlight_properties)); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6314 | props.max_brightness = bright_maxlvl; |
| 6315 | props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 6316 | ibm_backlight_device = backlight_device_register(TPACPI_BACKLIGHT_DEV_NAME, |
| 6317 | NULL, NULL, |
| 6318 | &ibm_backlight_data, |
| 6319 | &props); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6320 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6321 | int rc = PTR_ERR(ibm_backlight_device); |
| 6322 | ibm_backlight_device = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6323 | printk(TPACPI_ERR "Could not register backlight device\n"); |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6324 | return rc; |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6325 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6326 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6327 | "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6328 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6329 | if (quirks & TPACPI_BRGHT_Q_ASK) { |
| 6330 | printk(TPACPI_NOTICE |
| 6331 | "brightness: will use unverified default: " |
| 6332 | "brightness_mode=%d\n", brightness_mode); |
| 6333 | printk(TPACPI_NOTICE |
| 6334 | "brightness: please report to %s whether it works well " |
| 6335 | "or not on your ThinkPad\n", TPACPI_MAIL); |
| 6336 | } |
| 6337 | |
Henrique de Moraes Holschuh | 7d9745c | 2010-05-16 19:45:57 -0300 | [diff] [blame] | 6338 | /* Added by mistake in early 2007. Probably useless, but it could |
| 6339 | * be working around some unknown firmware problem where the value |
| 6340 | * read at startup doesn't match the real hardware state... so leave |
| 6341 | * it in place just in case */ |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6342 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6343 | |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6344 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6345 | "brightness: registering brightness hotkeys " |
| 6346 | "as change notification\n"); |
| 6347 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
| 6348 | | TP_ACPI_HKEY_BRGHTUP_MASK |
Joe Perches | 3098064 | 2010-11-14 19:04:38 -0800 | [diff] [blame] | 6349 | | TP_ACPI_HKEY_BRGHTDWN_MASK); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6350 | return 0; |
| 6351 | } |
| 6352 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6353 | static void brightness_suspend(pm_message_t state) |
| 6354 | { |
| 6355 | tpacpi_brightness_checkpoint_nvram(); |
| 6356 | } |
| 6357 | |
| 6358 | static void brightness_shutdown(void) |
| 6359 | { |
| 6360 | tpacpi_brightness_checkpoint_nvram(); |
| 6361 | } |
| 6362 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6363 | static void brightness_exit(void) |
| 6364 | { |
| 6365 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6366 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6367 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6368 | backlight_device_unregister(ibm_backlight_device); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6369 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6370 | |
| 6371 | tpacpi_brightness_checkpoint_nvram(); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6372 | } |
| 6373 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6374 | static int brightness_read(struct seq_file *m) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6375 | { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6376 | int level; |
| 6377 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6378 | level = brightness_get(NULL); |
| 6379 | if (level < 0) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6380 | seq_printf(m, "level:\t\tunreadable\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6381 | } else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6382 | seq_printf(m, "level:\t\t%d\n", level); |
| 6383 | seq_printf(m, "commands:\tup, down\n"); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6384 | seq_printf(m, "commands:\tlevel <level> (<level> is 0-%d)\n", |
| 6385 | bright_maxlvl); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6386 | } |
| 6387 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6388 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6389 | } |
| 6390 | |
| 6391 | static int brightness_write(char *buf) |
| 6392 | { |
| 6393 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6394 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6395 | char *cmd; |
| 6396 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6397 | level = brightness_get(NULL); |
| 6398 | if (level < 0) |
| 6399 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6400 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6401 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6402 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6403 | if (level < bright_maxlvl) |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6404 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6405 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6406 | if (level > 0) |
| 6407 | level--; |
| 6408 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6409 | level >= 0 && level <= bright_maxlvl) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6410 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6411 | } else |
| 6412 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6413 | } |
| 6414 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6415 | tpacpi_disclose_usertask("procfs brightness", |
| 6416 | "set level to %d\n", level); |
| 6417 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6418 | /* |
| 6419 | * Now we know what the final level should be, so we try to set it. |
| 6420 | * Doing it this way makes the syscall restartable in case of EINTR |
| 6421 | */ |
| 6422 | rc = brightness_set(level); |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6423 | if (!rc && ibm_backlight_device) |
| 6424 | backlight_force_update(ibm_backlight_device, |
| 6425 | BACKLIGHT_UPDATE_SYSFS); |
Roel Kluin | 80a8d12 | 2009-11-20 19:48:23 +0100 | [diff] [blame] | 6426 | return (rc == -EINTR)? -ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6427 | } |
| 6428 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6429 | static struct ibm_struct brightness_driver_data = { |
| 6430 | .name = "brightness", |
| 6431 | .read = brightness_read, |
| 6432 | .write = brightness_write, |
| 6433 | .exit = brightness_exit, |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6434 | .suspend = brightness_suspend, |
| 6435 | .shutdown = brightness_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6436 | }; |
| 6437 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6438 | /************************************************************************* |
| 6439 | * Volume subdriver |
| 6440 | */ |
| 6441 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6442 | /* |
| 6443 | * IBM ThinkPads have a simple volume controller with MUTE gating. |
| 6444 | * Very early Lenovo ThinkPads follow the IBM ThinkPad spec. |
| 6445 | * |
| 6446 | * Since the *61 series (and probably also the later *60 series), Lenovo |
| 6447 | * ThinkPads only implement the MUTE gate. |
| 6448 | * |
| 6449 | * EC register 0x30 |
| 6450 | * Bit 6: MUTE (1 mutes sound) |
| 6451 | * Bit 3-0: Volume |
| 6452 | * Other bits should be zero as far as we know. |
| 6453 | * |
| 6454 | * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and |
| 6455 | * bits 3-0 (volume). Other bits in NVRAM may have other functions, |
| 6456 | * such as bit 7 which is used to detect repeated presses of MUTE, |
| 6457 | * and we leave them unchanged. |
| 6458 | */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6459 | |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 6460 | #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT |
| 6461 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6462 | #define TPACPI_ALSA_DRVNAME "ThinkPad EC" |
| 6463 | #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control" |
| 6464 | #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME |
| 6465 | |
Henrique de Moraes Holschuh | ead510c | 2009-12-26 22:52:13 -0200 | [diff] [blame] | 6466 | static int alsa_index = ~((1 << (SNDRV_CARDS - 3)) - 1); /* last three slots */ |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6467 | static char *alsa_id = "ThinkPadEC"; |
| 6468 | static int alsa_enable = SNDRV_DEFAULT_ENABLE1; |
| 6469 | |
| 6470 | struct tpacpi_alsa_data { |
| 6471 | struct snd_card *card; |
| 6472 | struct snd_ctl_elem_id *ctl_mute_id; |
| 6473 | struct snd_ctl_elem_id *ctl_vol_id; |
| 6474 | }; |
| 6475 | |
| 6476 | static struct snd_card *alsa_card; |
| 6477 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6478 | enum { |
| 6479 | TP_EC_AUDIO = 0x30, |
| 6480 | |
| 6481 | /* TP_EC_AUDIO bits */ |
| 6482 | TP_EC_AUDIO_MUTESW = 6, |
| 6483 | |
| 6484 | /* TP_EC_AUDIO bitmasks */ |
| 6485 | TP_EC_AUDIO_LVL_MSK = 0x0F, |
| 6486 | TP_EC_AUDIO_MUTESW_MSK = (1 << TP_EC_AUDIO_MUTESW), |
| 6487 | |
| 6488 | /* Maximum volume */ |
| 6489 | TP_EC_VOLUME_MAX = 14, |
| 6490 | }; |
| 6491 | |
| 6492 | enum tpacpi_volume_access_mode { |
| 6493 | TPACPI_VOL_MODE_AUTO = 0, /* Not implemented yet */ |
| 6494 | TPACPI_VOL_MODE_EC, /* Pure EC control */ |
| 6495 | TPACPI_VOL_MODE_UCMS_STEP, /* UCMS step-based control: N/A */ |
| 6496 | TPACPI_VOL_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 6497 | TPACPI_VOL_MODE_MAX |
| 6498 | }; |
| 6499 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6500 | enum tpacpi_volume_capabilities { |
| 6501 | TPACPI_VOL_CAP_AUTO = 0, /* Use white/blacklist */ |
| 6502 | TPACPI_VOL_CAP_VOLMUTE, /* Output vol and mute */ |
| 6503 | TPACPI_VOL_CAP_MUTEONLY, /* Output mute only */ |
| 6504 | TPACPI_VOL_CAP_MAX |
| 6505 | }; |
| 6506 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6507 | static enum tpacpi_volume_access_mode volume_mode = |
| 6508 | TPACPI_VOL_MODE_MAX; |
| 6509 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6510 | static enum tpacpi_volume_capabilities volume_capabilities; |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 6511 | static int volume_control_allowed; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6512 | |
| 6513 | /* |
| 6514 | * Used to syncronize writers to TP_EC_AUDIO and |
| 6515 | * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write |
| 6516 | */ |
| 6517 | static struct mutex volume_mutex; |
| 6518 | |
| 6519 | static void tpacpi_volume_checkpoint_nvram(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6520 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6521 | u8 lec = 0; |
| 6522 | u8 b_nvram; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6523 | u8 ec_mask; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6524 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6525 | if (volume_mode != TPACPI_VOL_MODE_ECNVRAM) |
| 6526 | return; |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 6527 | if (!volume_control_allowed) |
| 6528 | return; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6529 | |
| 6530 | vdbg_printk(TPACPI_DBG_MIXER, |
| 6531 | "trying to checkpoint mixer state to NVRAM...\n"); |
| 6532 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6533 | if (tp_features.mixer_no_level_control) |
| 6534 | ec_mask = TP_EC_AUDIO_MUTESW_MSK; |
| 6535 | else |
| 6536 | ec_mask = TP_EC_AUDIO_MUTESW_MSK | TP_EC_AUDIO_LVL_MSK; |
| 6537 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6538 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6539 | return; |
| 6540 | |
| 6541 | if (unlikely(!acpi_ec_read(TP_EC_AUDIO, &lec))) |
| 6542 | goto unlock; |
| 6543 | lec &= ec_mask; |
| 6544 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 6545 | |
| 6546 | if (lec != (b_nvram & ec_mask)) { |
| 6547 | /* NVRAM needs update */ |
| 6548 | b_nvram &= ~ec_mask; |
| 6549 | b_nvram |= lec; |
| 6550 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_MIXER); |
| 6551 | dbg_printk(TPACPI_DBG_MIXER, |
| 6552 | "updated NVRAM mixer status to 0x%02x (0x%02x)\n", |
| 6553 | (unsigned int) lec, (unsigned int) b_nvram); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6554 | } else { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6555 | vdbg_printk(TPACPI_DBG_MIXER, |
| 6556 | "NVRAM mixer status already is 0x%02x (0x%02x)\n", |
| 6557 | (unsigned int) lec, (unsigned int) b_nvram); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6558 | } |
| 6559 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6560 | unlock: |
| 6561 | mutex_unlock(&volume_mutex); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6562 | } |
| 6563 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6564 | static int volume_get_status_ec(u8 *status) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6565 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6566 | u8 s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6567 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6568 | if (!acpi_ec_read(TP_EC_AUDIO, &s)) |
| 6569 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6570 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6571 | *status = s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6572 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6573 | dbg_printk(TPACPI_DBG_MIXER, "status 0x%02x\n", s); |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6574 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6575 | return 0; |
| 6576 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6577 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6578 | static int volume_get_status(u8 *status) |
| 6579 | { |
| 6580 | return volume_get_status_ec(status); |
| 6581 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6582 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6583 | static int volume_set_status_ec(const u8 status) |
| 6584 | { |
| 6585 | if (!acpi_ec_write(TP_EC_AUDIO, status)) |
| 6586 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6587 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6588 | dbg_printk(TPACPI_DBG_MIXER, "set EC mixer to 0x%02x\n", status); |
| 6589 | |
| 6590 | return 0; |
| 6591 | } |
| 6592 | |
| 6593 | static int volume_set_status(const u8 status) |
| 6594 | { |
| 6595 | return volume_set_status_ec(status); |
| 6596 | } |
| 6597 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6598 | /* returns < 0 on error, 0 on no change, 1 on change */ |
| 6599 | static int __volume_set_mute_ec(const bool mute) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6600 | { |
| 6601 | int rc; |
| 6602 | u8 s, n; |
| 6603 | |
| 6604 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6605 | return -EINTR; |
| 6606 | |
| 6607 | rc = volume_get_status_ec(&s); |
| 6608 | if (rc) |
| 6609 | goto unlock; |
| 6610 | |
| 6611 | n = (mute) ? s | TP_EC_AUDIO_MUTESW_MSK : |
| 6612 | s & ~TP_EC_AUDIO_MUTESW_MSK; |
| 6613 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6614 | if (n != s) { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6615 | rc = volume_set_status_ec(n); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6616 | if (!rc) |
| 6617 | rc = 1; |
| 6618 | } |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6619 | |
| 6620 | unlock: |
| 6621 | mutex_unlock(&volume_mutex); |
| 6622 | return rc; |
| 6623 | } |
| 6624 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6625 | static int volume_alsa_set_mute(const bool mute) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6626 | { |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6627 | dbg_printk(TPACPI_DBG_MIXER, "ALSA: trying to %smute\n", |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6628 | (mute) ? "" : "un"); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6629 | return __volume_set_mute_ec(mute); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6630 | } |
| 6631 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6632 | static int volume_set_mute(const bool mute) |
| 6633 | { |
| 6634 | int rc; |
| 6635 | |
| 6636 | dbg_printk(TPACPI_DBG_MIXER, "trying to %smute\n", |
| 6637 | (mute) ? "" : "un"); |
| 6638 | |
| 6639 | rc = __volume_set_mute_ec(mute); |
| 6640 | return (rc < 0) ? rc : 0; |
| 6641 | } |
| 6642 | |
| 6643 | /* returns < 0 on error, 0 on no change, 1 on change */ |
| 6644 | static int __volume_set_volume_ec(const u8 vol) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6645 | { |
| 6646 | int rc; |
| 6647 | u8 s, n; |
| 6648 | |
| 6649 | if (vol > TP_EC_VOLUME_MAX) |
| 6650 | return -EINVAL; |
| 6651 | |
| 6652 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6653 | return -EINTR; |
| 6654 | |
| 6655 | rc = volume_get_status_ec(&s); |
| 6656 | if (rc) |
| 6657 | goto unlock; |
| 6658 | |
| 6659 | n = (s & ~TP_EC_AUDIO_LVL_MSK) | vol; |
| 6660 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6661 | if (n != s) { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6662 | rc = volume_set_status_ec(n); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6663 | if (!rc) |
| 6664 | rc = 1; |
| 6665 | } |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6666 | |
| 6667 | unlock: |
| 6668 | mutex_unlock(&volume_mutex); |
| 6669 | return rc; |
| 6670 | } |
| 6671 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6672 | static int volume_alsa_set_volume(const u8 vol) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6673 | { |
| 6674 | dbg_printk(TPACPI_DBG_MIXER, |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6675 | "ALSA: trying to set volume level to %hu\n", vol); |
| 6676 | return __volume_set_volume_ec(vol); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6677 | } |
| 6678 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6679 | static void volume_alsa_notify_change(void) |
| 6680 | { |
| 6681 | struct tpacpi_alsa_data *d; |
| 6682 | |
| 6683 | if (alsa_card && alsa_card->private_data) { |
| 6684 | d = alsa_card->private_data; |
| 6685 | if (d->ctl_mute_id) |
| 6686 | snd_ctl_notify(alsa_card, |
| 6687 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 6688 | d->ctl_mute_id); |
| 6689 | if (d->ctl_vol_id) |
| 6690 | snd_ctl_notify(alsa_card, |
| 6691 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 6692 | d->ctl_vol_id); |
| 6693 | } |
| 6694 | } |
| 6695 | |
| 6696 | static int volume_alsa_vol_info(struct snd_kcontrol *kcontrol, |
| 6697 | struct snd_ctl_elem_info *uinfo) |
| 6698 | { |
| 6699 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 6700 | uinfo->count = 1; |
| 6701 | uinfo->value.integer.min = 0; |
| 6702 | uinfo->value.integer.max = TP_EC_VOLUME_MAX; |
| 6703 | return 0; |
| 6704 | } |
| 6705 | |
| 6706 | static int volume_alsa_vol_get(struct snd_kcontrol *kcontrol, |
| 6707 | struct snd_ctl_elem_value *ucontrol) |
| 6708 | { |
| 6709 | u8 s; |
| 6710 | int rc; |
| 6711 | |
| 6712 | rc = volume_get_status(&s); |
| 6713 | if (rc < 0) |
| 6714 | return rc; |
| 6715 | |
| 6716 | ucontrol->value.integer.value[0] = s & TP_EC_AUDIO_LVL_MSK; |
| 6717 | return 0; |
| 6718 | } |
| 6719 | |
| 6720 | static int volume_alsa_vol_put(struct snd_kcontrol *kcontrol, |
| 6721 | struct snd_ctl_elem_value *ucontrol) |
| 6722 | { |
Henrique de Moraes Holschuh | 38e11cd | 2010-05-16 19:45:40 -0300 | [diff] [blame] | 6723 | tpacpi_disclose_usertask("ALSA", "set volume to %ld\n", |
| 6724 | ucontrol->value.integer.value[0]); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6725 | return volume_alsa_set_volume(ucontrol->value.integer.value[0]); |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | #define volume_alsa_mute_info snd_ctl_boolean_mono_info |
| 6729 | |
| 6730 | static int volume_alsa_mute_get(struct snd_kcontrol *kcontrol, |
| 6731 | struct snd_ctl_elem_value *ucontrol) |
| 6732 | { |
| 6733 | u8 s; |
| 6734 | int rc; |
| 6735 | |
| 6736 | rc = volume_get_status(&s); |
| 6737 | if (rc < 0) |
| 6738 | return rc; |
| 6739 | |
| 6740 | ucontrol->value.integer.value[0] = |
| 6741 | (s & TP_EC_AUDIO_MUTESW_MSK) ? 0 : 1; |
| 6742 | return 0; |
| 6743 | } |
| 6744 | |
| 6745 | static int volume_alsa_mute_put(struct snd_kcontrol *kcontrol, |
| 6746 | struct snd_ctl_elem_value *ucontrol) |
| 6747 | { |
Henrique de Moraes Holschuh | 38e11cd | 2010-05-16 19:45:40 -0300 | [diff] [blame] | 6748 | tpacpi_disclose_usertask("ALSA", "%smute\n", |
| 6749 | ucontrol->value.integer.value[0] ? |
| 6750 | "un" : ""); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6751 | return volume_alsa_set_mute(!ucontrol->value.integer.value[0]); |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6752 | } |
| 6753 | |
| 6754 | static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata = { |
| 6755 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 6756 | .name = "Console Playback Volume", |
| 6757 | .index = 0, |
| 6758 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 6759 | .info = volume_alsa_vol_info, |
| 6760 | .get = volume_alsa_vol_get, |
| 6761 | }; |
| 6762 | |
| 6763 | static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata = { |
| 6764 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 6765 | .name = "Console Playback Switch", |
| 6766 | .index = 0, |
| 6767 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 6768 | .info = volume_alsa_mute_info, |
| 6769 | .get = volume_alsa_mute_get, |
| 6770 | }; |
| 6771 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6772 | static void volume_suspend(pm_message_t state) |
| 6773 | { |
| 6774 | tpacpi_volume_checkpoint_nvram(); |
| 6775 | } |
| 6776 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6777 | static void volume_resume(void) |
| 6778 | { |
| 6779 | volume_alsa_notify_change(); |
| 6780 | } |
| 6781 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6782 | static void volume_shutdown(void) |
| 6783 | { |
| 6784 | tpacpi_volume_checkpoint_nvram(); |
| 6785 | } |
| 6786 | |
| 6787 | static void volume_exit(void) |
| 6788 | { |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6789 | if (alsa_card) { |
| 6790 | snd_card_free(alsa_card); |
| 6791 | alsa_card = NULL; |
| 6792 | } |
| 6793 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6794 | tpacpi_volume_checkpoint_nvram(); |
| 6795 | } |
| 6796 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6797 | static int __init volume_create_alsa_mixer(void) |
| 6798 | { |
| 6799 | struct snd_card *card; |
| 6800 | struct tpacpi_alsa_data *data; |
| 6801 | struct snd_kcontrol *ctl_vol; |
| 6802 | struct snd_kcontrol *ctl_mute; |
| 6803 | int rc; |
| 6804 | |
| 6805 | rc = snd_card_create(alsa_index, alsa_id, THIS_MODULE, |
| 6806 | sizeof(struct tpacpi_alsa_data), &card); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6807 | if (rc < 0 || !card) { |
| 6808 | printk(TPACPI_ERR |
| 6809 | "Failed to create ALSA card structures: %d\n", rc); |
| 6810 | return 1; |
| 6811 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6812 | |
| 6813 | BUG_ON(!card->private_data); |
| 6814 | data = card->private_data; |
| 6815 | data->card = card; |
| 6816 | |
| 6817 | strlcpy(card->driver, TPACPI_ALSA_DRVNAME, |
| 6818 | sizeof(card->driver)); |
| 6819 | strlcpy(card->shortname, TPACPI_ALSA_SHRTNAME, |
| 6820 | sizeof(card->shortname)); |
| 6821 | snprintf(card->mixername, sizeof(card->mixername), "ThinkPad EC %s", |
| 6822 | (thinkpad_id.ec_version_str) ? |
| 6823 | thinkpad_id.ec_version_str : "(unknown)"); |
| 6824 | snprintf(card->longname, sizeof(card->longname), |
| 6825 | "%s at EC reg 0x%02x, fw %s", card->shortname, TP_EC_AUDIO, |
| 6826 | (thinkpad_id.ec_version_str) ? |
| 6827 | thinkpad_id.ec_version_str : "unknown"); |
| 6828 | |
| 6829 | if (volume_control_allowed) { |
| 6830 | volume_alsa_control_vol.put = volume_alsa_vol_put; |
| 6831 | volume_alsa_control_vol.access = |
| 6832 | SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 6833 | |
| 6834 | volume_alsa_control_mute.put = volume_alsa_mute_put; |
| 6835 | volume_alsa_control_mute.access = |
| 6836 | SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 6837 | } |
| 6838 | |
| 6839 | if (!tp_features.mixer_no_level_control) { |
| 6840 | ctl_vol = snd_ctl_new1(&volume_alsa_control_vol, NULL); |
| 6841 | rc = snd_ctl_add(card, ctl_vol); |
| 6842 | if (rc < 0) { |
| 6843 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6844 | "Failed to create ALSA volume control: %d\n", |
| 6845 | rc); |
| 6846 | goto err_exit; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6847 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6848 | data->ctl_vol_id = &ctl_vol->id; |
| 6849 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6850 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6851 | ctl_mute = snd_ctl_new1(&volume_alsa_control_mute, NULL); |
| 6852 | rc = snd_ctl_add(card, ctl_mute); |
| 6853 | if (rc < 0) { |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6854 | printk(TPACPI_ERR "Failed to create ALSA mute control: %d\n", |
| 6855 | rc); |
| 6856 | goto err_exit; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6857 | } |
| 6858 | data->ctl_mute_id = &ctl_mute->id; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6859 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6860 | snd_card_set_dev(card, &tpacpi_pdev->dev); |
| 6861 | rc = snd_card_register(card); |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6862 | if (rc < 0) { |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6863 | printk(TPACPI_ERR "Failed to register ALSA card: %d\n", rc); |
| 6864 | goto err_exit; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6865 | } |
| 6866 | |
| 6867 | alsa_card = card; |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6868 | return 0; |
| 6869 | |
| 6870 | err_exit: |
| 6871 | snd_card_free(card); |
| 6872 | return 1; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6873 | } |
| 6874 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6875 | #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */ |
| 6876 | #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */ |
| 6877 | |
| 6878 | static const struct tpacpi_quirk volume_quirk_table[] __initconst = { |
| 6879 | /* Whitelist volume level on all IBM by default */ |
| 6880 | { .vendor = PCI_VENDOR_ID_IBM, |
| 6881 | .bios = TPACPI_MATCH_ANY, |
| 6882 | .ec = TPACPI_MATCH_ANY, |
| 6883 | .quirks = TPACPI_VOL_Q_LEVEL }, |
| 6884 | |
| 6885 | /* Lenovo models with volume control (needs confirmation) */ |
| 6886 | TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL), /* R60/i */ |
| 6887 | TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL), /* R60e/i */ |
| 6888 | TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL), /* T60/p */ |
| 6889 | TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL), /* X60/s */ |
| 6890 | TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL), /* X60t */ |
| 6891 | TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL), /* Z60 */ |
| 6892 | TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL), /* Z61 */ |
| 6893 | |
| 6894 | /* Whitelist mute-only on all Lenovo by default */ |
| 6895 | { .vendor = PCI_VENDOR_ID_LENOVO, |
| 6896 | .bios = TPACPI_MATCH_ANY, |
| 6897 | .ec = TPACPI_MATCH_ANY, |
| 6898 | .quirks = TPACPI_VOL_Q_MUTEONLY } |
| 6899 | }; |
| 6900 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6901 | static int __init volume_init(struct ibm_init_struct *iibm) |
| 6902 | { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6903 | unsigned long quirks; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6904 | int rc; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6905 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6906 | vdbg_printk(TPACPI_DBG_INIT, "initializing volume subdriver\n"); |
| 6907 | |
| 6908 | mutex_init(&volume_mutex); |
| 6909 | |
| 6910 | /* |
| 6911 | * Check for module parameter bogosity, note that we |
| 6912 | * init volume_mode to TPACPI_VOL_MODE_MAX in order to be |
| 6913 | * able to detect "unspecified" |
| 6914 | */ |
| 6915 | if (volume_mode > TPACPI_VOL_MODE_MAX) |
| 6916 | return -EINVAL; |
| 6917 | |
| 6918 | if (volume_mode == TPACPI_VOL_MODE_UCMS_STEP) { |
| 6919 | printk(TPACPI_ERR |
| 6920 | "UCMS step volume mode not implemented, " |
| 6921 | "please contact %s\n", TPACPI_MAIL); |
| 6922 | return 1; |
| 6923 | } |
| 6924 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6925 | if (volume_capabilities >= TPACPI_VOL_CAP_MAX) |
| 6926 | return -EINVAL; |
| 6927 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6928 | /* |
| 6929 | * The ALSA mixer is our primary interface. |
| 6930 | * When disabled, don't install the subdriver at all |
| 6931 | */ |
| 6932 | if (!alsa_enable) { |
| 6933 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6934 | "ALSA mixer disabled by parameter, " |
| 6935 | "not loading volume subdriver...\n"); |
| 6936 | return 1; |
| 6937 | } |
| 6938 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6939 | quirks = tpacpi_check_quirks(volume_quirk_table, |
| 6940 | ARRAY_SIZE(volume_quirk_table)); |
| 6941 | |
| 6942 | switch (volume_capabilities) { |
| 6943 | case TPACPI_VOL_CAP_AUTO: |
| 6944 | if (quirks & TPACPI_VOL_Q_MUTEONLY) |
| 6945 | tp_features.mixer_no_level_control = 1; |
| 6946 | else if (quirks & TPACPI_VOL_Q_LEVEL) |
| 6947 | tp_features.mixer_no_level_control = 0; |
| 6948 | else |
| 6949 | return 1; /* no mixer */ |
| 6950 | break; |
| 6951 | case TPACPI_VOL_CAP_VOLMUTE: |
| 6952 | tp_features.mixer_no_level_control = 0; |
| 6953 | break; |
| 6954 | case TPACPI_VOL_CAP_MUTEONLY: |
| 6955 | tp_features.mixer_no_level_control = 1; |
| 6956 | break; |
| 6957 | default: |
| 6958 | return 1; |
| 6959 | } |
| 6960 | |
| 6961 | if (volume_capabilities != TPACPI_VOL_CAP_AUTO) |
| 6962 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6963 | "using user-supplied volume_capabilities=%d\n", |
| 6964 | volume_capabilities); |
| 6965 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6966 | if (volume_mode == TPACPI_VOL_MODE_AUTO || |
| 6967 | volume_mode == TPACPI_VOL_MODE_MAX) { |
| 6968 | volume_mode = TPACPI_VOL_MODE_ECNVRAM; |
| 6969 | |
| 6970 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6971 | "driver auto-selected volume_mode=%d\n", |
| 6972 | volume_mode); |
| 6973 | } else { |
| 6974 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6975 | "using user-supplied volume_mode=%d\n", |
| 6976 | volume_mode); |
| 6977 | } |
| 6978 | |
| 6979 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6980 | "mute is supported, volume control is %s\n", |
| 6981 | str_supported(!tp_features.mixer_no_level_control)); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6982 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6983 | rc = volume_create_alsa_mixer(); |
| 6984 | if (rc) { |
| 6985 | printk(TPACPI_ERR |
| 6986 | "Could not create the ALSA mixer interface\n"); |
| 6987 | return rc; |
| 6988 | } |
| 6989 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 6990 | printk(TPACPI_INFO |
| 6991 | "Console audio control enabled, mode: %s\n", |
| 6992 | (volume_control_allowed) ? |
| 6993 | "override (read/write)" : |
| 6994 | "monitor (read only)"); |
| 6995 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6996 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6997 | "registering volume hotkeys as change notification\n"); |
| 6998 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
| 6999 | | TP_ACPI_HKEY_VOLUP_MASK |
| 7000 | | TP_ACPI_HKEY_VOLDWN_MASK |
| 7001 | | TP_ACPI_HKEY_MUTE_MASK); |
| 7002 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7003 | return 0; |
| 7004 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7005 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7006 | static int volume_read(struct seq_file *m) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7007 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7008 | u8 status; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7009 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7010 | if (volume_get_status(&status) < 0) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7011 | seq_printf(m, "level:\t\tunreadable\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7012 | } else { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7013 | if (tp_features.mixer_no_level_control) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7014 | seq_printf(m, "level:\t\tunsupported\n"); |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7015 | else |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7016 | seq_printf(m, "level:\t\t%d\n", |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7017 | status & TP_EC_AUDIO_LVL_MSK); |
| 7018 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7019 | seq_printf(m, "mute:\t\t%s\n", |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7020 | onoff(status, TP_EC_AUDIO_MUTESW)); |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7021 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7022 | if (volume_control_allowed) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7023 | seq_printf(m, "commands:\tunmute, mute\n"); |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7024 | if (!tp_features.mixer_no_level_control) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7025 | seq_printf(m, |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7026 | "commands:\tup, down\n"); |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7027 | seq_printf(m, |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7028 | "commands:\tlevel <level>" |
| 7029 | " (<level> is 0-%d)\n", |
| 7030 | TP_EC_VOLUME_MAX); |
| 7031 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7032 | } |
| 7033 | } |
| 7034 | |
| 7035 | return 0; |
| 7036 | } |
| 7037 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7038 | static int volume_write(char *buf) |
| 7039 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7040 | u8 s; |
| 7041 | u8 new_level, new_mute; |
| 7042 | int l; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7043 | char *cmd; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7044 | int rc; |
| 7045 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7046 | /* |
| 7047 | * We do allow volume control at driver startup, so that the |
| 7048 | * user can set initial state through the volume=... parameter hack. |
| 7049 | */ |
| 7050 | if (!volume_control_allowed && tpacpi_lifecycle != TPACPI_LIFE_INIT) { |
| 7051 | if (unlikely(!tp_warned.volume_ctrl_forbidden)) { |
| 7052 | tp_warned.volume_ctrl_forbidden = 1; |
| 7053 | printk(TPACPI_NOTICE |
| 7054 | "Console audio control in monitor mode, " |
| 7055 | "changes are not allowed.\n"); |
| 7056 | printk(TPACPI_NOTICE |
| 7057 | "Use the volume_control=1 module parameter " |
| 7058 | "to enable volume control\n"); |
| 7059 | } |
| 7060 | return -EPERM; |
| 7061 | } |
| 7062 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7063 | rc = volume_get_status(&s); |
| 7064 | if (rc < 0) |
| 7065 | return rc; |
| 7066 | |
| 7067 | new_level = s & TP_EC_AUDIO_LVL_MSK; |
| 7068 | new_mute = s & TP_EC_AUDIO_MUTESW_MSK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7069 | |
| 7070 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7071 | if (!tp_features.mixer_no_level_control) { |
| 7072 | if (strlencmp(cmd, "up") == 0) { |
| 7073 | if (new_mute) |
| 7074 | new_mute = 0; |
| 7075 | else if (new_level < TP_EC_VOLUME_MAX) |
| 7076 | new_level++; |
| 7077 | continue; |
| 7078 | } else if (strlencmp(cmd, "down") == 0) { |
| 7079 | if (new_mute) |
| 7080 | new_mute = 0; |
| 7081 | else if (new_level > 0) |
| 7082 | new_level--; |
| 7083 | continue; |
| 7084 | } else if (sscanf(cmd, "level %u", &l) == 1 && |
| 7085 | l >= 0 && l <= TP_EC_VOLUME_MAX) { |
| 7086 | new_level = l; |
| 7087 | continue; |
| 7088 | } |
| 7089 | } |
| 7090 | if (strlencmp(cmd, "mute") == 0) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7091 | new_mute = TP_EC_AUDIO_MUTESW_MSK; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7092 | else if (strlencmp(cmd, "unmute") == 0) |
| 7093 | new_mute = 0; |
| 7094 | else |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7095 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7096 | } |
| 7097 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7098 | if (tp_features.mixer_no_level_control) { |
| 7099 | tpacpi_disclose_usertask("procfs volume", "%smute\n", |
| 7100 | new_mute ? "" : "un"); |
| 7101 | rc = volume_set_mute(!!new_mute); |
| 7102 | } else { |
| 7103 | tpacpi_disclose_usertask("procfs volume", |
| 7104 | "%smute and set level to %d\n", |
| 7105 | new_mute ? "" : "un", new_level); |
| 7106 | rc = volume_set_status(new_mute | new_level); |
| 7107 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7108 | volume_alsa_notify_change(); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7109 | |
| 7110 | return (rc == -EINTR) ? -ERESTARTSYS : rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7111 | } |
| 7112 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7113 | static struct ibm_struct volume_driver_data = { |
| 7114 | .name = "volume", |
| 7115 | .read = volume_read, |
| 7116 | .write = volume_write, |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7117 | .exit = volume_exit, |
| 7118 | .suspend = volume_suspend, |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7119 | .resume = volume_resume, |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7120 | .shutdown = volume_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7121 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7122 | |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 7123 | #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
| 7124 | |
| 7125 | #define alsa_card NULL |
| 7126 | |
| 7127 | static void inline volume_alsa_notify_change(void) |
| 7128 | { |
| 7129 | } |
| 7130 | |
| 7131 | static int __init volume_init(struct ibm_init_struct *iibm) |
| 7132 | { |
| 7133 | printk(TPACPI_INFO |
| 7134 | "volume: disabled as there is no ALSA support in this kernel\n"); |
| 7135 | |
| 7136 | return 1; |
| 7137 | } |
| 7138 | |
| 7139 | static struct ibm_struct volume_driver_data = { |
| 7140 | .name = "volume", |
| 7141 | }; |
| 7142 | |
| 7143 | #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
| 7144 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7145 | /************************************************************************* |
| 7146 | * Fan subdriver |
| 7147 | */ |
| 7148 | |
| 7149 | /* |
| 7150 | * FAN ACCESS MODES |
| 7151 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7152 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7153 | * ACPI GFAN method: returns fan level |
| 7154 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7155 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7156 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7157 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7158 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7159 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 7160 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7161 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 7162 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7163 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7164 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7165 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 7166 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7167 | * |
| 7168 | * Fan speed changes of any sort (including those caused by the |
| 7169 | * 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] | 7170 | * 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] | 7171 | * limited. |
| 7172 | * |
| 7173 | * Reading is not available if GFAN exists. |
| 7174 | * Writing is not available if SFAN exists. |
| 7175 | * |
| 7176 | * Bits |
| 7177 | * 7 automatic mode engaged; |
| 7178 | * (default operation mode of the ThinkPad) |
| 7179 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7180 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7181 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7182 | * the tachometer while the fan controller ramps up |
| 7183 | * the speed (which can take up to a few *minutes*). |
| 7184 | * Speeds up fan to 100% duty-cycle, which is far above |
| 7185 | * the standard RPM levels. It is not impossible that |
| 7186 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7187 | * 5-3 unused in some models. Extra bits for fan level |
| 7188 | * in others, but still useless as all values above |
| 7189 | * 7 map to the same speed as level 7 in these models. |
| 7190 | * 2-0 fan level (0..7 usually) |
| 7191 | * 0x00 = stop |
| 7192 | * 0x07 = max (set when temperatures critical) |
| 7193 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7194 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7195 | * |
| 7196 | * 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] | 7197 | * 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] | 7198 | * does so, its initial value is meaningless (0x07). |
| 7199 | * |
| 7200 | * For firmware bugs, refer to: |
| 7201 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 7202 | * |
| 7203 | * ---- |
| 7204 | * |
| 7205 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 7206 | * Main fan tachometer reading (in RPM) |
| 7207 | * |
| 7208 | * This register is present on all ThinkPads with a new-style EC, and |
| 7209 | * it is known not to be present on the A21m/e, and T22, as there is |
| 7210 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 7211 | * ThinkPads from this same time period (and earlier) probably lack the |
| 7212 | * tachometer as well. |
| 7213 | * |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 7214 | * 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] | 7215 | * was never fixed by IBM to report the EC firmware version string |
| 7216 | * probably support the tachometer (like the early X models), so |
| 7217 | * detecting it is quite hard. We need more data to know for sure. |
| 7218 | * |
| 7219 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 7220 | * might result. |
| 7221 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7222 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 7223 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7224 | * |
| 7225 | * For firmware bugs, refer to: |
| 7226 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 7227 | * |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7228 | * ---- |
| 7229 | * |
| 7230 | * ThinkPad EC register 0x31 bit 0 (only on select models) |
| 7231 | * |
| 7232 | * When bit 0 of EC register 0x31 is zero, the tachometer registers |
| 7233 | * show the speed of the main fan. When bit 0 of EC register 0x31 |
| 7234 | * is one, the tachometer registers show the speed of the auxiliary |
| 7235 | * fan. |
| 7236 | * |
| 7237 | * Fan control seems to affect both fans, regardless of the state |
| 7238 | * of this bit. |
| 7239 | * |
| 7240 | * So far, only the firmware for the X60/X61 non-tablet versions |
| 7241 | * seem to support this (firmware TP-7M). |
| 7242 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7243 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7244 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 7245 | * |
| 7246 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 7247 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 7248 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 7249 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 7250 | * |
| 7251 | * The speeds are stored on handles |
| 7252 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 7253 | * |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7254 | * There are three default speed sets, accessible as handles: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7255 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 7256 | * |
| 7257 | * ACPI DSDT switches which set is in use depending on various |
| 7258 | * factors. |
| 7259 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7260 | * 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] | 7261 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 7262 | * but the ACPI tables just mention level 7. |
| 7263 | */ |
| 7264 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7265 | enum { /* Fan control constants */ |
| 7266 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 7267 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 7268 | * 0x84 must be read before 0x85 */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7269 | fan_select_offset = 0x31, /* EC register 0x31 (Firmware 7M) |
| 7270 | bit 0 selects which fan is active */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7271 | |
| 7272 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 7273 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 7274 | |
| 7275 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 7276 | }; |
| 7277 | |
| 7278 | enum fan_status_access_mode { |
| 7279 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 7280 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 7281 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 7282 | }; |
| 7283 | |
| 7284 | enum fan_control_access_mode { |
| 7285 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 7286 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 7287 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 7288 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 7289 | }; |
| 7290 | |
| 7291 | enum fan_control_commands { |
| 7292 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 7293 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 7294 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 7295 | * and also watchdog cmd */ |
| 7296 | }; |
| 7297 | |
| 7298 | static int fan_control_allowed; |
| 7299 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7300 | static enum fan_status_access_mode fan_status_access_mode; |
| 7301 | static enum fan_control_access_mode fan_control_access_mode; |
| 7302 | static enum fan_control_commands fan_control_commands; |
| 7303 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7304 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7305 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7306 | static u8 fan_control_resume_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7307 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7308 | |
| 7309 | static struct mutex fan_mutex; |
| 7310 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7311 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 7312 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7313 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7314 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 7315 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7316 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 7317 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7318 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7319 | "JFNS", /* 770x-JL */ |
| 7320 | ); /* all others */ |
| 7321 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7322 | /* |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7323 | * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the |
| 7324 | * HFSP register at boot, so it contains 0x07 but the Thinkpad could |
| 7325 | * be in auto mode (0x80). |
| 7326 | * |
| 7327 | * This is corrected by any write to HFSP either by the driver, or |
| 7328 | * by the firmware. |
| 7329 | * |
| 7330 | * We assume 0x07 really means auto mode while this quirk is active, |
| 7331 | * as this is far more likely than the ThinkPad being in level 7, |
| 7332 | * which is only used by the firmware during thermal emergencies. |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7333 | * |
| 7334 | * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52), |
| 7335 | * TP-70 (T43, R52), which are known to be buggy. |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7336 | */ |
| 7337 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7338 | static void fan_quirk1_setup(void) |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7339 | { |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7340 | if (fan_control_initial_status == 0x07) { |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7341 | printk(TPACPI_NOTICE |
| 7342 | "fan_init: initial fan status is unknown, " |
| 7343 | "assuming it is in auto mode\n"); |
| 7344 | tp_features.fan_ctrl_status_undef = 1; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7345 | } |
| 7346 | } |
| 7347 | |
| 7348 | static void fan_quirk1_handle(u8 *fan_status) |
| 7349 | { |
| 7350 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 7351 | if (*fan_status != fan_control_initial_status) { |
| 7352 | /* something changed the HFSP regisnter since |
| 7353 | * driver init time, so it is not undefined |
| 7354 | * anymore */ |
| 7355 | tp_features.fan_ctrl_status_undef = 0; |
| 7356 | } else { |
| 7357 | /* Return most likely status. In fact, it |
| 7358 | * might be the only possible status */ |
| 7359 | *fan_status = TP_EC_FAN_AUTO; |
| 7360 | } |
| 7361 | } |
| 7362 | } |
| 7363 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7364 | /* Select main fan on X60/X61, NOOP on others */ |
| 7365 | static bool fan_select_fan1(void) |
| 7366 | { |
| 7367 | if (tp_features.second_fan) { |
| 7368 | u8 val; |
| 7369 | |
| 7370 | if (ec_read(fan_select_offset, &val) < 0) |
| 7371 | return false; |
| 7372 | val &= 0xFEU; |
| 7373 | if (ec_write(fan_select_offset, val) < 0) |
| 7374 | return false; |
| 7375 | } |
| 7376 | return true; |
| 7377 | } |
| 7378 | |
| 7379 | /* Select secondary fan on X60/X61 */ |
| 7380 | static bool fan_select_fan2(void) |
| 7381 | { |
| 7382 | u8 val; |
| 7383 | |
| 7384 | if (!tp_features.second_fan) |
| 7385 | return false; |
| 7386 | |
| 7387 | if (ec_read(fan_select_offset, &val) < 0) |
| 7388 | return false; |
| 7389 | val |= 0x01U; |
| 7390 | if (ec_write(fan_select_offset, val) < 0) |
| 7391 | return false; |
| 7392 | |
| 7393 | return true; |
| 7394 | } |
| 7395 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7396 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7397 | * Call with fan_mutex held |
| 7398 | */ |
| 7399 | static void fan_update_desired_level(u8 status) |
| 7400 | { |
| 7401 | if ((status & |
| 7402 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 7403 | if (status > 7) |
| 7404 | fan_control_desired_level = 7; |
| 7405 | else |
| 7406 | fan_control_desired_level = status; |
| 7407 | } |
| 7408 | } |
| 7409 | |
| 7410 | static int fan_get_status(u8 *status) |
| 7411 | { |
| 7412 | u8 s; |
| 7413 | |
| 7414 | /* TODO: |
| 7415 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 7416 | |
| 7417 | switch (fan_status_access_mode) { |
| 7418 | case TPACPI_FAN_RD_ACPI_GFAN: |
| 7419 | /* 570, 600e/x, 770e, 770x */ |
| 7420 | |
| 7421 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
| 7422 | return -EIO; |
| 7423 | |
| 7424 | if (likely(status)) |
| 7425 | *status = s & 0x07; |
| 7426 | |
| 7427 | break; |
| 7428 | |
| 7429 | case TPACPI_FAN_RD_TPEC: |
| 7430 | /* all except 570, 600e/x, 770e, 770x */ |
| 7431 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 7432 | return -EIO; |
| 7433 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7434 | if (likely(status)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7435 | *status = s; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7436 | fan_quirk1_handle(status); |
| 7437 | } |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7438 | |
| 7439 | break; |
| 7440 | |
| 7441 | default: |
| 7442 | return -ENXIO; |
| 7443 | } |
| 7444 | |
| 7445 | return 0; |
| 7446 | } |
| 7447 | |
| 7448 | static int fan_get_status_safe(u8 *status) |
| 7449 | { |
| 7450 | int rc; |
| 7451 | u8 s; |
| 7452 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7453 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7454 | return -ERESTARTSYS; |
| 7455 | rc = fan_get_status(&s); |
| 7456 | if (!rc) |
| 7457 | fan_update_desired_level(s); |
| 7458 | mutex_unlock(&fan_mutex); |
| 7459 | |
| 7460 | if (status) |
| 7461 | *status = s; |
| 7462 | |
| 7463 | return rc; |
| 7464 | } |
| 7465 | |
| 7466 | static int fan_get_speed(unsigned int *speed) |
| 7467 | { |
| 7468 | u8 hi, lo; |
| 7469 | |
| 7470 | switch (fan_status_access_mode) { |
| 7471 | case TPACPI_FAN_RD_TPEC: |
| 7472 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7473 | if (unlikely(!fan_select_fan1())) |
| 7474 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7475 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 7476 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 7477 | return -EIO; |
| 7478 | |
| 7479 | if (likely(speed)) |
| 7480 | *speed = (hi << 8) | lo; |
| 7481 | |
| 7482 | break; |
| 7483 | |
| 7484 | default: |
| 7485 | return -ENXIO; |
| 7486 | } |
| 7487 | |
| 7488 | return 0; |
| 7489 | } |
| 7490 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7491 | static int fan2_get_speed(unsigned int *speed) |
| 7492 | { |
| 7493 | u8 hi, lo; |
| 7494 | bool rc; |
| 7495 | |
| 7496 | switch (fan_status_access_mode) { |
| 7497 | case TPACPI_FAN_RD_TPEC: |
| 7498 | /* all except 570, 600e/x, 770e, 770x */ |
| 7499 | if (unlikely(!fan_select_fan2())) |
| 7500 | return -EIO; |
| 7501 | rc = !acpi_ec_read(fan_rpm_offset, &lo) || |
| 7502 | !acpi_ec_read(fan_rpm_offset + 1, &hi); |
| 7503 | fan_select_fan1(); /* play it safe */ |
| 7504 | if (rc) |
| 7505 | return -EIO; |
| 7506 | |
| 7507 | if (likely(speed)) |
| 7508 | *speed = (hi << 8) | lo; |
| 7509 | |
| 7510 | break; |
| 7511 | |
| 7512 | default: |
| 7513 | return -ENXIO; |
| 7514 | } |
| 7515 | |
| 7516 | return 0; |
| 7517 | } |
| 7518 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7519 | static int fan_set_level(int level) |
| 7520 | { |
| 7521 | if (!fan_control_allowed) |
| 7522 | return -EPERM; |
| 7523 | |
| 7524 | switch (fan_control_access_mode) { |
| 7525 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7526 | if (level >= 0 && level <= 7) { |
| 7527 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 7528 | return -EIO; |
| 7529 | } else |
| 7530 | return -EINVAL; |
| 7531 | break; |
| 7532 | |
| 7533 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7534 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7535 | if (!(level & TP_EC_FAN_AUTO) && |
| 7536 | !(level & TP_EC_FAN_FULLSPEED) && |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7537 | ((level < 0) || (level > 7))) |
| 7538 | return -EINVAL; |
| 7539 | |
| 7540 | /* safety net should the EC not support AUTO |
| 7541 | * or FULLSPEED mode bits and just ignore them */ |
| 7542 | if (level & TP_EC_FAN_FULLSPEED) |
| 7543 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 7544 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7545 | level |= 4; /* safety min speed 4 */ |
| 7546 | |
| 7547 | if (!acpi_ec_write(fan_status_offset, level)) |
| 7548 | return -EIO; |
| 7549 | else |
| 7550 | tp_features.fan_ctrl_status_undef = 0; |
| 7551 | break; |
| 7552 | |
| 7553 | default: |
| 7554 | return -ENXIO; |
| 7555 | } |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7556 | |
| 7557 | vdbg_printk(TPACPI_DBG_FAN, |
| 7558 | "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] | 7559 | return 0; |
| 7560 | } |
| 7561 | |
| 7562 | static int fan_set_level_safe(int level) |
| 7563 | { |
| 7564 | int rc; |
| 7565 | |
| 7566 | if (!fan_control_allowed) |
| 7567 | return -EPERM; |
| 7568 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7569 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7570 | return -ERESTARTSYS; |
| 7571 | |
| 7572 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 7573 | level = fan_control_desired_level; |
| 7574 | |
| 7575 | rc = fan_set_level(level); |
| 7576 | if (!rc) |
| 7577 | fan_update_desired_level(level); |
| 7578 | |
| 7579 | mutex_unlock(&fan_mutex); |
| 7580 | return rc; |
| 7581 | } |
| 7582 | |
| 7583 | static int fan_set_enable(void) |
| 7584 | { |
| 7585 | u8 s; |
| 7586 | int rc; |
| 7587 | |
| 7588 | if (!fan_control_allowed) |
| 7589 | return -EPERM; |
| 7590 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7591 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7592 | return -ERESTARTSYS; |
| 7593 | |
| 7594 | switch (fan_control_access_mode) { |
| 7595 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7596 | case TPACPI_FAN_WR_TPEC: |
| 7597 | rc = fan_get_status(&s); |
| 7598 | if (rc < 0) |
| 7599 | break; |
| 7600 | |
| 7601 | /* Don't go out of emergency fan mode */ |
| 7602 | if (s != 7) { |
| 7603 | s &= 0x07; |
| 7604 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 7605 | } |
| 7606 | |
| 7607 | if (!acpi_ec_write(fan_status_offset, s)) |
| 7608 | rc = -EIO; |
| 7609 | else { |
| 7610 | tp_features.fan_ctrl_status_undef = 0; |
| 7611 | rc = 0; |
| 7612 | } |
| 7613 | break; |
| 7614 | |
| 7615 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7616 | rc = fan_get_status(&s); |
| 7617 | if (rc < 0) |
| 7618 | break; |
| 7619 | |
| 7620 | s &= 0x07; |
| 7621 | |
| 7622 | /* Set fan to at least level 4 */ |
| 7623 | s |= 4; |
| 7624 | |
| 7625 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7626 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7627 | else |
| 7628 | rc = 0; |
| 7629 | break; |
| 7630 | |
| 7631 | default: |
| 7632 | rc = -ENXIO; |
| 7633 | } |
| 7634 | |
| 7635 | mutex_unlock(&fan_mutex); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7636 | |
| 7637 | if (!rc) |
| 7638 | vdbg_printk(TPACPI_DBG_FAN, |
| 7639 | "fan control: set fan control register to 0x%02x\n", |
| 7640 | s); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7641 | return rc; |
| 7642 | } |
| 7643 | |
| 7644 | static int fan_set_disable(void) |
| 7645 | { |
| 7646 | int rc; |
| 7647 | |
| 7648 | if (!fan_control_allowed) |
| 7649 | return -EPERM; |
| 7650 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7651 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7652 | return -ERESTARTSYS; |
| 7653 | |
| 7654 | rc = 0; |
| 7655 | switch (fan_control_access_mode) { |
| 7656 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7657 | case TPACPI_FAN_WR_TPEC: |
| 7658 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 7659 | rc = -EIO; |
| 7660 | else { |
| 7661 | fan_control_desired_level = 0; |
| 7662 | tp_features.fan_ctrl_status_undef = 0; |
| 7663 | } |
| 7664 | break; |
| 7665 | |
| 7666 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7667 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 7668 | rc = -EIO; |
| 7669 | else |
| 7670 | fan_control_desired_level = 0; |
| 7671 | break; |
| 7672 | |
| 7673 | default: |
| 7674 | rc = -ENXIO; |
| 7675 | } |
| 7676 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7677 | if (!rc) |
| 7678 | vdbg_printk(TPACPI_DBG_FAN, |
| 7679 | "fan control: set fan control register to 0\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7680 | |
| 7681 | mutex_unlock(&fan_mutex); |
| 7682 | return rc; |
| 7683 | } |
| 7684 | |
| 7685 | static int fan_set_speed(int speed) |
| 7686 | { |
| 7687 | int rc; |
| 7688 | |
| 7689 | if (!fan_control_allowed) |
| 7690 | return -EPERM; |
| 7691 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7692 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7693 | return -ERESTARTSYS; |
| 7694 | |
| 7695 | rc = 0; |
| 7696 | switch (fan_control_access_mode) { |
| 7697 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7698 | if (speed >= 0 && speed <= 65535) { |
| 7699 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 7700 | speed, speed, speed)) |
| 7701 | rc = -EIO; |
| 7702 | } else |
| 7703 | rc = -EINVAL; |
| 7704 | break; |
| 7705 | |
| 7706 | default: |
| 7707 | rc = -ENXIO; |
| 7708 | } |
| 7709 | |
| 7710 | mutex_unlock(&fan_mutex); |
| 7711 | return rc; |
| 7712 | } |
| 7713 | |
| 7714 | static void fan_watchdog_reset(void) |
| 7715 | { |
| 7716 | static int fan_watchdog_active; |
| 7717 | |
| 7718 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 7719 | return; |
| 7720 | |
| 7721 | if (fan_watchdog_active) |
| 7722 | cancel_delayed_work(&fan_watchdog_task); |
| 7723 | |
| 7724 | if (fan_watchdog_maxinterval > 0 && |
| 7725 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
| 7726 | fan_watchdog_active = 1; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7727 | if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task, |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7728 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 7729 | * 1000))) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7730 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7731 | "failed to queue the fan watchdog, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7732 | "watchdog will not trigger\n"); |
| 7733 | } |
| 7734 | } else |
| 7735 | fan_watchdog_active = 0; |
| 7736 | } |
| 7737 | |
| 7738 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 7739 | { |
| 7740 | int rc; |
| 7741 | |
| 7742 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 7743 | return; |
| 7744 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7745 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7746 | rc = fan_set_enable(); |
| 7747 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7748 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7749 | "will try again later...\n", -rc); |
| 7750 | /* reschedule for later */ |
| 7751 | fan_watchdog_reset(); |
| 7752 | } |
| 7753 | } |
| 7754 | |
| 7755 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7756 | * SYSFS fan layout: hwmon compatible (device) |
| 7757 | * |
| 7758 | * pwm*_enable: |
| 7759 | * 0: "disengaged" mode |
| 7760 | * 1: manual mode |
| 7761 | * 2: native EC "auto" mode (recommended, hardware default) |
| 7762 | * |
| 7763 | * pwm*: set speed in manual mode, ignored otherwise. |
| 7764 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 7765 | * interpolation. |
| 7766 | * |
| 7767 | * fan*_input: tachometer reading, RPM |
| 7768 | * |
| 7769 | * |
| 7770 | * SYSFS fan layout: extensions |
| 7771 | * |
| 7772 | * fan_watchdog (driver): |
| 7773 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 7774 | */ |
| 7775 | |
| 7776 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 7777 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 7778 | struct device_attribute *attr, |
| 7779 | char *buf) |
| 7780 | { |
| 7781 | int res, mode; |
| 7782 | u8 status; |
| 7783 | |
| 7784 | res = fan_get_status_safe(&status); |
| 7785 | if (res) |
| 7786 | return res; |
| 7787 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7788 | if (status & TP_EC_FAN_FULLSPEED) { |
| 7789 | mode = 0; |
| 7790 | } else if (status & TP_EC_FAN_AUTO) { |
| 7791 | mode = 2; |
| 7792 | } else |
| 7793 | mode = 1; |
| 7794 | |
| 7795 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 7796 | } |
| 7797 | |
| 7798 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 7799 | struct device_attribute *attr, |
| 7800 | const char *buf, size_t count) |
| 7801 | { |
| 7802 | unsigned long t; |
| 7803 | int res, level; |
| 7804 | |
| 7805 | if (parse_strtoul(buf, 2, &t)) |
| 7806 | return -EINVAL; |
| 7807 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7808 | tpacpi_disclose_usertask("hwmon pwm1_enable", |
| 7809 | "set fan mode to %lu\n", t); |
| 7810 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7811 | switch (t) { |
| 7812 | case 0: |
| 7813 | level = TP_EC_FAN_FULLSPEED; |
| 7814 | break; |
| 7815 | case 1: |
| 7816 | level = TPACPI_FAN_LAST_LEVEL; |
| 7817 | break; |
| 7818 | case 2: |
| 7819 | level = TP_EC_FAN_AUTO; |
| 7820 | break; |
| 7821 | case 3: |
| 7822 | /* reserved for software-controlled auto mode */ |
| 7823 | return -ENOSYS; |
| 7824 | default: |
| 7825 | return -EINVAL; |
| 7826 | } |
| 7827 | |
| 7828 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 7829 | if (res == -ENXIO) |
| 7830 | return -EINVAL; |
| 7831 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7832 | return res; |
| 7833 | |
| 7834 | fan_watchdog_reset(); |
| 7835 | |
| 7836 | return count; |
| 7837 | } |
| 7838 | |
| 7839 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 7840 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 7841 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 7842 | |
| 7843 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 7844 | static ssize_t fan_pwm1_show(struct device *dev, |
| 7845 | struct device_attribute *attr, |
| 7846 | char *buf) |
| 7847 | { |
| 7848 | int res; |
| 7849 | u8 status; |
| 7850 | |
| 7851 | res = fan_get_status_safe(&status); |
| 7852 | if (res) |
| 7853 | return res; |
| 7854 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7855 | if ((status & |
| 7856 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 7857 | status = fan_control_desired_level; |
| 7858 | |
| 7859 | if (status > 7) |
| 7860 | status = 7; |
| 7861 | |
| 7862 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 7863 | } |
| 7864 | |
| 7865 | static ssize_t fan_pwm1_store(struct device *dev, |
| 7866 | struct device_attribute *attr, |
| 7867 | const char *buf, size_t count) |
| 7868 | { |
| 7869 | unsigned long s; |
| 7870 | int rc; |
| 7871 | u8 status, newlevel; |
| 7872 | |
| 7873 | if (parse_strtoul(buf, 255, &s)) |
| 7874 | return -EINVAL; |
| 7875 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7876 | tpacpi_disclose_usertask("hwmon pwm1", |
| 7877 | "set fan speed to %lu\n", s); |
| 7878 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7879 | /* scale down from 0-255 to 0-7 */ |
| 7880 | newlevel = (s >> 5) & 0x07; |
| 7881 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7882 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 7883 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7884 | |
| 7885 | rc = fan_get_status(&status); |
| 7886 | if (!rc && (status & |
| 7887 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 7888 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 7889 | if (rc == -ENXIO) |
| 7890 | rc = -EINVAL; |
| 7891 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7892 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 7893 | fan_watchdog_reset(); |
| 7894 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7895 | } |
| 7896 | |
| 7897 | mutex_unlock(&fan_mutex); |
| 7898 | return (rc)? rc : count; |
| 7899 | } |
| 7900 | |
| 7901 | static struct device_attribute dev_attr_fan_pwm1 = |
| 7902 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 7903 | fan_pwm1_show, fan_pwm1_store); |
| 7904 | |
| 7905 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 7906 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 7907 | struct device_attribute *attr, |
| 7908 | char *buf) |
| 7909 | { |
| 7910 | int res; |
| 7911 | unsigned int speed; |
| 7912 | |
| 7913 | res = fan_get_speed(&speed); |
| 7914 | if (res < 0) |
| 7915 | return res; |
| 7916 | |
| 7917 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7918 | } |
| 7919 | |
| 7920 | static struct device_attribute dev_attr_fan_fan1_input = |
| 7921 | __ATTR(fan1_input, S_IRUGO, |
| 7922 | fan_fan1_input_show, NULL); |
| 7923 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7924 | /* sysfs fan fan2_input ------------------------------------------------ */ |
| 7925 | static ssize_t fan_fan2_input_show(struct device *dev, |
| 7926 | struct device_attribute *attr, |
| 7927 | char *buf) |
| 7928 | { |
| 7929 | int res; |
| 7930 | unsigned int speed; |
| 7931 | |
| 7932 | res = fan2_get_speed(&speed); |
| 7933 | if (res < 0) |
| 7934 | return res; |
| 7935 | |
| 7936 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7937 | } |
| 7938 | |
| 7939 | static struct device_attribute dev_attr_fan_fan2_input = |
| 7940 | __ATTR(fan2_input, S_IRUGO, |
| 7941 | fan_fan2_input_show, NULL); |
| 7942 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7943 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7944 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 7945 | char *buf) |
| 7946 | { |
| 7947 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 7948 | } |
| 7949 | |
| 7950 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 7951 | const char *buf, size_t count) |
| 7952 | { |
| 7953 | unsigned long t; |
| 7954 | |
| 7955 | if (parse_strtoul(buf, 120, &t)) |
| 7956 | return -EINVAL; |
| 7957 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7958 | if (!fan_control_allowed) |
| 7959 | return -EPERM; |
| 7960 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7961 | fan_watchdog_maxinterval = t; |
| 7962 | fan_watchdog_reset(); |
| 7963 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7964 | tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t); |
| 7965 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7966 | return count; |
| 7967 | } |
| 7968 | |
| 7969 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 7970 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 7971 | |
| 7972 | /* --------------------------------------------------------------------- */ |
| 7973 | static struct attribute *fan_attributes[] = { |
| 7974 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 7975 | &dev_attr_fan_fan1_input.attr, |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7976 | NULL, /* for fan2_input */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7977 | NULL |
| 7978 | }; |
| 7979 | |
| 7980 | static const struct attribute_group fan_attr_group = { |
| 7981 | .attrs = fan_attributes, |
| 7982 | }; |
| 7983 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7984 | #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */ |
| 7985 | #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] | 7986 | |
| 7987 | #define TPACPI_FAN_QI(__id1, __id2, __quirks) \ |
| 7988 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 7989 | .bios = TPACPI_MATCH_ANY, \ |
| 7990 | .ec = TPID(__id1, __id2), \ |
| 7991 | .quirks = __quirks } |
| 7992 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7993 | #define TPACPI_FAN_QL(__id1, __id2, __quirks) \ |
| 7994 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 7995 | .bios = TPACPI_MATCH_ANY, \ |
| 7996 | .ec = TPID(__id1, __id2), \ |
| 7997 | .quirks = __quirks } |
| 7998 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7999 | static const struct tpacpi_quirk fan_quirk_table[] __initconst = { |
| 8000 | TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1), |
| 8001 | TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1), |
| 8002 | TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1), |
| 8003 | TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1), |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8004 | TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN), |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8005 | }; |
| 8006 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8007 | #undef TPACPI_FAN_QL |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8008 | #undef TPACPI_FAN_QI |
| 8009 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8010 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8011 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8012 | int rc; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8013 | unsigned long quirks; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8014 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8015 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 8016 | "initializing fan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8017 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 8018 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8019 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 8020 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8021 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8022 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 8023 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8024 | tp_features.second_fan = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8025 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8026 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 8027 | if (tpacpi_is_ibm()) { |
| 8028 | TPACPI_ACPIHANDLE_INIT(fans); |
| 8029 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 8030 | TPACPI_ACPIHANDLE_INIT(sfan); |
| 8031 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8032 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8033 | quirks = tpacpi_check_quirks(fan_quirk_table, |
| 8034 | ARRAY_SIZE(fan_quirk_table)); |
| 8035 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8036 | if (gfan_handle) { |
| 8037 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8038 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8039 | } else { |
| 8040 | /* all other ThinkPads: note that even old-style |
| 8041 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8042 | if (likely(acpi_ec_read(fan_status_offset, |
| 8043 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8044 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8045 | if (quirks & TPACPI_FAN_Q1) |
| 8046 | fan_quirk1_setup(); |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8047 | if (quirks & TPACPI_FAN_2FAN) { |
| 8048 | tp_features.second_fan = 1; |
| 8049 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 8050 | "secondary fan support enabled\n"); |
| 8051 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8052 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8053 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8054 | "ThinkPad ACPI EC access misbehaving, " |
| 8055 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8056 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8057 | } |
| 8058 | } |
| 8059 | |
| 8060 | if (sfan_handle) { |
| 8061 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8062 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 8063 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8064 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8065 | } else { |
| 8066 | if (!gfan_handle) { |
| 8067 | /* gfan without sfan means no fan control */ |
| 8068 | /* all other models implement TP EC 0x2f control */ |
| 8069 | |
| 8070 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8071 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8072 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8073 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8074 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8075 | TPACPI_FAN_CMD_SPEED | |
| 8076 | TPACPI_FAN_CMD_LEVEL | |
| 8077 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8078 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8079 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8080 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8081 | TPACPI_FAN_CMD_LEVEL | |
| 8082 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8083 | } |
| 8084 | } |
| 8085 | } |
| 8086 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8087 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 8088 | "fan is %s, modes %d, %d\n", |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8089 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 8090 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 8091 | fan_status_access_mode, fan_control_access_mode); |
| 8092 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8093 | /* fan control master switch */ |
| 8094 | if (!fan_control_allowed) { |
| 8095 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 8096 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8097 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8098 | "fan control features disabled by parameter\n"); |
| 8099 | } |
| 8100 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8101 | /* update fan_control_desired_level */ |
| 8102 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 8103 | fan_get_status_safe(NULL); |
| 8104 | |
| 8105 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 8106 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8107 | if (tp_features.second_fan) { |
| 8108 | /* attach second fan tachometer */ |
| 8109 | fan_attributes[ARRAY_SIZE(fan_attributes)-2] = |
| 8110 | &dev_attr_fan_fan2_input.attr; |
| 8111 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8112 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8113 | &fan_attr_group); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8114 | if (rc < 0) |
| 8115 | return rc; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 8116 | |
| 8117 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
| 8118 | &driver_attr_fan_watchdog); |
| 8119 | if (rc < 0) { |
| 8120 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
| 8121 | &fan_attr_group); |
| 8122 | return rc; |
| 8123 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8124 | return 0; |
| 8125 | } else |
| 8126 | return 1; |
| 8127 | } |
| 8128 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8129 | static void fan_exit(void) |
| 8130 | { |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8131 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8132 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8133 | |
| 8134 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8135 | 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] | 8136 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 8137 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8138 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8139 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8140 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8141 | } |
| 8142 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8143 | static void fan_suspend(pm_message_t state) |
| 8144 | { |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8145 | int rc; |
| 8146 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8147 | if (!fan_control_allowed) |
| 8148 | return; |
| 8149 | |
| 8150 | /* Store fan status in cache */ |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8151 | fan_control_resume_level = 0; |
| 8152 | rc = fan_get_status_safe(&fan_control_resume_level); |
| 8153 | if (rc < 0) |
| 8154 | printk(TPACPI_NOTICE |
| 8155 | "failed to read fan level for later " |
| 8156 | "restore during resume: %d\n", rc); |
| 8157 | |
| 8158 | /* if it is undefined, don't attempt to restore it. |
| 8159 | * KEEP THIS LAST */ |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8160 | if (tp_features.fan_ctrl_status_undef) |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8161 | fan_control_resume_level = 0; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8162 | } |
| 8163 | |
| 8164 | static void fan_resume(void) |
| 8165 | { |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8166 | u8 current_level = 7; |
| 8167 | bool do_set = false; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8168 | int rc; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8169 | |
| 8170 | /* DSDT *always* updates status on resume */ |
| 8171 | tp_features.fan_ctrl_status_undef = 0; |
| 8172 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8173 | if (!fan_control_allowed || |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8174 | !fan_control_resume_level || |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8175 | (fan_get_status_safe(¤t_level) < 0)) |
| 8176 | return; |
| 8177 | |
| 8178 | switch (fan_control_access_mode) { |
| 8179 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8180 | /* never decrease fan level */ |
| 8181 | do_set = (fan_control_resume_level > current_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8182 | break; |
| 8183 | case TPACPI_FAN_WR_ACPI_FANS: |
| 8184 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8185 | /* never decrease fan level, scale is: |
| 8186 | * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO |
| 8187 | * |
| 8188 | * We expect the firmware to set either 7 or AUTO, but we |
| 8189 | * handle FULLSPEED out of paranoia. |
| 8190 | * |
| 8191 | * So, we can safely only restore FULLSPEED or 7, anything |
| 8192 | * else could slow the fan. Restoring AUTO is useless, at |
| 8193 | * best that's exactly what the DSDT already set (it is the |
| 8194 | * slower it uses). |
| 8195 | * |
| 8196 | * Always keep in mind that the DSDT *will* have set the |
| 8197 | * fans to what the vendor supposes is the best level. We |
| 8198 | * muck with it only to speed the fan up. |
| 8199 | */ |
| 8200 | if (fan_control_resume_level != 7 && |
| 8201 | !(fan_control_resume_level & TP_EC_FAN_FULLSPEED)) |
| 8202 | return; |
| 8203 | else |
| 8204 | do_set = !(current_level & TP_EC_FAN_FULLSPEED) && |
| 8205 | (current_level != fan_control_resume_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8206 | break; |
| 8207 | default: |
| 8208 | return; |
| 8209 | } |
| 8210 | if (do_set) { |
| 8211 | printk(TPACPI_NOTICE |
| 8212 | "restoring fan level to 0x%02x\n", |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8213 | fan_control_resume_level); |
| 8214 | rc = fan_set_level_safe(fan_control_resume_level); |
| 8215 | if (rc < 0) |
| 8216 | printk(TPACPI_NOTICE |
| 8217 | "failed to restore fan level: %d\n", rc); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8218 | } |
| 8219 | } |
| 8220 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8221 | static int fan_read(struct seq_file *m) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8222 | { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8223 | int rc; |
| 8224 | u8 status; |
| 8225 | unsigned int speed = 0; |
| 8226 | |
| 8227 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8228 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8229 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8230 | rc = fan_get_status_safe(&status); |
| 8231 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8232 | return rc; |
| 8233 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8234 | seq_printf(m, "status:\t\t%s\n" |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8235 | "level:\t\t%d\n", |
| 8236 | (status != 0) ? "enabled" : "disabled", status); |
| 8237 | break; |
| 8238 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8239 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8240 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8241 | rc = fan_get_status_safe(&status); |
| 8242 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8243 | return rc; |
| 8244 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8245 | seq_printf(m, "status:\t\t%s\n", |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8246 | (status != 0) ? "enabled" : "disabled"); |
| 8247 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8248 | rc = fan_get_speed(&speed); |
| 8249 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8250 | return rc; |
| 8251 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8252 | seq_printf(m, "speed:\t\t%d\n", speed); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8253 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8254 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8255 | /* Disengaged mode takes precedence */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8256 | seq_printf(m, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8257 | else if (status & TP_EC_FAN_AUTO) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8258 | seq_printf(m, "level:\t\tauto\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8259 | else |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8260 | seq_printf(m, "level:\t\t%d\n", status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8261 | break; |
| 8262 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8263 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8264 | default: |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8265 | seq_printf(m, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8266 | } |
| 8267 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8268 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8269 | seq_printf(m, "commands:\tlevel <level>"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8270 | |
| 8271 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8272 | case TPACPI_FAN_WR_ACPI_SFAN: |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8273 | seq_printf(m, " (<level> is 0-7)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8274 | break; |
| 8275 | |
| 8276 | default: |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8277 | seq_printf(m, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8278 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8279 | break; |
| 8280 | } |
| 8281 | } |
| 8282 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8283 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8284 | seq_printf(m, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8285 | "commands:\twatchdog <timeout> (<timeout> " |
| 8286 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8287 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8288 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8289 | seq_printf(m, "commands:\tspeed <speed>" |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8290 | " (<speed> is 0-65535)\n"); |
| 8291 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8292 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8293 | } |
| 8294 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8295 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 8296 | { |
| 8297 | int level; |
| 8298 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8299 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8300 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8301 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8302 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8303 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8304 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8305 | return 0; |
| 8306 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8307 | *rc = fan_set_level_safe(level); |
| 8308 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8309 | printk(TPACPI_ERR "level command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8310 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8311 | else if (!*rc) |
| 8312 | tpacpi_disclose_usertask("procfs fan", |
| 8313 | "set level to %d\n", level); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8314 | |
| 8315 | return 1; |
| 8316 | } |
| 8317 | |
| 8318 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 8319 | { |
| 8320 | if (strlencmp(cmd, "enable") != 0) |
| 8321 | return 0; |
| 8322 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8323 | *rc = fan_set_enable(); |
| 8324 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8325 | printk(TPACPI_ERR "enable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8326 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8327 | else if (!*rc) |
| 8328 | tpacpi_disclose_usertask("procfs fan", "enable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8329 | |
| 8330 | return 1; |
| 8331 | } |
| 8332 | |
| 8333 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 8334 | { |
| 8335 | if (strlencmp(cmd, "disable") != 0) |
| 8336 | return 0; |
| 8337 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8338 | *rc = fan_set_disable(); |
| 8339 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8340 | printk(TPACPI_ERR "disable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8341 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8342 | else if (!*rc) |
| 8343 | tpacpi_disclose_usertask("procfs fan", "disable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8344 | |
| 8345 | return 1; |
| 8346 | } |
| 8347 | |
| 8348 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 8349 | { |
| 8350 | int speed; |
| 8351 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8352 | /* TODO: |
| 8353 | * Support speed <low> <medium> <high> ? */ |
| 8354 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8355 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 8356 | return 0; |
| 8357 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8358 | *rc = fan_set_speed(speed); |
| 8359 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8360 | printk(TPACPI_ERR "speed command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8361 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8362 | else if (!*rc) |
| 8363 | tpacpi_disclose_usertask("procfs fan", |
| 8364 | "set speed to %d\n", speed); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8365 | |
| 8366 | return 1; |
| 8367 | } |
| 8368 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8369 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 8370 | { |
| 8371 | int interval; |
| 8372 | |
| 8373 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 8374 | return 0; |
| 8375 | |
| 8376 | if (interval < 0 || interval > 120) |
| 8377 | *rc = -EINVAL; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8378 | else { |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8379 | fan_watchdog_maxinterval = interval; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8380 | tpacpi_disclose_usertask("procfs fan", |
| 8381 | "set watchdog timer to %d\n", |
| 8382 | interval); |
| 8383 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8384 | |
| 8385 | return 1; |
| 8386 | } |
| 8387 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8388 | static int fan_write(char *buf) |
| 8389 | { |
| 8390 | char *cmd; |
| 8391 | int rc = 0; |
| 8392 | |
| 8393 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8394 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8395 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8396 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8397 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8398 | fan_write_cmd_disable(cmd, &rc) || |
| 8399 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8400 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8401 | fan_write_cmd_speed(cmd, &rc)) |
| 8402 | ) |
| 8403 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8404 | else if (!rc) |
| 8405 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8406 | } |
| 8407 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8408 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8409 | } |
| 8410 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8411 | static struct ibm_struct fan_driver_data = { |
| 8412 | .name = "fan", |
| 8413 | .read = fan_read, |
| 8414 | .write = fan_write, |
| 8415 | .exit = fan_exit, |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8416 | .suspend = fan_suspend, |
| 8417 | .resume = fan_resume, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8418 | }; |
| 8419 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8420 | /**************************************************************************** |
| 8421 | **************************************************************************** |
| 8422 | * |
| 8423 | * Infrastructure |
| 8424 | * |
| 8425 | **************************************************************************** |
| 8426 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8427 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8428 | /* |
| 8429 | * HKEY event callout for other subdrivers go here |
| 8430 | * (yes, it is ugly, but it is quick, safe, and gets the job done |
| 8431 | */ |
| 8432 | static void tpacpi_driver_event(const unsigned int hkey_event) |
| 8433 | { |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 8434 | if (ibm_backlight_device) { |
| 8435 | switch (hkey_event) { |
| 8436 | case TP_HKEY_EV_BRGHT_UP: |
| 8437 | case TP_HKEY_EV_BRGHT_DOWN: |
| 8438 | tpacpi_brightness_notify_change(); |
| 8439 | } |
| 8440 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 8441 | if (alsa_card) { |
| 8442 | switch (hkey_event) { |
| 8443 | case TP_HKEY_EV_VOL_UP: |
| 8444 | case TP_HKEY_EV_VOL_DOWN: |
| 8445 | case TP_HKEY_EV_VOL_MUTE: |
| 8446 | volume_alsa_notify_change(); |
| 8447 | } |
| 8448 | } |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8449 | } |
| 8450 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8451 | static void hotkey_driver_event(const unsigned int scancode) |
| 8452 | { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 8453 | tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8454 | } |
| 8455 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8456 | /* sysfs name ---------------------------------------------------------- */ |
| 8457 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 8458 | struct device_attribute *attr, |
| 8459 | char *buf) |
| 8460 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8461 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8462 | } |
| 8463 | |
| 8464 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 8465 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 8466 | |
| 8467 | /* --------------------------------------------------------------------- */ |
| 8468 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8469 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 8470 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8471 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8472 | /* |
| 8473 | * Module and infrastructure proble, init and exit handling |
| 8474 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8475 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8476 | static int force_load; |
| 8477 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8478 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8479 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8480 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8481 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8482 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8483 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8484 | } |
| 8485 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 8486 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8487 | static void ibm_exit(struct ibm_struct *ibm) |
| 8488 | { |
| 8489 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 8490 | |
| 8491 | list_del_init(&ibm->all_drivers); |
| 8492 | |
| 8493 | if (ibm->flags.acpi_notify_installed) { |
| 8494 | dbg_printk(TPACPI_DBG_EXIT, |
| 8495 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 8496 | BUG_ON(!ibm->acpi); |
| 8497 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 8498 | ibm->acpi->type, |
| 8499 | dispatch_acpi_notify); |
| 8500 | ibm->flags.acpi_notify_installed = 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8501 | } |
| 8502 | |
| 8503 | if (ibm->flags.proc_created) { |
| 8504 | dbg_printk(TPACPI_DBG_EXIT, |
| 8505 | "%s: remove_proc_entry\n", ibm->name); |
| 8506 | remove_proc_entry(ibm->name, proc_dir); |
| 8507 | ibm->flags.proc_created = 0; |
| 8508 | } |
| 8509 | |
| 8510 | if (ibm->flags.acpi_driver_registered) { |
| 8511 | dbg_printk(TPACPI_DBG_EXIT, |
| 8512 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 8513 | BUG_ON(!ibm->acpi); |
| 8514 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 8515 | kfree(ibm->acpi->driver); |
| 8516 | ibm->acpi->driver = NULL; |
| 8517 | ibm->flags.acpi_driver_registered = 0; |
| 8518 | } |
| 8519 | |
| 8520 | if (ibm->flags.init_called && ibm->exit) { |
| 8521 | ibm->exit(); |
| 8522 | ibm->flags.init_called = 0; |
| 8523 | } |
| 8524 | |
| 8525 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 8526 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 8527 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8528 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8529 | { |
| 8530 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8531 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8532 | struct proc_dir_entry *entry; |
| 8533 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8534 | BUG_ON(ibm == NULL); |
| 8535 | |
| 8536 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 8537 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8538 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8539 | return 0; |
| 8540 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8541 | dbg_printk(TPACPI_DBG_INIT, |
| 8542 | "probing for %s\n", ibm->name); |
| 8543 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8544 | if (iibm->init) { |
| 8545 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8546 | if (ret > 0) |
| 8547 | return 0; /* probe failed */ |
| 8548 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8549 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8550 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8551 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8552 | } |
| 8553 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8554 | if (ibm->acpi) { |
| 8555 | if (ibm->acpi->hid) { |
| 8556 | ret = register_tpacpi_subdriver(ibm); |
| 8557 | if (ret) |
| 8558 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8559 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8560 | |
| 8561 | if (ibm->acpi->notify) { |
| 8562 | ret = setup_acpi_notify(ibm); |
| 8563 | if (ret == -ENODEV) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8564 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8565 | ibm->name); |
| 8566 | ret = 0; |
| 8567 | goto err_out; |
| 8568 | } |
| 8569 | if (ret < 0) |
| 8570 | goto err_out; |
| 8571 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8572 | } |
| 8573 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8574 | dbg_printk(TPACPI_DBG_INIT, |
| 8575 | "%s installed\n", ibm->name); |
| 8576 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8577 | if (ibm->read) { |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 8578 | mode_t mode = iibm->base_procfs_mode; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8579 | |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 8580 | if (!mode) |
| 8581 | mode = S_IRUGO; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8582 | if (ibm->write) |
| 8583 | mode |= S_IWUSR; |
| 8584 | entry = proc_create_data(ibm->name, mode, proc_dir, |
| 8585 | &dispatch_proc_fops, ibm); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8586 | if (!entry) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8587 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8588 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8589 | ret = -ENODEV; |
| 8590 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8591 | } |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8592 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8593 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8594 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8595 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 8596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8597 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8598 | |
| 8599 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8600 | dbg_printk(TPACPI_DBG_INIT, |
| 8601 | "%s: at error exit path with result %d\n", |
| 8602 | ibm->name, ret); |
| 8603 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8604 | ibm_exit(ibm); |
| 8605 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8606 | } |
| 8607 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8608 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8609 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8610 | static bool __pure __init tpacpi_is_fw_digit(const char c) |
| 8611 | { |
| 8612 | return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); |
| 8613 | } |
| 8614 | |
| 8615 | /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */ |
| 8616 | static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, |
| 8617 | const char t) |
| 8618 | { |
| 8619 | return s && strlen(s) >= 8 && |
| 8620 | tpacpi_is_fw_digit(s[0]) && |
| 8621 | tpacpi_is_fw_digit(s[1]) && |
| 8622 | s[2] == t && s[3] == 'T' && |
| 8623 | tpacpi_is_fw_digit(s[4]) && |
| 8624 | tpacpi_is_fw_digit(s[5]) && |
| 8625 | s[6] == 'W' && s[7] == 'W'; |
| 8626 | } |
| 8627 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8628 | /* returns 0 - probe ok, or < 0 - probe error. |
| 8629 | * Probe ok doesn't mean thinkpad found. |
| 8630 | * On error, kfree() cleanup on tp->* is not performed, caller must do it */ |
| 8631 | static int __must_check __init get_thinkpad_model_data( |
| 8632 | struct thinkpad_id_data *tp) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8633 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 8634 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8635 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8636 | char const *s; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8637 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8638 | if (!tp) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8639 | return -EINVAL; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8640 | |
| 8641 | memset(tp, 0, sizeof(*tp)); |
| 8642 | |
| 8643 | if (dmi_name_in_vendors("IBM")) |
| 8644 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 8645 | else if (dmi_name_in_vendors("LENOVO")) |
| 8646 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 8647 | else |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8648 | return 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8649 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8650 | s = dmi_get_system_info(DMI_BIOS_VERSION); |
| 8651 | tp->bios_version_str = kstrdup(s, GFP_KERNEL); |
| 8652 | if (s && !tp->bios_version_str) |
| 8653 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8654 | |
| 8655 | /* Really ancient ThinkPad 240X will fail this, which is fine */ |
| 8656 | if (!tpacpi_is_valid_fw_id(tp->bios_version_str, 'E')) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8657 | return 0; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8658 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8659 | tp->bios_model = tp->bios_version_str[0] |
| 8660 | | (tp->bios_version_str[1] << 8); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8661 | tp->bios_release = (tp->bios_version_str[4] << 8) |
| 8662 | | tp->bios_version_str[5]; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8663 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8664 | /* |
| 8665 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 8666 | * X32 or newer, all Z series; Some models must have an |
| 8667 | * up-to-date BIOS or they will not be detected. |
| 8668 | * |
| 8669 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 8670 | */ |
| 8671 | 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] | 8672 | if (sscanf(dev->name, |
| 8673 | "IBM ThinkPad Embedded Controller -[%17c", |
| 8674 | ec_fw_string) == 1) { |
| 8675 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 8676 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8677 | |
| 8678 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8679 | if (!tp->ec_version_str) |
| 8680 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8681 | |
| 8682 | if (tpacpi_is_valid_fw_id(ec_fw_string, 'H')) { |
| 8683 | tp->ec_model = ec_fw_string[0] |
| 8684 | | (ec_fw_string[1] << 8); |
| 8685 | tp->ec_release = (ec_fw_string[4] << 8) |
| 8686 | | ec_fw_string[5]; |
| 8687 | } else { |
| 8688 | printk(TPACPI_NOTICE |
| 8689 | "ThinkPad firmware release %s " |
| 8690 | "doesn't match the known patterns\n", |
| 8691 | ec_fw_string); |
| 8692 | printk(TPACPI_NOTICE |
| 8693 | "please report this to %s\n", |
| 8694 | TPACPI_MAIL); |
| 8695 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8696 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8697 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8698 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8699 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8700 | s = dmi_get_system_info(DMI_PRODUCT_VERSION); |
| 8701 | if (s && !strnicmp(s, "ThinkPad", 8)) { |
| 8702 | tp->model_str = kstrdup(s, GFP_KERNEL); |
| 8703 | if (!tp->model_str) |
| 8704 | return -ENOMEM; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8705 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 8706 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8707 | s = dmi_get_system_info(DMI_PRODUCT_NAME); |
| 8708 | tp->nummodel_str = kstrdup(s, GFP_KERNEL); |
| 8709 | if (s && !tp->nummodel_str) |
| 8710 | return -ENOMEM; |
| 8711 | |
| 8712 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8713 | } |
| 8714 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8715 | static int __init probe_for_thinkpad(void) |
| 8716 | { |
| 8717 | int is_thinkpad; |
| 8718 | |
| 8719 | if (acpi_disabled) |
| 8720 | return -ENODEV; |
| 8721 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 8722 | /* It would be dangerous to run the driver in this case */ |
| 8723 | if (!tpacpi_is_ibm() && !tpacpi_is_lenovo()) |
| 8724 | return -ENODEV; |
| 8725 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8726 | /* |
| 8727 | * 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] | 8728 | * 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] | 8729 | */ |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 8730 | is_thinkpad = (thinkpad_id.model_str != NULL) || |
| 8731 | (thinkpad_id.ec_model != 0) || |
| 8732 | tpacpi_is_fw_known(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8733 | |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 8734 | /* The EC handler is required */ |
| 8735 | 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] | 8736 | if (!ec_handle) { |
| 8737 | if (is_thinkpad) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8738 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8739 | "Not yet supported ThinkPad detected!\n"); |
| 8740 | return -ENODEV; |
| 8741 | } |
| 8742 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 8743 | if (!is_thinkpad && !force_load) |
| 8744 | return -ENODEV; |
| 8745 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8746 | return 0; |
| 8747 | } |
| 8748 | |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 8749 | static void __init thinkpad_acpi_init_banner(void) |
| 8750 | { |
| 8751 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 8752 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
| 8753 | |
| 8754 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", |
| 8755 | (thinkpad_id.bios_version_str) ? |
| 8756 | thinkpad_id.bios_version_str : "unknown", |
| 8757 | (thinkpad_id.ec_version_str) ? |
| 8758 | thinkpad_id.ec_version_str : "unknown"); |
| 8759 | |
| 8760 | BUG_ON(!thinkpad_id.vendor); |
| 8761 | |
| 8762 | if (thinkpad_id.model_str) |
| 8763 | printk(TPACPI_INFO "%s %s, model %s\n", |
| 8764 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 8765 | "IBM" : ((thinkpad_id.vendor == |
| 8766 | PCI_VENDOR_ID_LENOVO) ? |
| 8767 | "Lenovo" : "Unknown vendor"), |
| 8768 | thinkpad_id.model_str, |
| 8769 | (thinkpad_id.nummodel_str) ? |
| 8770 | thinkpad_id.nummodel_str : "unknown"); |
| 8771 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8772 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8773 | /* Module init, exit, parameters */ |
| 8774 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8775 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 8776 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8777 | .data = &thinkpad_acpi_driver_data, |
| 8778 | }, |
| 8779 | { |
| 8780 | .init = hotkey_init, |
| 8781 | .data = &hotkey_driver_data, |
| 8782 | }, |
| 8783 | { |
| 8784 | .init = bluetooth_init, |
| 8785 | .data = &bluetooth_driver_data, |
| 8786 | }, |
| 8787 | { |
| 8788 | .init = wan_init, |
| 8789 | .data = &wan_driver_data, |
| 8790 | }, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8791 | { |
| 8792 | .init = uwb_init, |
| 8793 | .data = &uwb_driver_data, |
| 8794 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 8795 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8796 | { |
| 8797 | .init = video_init, |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 8798 | .base_procfs_mode = S_IRUSR, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8799 | .data = &video_driver_data, |
| 8800 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 8801 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8802 | { |
| 8803 | .init = light_init, |
| 8804 | .data = &light_driver_data, |
| 8805 | }, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8806 | { |
| 8807 | .init = cmos_init, |
| 8808 | .data = &cmos_driver_data, |
| 8809 | }, |
| 8810 | { |
| 8811 | .init = led_init, |
| 8812 | .data = &led_driver_data, |
| 8813 | }, |
| 8814 | { |
| 8815 | .init = beep_init, |
| 8816 | .data = &beep_driver_data, |
| 8817 | }, |
| 8818 | { |
| 8819 | .init = thermal_init, |
| 8820 | .data = &thermal_driver_data, |
| 8821 | }, |
| 8822 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8823 | .init = brightness_init, |
| 8824 | .data = &brightness_driver_data, |
| 8825 | }, |
| 8826 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 8827 | .init = volume_init, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8828 | .data = &volume_driver_data, |
| 8829 | }, |
| 8830 | { |
| 8831 | .init = fan_init, |
| 8832 | .data = &fan_driver_data, |
| 8833 | }, |
| 8834 | }; |
| 8835 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8836 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 8837 | { |
| 8838 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8839 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8840 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 8841 | if (!kp || !kp->name || !val) |
| 8842 | return -EINVAL; |
| 8843 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8844 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 8845 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 8846 | WARN_ON(ibm == NULL); |
| 8847 | |
| 8848 | if (!ibm || !ibm->name) |
| 8849 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8850 | |
| 8851 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 8852 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8853 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8854 | strcpy(ibms_init[i].param, val); |
| 8855 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8856 | return 0; |
| 8857 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8858 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8859 | |
| 8860 | return -EINVAL; |
| 8861 | } |
| 8862 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8863 | module_param(experimental, int, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8864 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8865 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8866 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 8867 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8868 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 8869 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8870 | module_param(force_load, bool, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8871 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8872 | "Attempts to load the driver even on a " |
| 8873 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 8874 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8875 | module_param_named(fan_control, fan_control_allowed, bool, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8876 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8877 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8878 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8879 | module_param_named(brightness_mode, brightness_mode, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8880 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8881 | "Selects brightness control strategy: " |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 8882 | "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 8883 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8884 | module_param(brightness_enable, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8885 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8886 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 8887 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8888 | module_param(hotkey_report_mode, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8889 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8890 | "used for backwards compatibility with userspace, " |
| 8891 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8892 | |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 8893 | #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 8894 | module_param_named(volume_mode, volume_mode, uint, 0444); |
| 8895 | MODULE_PARM_DESC(volume_mode, |
| 8896 | "Selects volume control strategy: " |
| 8897 | "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM"); |
| 8898 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 8899 | module_param_named(volume_capabilities, volume_capabilities, uint, 0444); |
| 8900 | MODULE_PARM_DESC(volume_capabilities, |
| 8901 | "Selects the mixer capabilites: " |
| 8902 | "0=auto, 1=volume and mute, 2=mute only"); |
| 8903 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 8904 | module_param_named(volume_control, volume_control_allowed, bool, 0444); |
| 8905 | MODULE_PARM_DESC(volume_control, |
| 8906 | "Enables software override for the console audio " |
| 8907 | "control when true"); |
| 8908 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 8909 | /* ALSA module API parameters */ |
| 8910 | module_param_named(index, alsa_index, int, 0444); |
| 8911 | MODULE_PARM_DESC(index, "ALSA index for the ACPI EC Mixer"); |
| 8912 | module_param_named(id, alsa_id, charp, 0444); |
| 8913 | MODULE_PARM_DESC(id, "ALSA id for the ACPI EC Mixer"); |
| 8914 | module_param_named(enable, alsa_enable, bool, 0444); |
| 8915 | 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] | 8916 | #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 8917 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8918 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8919 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 8920 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8921 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8922 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8923 | TPACPI_PARAM(hotkey); |
| 8924 | TPACPI_PARAM(bluetooth); |
| 8925 | TPACPI_PARAM(video); |
| 8926 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8927 | TPACPI_PARAM(cmos); |
| 8928 | TPACPI_PARAM(led); |
| 8929 | TPACPI_PARAM(beep); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8930 | TPACPI_PARAM(brightness); |
| 8931 | TPACPI_PARAM(volume); |
| 8932 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8933 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8934 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8935 | module_param(dbg_wlswemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8936 | MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation"); |
| 8937 | module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0); |
| 8938 | MODULE_PARM_DESC(wlsw_state, |
| 8939 | "Initial state of the emulated WLSW switch"); |
| 8940 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8941 | module_param(dbg_bluetoothemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8942 | MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation"); |
| 8943 | module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0); |
| 8944 | MODULE_PARM_DESC(bluetooth_state, |
| 8945 | "Initial state of the emulated bluetooth switch"); |
| 8946 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8947 | module_param(dbg_wwanemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8948 | MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation"); |
| 8949 | module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0); |
| 8950 | MODULE_PARM_DESC(wwan_state, |
| 8951 | "Initial state of the emulated WWAN switch"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8952 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8953 | module_param(dbg_uwbemul, uint, 0444); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8954 | MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation"); |
| 8955 | module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0); |
| 8956 | MODULE_PARM_DESC(uwb_state, |
| 8957 | "Initial state of the emulated UWB switch"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8958 | #endif |
| 8959 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8960 | static void thinkpad_acpi_module_exit(void) |
| 8961 | { |
| 8962 | struct ibm_struct *ibm, *itmp; |
| 8963 | |
| 8964 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 8965 | |
| 8966 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 8967 | &tpacpi_all_drivers, |
| 8968 | all_drivers) { |
| 8969 | ibm_exit(ibm); |
| 8970 | } |
| 8971 | |
| 8972 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 8973 | |
| 8974 | if (tpacpi_inputdev) { |
| 8975 | if (tp_features.input_device_registered) |
| 8976 | input_unregister_device(tpacpi_inputdev); |
| 8977 | else |
| 8978 | input_free_device(tpacpi_inputdev); |
| 8979 | } |
| 8980 | |
| 8981 | if (tpacpi_hwmon) |
| 8982 | hwmon_device_unregister(tpacpi_hwmon); |
| 8983 | |
| 8984 | if (tp_features.sensors_pdev_attrs_registered) |
| 8985 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 8986 | &dev_attr_thinkpad_acpi_pdev_name); |
| 8987 | if (tpacpi_sensors_pdev) |
| 8988 | platform_device_unregister(tpacpi_sensors_pdev); |
| 8989 | if (tpacpi_pdev) |
| 8990 | platform_device_unregister(tpacpi_pdev); |
| 8991 | |
| 8992 | if (tp_features.sensors_pdrv_attrs_registered) |
| 8993 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 8994 | if (tp_features.platform_drv_attrs_registered) |
| 8995 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 8996 | |
| 8997 | if (tp_features.sensors_pdrv_registered) |
| 8998 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 8999 | |
| 9000 | if (tp_features.platform_drv_registered) |
| 9001 | platform_driver_unregister(&tpacpi_pdriver); |
| 9002 | |
| 9003 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9004 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 9005 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 9006 | if (tpacpi_wq) |
| 9007 | destroy_workqueue(tpacpi_wq); |
| 9008 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 9009 | kfree(thinkpad_id.bios_version_str); |
| 9010 | kfree(thinkpad_id.ec_version_str); |
| 9011 | kfree(thinkpad_id.model_str); |
| 9012 | } |
| 9013 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 9014 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9015 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9016 | { |
| 9017 | int ret, i; |
| 9018 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 9019 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 9020 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 9021 | /* Parameter checking */ |
| 9022 | if (hotkey_report_mode > 2) |
| 9023 | return -EINVAL; |
| 9024 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9025 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9026 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 9027 | ret = get_thinkpad_model_data(&thinkpad_id); |
| 9028 | if (ret) { |
| 9029 | printk(TPACPI_ERR |
| 9030 | "unable to get DMI data: %d\n", ret); |
| 9031 | thinkpad_acpi_module_exit(); |
| 9032 | return ret; |
| 9033 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9034 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9035 | if (ret) { |
| 9036 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 9037 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9039 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9040 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9041 | |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 9042 | thinkpad_acpi_init_banner(); |
| 9043 | tpacpi_check_outdated_fw(); |
| 9044 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9045 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 9046 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9047 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 9048 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
| 9049 | if (!tpacpi_wq) { |
| 9050 | thinkpad_acpi_module_exit(); |
| 9051 | return -ENOMEM; |
| 9052 | } |
| 9053 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9054 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9055 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9056 | printk(TPACPI_ERR |
| 9057 | "unable to create proc dir " TPACPI_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9058 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9059 | return -ENODEV; |
| 9060 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 9061 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9062 | ret = platform_driver_register(&tpacpi_pdriver); |
| 9063 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9064 | printk(TPACPI_ERR |
| 9065 | "unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9066 | thinkpad_acpi_module_exit(); |
| 9067 | return ret; |
| 9068 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 9069 | tp_features.platform_drv_registered = 1; |
| 9070 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9071 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 9072 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9073 | printk(TPACPI_ERR |
| 9074 | "unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9075 | thinkpad_acpi_module_exit(); |
| 9076 | return ret; |
| 9077 | } |
| 9078 | tp_features.sensors_pdrv_registered = 1; |
| 9079 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9080 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 9081 | if (!ret) { |
| 9082 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9083 | ret = tpacpi_create_driver_attributes( |
| 9084 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 9085 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9086 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9087 | printk(TPACPI_ERR |
| 9088 | "unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9089 | thinkpad_acpi_module_exit(); |
| 9090 | return ret; |
| 9091 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 9092 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9093 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9094 | |
| 9095 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9096 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9097 | NULL, 0); |
| 9098 | if (IS_ERR(tpacpi_pdev)) { |
| 9099 | ret = PTR_ERR(tpacpi_pdev); |
| 9100 | tpacpi_pdev = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9101 | printk(TPACPI_ERR "unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9102 | thinkpad_acpi_module_exit(); |
| 9103 | return ret; |
| 9104 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9105 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9106 | TPACPI_HWMON_DRVR_NAME, |
| 9107 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9108 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 9109 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 9110 | tpacpi_sensors_pdev = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9111 | printk(TPACPI_ERR |
| 9112 | "unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9113 | thinkpad_acpi_module_exit(); |
| 9114 | return ret; |
| 9115 | } |
| 9116 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 9117 | &dev_attr_thinkpad_acpi_pdev_name); |
| 9118 | if (ret) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9119 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9120 | "unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9121 | thinkpad_acpi_module_exit(); |
| 9122 | return ret; |
| 9123 | } |
| 9124 | tp_features.sensors_pdev_attrs_registered = 1; |
| 9125 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9126 | if (IS_ERR(tpacpi_hwmon)) { |
| 9127 | ret = PTR_ERR(tpacpi_hwmon); |
| 9128 | tpacpi_hwmon = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9129 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9130 | thinkpad_acpi_module_exit(); |
| 9131 | return ret; |
| 9132 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 9133 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9134 | tpacpi_inputdev = input_allocate_device(); |
| 9135 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9136 | printk(TPACPI_ERR "unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9137 | thinkpad_acpi_module_exit(); |
| 9138 | return -ENOMEM; |
| 9139 | } else { |
| 9140 | /* Prepare input device, but don't register */ |
| 9141 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9142 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9143 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 9144 | tpacpi_inputdev->id.vendor = thinkpad_id.vendor; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9145 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 9146 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
Henrique de Moraes Holschuh | d112ef9 | 2009-12-09 01:36:26 +0000 | [diff] [blame] | 9147 | tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9148 | } |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 9149 | |
| 9150 | /* Init subdriver dependencies */ |
| 9151 | tpacpi_detect_brightness_capabilities(); |
| 9152 | |
| 9153 | /* Init subdrivers */ |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9154 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 9155 | ret = ibm_init(&ibms_init[i]); |
| 9156 | if (ret >= 0 && *ibms_init[i].param) |
| 9157 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9158 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9159 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9160 | return ret; |
| 9161 | } |
| 9162 | } |
Henrique de Moraes Holschuh | b589ea4 | 2010-02-25 21:28:58 -0300 | [diff] [blame] | 9163 | |
| 9164 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
| 9165 | |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9166 | ret = input_register_device(tpacpi_inputdev); |
| 9167 | if (ret < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9168 | printk(TPACPI_ERR "unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9169 | thinkpad_acpi_module_exit(); |
| 9170 | return ret; |
| 9171 | } else { |
| 9172 | tp_features.input_device_registered = 1; |
| 9173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9174 | |
| 9175 | return 0; |
| 9176 | } |
| 9177 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 9178 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 9179 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9180 | /* |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 9181 | * This will autoload the driver in almost every ThinkPad |
| 9182 | * in widespread use. |
| 9183 | * |
| 9184 | * Only _VERY_ old models, like the 240, 240x and 570 lack |
| 9185 | * the HKEY event interface. |
| 9186 | */ |
| 9187 | MODULE_DEVICE_TABLE(acpi, ibm_htk_device_ids); |
| 9188 | |
| 9189 | /* |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9190 | * DMI matching for module autoloading |
| 9191 | * |
| 9192 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 9193 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 9194 | * |
| 9195 | * Only models listed in thinkwiki will be supported, so add yours |
| 9196 | * if it is not there yet. |
| 9197 | */ |
| 9198 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
Mathieu Chouquet-Stringer | b36a50f | 2009-03-14 16:35:26 +0100 | [diff] [blame] | 9199 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*") |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9200 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9201 | /* Ancient thinkpad BIOSes have to be identified by |
| 9202 | * BIOS type or model number, and there are far less |
| 9203 | * BIOS types than model numbers... */ |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 9204 | IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9205 | |
Henrique de Moraes Holschuh | f68f53a | 2009-04-14 02:44:12 +0000 | [diff] [blame] | 9206 | MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>"); |
| 9207 | MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9208 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 9209 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9210 | MODULE_LICENSE("GPL"); |
| 9211 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9212 | module_init(thinkpad_acpi_module_init); |
| 9213 | module_exit(thinkpad_acpi_module_exit); |