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 | b57f7e7 | 2009-04-14 02:44:14 +0000 | [diff] [blame] | 24 | #define TPACPI_VERSION "0.23" |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 25 | #define TPACPI_SYSFS_VERSION 0x020500 |
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> |
| 61 | |
| 62 | #include <linux/nvram.h> |
| 63 | #include <linux/proc_fs.h> |
| 64 | #include <linux/sysfs.h> |
| 65 | #include <linux/backlight.h> |
| 66 | #include <linux/fb.h> |
| 67 | #include <linux/platform_device.h> |
| 68 | #include <linux/hwmon.h> |
| 69 | #include <linux/hwmon-sysfs.h> |
| 70 | #include <linux/input.h> |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 71 | #include <linux/leds.h> |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 72 | #include <linux/rfkill.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 73 | #include <asm/uaccess.h> |
| 74 | |
| 75 | #include <linux/dmi.h> |
| 76 | #include <linux/jiffies.h> |
| 77 | #include <linux/workqueue.h> |
| 78 | |
| 79 | #include <acpi/acpi_drivers.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 80 | |
| 81 | #include <linux/pci_ids.h> |
| 82 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 83 | |
| 84 | /* ThinkPad CMOS commands */ |
| 85 | #define TP_CMOS_VOLUME_DOWN 0 |
| 86 | #define TP_CMOS_VOLUME_UP 1 |
| 87 | #define TP_CMOS_VOLUME_MUTE 2 |
| 88 | #define TP_CMOS_BRIGHTNESS_UP 4 |
| 89 | #define TP_CMOS_BRIGHTNESS_DOWN 5 |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 90 | #define TP_CMOS_THINKLIGHT_ON 12 |
| 91 | #define TP_CMOS_THINKLIGHT_OFF 13 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 92 | |
| 93 | /* NVRAM Addresses */ |
| 94 | enum tp_nvram_addr { |
| 95 | TP_NVRAM_ADDR_HK2 = 0x57, |
| 96 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, |
| 97 | TP_NVRAM_ADDR_VIDEO = 0x59, |
| 98 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, |
| 99 | TP_NVRAM_ADDR_MIXER = 0x60, |
| 100 | }; |
| 101 | |
| 102 | /* NVRAM bit masks */ |
| 103 | enum { |
| 104 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, |
| 105 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, |
| 106 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, |
| 107 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, |
| 108 | TP_NVRAM_MASK_THINKLIGHT = 0x10, |
| 109 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, |
| 110 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, |
| 111 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, |
| 112 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, |
| 113 | TP_NVRAM_MASK_MUTE = 0x40, |
| 114 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, |
| 115 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, |
| 116 | TP_NVRAM_POS_LEVEL_VOLUME = 0, |
| 117 | }; |
| 118 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 119 | /* ACPI HIDs */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 120 | #define TPACPI_ACPI_HKEY_HID "IBM0068" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 121 | |
| 122 | /* Input IDs */ |
| 123 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ |
| 124 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 |
| 125 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 126 | /* ACPI \WGSV commands */ |
| 127 | enum { |
| 128 | TP_ACPI_WGSV_GET_STATE = 0x01, /* Get state information */ |
| 129 | TP_ACPI_WGSV_PWR_ON_ON_RESUME = 0x02, /* Resume WWAN powered on */ |
| 130 | TP_ACPI_WGSV_PWR_OFF_ON_RESUME = 0x03, /* Resume WWAN powered off */ |
| 131 | TP_ACPI_WGSV_SAVE_STATE = 0x04, /* Save state for S4/S5 */ |
| 132 | }; |
| 133 | |
| 134 | /* TP_ACPI_WGSV_GET_STATE bits */ |
| 135 | enum { |
| 136 | TP_ACPI_WGSV_STATE_WWANEXIST = 0x0001, /* WWAN hw available */ |
| 137 | TP_ACPI_WGSV_STATE_WWANPWR = 0x0002, /* WWAN radio enabled */ |
| 138 | TP_ACPI_WGSV_STATE_WWANPWRRES = 0x0004, /* WWAN state at resume */ |
| 139 | TP_ACPI_WGSV_STATE_WWANBIOSOFF = 0x0008, /* WWAN disabled in BIOS */ |
| 140 | TP_ACPI_WGSV_STATE_BLTHEXIST = 0x0001, /* BLTH hw available */ |
| 141 | TP_ACPI_WGSV_STATE_BLTHPWR = 0x0002, /* BLTH radio enabled */ |
| 142 | TP_ACPI_WGSV_STATE_BLTHPWRRES = 0x0004, /* BLTH state at resume */ |
| 143 | TP_ACPI_WGSV_STATE_BLTHBIOSOFF = 0x0008, /* BLTH disabled in BIOS */ |
| 144 | TP_ACPI_WGSV_STATE_UWBEXIST = 0x0010, /* UWB hw available */ |
| 145 | TP_ACPI_WGSV_STATE_UWBPWR = 0x0020, /* UWB radio enabled */ |
| 146 | }; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 147 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 148 | /* HKEY events */ |
| 149 | enum tpacpi_hkey_event_t { |
| 150 | /* Hotkey-related */ |
| 151 | TP_HKEY_EV_HOTKEY_BASE = 0x1001, /* first hotkey (FN+F1) */ |
| 152 | TP_HKEY_EV_BRGHT_UP = 0x1010, /* Brightness up */ |
| 153 | TP_HKEY_EV_BRGHT_DOWN = 0x1011, /* Brightness down */ |
| 154 | TP_HKEY_EV_VOL_UP = 0x1015, /* Volume up or unmute */ |
| 155 | TP_HKEY_EV_VOL_DOWN = 0x1016, /* Volume down or unmute */ |
| 156 | TP_HKEY_EV_VOL_MUTE = 0x1017, /* Mixer output mute */ |
| 157 | |
| 158 | /* Reasons for waking up from S3/S4 */ |
| 159 | TP_HKEY_EV_WKUP_S3_UNDOCK = 0x2304, /* undock requested, S3 */ |
| 160 | TP_HKEY_EV_WKUP_S4_UNDOCK = 0x2404, /* undock requested, S4 */ |
| 161 | TP_HKEY_EV_WKUP_S3_BAYEJ = 0x2305, /* bay ejection req, S3 */ |
| 162 | TP_HKEY_EV_WKUP_S4_BAYEJ = 0x2405, /* bay ejection req, S4 */ |
| 163 | TP_HKEY_EV_WKUP_S3_BATLOW = 0x2313, /* battery empty, S3 */ |
| 164 | TP_HKEY_EV_WKUP_S4_BATLOW = 0x2413, /* battery empty, S4 */ |
| 165 | |
| 166 | /* Auto-sleep after eject request */ |
| 167 | TP_HKEY_EV_BAYEJ_ACK = 0x3003, /* bay ejection complete */ |
| 168 | TP_HKEY_EV_UNDOCK_ACK = 0x4003, /* undock complete */ |
| 169 | |
| 170 | /* Misc bay events */ |
| 171 | TP_HKEY_EV_OPTDRV_EJ = 0x3006, /* opt. drive tray ejected */ |
| 172 | |
| 173 | /* User-interface events */ |
| 174 | TP_HKEY_EV_LID_CLOSE = 0x5001, /* laptop lid closed */ |
| 175 | TP_HKEY_EV_LID_OPEN = 0x5002, /* laptop lid opened */ |
| 176 | TP_HKEY_EV_TABLET_TABLET = 0x5009, /* tablet swivel up */ |
| 177 | TP_HKEY_EV_TABLET_NOTEBOOK = 0x500a, /* tablet swivel down */ |
| 178 | TP_HKEY_EV_PEN_INSERTED = 0x500b, /* tablet pen inserted */ |
| 179 | TP_HKEY_EV_PEN_REMOVED = 0x500c, /* tablet pen removed */ |
| 180 | TP_HKEY_EV_BRGHT_CHANGED = 0x5010, /* backlight control event */ |
| 181 | |
| 182 | /* Thermal events */ |
| 183 | TP_HKEY_EV_ALARM_BAT_HOT = 0x6011, /* battery too hot */ |
| 184 | TP_HKEY_EV_ALARM_BAT_XHOT = 0x6012, /* battery critically hot */ |
| 185 | TP_HKEY_EV_ALARM_SENSOR_HOT = 0x6021, /* sensor too hot */ |
| 186 | TP_HKEY_EV_ALARM_SENSOR_XHOT = 0x6022, /* sensor critically hot */ |
| 187 | TP_HKEY_EV_THM_TABLE_CHANGED = 0x6030, /* thermal table changed */ |
| 188 | |
| 189 | /* Misc */ |
| 190 | TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */ |
| 191 | }; |
| 192 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 193 | /**************************************************************************** |
| 194 | * Main driver |
| 195 | */ |
| 196 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 197 | #define TPACPI_NAME "thinkpad" |
| 198 | #define TPACPI_DESC "ThinkPad ACPI Extras" |
| 199 | #define TPACPI_FILE TPACPI_NAME "_acpi" |
| 200 | #define TPACPI_URL "http://ibm-acpi.sf.net/" |
| 201 | #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 202 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 203 | #define TPACPI_PROC_DIR "ibm" |
| 204 | #define TPACPI_ACPI_EVENT_PREFIX "ibm" |
| 205 | #define TPACPI_DRVR_NAME TPACPI_FILE |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 206 | #define TPACPI_DRVR_SHORTNAME "tpacpi" |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 207 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 208 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 209 | #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd" |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 210 | #define TPACPI_WORKQUEUE_NAME "ktpacpid" |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 211 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 212 | #define TPACPI_MAX_ACPI_ARGS 3 |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 213 | |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 214 | /* printk headers */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 215 | #define TPACPI_LOG TPACPI_FILE ": " |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 216 | #define TPACPI_EMERG KERN_EMERG TPACPI_LOG |
| 217 | #define TPACPI_ALERT KERN_ALERT TPACPI_LOG |
| 218 | #define TPACPI_CRIT KERN_CRIT TPACPI_LOG |
| 219 | #define TPACPI_ERR KERN_ERR TPACPI_LOG |
| 220 | #define TPACPI_WARN KERN_WARNING TPACPI_LOG |
| 221 | #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG |
| 222 | #define TPACPI_INFO KERN_INFO TPACPI_LOG |
| 223 | #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 224 | |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 225 | /* Debugging printk groups */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 226 | #define TPACPI_DBG_ALL 0xffff |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 227 | #define TPACPI_DBG_DISCLOSETASK 0x8000 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 228 | #define TPACPI_DBG_INIT 0x0001 |
| 229 | #define TPACPI_DBG_EXIT 0x0002 |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 230 | #define TPACPI_DBG_RFKILL 0x0004 |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 231 | #define TPACPI_DBG_HKEY 0x0008 |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 232 | #define TPACPI_DBG_FAN 0x0010 |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 233 | #define TPACPI_DBG_BRGHT 0x0020 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 234 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 235 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 236 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 237 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 238 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 239 | |
| 240 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 241 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 242 | */ |
| 243 | |
| 244 | struct ibm_struct; |
| 245 | |
| 246 | struct tp_acpi_drv_struct { |
| 247 | const struct acpi_device_id *hid; |
| 248 | struct acpi_driver *driver; |
| 249 | |
| 250 | void (*notify) (struct ibm_struct *, u32); |
| 251 | acpi_handle *handle; |
| 252 | u32 type; |
| 253 | struct acpi_device *device; |
| 254 | }; |
| 255 | |
| 256 | struct ibm_struct { |
| 257 | char *name; |
| 258 | |
| 259 | int (*read) (char *); |
| 260 | int (*write) (char *); |
| 261 | void (*exit) (void); |
| 262 | void (*resume) (void); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 263 | void (*suspend) (pm_message_t state); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 264 | void (*shutdown) (void); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 265 | |
| 266 | struct list_head all_drivers; |
| 267 | |
| 268 | struct tp_acpi_drv_struct *acpi; |
| 269 | |
| 270 | struct { |
| 271 | u8 acpi_driver_registered:1; |
| 272 | u8 acpi_notify_installed:1; |
| 273 | u8 proc_created:1; |
| 274 | u8 init_called:1; |
| 275 | u8 experimental:1; |
| 276 | } flags; |
| 277 | }; |
| 278 | |
| 279 | struct ibm_init_struct { |
| 280 | char param[32]; |
| 281 | |
| 282 | int (*init) (struct ibm_init_struct *); |
| 283 | struct ibm_struct *data; |
| 284 | }; |
| 285 | |
| 286 | static struct { |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 287 | u32 bluetooth:1; |
| 288 | u32 hotkey:1; |
| 289 | u32 hotkey_mask:1; |
| 290 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 291 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 292 | u32 light:1; |
| 293 | u32 light_status:1; |
| 294 | u32 bright_16levels:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 295 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 296 | u32 wan:1; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 297 | u32 uwb:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 298 | u32 fan_ctrl_status_undef:1; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 299 | u32 second_fan:1; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 300 | u32 beep_needs_two_args:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 301 | u32 input_device_registered:1; |
| 302 | u32 platform_drv_registered:1; |
| 303 | u32 platform_drv_attrs_registered:1; |
| 304 | u32 sensors_pdrv_registered:1; |
| 305 | u32 sensors_pdrv_attrs_registered:1; |
| 306 | u32 sensors_pdev_attrs_registered:1; |
| 307 | u32 hotkey_poll_active:1; |
| 308 | } tp_features; |
| 309 | |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 310 | static struct { |
| 311 | u16 hotkey_mask_ff:1; |
| 312 | } tp_warned; |
| 313 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 314 | struct thinkpad_id_data { |
| 315 | unsigned int vendor; /* ThinkPad vendor: |
| 316 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 317 | |
| 318 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 319 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 320 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 321 | u16 bios_model; /* 1Y = 0x5931, 0 = unknown */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 322 | u16 ec_model; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 323 | u16 bios_release; /* 1ZETK1WW = 0x314b, 0 = unknown */ |
| 324 | u16 ec_release; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 325 | |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 326 | char *model_str; /* ThinkPad T43 */ |
| 327 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 328 | }; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 329 | static struct thinkpad_id_data thinkpad_id; |
| 330 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 331 | static enum { |
| 332 | TPACPI_LIFE_INIT = 0, |
| 333 | TPACPI_LIFE_RUNNING, |
| 334 | TPACPI_LIFE_EXITING, |
| 335 | } tpacpi_lifecycle; |
| 336 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 337 | static int experimental; |
| 338 | static u32 dbg_level; |
| 339 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 340 | static struct workqueue_struct *tpacpi_wq; |
| 341 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 342 | enum led_status_t { |
| 343 | TPACPI_LED_OFF = 0, |
| 344 | TPACPI_LED_ON, |
| 345 | TPACPI_LED_BLINK, |
| 346 | }; |
| 347 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 348 | /* Special LED class that can defer work */ |
| 349 | struct tpacpi_led_classdev { |
| 350 | struct led_classdev led_classdev; |
| 351 | struct work_struct work; |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 352 | enum led_status_t new_state; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 353 | unsigned int led; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 354 | }; |
| 355 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 356 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 357 | static int dbg_wlswemul; |
| 358 | static int tpacpi_wlsw_emulstate; |
| 359 | static int dbg_bluetoothemul; |
| 360 | static int tpacpi_bluetooth_emulstate; |
| 361 | static int dbg_wwanemul; |
| 362 | static int tpacpi_wwan_emulstate; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 363 | static int dbg_uwbemul; |
| 364 | static int tpacpi_uwb_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 365 | #endif |
| 366 | |
| 367 | |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 368 | /************************************************************************* |
| 369 | * Debugging helpers |
| 370 | */ |
| 371 | |
| 372 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 373 | do { if (dbg_level & (a_dbg_level)) \ |
| 374 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ |
| 375 | } while (0) |
| 376 | |
| 377 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 378 | #define vdbg_printk dbg_printk |
| 379 | static const char *str_supported(int is_supported); |
| 380 | #else |
| 381 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 382 | do { } while (0) |
| 383 | #endif |
| 384 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 385 | static void tpacpi_log_usertask(const char * const what) |
| 386 | { |
| 387 | printk(TPACPI_DEBUG "%s: access by process with PID %d\n", |
| 388 | what, task_tgid_vnr(current)); |
| 389 | } |
| 390 | |
| 391 | #define tpacpi_disclose_usertask(what, format, arg...) \ |
| 392 | do { \ |
| 393 | if (unlikely( \ |
| 394 | (dbg_level & TPACPI_DBG_DISCLOSETASK) && \ |
| 395 | (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \ |
| 396 | printk(TPACPI_DEBUG "%s: PID %d: " format, \ |
| 397 | what, task_tgid_vnr(current), ## arg); \ |
| 398 | } \ |
| 399 | } while (0) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 400 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 401 | /* |
| 402 | * Quirk handling helpers |
| 403 | * |
| 404 | * ThinkPad IDs and versions seen in the field so far |
| 405 | * are two-characters from the set [0-9A-Z], i.e. base 36. |
| 406 | * |
| 407 | * We use values well outside that range as specials. |
| 408 | */ |
| 409 | |
| 410 | #define TPACPI_MATCH_ANY 0xffffU |
| 411 | #define TPACPI_MATCH_UNKNOWN 0U |
| 412 | |
| 413 | /* TPID('1', 'Y') == 0x5931 */ |
| 414 | #define TPID(__c1, __c2) (((__c2) << 8) | (__c1)) |
| 415 | |
| 416 | #define TPACPI_Q_IBM(__id1, __id2, __quirk) \ |
| 417 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 418 | .bios = TPID(__id1, __id2), \ |
| 419 | .ec = TPACPI_MATCH_ANY, \ |
| 420 | .quirks = (__quirk) } |
| 421 | |
| 422 | #define TPACPI_Q_LNV(__id1, __id2, __quirk) \ |
| 423 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 424 | .bios = TPID(__id1, __id2), \ |
| 425 | .ec = TPACPI_MATCH_ANY, \ |
| 426 | .quirks = (__quirk) } |
| 427 | |
| 428 | struct tpacpi_quirk { |
| 429 | unsigned int vendor; |
| 430 | u16 bios; |
| 431 | u16 ec; |
| 432 | unsigned long quirks; |
| 433 | }; |
| 434 | |
| 435 | /** |
| 436 | * tpacpi_check_quirks() - search BIOS/EC version on a list |
| 437 | * @qlist: array of &struct tpacpi_quirk |
| 438 | * @qlist_size: number of elements in @qlist |
| 439 | * |
| 440 | * Iterates over a quirks list until one is found that matches the |
| 441 | * ThinkPad's vendor, BIOS and EC model. |
| 442 | * |
| 443 | * Returns 0 if nothing matches, otherwise returns the quirks field of |
| 444 | * the matching &struct tpacpi_quirk entry. |
| 445 | * |
| 446 | * The match criteria is: vendor, ec and bios much match. |
| 447 | */ |
| 448 | static unsigned long __init tpacpi_check_quirks( |
| 449 | const struct tpacpi_quirk *qlist, |
| 450 | unsigned int qlist_size) |
| 451 | { |
| 452 | while (qlist_size) { |
| 453 | if ((qlist->vendor == thinkpad_id.vendor || |
| 454 | qlist->vendor == TPACPI_MATCH_ANY) && |
| 455 | (qlist->bios == thinkpad_id.bios_model || |
| 456 | qlist->bios == TPACPI_MATCH_ANY) && |
| 457 | (qlist->ec == thinkpad_id.ec_model || |
| 458 | qlist->ec == TPACPI_MATCH_ANY)) |
| 459 | return qlist->quirks; |
| 460 | |
| 461 | qlist_size--; |
| 462 | qlist++; |
| 463 | } |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 468 | /**************************************************************************** |
| 469 | **************************************************************************** |
| 470 | * |
| 471 | * ACPI Helpers and device model |
| 472 | * |
| 473 | **************************************************************************** |
| 474 | ****************************************************************************/ |
| 475 | |
| 476 | /************************************************************************* |
| 477 | * ACPI basic handles |
| 478 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 480 | static acpi_handle root_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 482 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | static acpi_handle object##_handle; \ |
| 484 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 485 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | static char *object##_paths[] = { paths } |
| 487 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 488 | TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 489 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 490 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 491 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 492 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 493 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 494 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 495 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 497 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 498 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 500 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 501 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 502 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 503 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 504 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 505 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 506 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 507 | "^HKEY", /* R30, R31 */ |
| 508 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 509 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 510 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 511 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 512 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 513 | "\\_SB.PCI0.VID0", /* 770e */ |
| 514 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 515 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 516 | ); /* R30, R31 */ |
| 517 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 518 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 519 | /************************************************************************* |
| 520 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 521 | */ |
| 522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | static int acpi_evalf(acpi_handle handle, |
| 524 | void *res, char *method, char *fmt, ...) |
| 525 | { |
| 526 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 527 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 528 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 529 | struct acpi_buffer result, *resultp; |
| 530 | union acpi_object out_obj; |
| 531 | acpi_status status; |
| 532 | va_list ap; |
| 533 | char res_type; |
| 534 | int success; |
| 535 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
| 537 | if (!*fmt) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 538 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | if (*fmt == 'q') { |
| 543 | quiet = 1; |
| 544 | fmt++; |
| 545 | } else |
| 546 | quiet = 0; |
| 547 | |
| 548 | res_type = *(fmt++); |
| 549 | |
| 550 | params.count = 0; |
| 551 | params.pointer = &in_objs[0]; |
| 552 | |
| 553 | va_start(ap, fmt); |
| 554 | while (*fmt) { |
| 555 | char c = *(fmt++); |
| 556 | switch (c) { |
| 557 | case 'd': /* int */ |
| 558 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 559 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 560 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 561 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 563 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | "with invalid format character '%c'\n", c); |
| 565 | return 0; |
| 566 | } |
| 567 | } |
| 568 | va_end(ap); |
| 569 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 570 | if (res_type != 'v') { |
| 571 | result.length = sizeof(out_obj); |
| 572 | result.pointer = &out_obj; |
| 573 | resultp = &result; |
| 574 | } else |
| 575 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 577 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
| 579 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 580 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | if (res) |
| 582 | *(int *)res = out_obj.integer.value; |
| 583 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 584 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 585 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | success = status == AE_OK; |
| 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", res_type); |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | if (!success && !quiet) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 596 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | method, fmt0, status); |
| 598 | |
| 599 | return success; |
| 600 | } |
| 601 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 602 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 603 | { |
| 604 | int v; |
| 605 | |
| 606 | if (ecrd_handle) { |
| 607 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 608 | return 0; |
| 609 | *p = v; |
| 610 | } else { |
| 611 | if (ec_read(i, p) < 0) |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | return 1; |
| 616 | } |
| 617 | |
| 618 | static int acpi_ec_write(int i, u8 v) |
| 619 | { |
| 620 | if (ecwr_handle) { |
| 621 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 622 | return 0; |
| 623 | } else { |
| 624 | if (ec_write(i, v) < 0) |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | return 1; |
| 629 | } |
| 630 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 631 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 632 | { |
| 633 | if (!cmos_handle) |
| 634 | return -ENXIO; |
| 635 | |
| 636 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 637 | return -EIO; |
| 638 | |
| 639 | return 0; |
| 640 | } |
| 641 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 642 | /************************************************************************* |
| 643 | * ACPI device model |
| 644 | */ |
| 645 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 646 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 647 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 648 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
| 649 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 650 | static void drv_acpi_handle_init(char *name, |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 651 | acpi_handle *handle, acpi_handle parent, |
| 652 | char **paths, int num_paths, char **path) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 653 | { |
| 654 | int i; |
| 655 | acpi_status status; |
| 656 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 657 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 658 | name); |
| 659 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 660 | for (i = 0; i < num_paths; i++) { |
| 661 | status = acpi_get_handle(parent, paths[i], handle); |
| 662 | if (ACPI_SUCCESS(status)) { |
| 663 | *path = paths[i]; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 664 | dbg_printk(TPACPI_DBG_INIT, |
| 665 | "Found ACPI handle %s for %s\n", |
| 666 | *path, name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 667 | return; |
| 668 | } |
| 669 | } |
| 670 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 671 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 672 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 673 | *handle = NULL; |
| 674 | } |
| 675 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 676 | 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] | 677 | { |
| 678 | struct ibm_struct *ibm = data; |
| 679 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 680 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 681 | return; |
| 682 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 683 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 684 | return; |
| 685 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 686 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 687 | } |
| 688 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 689 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 690 | { |
| 691 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 692 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 693 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 694 | BUG_ON(!ibm->acpi); |
| 695 | |
| 696 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 697 | return 0; |
| 698 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 699 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 700 | "setting up ACPI notify for %s\n", ibm->name); |
| 701 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 702 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 703 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 704 | 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] | 705 | ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 706 | return -ENODEV; |
| 707 | } |
| 708 | |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 709 | ibm->acpi->device->driver_data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 710 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 711 | TPACPI_ACPI_EVENT_PREFIX, |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 712 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 713 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 714 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 715 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 716 | if (ACPI_FAILURE(status)) { |
| 717 | if (status == AE_ALREADY_EXISTS) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 718 | printk(TPACPI_NOTICE |
| 719 | "another device driver is already " |
| 720 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 721 | } else { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 722 | printk(TPACPI_ERR |
| 723 | "acpi_install_notify_handler(%s) failed: %d\n", |
| 724 | ibm->name, status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 725 | } |
| 726 | return -ENODEV; |
| 727 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 728 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 729 | return 0; |
| 730 | } |
| 731 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 732 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 733 | { |
| 734 | return 0; |
| 735 | } |
| 736 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 737 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 738 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 739 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 740 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 741 | dbg_printk(TPACPI_DBG_INIT, |
| 742 | "registering %s as an ACPI driver\n", ibm->name); |
| 743 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 744 | BUG_ON(!ibm->acpi); |
| 745 | |
| 746 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 747 | if (!ibm->acpi->driver) { |
Mariusz Kozlowski | 4f778b9 | 2008-10-18 14:23:53 -0300 | [diff] [blame] | 748 | printk(TPACPI_ERR |
| 749 | "failed to allocate memory for ibm->acpi->driver\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 750 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 751 | } |
| 752 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 753 | 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] | 754 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 755 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 756 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 757 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 758 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 759 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 760 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 761 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 762 | kfree(ibm->acpi->driver); |
| 763 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 764 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 765 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 766 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 767 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | |
| 771 | /**************************************************************************** |
| 772 | **************************************************************************** |
| 773 | * |
| 774 | * Procfs Helpers |
| 775 | * |
| 776 | **************************************************************************** |
| 777 | ****************************************************************************/ |
| 778 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 779 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 780 | int count, int *eof, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 781 | { |
| 782 | struct ibm_struct *ibm = data; |
| 783 | int len; |
| 784 | |
| 785 | if (!ibm || !ibm->read) |
| 786 | return -EINVAL; |
| 787 | |
| 788 | len = ibm->read(page); |
| 789 | if (len < 0) |
| 790 | return len; |
| 791 | |
| 792 | if (len <= off + count) |
| 793 | *eof = 1; |
| 794 | *start = page + off; |
| 795 | len -= off; |
| 796 | if (len > count) |
| 797 | len = count; |
| 798 | if (len < 0) |
| 799 | len = 0; |
| 800 | |
| 801 | return len; |
| 802 | } |
| 803 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 804 | static int dispatch_procfs_write(struct file *file, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 805 | const char __user *userbuf, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 806 | unsigned long count, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 807 | { |
| 808 | struct ibm_struct *ibm = data; |
| 809 | char *kernbuf; |
| 810 | int ret; |
| 811 | |
| 812 | if (!ibm || !ibm->write) |
| 813 | return -EINVAL; |
Michael Buesch | 5b05d46 | 2009-08-01 12:04:19 -0300 | [diff] [blame] | 814 | if (count > PAGE_SIZE - 2) |
| 815 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 816 | |
| 817 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 818 | if (!kernbuf) |
| 819 | return -ENOMEM; |
| 820 | |
| 821 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 822 | kfree(kernbuf); |
| 823 | return -EFAULT; |
| 824 | } |
| 825 | |
| 826 | kernbuf[count] = 0; |
| 827 | strcat(kernbuf, ","); |
| 828 | ret = ibm->write(kernbuf); |
| 829 | if (ret == 0) |
| 830 | ret = count; |
| 831 | |
| 832 | kfree(kernbuf); |
| 833 | |
| 834 | return ret; |
| 835 | } |
| 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | static char *next_cmd(char **cmds) |
| 838 | { |
| 839 | char *start = *cmds; |
| 840 | char *end; |
| 841 | |
| 842 | while ((end = strchr(start, ',')) && end == start) |
| 843 | start = end + 1; |
| 844 | |
| 845 | if (!end) |
| 846 | return NULL; |
| 847 | |
| 848 | *end = 0; |
| 849 | *cmds = end + 1; |
| 850 | return start; |
| 851 | } |
| 852 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 853 | |
| 854 | /**************************************************************************** |
| 855 | **************************************************************************** |
| 856 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 857 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 858 | * |
| 859 | **************************************************************************** |
| 860 | ****************************************************************************/ |
| 861 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 862 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 863 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 864 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 865 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 866 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 867 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 868 | |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 869 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
| 870 | pm_message_t state) |
| 871 | { |
| 872 | struct ibm_struct *ibm, *itmp; |
| 873 | |
| 874 | list_for_each_entry_safe(ibm, itmp, |
| 875 | &tpacpi_all_drivers, |
| 876 | all_drivers) { |
| 877 | if (ibm->suspend) |
| 878 | (ibm->suspend)(state); |
| 879 | } |
| 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 884 | static int tpacpi_resume_handler(struct platform_device *pdev) |
| 885 | { |
| 886 | struct ibm_struct *ibm, *itmp; |
| 887 | |
| 888 | list_for_each_entry_safe(ibm, itmp, |
| 889 | &tpacpi_all_drivers, |
| 890 | all_drivers) { |
| 891 | if (ibm->resume) |
| 892 | (ibm->resume)(); |
| 893 | } |
| 894 | |
| 895 | return 0; |
| 896 | } |
| 897 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 898 | static void tpacpi_shutdown_handler(struct platform_device *pdev) |
| 899 | { |
| 900 | struct ibm_struct *ibm, *itmp; |
| 901 | |
| 902 | list_for_each_entry_safe(ibm, itmp, |
| 903 | &tpacpi_all_drivers, |
| 904 | all_drivers) { |
| 905 | if (ibm->shutdown) |
| 906 | (ibm->shutdown)(); |
| 907 | } |
| 908 | } |
| 909 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 910 | static struct platform_driver tpacpi_pdriver = { |
| 911 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 912 | .name = TPACPI_DRVR_NAME, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 913 | .owner = THIS_MODULE, |
| 914 | }, |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 915 | .suspend = tpacpi_suspend_handler, |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 916 | .resume = tpacpi_resume_handler, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 917 | .shutdown = tpacpi_shutdown_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 918 | }; |
| 919 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 920 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 921 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 922 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 923 | .owner = THIS_MODULE, |
| 924 | }, |
| 925 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 926 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 927 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 928 | * sysfs support helpers |
| 929 | */ |
| 930 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 931 | struct attribute_set { |
| 932 | unsigned int members, max_members; |
| 933 | struct attribute_group group; |
| 934 | }; |
| 935 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 936 | struct attribute_set_obj { |
| 937 | struct attribute_set s; |
| 938 | struct attribute *a; |
| 939 | } __attribute__((packed)); |
| 940 | |
| 941 | 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] | 942 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 943 | { |
| 944 | struct attribute_set_obj *sobj; |
| 945 | |
| 946 | if (max_members == 0) |
| 947 | return NULL; |
| 948 | |
| 949 | /* Allocates space for implicit NULL at the end too */ |
| 950 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 951 | max_members * sizeof(struct attribute *), |
| 952 | GFP_KERNEL); |
| 953 | if (!sobj) |
| 954 | return NULL; |
| 955 | sobj->s.max_members = max_members; |
| 956 | sobj->s.group.attrs = &sobj->a; |
| 957 | sobj->s.group.name = name; |
| 958 | |
| 959 | return &sobj->s; |
| 960 | } |
| 961 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 962 | #define destroy_attr_set(_set) \ |
| 963 | kfree(_set); |
| 964 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 965 | /* 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] | 966 | 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] | 967 | { |
| 968 | if (!s || !attr) |
| 969 | return -EINVAL; |
| 970 | |
| 971 | if (s->members >= s->max_members) |
| 972 | return -ENOMEM; |
| 973 | |
| 974 | s->group.attrs[s->members] = attr; |
| 975 | s->members++; |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 980 | 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] | 981 | struct attribute **attr, |
| 982 | unsigned int count) |
| 983 | { |
| 984 | int i, res; |
| 985 | |
| 986 | for (i = 0; i < count; i++) { |
| 987 | res = add_to_attr_set(s, attr[i]); |
| 988 | if (res) |
| 989 | return res; |
| 990 | } |
| 991 | |
| 992 | return 0; |
| 993 | } |
| 994 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 995 | 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] | 996 | { |
| 997 | sysfs_remove_group(kobj, &s->group); |
| 998 | destroy_attr_set(s); |
| 999 | } |
| 1000 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1001 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 1002 | sysfs_create_group(_kobj, &_attr_set->group) |
| 1003 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1004 | static int parse_strtoul(const char *buf, |
| 1005 | unsigned long max, unsigned long *value) |
| 1006 | { |
| 1007 | char *endp; |
| 1008 | |
Henrique de Moraes Holschuh | 32afbf0 | 2007-10-08 10:12:56 -0300 | [diff] [blame] | 1009 | while (*buf && isspace(*buf)) |
| 1010 | buf++; |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1011 | *value = simple_strtoul(buf, &endp, 0); |
| 1012 | while (*endp && isspace(*endp)) |
| 1013 | endp++; |
| 1014 | if (*endp || *value > max) |
| 1015 | return -EINVAL; |
| 1016 | |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 1020 | static void tpacpi_disable_brightness_delay(void) |
| 1021 | { |
| 1022 | if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0)) |
| 1023 | printk(TPACPI_NOTICE |
| 1024 | "ACPI backlight control delay disabled\n"); |
| 1025 | } |
| 1026 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 1027 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 1028 | { |
| 1029 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 1030 | union acpi_object *obj; |
| 1031 | int rc; |
| 1032 | |
| 1033 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { |
| 1034 | obj = (union acpi_object *)buffer.pointer; |
| 1035 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
| 1036 | printk(TPACPI_ERR "Unknown _BCL data, " |
| 1037 | "please report this to %s\n", TPACPI_MAIL); |
| 1038 | rc = 0; |
| 1039 | } else { |
| 1040 | rc = obj->package.count; |
| 1041 | } |
| 1042 | } else { |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
| 1046 | kfree(buffer.pointer); |
| 1047 | return rc; |
| 1048 | } |
| 1049 | |
| 1050 | static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle, |
| 1051 | u32 lvl, void *context, void **rv) |
| 1052 | { |
| 1053 | char name[ACPI_PATH_SEGMENT_LENGTH]; |
| 1054 | struct acpi_buffer buffer = { sizeof(name), &name }; |
| 1055 | |
| 1056 | if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && |
| 1057 | !strncmp("_BCL", name, sizeof(name) - 1)) { |
| 1058 | BUG_ON(!rv || !*rv); |
| 1059 | **(int **)rv = tpacpi_query_bcl_levels(handle); |
| 1060 | return AE_CTRL_TERMINATE; |
| 1061 | } else { |
| 1062 | return AE_OK; |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | /* |
| 1067 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 1068 | */ |
| 1069 | static int __init tpacpi_check_std_acpi_brightness_support(void) |
| 1070 | { |
| 1071 | int status; |
| 1072 | int bcl_levels = 0; |
| 1073 | void *bcl_ptr = &bcl_levels; |
| 1074 | |
| 1075 | if (!vid_handle) { |
| 1076 | TPACPI_ACPIHANDLE_INIT(vid); |
| 1077 | } |
| 1078 | if (!vid_handle) |
| 1079 | return 0; |
| 1080 | |
| 1081 | /* |
| 1082 | * Search for a _BCL method, and execute it. This is safe on all |
| 1083 | * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista |
| 1084 | * BIOS in ACPI backlight control mode. We do NOT have to care |
| 1085 | * about calling the _BCL method in an enabled video device, any |
| 1086 | * will do for our purposes. |
| 1087 | */ |
| 1088 | |
| 1089 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, |
| 1090 | tpacpi_acpi_walk_find_bcl, NULL, |
| 1091 | &bcl_ptr); |
| 1092 | |
| 1093 | if (ACPI_SUCCESS(status) && bcl_levels > 2) { |
| 1094 | tp_features.bright_acpimode = 1; |
| 1095 | return (bcl_levels - 2); |
| 1096 | } |
| 1097 | |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1101 | static void printk_deprecated_attribute(const char * const what, |
| 1102 | const char * const details) |
| 1103 | { |
| 1104 | tpacpi_log_usertask("deprecated sysfs attribute"); |
| 1105 | printk(TPACPI_WARN "WARNING: sysfs attribute %s is deprecated and " |
| 1106 | "will be removed. %s\n", |
| 1107 | what, details); |
| 1108 | } |
| 1109 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1110 | /************************************************************************* |
| 1111 | * rfkill and radio control support helpers |
| 1112 | */ |
| 1113 | |
| 1114 | /* |
| 1115 | * ThinkPad-ACPI firmware handling model: |
| 1116 | * |
| 1117 | * WLSW (master wireless switch) is event-driven, and is common to all |
| 1118 | * firmware-controlled radios. It cannot be controlled, just monitored, |
| 1119 | * as expected. It overrides all radio state in firmware |
| 1120 | * |
| 1121 | * The kernel, a masked-off hotkey, and WLSW can change the radio state |
| 1122 | * (TODO: verify how WLSW interacts with the returned radio state). |
| 1123 | * |
| 1124 | * The only time there are shadow radio state changes, is when |
| 1125 | * masked-off hotkeys are used. |
| 1126 | */ |
| 1127 | |
| 1128 | /* |
| 1129 | * Internal driver API for radio state: |
| 1130 | * |
| 1131 | * int: < 0 = error, otherwise enum tpacpi_rfkill_state |
| 1132 | * bool: true means radio blocked (off) |
| 1133 | */ |
| 1134 | enum tpacpi_rfkill_state { |
| 1135 | TPACPI_RFK_RADIO_OFF = 0, |
| 1136 | TPACPI_RFK_RADIO_ON |
| 1137 | }; |
| 1138 | |
| 1139 | /* rfkill switches */ |
| 1140 | enum tpacpi_rfk_id { |
| 1141 | TPACPI_RFK_BLUETOOTH_SW_ID = 0, |
| 1142 | TPACPI_RFK_WWAN_SW_ID, |
| 1143 | TPACPI_RFK_UWB_SW_ID, |
| 1144 | TPACPI_RFK_SW_MAX |
| 1145 | }; |
| 1146 | |
| 1147 | static const char *tpacpi_rfkill_names[] = { |
| 1148 | [TPACPI_RFK_BLUETOOTH_SW_ID] = "bluetooth", |
| 1149 | [TPACPI_RFK_WWAN_SW_ID] = "wwan", |
| 1150 | [TPACPI_RFK_UWB_SW_ID] = "uwb", |
| 1151 | [TPACPI_RFK_SW_MAX] = NULL |
| 1152 | }; |
| 1153 | |
| 1154 | /* ThinkPad-ACPI rfkill subdriver */ |
| 1155 | struct tpacpi_rfk { |
| 1156 | struct rfkill *rfkill; |
| 1157 | enum tpacpi_rfk_id id; |
| 1158 | const struct tpacpi_rfk_ops *ops; |
| 1159 | }; |
| 1160 | |
| 1161 | struct tpacpi_rfk_ops { |
| 1162 | /* firmware interface */ |
| 1163 | int (*get_status)(void); |
| 1164 | int (*set_status)(const enum tpacpi_rfkill_state); |
| 1165 | }; |
| 1166 | |
| 1167 | static struct tpacpi_rfk *tpacpi_rfkill_switches[TPACPI_RFK_SW_MAX]; |
| 1168 | |
| 1169 | /* Query FW and update rfkill sw state for a given rfkill switch */ |
| 1170 | static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk *tp_rfk) |
| 1171 | { |
| 1172 | int status; |
| 1173 | |
| 1174 | if (!tp_rfk) |
| 1175 | return -ENODEV; |
| 1176 | |
| 1177 | status = (tp_rfk->ops->get_status)(); |
| 1178 | if (status < 0) |
| 1179 | return status; |
| 1180 | |
| 1181 | rfkill_set_sw_state(tp_rfk->rfkill, |
| 1182 | (status == TPACPI_RFK_RADIO_OFF)); |
| 1183 | |
| 1184 | return status; |
| 1185 | } |
| 1186 | |
| 1187 | /* Query FW and update rfkill sw state for all rfkill switches */ |
| 1188 | static void tpacpi_rfk_update_swstate_all(void) |
| 1189 | { |
| 1190 | unsigned int i; |
| 1191 | |
| 1192 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) |
| 1193 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[i]); |
| 1194 | } |
| 1195 | |
| 1196 | /* |
| 1197 | * Sync the HW-blocking state of all rfkill switches, |
| 1198 | * do notice it causes the rfkill core to schedule uevents |
| 1199 | */ |
| 1200 | static void tpacpi_rfk_update_hwblock_state(bool blocked) |
| 1201 | { |
| 1202 | unsigned int i; |
| 1203 | struct tpacpi_rfk *tp_rfk; |
| 1204 | |
| 1205 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) { |
| 1206 | tp_rfk = tpacpi_rfkill_switches[i]; |
| 1207 | if (tp_rfk) { |
| 1208 | if (rfkill_set_hw_state(tp_rfk->rfkill, |
| 1209 | blocked)) { |
| 1210 | /* ignore -- we track sw block */ |
| 1211 | } |
| 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | /* Call to get the WLSW state from the firmware */ |
| 1217 | static int hotkey_get_wlsw(void); |
| 1218 | |
| 1219 | /* Call to query WLSW state and update all rfkill switches */ |
| 1220 | static bool tpacpi_rfk_check_hwblock_state(void) |
| 1221 | { |
| 1222 | int res = hotkey_get_wlsw(); |
| 1223 | int hw_blocked; |
| 1224 | |
| 1225 | /* When unknown or unsupported, we have to assume it is unblocked */ |
| 1226 | if (res < 0) |
| 1227 | return false; |
| 1228 | |
| 1229 | hw_blocked = (res == TPACPI_RFK_RADIO_OFF); |
| 1230 | tpacpi_rfk_update_hwblock_state(hw_blocked); |
| 1231 | |
| 1232 | return hw_blocked; |
| 1233 | } |
| 1234 | |
| 1235 | static int tpacpi_rfk_hook_set_block(void *data, bool blocked) |
| 1236 | { |
| 1237 | struct tpacpi_rfk *tp_rfk = data; |
| 1238 | int res; |
| 1239 | |
| 1240 | dbg_printk(TPACPI_DBG_RFKILL, |
| 1241 | "request to change radio state to %s\n", |
| 1242 | blocked ? "blocked" : "unblocked"); |
| 1243 | |
| 1244 | /* try to set radio state */ |
| 1245 | res = (tp_rfk->ops->set_status)(blocked ? |
| 1246 | TPACPI_RFK_RADIO_OFF : TPACPI_RFK_RADIO_ON); |
| 1247 | |
| 1248 | /* and update the rfkill core with whatever the FW really did */ |
| 1249 | tpacpi_rfk_update_swstate(tp_rfk); |
| 1250 | |
| 1251 | return (res < 0) ? res : 0; |
| 1252 | } |
| 1253 | |
| 1254 | static const struct rfkill_ops tpacpi_rfk_rfkill_ops = { |
| 1255 | .set_block = tpacpi_rfk_hook_set_block, |
| 1256 | }; |
| 1257 | |
| 1258 | static int __init tpacpi_new_rfkill(const enum tpacpi_rfk_id id, |
| 1259 | const struct tpacpi_rfk_ops *tp_rfkops, |
| 1260 | const enum rfkill_type rfktype, |
| 1261 | const char *name, |
| 1262 | const bool set_default) |
| 1263 | { |
| 1264 | struct tpacpi_rfk *atp_rfk; |
| 1265 | int res; |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1266 | bool sw_state = false; |
| 1267 | int sw_status; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1268 | |
| 1269 | BUG_ON(id >= TPACPI_RFK_SW_MAX || tpacpi_rfkill_switches[id]); |
| 1270 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1271 | atp_rfk = kzalloc(sizeof(struct tpacpi_rfk), GFP_KERNEL); |
| 1272 | if (atp_rfk) |
| 1273 | atp_rfk->rfkill = rfkill_alloc(name, |
| 1274 | &tpacpi_pdev->dev, |
| 1275 | rfktype, |
| 1276 | &tpacpi_rfk_rfkill_ops, |
| 1277 | atp_rfk); |
| 1278 | if (!atp_rfk || !atp_rfk->rfkill) { |
| 1279 | printk(TPACPI_ERR |
| 1280 | "failed to allocate memory for rfkill class\n"); |
| 1281 | kfree(atp_rfk); |
| 1282 | return -ENOMEM; |
| 1283 | } |
| 1284 | |
| 1285 | atp_rfk->id = id; |
| 1286 | atp_rfk->ops = tp_rfkops; |
| 1287 | |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1288 | sw_status = (tp_rfkops->get_status)(); |
| 1289 | if (sw_status < 0) { |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1290 | printk(TPACPI_ERR |
| 1291 | "failed to read initial state for %s, error %d\n", |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1292 | name, sw_status); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1293 | } else { |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1294 | sw_state = (sw_status == TPACPI_RFK_RADIO_OFF); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1295 | if (set_default) { |
| 1296 | /* try to keep the initial state, since we ask the |
| 1297 | * firmware to preserve it across S5 in NVRAM */ |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1298 | rfkill_init_sw_state(atp_rfk->rfkill, sw_state); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1299 | } |
| 1300 | } |
| 1301 | rfkill_set_hw_state(atp_rfk->rfkill, tpacpi_rfk_check_hwblock_state()); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1302 | |
| 1303 | res = rfkill_register(atp_rfk->rfkill); |
| 1304 | if (res < 0) { |
| 1305 | printk(TPACPI_ERR |
| 1306 | "failed to register %s rfkill switch: %d\n", |
| 1307 | name, res); |
| 1308 | rfkill_destroy(atp_rfk->rfkill); |
| 1309 | kfree(atp_rfk); |
| 1310 | return res; |
| 1311 | } |
| 1312 | |
| 1313 | tpacpi_rfkill_switches[id] = atp_rfk; |
| 1314 | return 0; |
| 1315 | } |
| 1316 | |
| 1317 | static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id) |
| 1318 | { |
| 1319 | struct tpacpi_rfk *tp_rfk; |
| 1320 | |
| 1321 | BUG_ON(id >= TPACPI_RFK_SW_MAX); |
| 1322 | |
| 1323 | tp_rfk = tpacpi_rfkill_switches[id]; |
| 1324 | if (tp_rfk) { |
| 1325 | rfkill_unregister(tp_rfk->rfkill); |
Corentin Chary | 5f0dadb | 2009-09-14 12:43:52 +0200 | [diff] [blame] | 1326 | rfkill_destroy(tp_rfk->rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1327 | tpacpi_rfkill_switches[id] = NULL; |
| 1328 | kfree(tp_rfk); |
| 1329 | } |
| 1330 | } |
| 1331 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1332 | static void printk_deprecated_rfkill_attribute(const char * const what) |
| 1333 | { |
| 1334 | printk_deprecated_attribute(what, |
| 1335 | "Please switch to generic rfkill before year 2010"); |
| 1336 | } |
| 1337 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1338 | /* sysfs <radio> enable ------------------------------------------------ */ |
| 1339 | static ssize_t tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id, |
| 1340 | struct device_attribute *attr, |
| 1341 | char *buf) |
| 1342 | { |
| 1343 | int status; |
| 1344 | |
| 1345 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1346 | |
| 1347 | /* This is in the ABI... */ |
| 1348 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1349 | status = TPACPI_RFK_RADIO_OFF; |
| 1350 | } else { |
| 1351 | status = tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1352 | if (status < 0) |
| 1353 | return status; |
| 1354 | } |
| 1355 | |
| 1356 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1357 | (status == TPACPI_RFK_RADIO_ON) ? 1 : 0); |
| 1358 | } |
| 1359 | |
| 1360 | static ssize_t tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id, |
| 1361 | struct device_attribute *attr, |
| 1362 | const char *buf, size_t count) |
| 1363 | { |
| 1364 | unsigned long t; |
| 1365 | int res; |
| 1366 | |
| 1367 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1368 | |
| 1369 | if (parse_strtoul(buf, 1, &t)) |
| 1370 | return -EINVAL; |
| 1371 | |
| 1372 | tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); |
| 1373 | |
| 1374 | /* This is in the ABI... */ |
| 1375 | if (tpacpi_rfk_check_hwblock_state() && !!t) |
| 1376 | return -EPERM; |
| 1377 | |
| 1378 | res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? |
| 1379 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF); |
| 1380 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1381 | |
| 1382 | return (res < 0) ? res : count; |
| 1383 | } |
| 1384 | |
| 1385 | /* procfs -------------------------------------------------------------- */ |
| 1386 | static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id, char *p) |
| 1387 | { |
| 1388 | int len = 0; |
| 1389 | |
| 1390 | if (id >= TPACPI_RFK_SW_MAX) |
| 1391 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1392 | else { |
| 1393 | int status; |
| 1394 | |
| 1395 | /* This is in the ABI... */ |
| 1396 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1397 | status = TPACPI_RFK_RADIO_OFF; |
| 1398 | } else { |
| 1399 | status = tpacpi_rfk_update_swstate( |
| 1400 | tpacpi_rfkill_switches[id]); |
| 1401 | if (status < 0) |
| 1402 | return status; |
| 1403 | } |
| 1404 | |
| 1405 | len += sprintf(p + len, "status:\t\t%s\n", |
| 1406 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1407 | "enabled" : "disabled"); |
| 1408 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 1409 | } |
| 1410 | |
| 1411 | return len; |
| 1412 | } |
| 1413 | |
| 1414 | static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf) |
| 1415 | { |
| 1416 | char *cmd; |
| 1417 | int status = -1; |
| 1418 | int res = 0; |
| 1419 | |
| 1420 | if (id >= TPACPI_RFK_SW_MAX) |
| 1421 | return -ENODEV; |
| 1422 | |
| 1423 | while ((cmd = next_cmd(&buf))) { |
| 1424 | if (strlencmp(cmd, "enable") == 0) |
| 1425 | status = TPACPI_RFK_RADIO_ON; |
| 1426 | else if (strlencmp(cmd, "disable") == 0) |
| 1427 | status = TPACPI_RFK_RADIO_OFF; |
| 1428 | else |
| 1429 | return -EINVAL; |
| 1430 | } |
| 1431 | |
| 1432 | if (status != -1) { |
| 1433 | tpacpi_disclose_usertask("procfs", "attempt to %s %s\n", |
| 1434 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1435 | "enable" : "disable", |
| 1436 | tpacpi_rfkill_names[id]); |
| 1437 | res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); |
| 1438 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1439 | } |
| 1440 | |
| 1441 | return res; |
| 1442 | } |
| 1443 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1444 | /************************************************************************* |
| 1445 | * thinkpad-acpi driver attributes |
| 1446 | */ |
| 1447 | |
| 1448 | /* interface_version --------------------------------------------------- */ |
| 1449 | static ssize_t tpacpi_driver_interface_version_show( |
| 1450 | struct device_driver *drv, |
| 1451 | char *buf) |
| 1452 | { |
| 1453 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 1454 | } |
| 1455 | |
| 1456 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 1457 | tpacpi_driver_interface_version_show, NULL); |
| 1458 | |
| 1459 | /* debug_level --------------------------------------------------------- */ |
| 1460 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 1461 | char *buf) |
| 1462 | { |
| 1463 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 1464 | } |
| 1465 | |
| 1466 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 1467 | const char *buf, size_t count) |
| 1468 | { |
| 1469 | unsigned long t; |
| 1470 | |
| 1471 | if (parse_strtoul(buf, 0xffff, &t)) |
| 1472 | return -EINVAL; |
| 1473 | |
| 1474 | dbg_level = t; |
| 1475 | |
| 1476 | return count; |
| 1477 | } |
| 1478 | |
| 1479 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1480 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 1481 | |
| 1482 | /* version ------------------------------------------------------------- */ |
| 1483 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 1484 | char *buf) |
| 1485 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1486 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 1487 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | static DRIVER_ATTR(version, S_IRUGO, |
| 1491 | tpacpi_driver_version_show, NULL); |
| 1492 | |
| 1493 | /* --------------------------------------------------------------------- */ |
| 1494 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1495 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1496 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1497 | /* wlsw_emulstate ------------------------------------------------------ */ |
| 1498 | static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv, |
| 1499 | char *buf) |
| 1500 | { |
| 1501 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate); |
| 1502 | } |
| 1503 | |
| 1504 | static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv, |
| 1505 | const char *buf, size_t count) |
| 1506 | { |
| 1507 | unsigned long t; |
| 1508 | |
| 1509 | if (parse_strtoul(buf, 1, &t)) |
| 1510 | return -EINVAL; |
| 1511 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1512 | if (tpacpi_wlsw_emulstate != !!t) { |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1513 | tpacpi_wlsw_emulstate = !!t; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1514 | tpacpi_rfk_update_hwblock_state(!t); /* negative logic */ |
| 1515 | } |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1516 | |
| 1517 | return count; |
| 1518 | } |
| 1519 | |
| 1520 | static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO, |
| 1521 | tpacpi_driver_wlsw_emulstate_show, |
| 1522 | tpacpi_driver_wlsw_emulstate_store); |
| 1523 | |
| 1524 | /* bluetooth_emulstate ------------------------------------------------- */ |
| 1525 | static ssize_t tpacpi_driver_bluetooth_emulstate_show( |
| 1526 | struct device_driver *drv, |
| 1527 | char *buf) |
| 1528 | { |
| 1529 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate); |
| 1530 | } |
| 1531 | |
| 1532 | static ssize_t tpacpi_driver_bluetooth_emulstate_store( |
| 1533 | struct device_driver *drv, |
| 1534 | const char *buf, size_t count) |
| 1535 | { |
| 1536 | unsigned long t; |
| 1537 | |
| 1538 | if (parse_strtoul(buf, 1, &t)) |
| 1539 | return -EINVAL; |
| 1540 | |
| 1541 | tpacpi_bluetooth_emulstate = !!t; |
| 1542 | |
| 1543 | return count; |
| 1544 | } |
| 1545 | |
| 1546 | static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO, |
| 1547 | tpacpi_driver_bluetooth_emulstate_show, |
| 1548 | tpacpi_driver_bluetooth_emulstate_store); |
| 1549 | |
| 1550 | /* wwan_emulstate ------------------------------------------------- */ |
| 1551 | static ssize_t tpacpi_driver_wwan_emulstate_show( |
| 1552 | struct device_driver *drv, |
| 1553 | char *buf) |
| 1554 | { |
| 1555 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate); |
| 1556 | } |
| 1557 | |
| 1558 | static ssize_t tpacpi_driver_wwan_emulstate_store( |
| 1559 | struct device_driver *drv, |
| 1560 | const char *buf, size_t count) |
| 1561 | { |
| 1562 | unsigned long t; |
| 1563 | |
| 1564 | if (parse_strtoul(buf, 1, &t)) |
| 1565 | return -EINVAL; |
| 1566 | |
| 1567 | tpacpi_wwan_emulstate = !!t; |
| 1568 | |
| 1569 | return count; |
| 1570 | } |
| 1571 | |
| 1572 | static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO, |
| 1573 | tpacpi_driver_wwan_emulstate_show, |
| 1574 | tpacpi_driver_wwan_emulstate_store); |
| 1575 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1576 | /* uwb_emulstate ------------------------------------------------- */ |
| 1577 | static ssize_t tpacpi_driver_uwb_emulstate_show( |
| 1578 | struct device_driver *drv, |
| 1579 | char *buf) |
| 1580 | { |
| 1581 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate); |
| 1582 | } |
| 1583 | |
| 1584 | static ssize_t tpacpi_driver_uwb_emulstate_store( |
| 1585 | struct device_driver *drv, |
| 1586 | const char *buf, size_t count) |
| 1587 | { |
| 1588 | unsigned long t; |
| 1589 | |
| 1590 | if (parse_strtoul(buf, 1, &t)) |
| 1591 | return -EINVAL; |
| 1592 | |
| 1593 | tpacpi_uwb_emulstate = !!t; |
| 1594 | |
| 1595 | return count; |
| 1596 | } |
| 1597 | |
| 1598 | static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO, |
| 1599 | tpacpi_driver_uwb_emulstate_show, |
| 1600 | tpacpi_driver_uwb_emulstate_store); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1601 | #endif |
| 1602 | |
| 1603 | /* --------------------------------------------------------------------- */ |
| 1604 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1605 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1606 | &driver_attr_debug_level, &driver_attr_version, |
| 1607 | &driver_attr_interface_version, |
| 1608 | }; |
| 1609 | |
| 1610 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 1611 | { |
| 1612 | int i, res; |
| 1613 | |
| 1614 | i = 0; |
| 1615 | res = 0; |
| 1616 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 1617 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 1618 | i++; |
| 1619 | } |
| 1620 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1621 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1622 | if (!res && dbg_wlswemul) |
| 1623 | res = driver_create_file(drv, &driver_attr_wlsw_emulstate); |
| 1624 | if (!res && dbg_bluetoothemul) |
| 1625 | res = driver_create_file(drv, &driver_attr_bluetooth_emulstate); |
| 1626 | if (!res && dbg_wwanemul) |
| 1627 | res = driver_create_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1628 | if (!res && dbg_uwbemul) |
| 1629 | res = driver_create_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1630 | #endif |
| 1631 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1632 | return res; |
| 1633 | } |
| 1634 | |
| 1635 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 1636 | { |
| 1637 | int i; |
| 1638 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1639 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1640 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1641 | |
| 1642 | #ifdef THINKPAD_ACPI_DEBUGFACILITIES |
| 1643 | driver_remove_file(drv, &driver_attr_wlsw_emulstate); |
| 1644 | driver_remove_file(drv, &driver_attr_bluetooth_emulstate); |
| 1645 | driver_remove_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1646 | driver_remove_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1647 | #endif |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1648 | } |
| 1649 | |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1650 | /************************************************************************* |
| 1651 | * Firmware Data |
| 1652 | */ |
| 1653 | |
| 1654 | /* |
| 1655 | * Table of recommended minimum BIOS versions |
| 1656 | * |
| 1657 | * Reasons for listing: |
| 1658 | * 1. Stable BIOS, listed because the unknown ammount of |
| 1659 | * bugs and bad ACPI behaviour on older versions |
| 1660 | * |
| 1661 | * 2. BIOS or EC fw with known bugs that trigger on Linux |
| 1662 | * |
| 1663 | * 3. BIOS with known reduced functionality in older versions |
| 1664 | * |
| 1665 | * We recommend the latest BIOS and EC version. |
| 1666 | * We only support the latest BIOS and EC fw version as a rule. |
| 1667 | * |
| 1668 | * Sources: IBM ThinkPad Public Web Documents (update changelogs), |
| 1669 | * Information from users in ThinkWiki |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1670 | * |
| 1671 | * WARNING: we use this table also to detect that the machine is |
| 1672 | * 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] | 1673 | */ |
| 1674 | |
| 1675 | #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \ |
| 1676 | { .vendor = (__v), \ |
| 1677 | .bios = TPID(__id1, __id2), \ |
| 1678 | .ec = TPACPI_MATCH_ANY, \ |
| 1679 | .quirks = TPACPI_MATCH_ANY << 16 \ |
| 1680 | | (__bv1) << 8 | (__bv2) } |
| 1681 | |
| 1682 | #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \ |
| 1683 | __eid1, __eid2, __ev1, __ev2) \ |
| 1684 | { .vendor = (__v), \ |
| 1685 | .bios = TPID(__bid1, __bid2), \ |
| 1686 | .ec = TPID(__eid1, __eid2), \ |
| 1687 | .quirks = (__ev1) << 24 | (__ev2) << 16 \ |
| 1688 | | (__bv1) << 8 | (__bv2) } |
| 1689 | |
| 1690 | #define TPV_QI0(__id1, __id2, __bv1, __bv2) \ |
| 1691 | TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2) |
| 1692 | |
| 1693 | #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1694 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
| 1695 | __bv1, __bv2, __id1, __id2, __ev1, __ev2) |
| 1696 | |
| 1697 | #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \ |
| 1698 | __eid1, __eid2, __ev1, __ev2) \ |
| 1699 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
| 1700 | __bv1, __bv2, __eid1, __eid2, __ev1, __ev2) |
| 1701 | |
| 1702 | #define TPV_QL0(__id1, __id2, __bv1, __bv2) \ |
| 1703 | TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2) |
| 1704 | |
| 1705 | #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1706 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \ |
| 1707 | __bv1, __bv2, __id1, __id2, __ev1, __ev2) |
| 1708 | |
| 1709 | #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \ |
| 1710 | __eid1, __eid2, __ev1, __ev2) \ |
| 1711 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \ |
| 1712 | __bv1, __bv2, __eid1, __eid2, __ev1, __ev2) |
| 1713 | |
| 1714 | static const struct tpacpi_quirk tpacpi_bios_version_qtable[] __initconst = { |
| 1715 | /* Numeric models ------------------ */ |
| 1716 | /* FW MODEL BIOS VERS */ |
| 1717 | TPV_QI0('I', 'M', '6', '5'), /* 570 */ |
| 1718 | TPV_QI0('I', 'U', '2', '6'), /* 570E */ |
| 1719 | TPV_QI0('I', 'B', '5', '4'), /* 600 */ |
| 1720 | TPV_QI0('I', 'H', '4', '7'), /* 600E */ |
| 1721 | TPV_QI0('I', 'N', '3', '6'), /* 600E */ |
| 1722 | TPV_QI0('I', 'T', '5', '5'), /* 600X */ |
| 1723 | TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */ |
| 1724 | TPV_QI0('I', 'I', '4', '2'), /* 770X */ |
| 1725 | TPV_QI0('I', 'O', '2', '3'), /* 770Z */ |
| 1726 | |
| 1727 | /* A-series ------------------------- */ |
| 1728 | /* FW MODEL BIOS VERS EC VERS */ |
| 1729 | TPV_QI0('I', 'W', '5', '9'), /* A20m */ |
| 1730 | TPV_QI0('I', 'V', '6', '9'), /* A20p */ |
| 1731 | TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */ |
| 1732 | TPV_QI0('K', 'U', '3', '6'), /* A21e */ |
| 1733 | TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */ |
| 1734 | TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */ |
| 1735 | TPV_QI0('1', 'B', '1', '7'), /* A22e */ |
| 1736 | TPV_QI0('1', '3', '2', '0'), /* A22m */ |
| 1737 | TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */ |
| 1738 | TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */ |
| 1739 | TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */ |
| 1740 | |
| 1741 | /* G-series ------------------------- */ |
| 1742 | /* FW MODEL BIOS VERS */ |
| 1743 | TPV_QI0('1', 'T', 'A', '6'), /* G40 */ |
| 1744 | TPV_QI0('1', 'X', '5', '7'), /* G41 */ |
| 1745 | |
| 1746 | /* R-series, T-series --------------- */ |
| 1747 | /* FW MODEL BIOS VERS EC VERS */ |
| 1748 | TPV_QI0('1', 'C', 'F', '0'), /* R30 */ |
| 1749 | TPV_QI0('1', 'F', 'F', '1'), /* R31 */ |
| 1750 | TPV_QI0('1', 'M', '9', '7'), /* R32 */ |
| 1751 | TPV_QI0('1', 'O', '6', '1'), /* R40 */ |
| 1752 | TPV_QI0('1', 'P', '6', '5'), /* R40 */ |
| 1753 | TPV_QI0('1', 'S', '7', '0'), /* R40e */ |
| 1754 | TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51, |
| 1755 | T40/p, T41/p, T42/p (1) */ |
| 1756 | TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */ |
| 1757 | TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */ |
| 1758 | TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */ |
| 1759 | TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */ |
| 1760 | |
| 1761 | TPV_QI0('I', 'Y', '6', '1'), /* T20 */ |
| 1762 | TPV_QI0('K', 'Z', '3', '4'), /* T21 */ |
| 1763 | TPV_QI0('1', '6', '3', '2'), /* T22 */ |
| 1764 | TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */ |
| 1765 | TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */ |
| 1766 | TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */ |
| 1767 | |
| 1768 | TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */ |
| 1769 | TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */ |
| 1770 | TPV_QL0('7', 'E', 'D', '0'), /* R60e, R60i */ |
| 1771 | |
| 1772 | /* BIOS FW BIOS VERS EC FW EC VERS */ |
| 1773 | TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */ |
| 1774 | TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */ |
| 1775 | |
| 1776 | /* X-series ------------------------- */ |
| 1777 | /* FW MODEL BIOS VERS EC VERS */ |
| 1778 | TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */ |
| 1779 | TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */ |
| 1780 | TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */ |
| 1781 | TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */ |
| 1782 | TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */ |
| 1783 | TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */ |
| 1784 | TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */ |
| 1785 | |
| 1786 | TPV_QL0('7', 'B', 'D', '7'), /* X60/s */ |
| 1787 | TPV_QL0('7', 'J', '3', '0'), /* X60t */ |
| 1788 | |
| 1789 | /* (0) - older versions lack DMI EC fw string and functionality */ |
| 1790 | /* (1) - older versions known to lack functionality */ |
| 1791 | }; |
| 1792 | |
| 1793 | #undef TPV_QL1 |
| 1794 | #undef TPV_QL0 |
| 1795 | #undef TPV_QI2 |
| 1796 | #undef TPV_QI1 |
| 1797 | #undef TPV_QI0 |
| 1798 | #undef TPV_Q_X |
| 1799 | #undef TPV_Q |
| 1800 | |
| 1801 | static void __init tpacpi_check_outdated_fw(void) |
| 1802 | { |
| 1803 | unsigned long fwvers; |
| 1804 | u16 ec_version, bios_version; |
| 1805 | |
| 1806 | fwvers = tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1807 | ARRAY_SIZE(tpacpi_bios_version_qtable)); |
| 1808 | |
| 1809 | if (!fwvers) |
| 1810 | return; |
| 1811 | |
| 1812 | bios_version = fwvers & 0xffffU; |
| 1813 | ec_version = (fwvers >> 16) & 0xffffU; |
| 1814 | |
| 1815 | /* note that unknown versions are set to 0x0000 and we use that */ |
| 1816 | if ((bios_version > thinkpad_id.bios_release) || |
| 1817 | (ec_version > thinkpad_id.ec_release && |
| 1818 | ec_version != TPACPI_MATCH_ANY)) { |
| 1819 | /* |
| 1820 | * The changelogs would let us track down the exact |
| 1821 | * reason, but it is just too much of a pain to track |
| 1822 | * it. We only list BIOSes that are either really |
| 1823 | * broken, or really stable to begin with, so it is |
| 1824 | * best if the user upgrades the firmware anyway. |
| 1825 | */ |
| 1826 | printk(TPACPI_WARN |
| 1827 | "WARNING: Outdated ThinkPad BIOS/EC firmware\n"); |
| 1828 | printk(TPACPI_WARN |
| 1829 | "WARNING: This firmware may be missing critical bug " |
| 1830 | "fixes and/or important features\n"); |
| 1831 | } |
| 1832 | } |
| 1833 | |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1834 | static bool __init tpacpi_is_fw_known(void) |
| 1835 | { |
| 1836 | return tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1837 | ARRAY_SIZE(tpacpi_bios_version_qtable)) != 0; |
| 1838 | } |
| 1839 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1840 | /**************************************************************************** |
| 1841 | **************************************************************************** |
| 1842 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1843 | * Subdrivers |
| 1844 | * |
| 1845 | **************************************************************************** |
| 1846 | ****************************************************************************/ |
| 1847 | |
| 1848 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 1849 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1850 | */ |
| 1851 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1852 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1854 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 1855 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1857 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1858 | (thinkpad_id.bios_version_str) ? |
| 1859 | thinkpad_id.bios_version_str : "unknown", |
| 1860 | (thinkpad_id.ec_version_str) ? |
| 1861 | thinkpad_id.ec_version_str : "unknown"); |
| 1862 | |
| 1863 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1864 | printk(TPACPI_INFO "%s %s, model %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1865 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 1866 | "IBM" : ((thinkpad_id.vendor == |
| 1867 | PCI_VENDOR_ID_LENOVO) ? |
| 1868 | "Lenovo" : "Unknown vendor"), |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1869 | thinkpad_id.model_str, |
| 1870 | (thinkpad_id.nummodel_str) ? |
| 1871 | thinkpad_id.nummodel_str : "unknown"); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 1872 | |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1873 | tpacpi_check_outdated_fw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | return 0; |
| 1875 | } |
| 1876 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1877 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | { |
| 1879 | int len = 0; |
| 1880 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1881 | len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); |
| 1882 | len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | |
| 1884 | return len; |
| 1885 | } |
| 1886 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1887 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1888 | .name = "driver", |
| 1889 | .read = thinkpad_acpi_driver_read, |
| 1890 | }; |
| 1891 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1892 | /************************************************************************* |
| 1893 | * Hotkey subdriver |
| 1894 | */ |
| 1895 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1896 | /* |
| 1897 | * ThinkPad firmware event model |
| 1898 | * |
| 1899 | * The ThinkPad firmware has two main event interfaces: normal ACPI |
| 1900 | * notifications (which follow the ACPI standard), and a private event |
| 1901 | * interface. |
| 1902 | * |
| 1903 | * The private event interface also issues events for the hotkeys. As |
| 1904 | * the driver gained features, the event handling code ended up being |
| 1905 | * built around the hotkey subdriver. This will need to be refactored |
| 1906 | * to a more formal event API eventually. |
| 1907 | * |
| 1908 | * Some "hotkeys" are actually supposed to be used as event reports, |
| 1909 | * such as "brightness has changed", "volume has changed", depending on |
| 1910 | * the ThinkPad model and how the firmware is operating. |
| 1911 | * |
| 1912 | * Unlike other classes, hotkey-class events have mask/unmask control on |
| 1913 | * non-ancient firmware. However, how it behaves changes a lot with the |
| 1914 | * firmware model and version. |
| 1915 | */ |
| 1916 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1917 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1918 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1919 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1920 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1921 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1922 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1923 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1924 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1925 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1926 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1927 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1928 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1929 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1930 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1931 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1932 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1933 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1934 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1935 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1936 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1937 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1938 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1939 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1940 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1941 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1942 | }; |
| 1943 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1944 | enum { /* Keys/events available through NVRAM polling */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1945 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1946 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1947 | }; |
| 1948 | |
| 1949 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1950 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1951 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1952 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1953 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1954 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1955 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1956 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1957 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1958 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1959 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1960 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1961 | }; |
| 1962 | |
| 1963 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1964 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1965 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1966 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1967 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1968 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1969 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1970 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1971 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1972 | TP_ACPI_HKEY_MUTE_MASK, |
| 1973 | }; |
| 1974 | |
| 1975 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1976 | struct tp_nvram_state { |
| 1977 | u16 thinkpad_toggle:1; |
| 1978 | u16 zoom_toggle:1; |
| 1979 | u16 display_toggle:1; |
| 1980 | u16 thinklight_toggle:1; |
| 1981 | u16 hibernate_toggle:1; |
| 1982 | u16 displayexp_toggle:1; |
| 1983 | u16 display_state:1; |
| 1984 | u16 brightness_toggle:1; |
| 1985 | u16 volume_toggle:1; |
| 1986 | u16 mute:1; |
| 1987 | |
| 1988 | u8 brightness_level; |
| 1989 | u8 volume_level; |
| 1990 | }; |
| 1991 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1992 | /* kthread for the hotkey poller */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1993 | static struct task_struct *tpacpi_hotkey_task; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1994 | |
| 1995 | /* 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] | 1996 | static struct mutex hotkey_thread_mutex; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1997 | |
| 1998 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1999 | * Acquire mutex to write poller control variables as an |
| 2000 | * atomic block. |
| 2001 | * |
| 2002 | * Increment hotkey_config_change when changing them if you |
| 2003 | * want the kthread to forget old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2004 | * |
| 2005 | * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 2006 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2007 | static struct mutex hotkey_thread_data_mutex; |
| 2008 | static unsigned int hotkey_config_change; |
| 2009 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2010 | /* |
| 2011 | * hotkey poller control variables |
| 2012 | * |
| 2013 | * 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] | 2014 | * |
| 2015 | * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 2016 | * should be used only when the changes need to be taken as |
| 2017 | * a block, OR when one needs to force the kthread to forget |
| 2018 | * old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2019 | */ |
| 2020 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 2021 | static unsigned int hotkey_poll_freq = 10; /* Hz */ |
| 2022 | |
| 2023 | #define HOTKEY_CONFIG_CRITICAL_START \ |
| 2024 | do { \ |
| 2025 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 2026 | hotkey_config_change++; \ |
| 2027 | } while (0); |
| 2028 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 2029 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2030 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2031 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2032 | |
| 2033 | #define hotkey_source_mask 0U |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2034 | #define HOTKEY_CONFIG_CRITICAL_START |
| 2035 | #define HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2036 | |
| 2037 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2038 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2039 | static struct mutex hotkey_mutex; |
| 2040 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2041 | static enum { /* Reasons for waking up */ |
| 2042 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 2043 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 2044 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 2045 | } hotkey_wakeup_reason; |
| 2046 | |
| 2047 | static int hotkey_autosleep_ack; |
| 2048 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2049 | static u32 hotkey_orig_mask; /* events the BIOS had enabled */ |
| 2050 | static u32 hotkey_all_mask; /* all events supported in fw */ |
| 2051 | static u32 hotkey_reserved_mask; /* events better left disabled */ |
| 2052 | static u32 hotkey_driver_mask; /* events needed by the driver */ |
| 2053 | static u32 hotkey_user_mask; /* events visible to userspace */ |
| 2054 | static u32 hotkey_acpi_mask; /* events enabled in firmware */ |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2055 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 2056 | static unsigned int hotkey_report_mode; |
| 2057 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2058 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2059 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 2060 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2061 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2062 | static void tpacpi_driver_event(const unsigned int hkey_event); |
| 2063 | static void hotkey_driver_event(const unsigned int scancode); |
| 2064 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2065 | /* HKEY.MHKG() return bits */ |
| 2066 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 2067 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2068 | static int hotkey_get_wlsw(void) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2069 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2070 | int status; |
| 2071 | |
| 2072 | if (!tp_features.hotkey_wlsw) |
| 2073 | return -ENODEV; |
| 2074 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2075 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2076 | if (dbg_wlswemul) |
| 2077 | return (tpacpi_wlsw_emulstate) ? |
| 2078 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2079 | #endif |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2080 | |
| 2081 | if (!acpi_evalf(hkey_handle, &status, "WLSW", "d")) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2082 | return -EIO; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2083 | |
| 2084 | return (status) ? TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2085 | } |
| 2086 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2087 | static int hotkey_get_tablet_mode(int *status) |
| 2088 | { |
| 2089 | int s; |
| 2090 | |
| 2091 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 2092 | return -EIO; |
| 2093 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 2094 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 2095 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2096 | } |
| 2097 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2098 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2099 | * Reads current event mask from firmware, and updates |
| 2100 | * hotkey_acpi_mask accordingly. Also resets any bits |
| 2101 | * from hotkey_user_mask that are unavailable to be |
| 2102 | * delivered (shadow requirement of the userspace ABI). |
| 2103 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2104 | * Call with hotkey_mutex held |
| 2105 | */ |
| 2106 | static int hotkey_mask_get(void) |
| 2107 | { |
| 2108 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2109 | u32 m = 0; |
| 2110 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2111 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2112 | return -EIO; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2113 | |
| 2114 | hotkey_acpi_mask = m; |
| 2115 | } else { |
| 2116 | /* no mask support doesn't mean no event support... */ |
| 2117 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2118 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2119 | |
| 2120 | /* sync userspace-visible mask */ |
| 2121 | hotkey_user_mask &= (hotkey_acpi_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2122 | |
| 2123 | return 0; |
| 2124 | } |
| 2125 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2126 | void static hotkey_mask_warn_incomplete_mask(void) |
| 2127 | { |
| 2128 | /* log only what the user can fix... */ |
| 2129 | const u32 wantedmask = hotkey_driver_mask & |
| 2130 | ~(hotkey_acpi_mask | hotkey_source_mask) & |
| 2131 | (hotkey_all_mask | TPACPI_HKEY_NVRAM_KNOWN_MASK); |
| 2132 | |
| 2133 | if (wantedmask) |
| 2134 | printk(TPACPI_NOTICE |
| 2135 | "required events 0x%08x not enabled!\n", |
| 2136 | wantedmask); |
| 2137 | } |
| 2138 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2139 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2140 | * Set the firmware mask when supported |
| 2141 | * |
| 2142 | * Also calls hotkey_mask_get to update hotkey_acpi_mask. |
| 2143 | * |
| 2144 | * NOTE: does not set bits in hotkey_user_mask, but may reset them. |
| 2145 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2146 | * Call with hotkey_mutex held |
| 2147 | */ |
| 2148 | static int hotkey_mask_set(u32 mask) |
| 2149 | { |
| 2150 | int i; |
| 2151 | int rc = 0; |
| 2152 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2153 | const u32 fwmask = mask & ~hotkey_source_mask; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 2154 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2155 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2156 | for (i = 0; i < 32; i++) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2157 | if (!acpi_evalf(hkey_handle, |
| 2158 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2159 | !!(mask & (1 << i)))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2160 | rc = -EIO; |
| 2161 | break; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2162 | } |
| 2163 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2164 | } |
| 2165 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2166 | /* |
| 2167 | * We *must* make an inconditional call to hotkey_mask_get to |
| 2168 | * refresh hotkey_acpi_mask and update hotkey_user_mask |
| 2169 | * |
| 2170 | * Take the opportunity to also log when we cannot _enable_ |
| 2171 | * a given event. |
| 2172 | */ |
| 2173 | if (!hotkey_mask_get() && !rc && (fwmask & ~hotkey_acpi_mask)) { |
| 2174 | printk(TPACPI_NOTICE |
| 2175 | "asked for hotkey mask 0x%08x, but " |
| 2176 | "firmware forced it to 0x%08x\n", |
| 2177 | fwmask, hotkey_acpi_mask); |
| 2178 | } |
| 2179 | |
| 2180 | hotkey_mask_warn_incomplete_mask(); |
| 2181 | |
| 2182 | return rc; |
| 2183 | } |
| 2184 | |
| 2185 | /* |
| 2186 | * Sets hotkey_user_mask and tries to set the firmware mask |
| 2187 | * |
| 2188 | * Call with hotkey_mutex held |
| 2189 | */ |
| 2190 | static int hotkey_user_mask_set(const u32 mask) |
| 2191 | { |
| 2192 | int rc; |
| 2193 | |
| 2194 | /* Give people a chance to notice they are doing something that |
| 2195 | * is bound to go boom on their users sooner or later */ |
| 2196 | if (!tp_warned.hotkey_mask_ff && |
| 2197 | (mask == 0xffff || mask == 0xffffff || |
| 2198 | mask == 0xffffffff)) { |
| 2199 | tp_warned.hotkey_mask_ff = 1; |
| 2200 | printk(TPACPI_NOTICE |
| 2201 | "setting the hotkey mask to 0x%08x is likely " |
| 2202 | "not the best way to go about it\n", mask); |
| 2203 | printk(TPACPI_NOTICE |
| 2204 | "please consider using the driver defaults, " |
| 2205 | "and refer to up-to-date thinkpad-acpi " |
| 2206 | "documentation\n"); |
| 2207 | } |
| 2208 | |
| 2209 | /* Try to enable what the user asked for, plus whatever we need. |
| 2210 | * this syncs everything but won't enable bits in hotkey_user_mask */ |
| 2211 | rc = hotkey_mask_set((mask | hotkey_driver_mask) & ~hotkey_source_mask); |
| 2212 | |
| 2213 | /* Enable the available bits in hotkey_user_mask */ |
| 2214 | hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask); |
| 2215 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2216 | return rc; |
| 2217 | } |
| 2218 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2219 | /* |
| 2220 | * Sets the driver hotkey mask. |
| 2221 | * |
| 2222 | * Can be called even if the hotkey subdriver is inactive |
| 2223 | */ |
| 2224 | static int tpacpi_hotkey_driver_mask_set(const u32 mask) |
| 2225 | { |
| 2226 | int rc; |
| 2227 | |
| 2228 | /* Do the right thing if hotkey_init has not been called yet */ |
| 2229 | if (!tp_features.hotkey) { |
| 2230 | hotkey_driver_mask = mask; |
| 2231 | return 0; |
| 2232 | } |
| 2233 | |
| 2234 | mutex_lock(&hotkey_mutex); |
| 2235 | |
| 2236 | HOTKEY_CONFIG_CRITICAL_START |
| 2237 | hotkey_driver_mask = mask; |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2238 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2239 | hotkey_source_mask |= (mask & ~hotkey_all_mask); |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2240 | #endif |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2241 | HOTKEY_CONFIG_CRITICAL_END |
| 2242 | |
| 2243 | rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) & |
| 2244 | ~hotkey_source_mask); |
| 2245 | mutex_unlock(&hotkey_mutex); |
| 2246 | |
| 2247 | return rc; |
| 2248 | } |
| 2249 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2250 | static int hotkey_status_get(int *status) |
| 2251 | { |
| 2252 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 2253 | return -EIO; |
| 2254 | |
| 2255 | return 0; |
| 2256 | } |
| 2257 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2258 | static int hotkey_status_set(bool enable) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2259 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2260 | 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] | 2261 | return -EIO; |
| 2262 | |
| 2263 | return 0; |
| 2264 | } |
| 2265 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2266 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2267 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2268 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2269 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2270 | if (tp_features.hotkey_tablet && |
| 2271 | !hotkey_get_tablet_mode(&state)) { |
| 2272 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2273 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2274 | input_report_switch(tpacpi_inputdev, |
| 2275 | SW_TABLET_MODE, !!state); |
| 2276 | input_sync(tpacpi_inputdev); |
| 2277 | |
| 2278 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2279 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2280 | } |
| 2281 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2282 | /* Do NOT call without validating scancode first */ |
| 2283 | static void tpacpi_input_send_key(const unsigned int scancode) |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2284 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2285 | const unsigned int keycode = hotkey_keycode_map[scancode]; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2286 | |
| 2287 | if (keycode != KEY_RESERVED) { |
| 2288 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2289 | |
| 2290 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 2291 | if (keycode == KEY_UNKNOWN) |
| 2292 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 2293 | scancode); |
| 2294 | input_sync(tpacpi_inputdev); |
| 2295 | |
| 2296 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 2297 | if (keycode == KEY_UNKNOWN) |
| 2298 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 2299 | scancode); |
| 2300 | input_sync(tpacpi_inputdev); |
| 2301 | |
| 2302 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2303 | } |
| 2304 | } |
| 2305 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2306 | /* Do NOT call without validating scancode first */ |
| 2307 | static void tpacpi_input_send_key_masked(const unsigned int scancode) |
| 2308 | { |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2309 | hotkey_driver_event(scancode); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2310 | if (hotkey_user_mask & (1 << scancode)) |
| 2311 | tpacpi_input_send_key(scancode); |
| 2312 | } |
| 2313 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2314 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2315 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 2316 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2317 | /* Do NOT call without validating scancode first */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2318 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 2319 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2320 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2321 | if (hotkey_report_mode < 2) { |
| 2322 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 2323 | 0x80, TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2324 | } |
| 2325 | } |
| 2326 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2327 | 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] | 2328 | { |
| 2329 | u8 d; |
| 2330 | |
| 2331 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 2332 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 2333 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 2334 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 2335 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 2336 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 2337 | } |
| 2338 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 2339 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 2340 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 2341 | } |
| 2342 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 2343 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 2344 | n->displayexp_toggle = |
| 2345 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 2346 | } |
| 2347 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 2348 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 2349 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 2350 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 2351 | n->brightness_toggle = |
| 2352 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 2353 | } |
| 2354 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 2355 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 2356 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 2357 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 2358 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 2359 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 2360 | } |
| 2361 | } |
| 2362 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2363 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
| 2364 | struct tp_nvram_state *newn, |
| 2365 | const u32 event_mask) |
| 2366 | { |
| 2367 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2368 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2369 | do { \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2370 | if ((event_mask & (1 << __scancode)) && \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2371 | oldn->__member != newn->__member) \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2372 | tpacpi_hotkey_send_key(__scancode); \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2373 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2374 | |
| 2375 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2376 | do { \ |
| 2377 | if (event_mask & (1 << __scancode)) \ |
| 2378 | tpacpi_hotkey_send_key(__scancode); \ |
| 2379 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2380 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2381 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 2382 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 2383 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 2384 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 2385 | |
| 2386 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 2387 | |
| 2388 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 2389 | |
| 2390 | /* handle volume */ |
| 2391 | if (oldn->volume_toggle != newn->volume_toggle) { |
| 2392 | if (oldn->mute != newn->mute) { |
| 2393 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2394 | } |
| 2395 | if (oldn->volume_level > newn->volume_level) { |
| 2396 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2397 | } else if (oldn->volume_level < newn->volume_level) { |
| 2398 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2399 | } else if (oldn->mute == newn->mute) { |
| 2400 | /* repeated key presses that didn't change state */ |
| 2401 | if (newn->mute) { |
| 2402 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2403 | } else if (newn->volume_level != 0) { |
| 2404 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2405 | } else { |
| 2406 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2407 | } |
| 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | /* handle brightness */ |
| 2412 | if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 2413 | if (oldn->brightness_level < newn->brightness_level) { |
| 2414 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2415 | } else if (oldn->brightness_level > newn->brightness_level) { |
| 2416 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2417 | } else { |
| 2418 | /* repeated key presses that didn't change state */ |
| 2419 | if (newn->brightness_level != 0) { |
| 2420 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2421 | } else { |
| 2422 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2423 | } |
| 2424 | } |
| 2425 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2426 | |
| 2427 | #undef TPACPI_COMPARE_KEY |
| 2428 | #undef TPACPI_MAY_SEND_KEY |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2429 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2430 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2431 | /* |
| 2432 | * Polling driver |
| 2433 | * |
| 2434 | * We track all events in hotkey_source_mask all the time, since |
| 2435 | * most of them are edge-based. We only issue those requested by |
| 2436 | * hotkey_user_mask or hotkey_driver_mask, though. |
| 2437 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2438 | static int hotkey_kthread(void *data) |
| 2439 | { |
| 2440 | struct tp_nvram_state s[2]; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2441 | u32 poll_mask, event_mask; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2442 | unsigned int si, so; |
| 2443 | unsigned long t; |
| 2444 | unsigned int change_detector, must_reset; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2445 | unsigned int poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2446 | |
| 2447 | mutex_lock(&hotkey_thread_mutex); |
| 2448 | |
| 2449 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 2450 | goto exit; |
| 2451 | |
| 2452 | set_freezable(); |
| 2453 | |
| 2454 | so = 0; |
| 2455 | si = 1; |
| 2456 | t = 0; |
| 2457 | |
| 2458 | /* Initial state for compares */ |
| 2459 | mutex_lock(&hotkey_thread_data_mutex); |
| 2460 | change_detector = hotkey_config_change; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2461 | poll_mask = hotkey_source_mask; |
| 2462 | event_mask = hotkey_source_mask & |
| 2463 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2464 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2465 | mutex_unlock(&hotkey_thread_data_mutex); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2466 | hotkey_read_nvram(&s[so], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2467 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2468 | while (!kthread_should_stop()) { |
| 2469 | if (t == 0) { |
| 2470 | if (likely(poll_freq)) |
| 2471 | t = 1000/poll_freq; |
| 2472 | else |
| 2473 | t = 100; /* should never happen... */ |
| 2474 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2475 | t = msleep_interruptible(t); |
| 2476 | if (unlikely(kthread_should_stop())) |
| 2477 | break; |
| 2478 | must_reset = try_to_freeze(); |
| 2479 | if (t > 0 && !must_reset) |
| 2480 | continue; |
| 2481 | |
| 2482 | mutex_lock(&hotkey_thread_data_mutex); |
| 2483 | if (must_reset || hotkey_config_change != change_detector) { |
| 2484 | /* forget old state on thaw or config change */ |
| 2485 | si = so; |
| 2486 | t = 0; |
| 2487 | change_detector = hotkey_config_change; |
| 2488 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2489 | poll_mask = hotkey_source_mask; |
| 2490 | event_mask = hotkey_source_mask & |
| 2491 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2492 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2493 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2494 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2495 | if (likely(poll_mask)) { |
| 2496 | hotkey_read_nvram(&s[si], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2497 | if (likely(si != so)) { |
| 2498 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2499 | event_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2500 | } |
| 2501 | } |
| 2502 | |
| 2503 | so = si; |
| 2504 | si ^= 1; |
| 2505 | } |
| 2506 | |
| 2507 | exit: |
| 2508 | mutex_unlock(&hotkey_thread_mutex); |
| 2509 | return 0; |
| 2510 | } |
| 2511 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2512 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2513 | static void hotkey_poll_stop_sync(void) |
| 2514 | { |
| 2515 | if (tpacpi_hotkey_task) { |
| 2516 | if (frozen(tpacpi_hotkey_task) || |
| 2517 | freezing(tpacpi_hotkey_task)) |
| 2518 | thaw_process(tpacpi_hotkey_task); |
| 2519 | |
| 2520 | kthread_stop(tpacpi_hotkey_task); |
| 2521 | tpacpi_hotkey_task = NULL; |
| 2522 | mutex_lock(&hotkey_thread_mutex); |
| 2523 | /* at this point, the thread did exit */ |
| 2524 | mutex_unlock(&hotkey_thread_mutex); |
| 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2529 | static void hotkey_poll_setup(bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2530 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2531 | const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask; |
| 2532 | 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] | 2533 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2534 | if (hotkey_poll_freq > 0 && |
| 2535 | (poll_driver_mask || |
| 2536 | (poll_user_mask && tpacpi_inputdev->users > 0))) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2537 | if (!tpacpi_hotkey_task) { |
| 2538 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 2539 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2540 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 2541 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2542 | printk(TPACPI_ERR |
| 2543 | "could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2544 | "for hotkey polling\n"); |
| 2545 | } |
| 2546 | } |
| 2547 | } else { |
| 2548 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2549 | if (may_warn && (poll_driver_mask || poll_user_mask) && |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2550 | hotkey_poll_freq == 0) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2551 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2552 | "hot keys 0x%08x and/or events 0x%08x " |
| 2553 | "require polling, which is currently " |
| 2554 | "disabled\n", |
| 2555 | poll_user_mask, poll_driver_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2556 | } |
| 2557 | } |
| 2558 | } |
| 2559 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2560 | static void hotkey_poll_setup_safe(bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2561 | { |
| 2562 | mutex_lock(&hotkey_mutex); |
| 2563 | hotkey_poll_setup(may_warn); |
| 2564 | mutex_unlock(&hotkey_mutex); |
| 2565 | } |
| 2566 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2567 | /* call with hotkey_mutex held */ |
| 2568 | static void hotkey_poll_set_freq(unsigned int freq) |
| 2569 | { |
| 2570 | if (!freq) |
| 2571 | hotkey_poll_stop_sync(); |
| 2572 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2573 | hotkey_poll_freq = freq; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2574 | } |
| 2575 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2576 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2577 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2578 | static void hotkey_poll_setup_safe(bool __unused) |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2579 | { |
| 2580 | } |
| 2581 | |
| 2582 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2583 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2584 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 2585 | { |
| 2586 | switch (tpacpi_lifecycle) { |
| 2587 | case TPACPI_LIFE_INIT: |
| 2588 | /* |
| 2589 | * hotkey_init will call hotkey_poll_setup_safe |
| 2590 | * at the appropriate moment |
| 2591 | */ |
| 2592 | return 0; |
| 2593 | case TPACPI_LIFE_EXITING: |
| 2594 | return -EBUSY; |
| 2595 | case TPACPI_LIFE_RUNNING: |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2596 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2597 | return 0; |
| 2598 | } |
| 2599 | |
| 2600 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 2601 | BUG(); |
| 2602 | return -EBUSY; |
| 2603 | } |
| 2604 | |
| 2605 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 2606 | { |
| 2607 | /* disable hotkey polling when possible */ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2608 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING && |
| 2609 | !(hotkey_source_mask & hotkey_driver_mask)) |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2610 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2611 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2612 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2613 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 2614 | static ssize_t hotkey_enable_show(struct device *dev, |
| 2615 | struct device_attribute *attr, |
| 2616 | char *buf) |
| 2617 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2618 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2619 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2620 | printk_deprecated_attribute("hotkey_enable", |
| 2621 | "Hotkey reporting is always enabled"); |
| 2622 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2623 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2624 | if (res) |
| 2625 | return res; |
| 2626 | |
| 2627 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 2628 | } |
| 2629 | |
| 2630 | static ssize_t hotkey_enable_store(struct device *dev, |
| 2631 | struct device_attribute *attr, |
| 2632 | const char *buf, size_t count) |
| 2633 | { |
| 2634 | unsigned long t; |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2635 | |
| 2636 | printk_deprecated_attribute("hotkey_enable", |
| 2637 | "Hotkeys can be disabled through hotkey_mask"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2638 | |
| 2639 | if (parse_strtoul(buf, 1, &t)) |
| 2640 | return -EINVAL; |
| 2641 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2642 | if (t == 0) |
| 2643 | return -EPERM; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2644 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2645 | return count; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2649 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2650 | hotkey_enable_show, hotkey_enable_store); |
| 2651 | |
| 2652 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 2653 | static ssize_t hotkey_mask_show(struct device *dev, |
| 2654 | struct device_attribute *attr, |
| 2655 | char *buf) |
| 2656 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2657 | 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] | 2658 | } |
| 2659 | |
| 2660 | static ssize_t hotkey_mask_store(struct device *dev, |
| 2661 | struct device_attribute *attr, |
| 2662 | const char *buf, size_t count) |
| 2663 | { |
| 2664 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2665 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2666 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2667 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2668 | return -EINVAL; |
| 2669 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2670 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2671 | return -ERESTARTSYS; |
| 2672 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2673 | res = hotkey_user_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2674 | |
| 2675 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2676 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2677 | #endif |
| 2678 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2679 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2680 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2681 | tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t); |
| 2682 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2683 | return (res) ? res : count; |
| 2684 | } |
| 2685 | |
| 2686 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2687 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2688 | hotkey_mask_show, hotkey_mask_store); |
| 2689 | |
| 2690 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 2691 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 2692 | struct device_attribute *attr, |
| 2693 | char *buf) |
| 2694 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2695 | return sprintf(buf, "0\n"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2699 | __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] | 2700 | |
| 2701 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 2702 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 2703 | struct device_attribute *attr, |
| 2704 | char *buf) |
| 2705 | { |
Henrique de Moraes Holschuh | 06777be | 2009-09-12 15:22:15 -0300 | [diff] [blame] | 2706 | printk_deprecated_attribute("hotkey_bios_mask", |
| 2707 | "This attribute is useless."); |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2708 | 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] | 2709 | } |
| 2710 | |
| 2711 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2712 | __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] | 2713 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2714 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 2715 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 2716 | struct device_attribute *attr, |
| 2717 | char *buf) |
| 2718 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2719 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 2720 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 2724 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 2725 | |
| 2726 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 2727 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 2728 | struct device_attribute *attr, |
| 2729 | char *buf) |
| 2730 | { |
| 2731 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2732 | (hotkey_all_mask | hotkey_source_mask) |
| 2733 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 2737 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 2738 | hotkey_recommended_mask_show, NULL); |
| 2739 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2740 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2741 | |
| 2742 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 2743 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 2744 | struct device_attribute *attr, |
| 2745 | char *buf) |
| 2746 | { |
| 2747 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 2748 | } |
| 2749 | |
| 2750 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 2751 | struct device_attribute *attr, |
| 2752 | const char *buf, size_t count) |
| 2753 | { |
| 2754 | unsigned long t; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2755 | u32 r_ev; |
| 2756 | int rc; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2757 | |
| 2758 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 2759 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 2760 | return -EINVAL; |
| 2761 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2762 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2763 | return -ERESTARTSYS; |
| 2764 | |
| 2765 | HOTKEY_CONFIG_CRITICAL_START |
| 2766 | hotkey_source_mask = t; |
| 2767 | HOTKEY_CONFIG_CRITICAL_END |
| 2768 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2769 | rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) & |
| 2770 | ~hotkey_source_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2771 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2772 | |
| 2773 | /* check if events needed by the driver got disabled */ |
| 2774 | r_ev = hotkey_driver_mask & ~(hotkey_acpi_mask & hotkey_all_mask) |
| 2775 | & ~hotkey_source_mask & TPACPI_HKEY_NVRAM_KNOWN_MASK; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2776 | |
| 2777 | mutex_unlock(&hotkey_mutex); |
| 2778 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2779 | if (rc < 0) |
| 2780 | printk(TPACPI_ERR "hotkey_source_mask: failed to update the" |
| 2781 | "firmware event mask!\n"); |
| 2782 | |
| 2783 | if (r_ev) |
| 2784 | printk(TPACPI_NOTICE "hotkey_source_mask: " |
| 2785 | "some important events were disabled: " |
| 2786 | "0x%04x\n", r_ev); |
| 2787 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2788 | tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); |
| 2789 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2790 | return (rc < 0) ? rc : count; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 2794 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 2795 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 2796 | |
| 2797 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 2798 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 2799 | struct device_attribute *attr, |
| 2800 | char *buf) |
| 2801 | { |
| 2802 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 2803 | } |
| 2804 | |
| 2805 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 2806 | struct device_attribute *attr, |
| 2807 | const char *buf, size_t count) |
| 2808 | { |
| 2809 | unsigned long t; |
| 2810 | |
| 2811 | if (parse_strtoul(buf, 25, &t)) |
| 2812 | return -EINVAL; |
| 2813 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2814 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2815 | return -ERESTARTSYS; |
| 2816 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2817 | hotkey_poll_set_freq(t); |
| 2818 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2819 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2820 | mutex_unlock(&hotkey_mutex); |
| 2821 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2822 | tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t); |
| 2823 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2824 | return count; |
| 2825 | } |
| 2826 | |
| 2827 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 2828 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 2829 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 2830 | |
| 2831 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2832 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2833 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2834 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 2835 | struct device_attribute *attr, |
| 2836 | char *buf) |
| 2837 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2838 | int res; |
| 2839 | res = hotkey_get_wlsw(); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2840 | if (res < 0) |
| 2841 | return res; |
| 2842 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2843 | /* Opportunistic update */ |
| 2844 | tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF)); |
| 2845 | |
| 2846 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2847 | (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 2851 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 2852 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2853 | static void hotkey_radio_sw_notify_change(void) |
| 2854 | { |
| 2855 | if (tp_features.hotkey_wlsw) |
| 2856 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2857 | "hotkey_radio_sw"); |
| 2858 | } |
| 2859 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2860 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 2861 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 2862 | struct device_attribute *attr, |
| 2863 | char *buf) |
| 2864 | { |
| 2865 | int res, s; |
| 2866 | res = hotkey_get_tablet_mode(&s); |
| 2867 | if (res < 0) |
| 2868 | return res; |
| 2869 | |
| 2870 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 2871 | } |
| 2872 | |
| 2873 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 2874 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 2875 | |
| 2876 | static void hotkey_tablet_mode_notify_change(void) |
| 2877 | { |
| 2878 | if (tp_features.hotkey_tablet) |
| 2879 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2880 | "hotkey_tablet_mode"); |
| 2881 | } |
| 2882 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2883 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 2884 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 2885 | struct device_attribute *attr, |
| 2886 | char *buf) |
| 2887 | { |
| 2888 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2889 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 2890 | } |
| 2891 | |
| 2892 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 2893 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 2894 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2895 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2896 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 2897 | struct device_attribute *attr, |
| 2898 | char *buf) |
| 2899 | { |
| 2900 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 2901 | } |
| 2902 | |
| 2903 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 2904 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 2905 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2906 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2907 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2908 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2909 | "wakeup_reason"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2913 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 2914 | struct device_attribute *attr, |
| 2915 | char *buf) |
| 2916 | { |
| 2917 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 2918 | } |
| 2919 | |
| 2920 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 2921 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 2922 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 2923 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2924 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2925 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2926 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2927 | "wakeup_hotunplug_complete"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2928 | } |
| 2929 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2930 | /* --------------------------------------------------------------------- */ |
| 2931 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2932 | static struct attribute *hotkey_attributes[] __initdata = { |
| 2933 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2934 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2935 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2936 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2937 | &dev_attr_hotkey_wakeup_reason.attr, |
| 2938 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2939 | &dev_attr_hotkey_mask.attr, |
| 2940 | &dev_attr_hotkey_all_mask.attr, |
| 2941 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2942 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2943 | &dev_attr_hotkey_source_mask.attr, |
| 2944 | &dev_attr_hotkey_poll_freq.attr, |
| 2945 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2946 | }; |
| 2947 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2948 | /* |
| 2949 | * Sync both the hw and sw blocking state of all switches |
| 2950 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2951 | static void tpacpi_send_radiosw_update(void) |
| 2952 | { |
| 2953 | int wlsw; |
| 2954 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2955 | /* |
| 2956 | * We must sync all rfkill controllers *before* issuing any |
| 2957 | * rfkill input events, or we will race the rfkill core input |
| 2958 | * handler. |
| 2959 | * |
| 2960 | * tpacpi_inputdev_send_mutex works as a syncronization point |
| 2961 | * for the above. |
| 2962 | * |
| 2963 | * We optimize to avoid numerous calls to hotkey_get_wlsw. |
| 2964 | */ |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 2965 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2966 | wlsw = hotkey_get_wlsw(); |
| 2967 | |
| 2968 | /* Sync hw blocking state first if it is hw-blocked */ |
| 2969 | if (wlsw == TPACPI_RFK_RADIO_OFF) |
| 2970 | tpacpi_rfk_update_hwblock_state(true); |
| 2971 | |
| 2972 | /* Sync sw blocking state */ |
| 2973 | tpacpi_rfk_update_swstate_all(); |
| 2974 | |
| 2975 | /* Sync hw blocking state last if it is hw-unblocked */ |
| 2976 | if (wlsw == TPACPI_RFK_RADIO_ON) |
| 2977 | tpacpi_rfk_update_hwblock_state(false); |
| 2978 | |
| 2979 | /* Issue rfkill input event for WLSW switch */ |
| 2980 | if (!(wlsw < 0)) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2981 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2982 | |
| 2983 | input_report_switch(tpacpi_inputdev, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2984 | SW_RFKILL_ALL, (wlsw > 0)); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2985 | input_sync(tpacpi_inputdev); |
| 2986 | |
| 2987 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2988 | } |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2989 | |
| 2990 | /* |
| 2991 | * this can be unconditional, as we will poll state again |
| 2992 | * if userspace uses the notify to read data |
| 2993 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2994 | hotkey_radio_sw_notify_change(); |
| 2995 | } |
| 2996 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2997 | static void hotkey_exit(void) |
| 2998 | { |
| 2999 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3000 | mutex_lock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3001 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3002 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3003 | #endif |
| 3004 | |
| 3005 | if (hotkey_dev_attributes) |
| 3006 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3007 | |
| 3008 | kfree(hotkey_keycode_map); |
| 3009 | |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3010 | dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3011 | "restoring original HKEY status and mask\n"); |
| 3012 | /* yes, there is a bitwise or below, we want the |
| 3013 | * functions to be called even if one of them fail */ |
| 3014 | if (((tp_features.hotkey_mask && |
| 3015 | hotkey_mask_set(hotkey_orig_mask)) | |
| 3016 | hotkey_status_set(false)) != 0) |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3017 | printk(TPACPI_ERR |
| 3018 | "failed to restore hot key mask " |
| 3019 | "to BIOS defaults\n"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3020 | } |
| 3021 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3022 | static void __init hotkey_unmap(const unsigned int scancode) |
| 3023 | { |
| 3024 | if (hotkey_keycode_map[scancode] != KEY_RESERVED) { |
| 3025 | clear_bit(hotkey_keycode_map[scancode], |
| 3026 | tpacpi_inputdev->keybit); |
| 3027 | hotkey_keycode_map[scancode] = KEY_RESERVED; |
| 3028 | } |
| 3029 | } |
| 3030 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3031 | /* |
| 3032 | * HKEY quirks: |
| 3033 | * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12 |
| 3034 | */ |
| 3035 | |
| 3036 | #define TPACPI_HK_Q_INIMASK 0x0001 |
| 3037 | |
| 3038 | static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = { |
| 3039 | TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3040 | TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3041 | TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK), /* 770, 770E, 770ED */ |
| 3042 | TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK), /* A20m */ |
| 3043 | TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK), /* A20p */ |
| 3044 | TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK), /* A21e, A22e */ |
| 3045 | TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK), /* A21e */ |
| 3046 | TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK), /* A21m, A22m */ |
| 3047 | TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK), /* A21p, A22p */ |
| 3048 | TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK), /* A22e */ |
| 3049 | TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK), /* A22m */ |
| 3050 | TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK), /* A30/p (0) */ |
| 3051 | TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK), /* R30 */ |
| 3052 | TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK), /* R31 */ |
| 3053 | TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK), /* T20 */ |
| 3054 | TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK), /* T21 */ |
| 3055 | TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK), /* T22 */ |
| 3056 | TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK), /* X20, X21 */ |
| 3057 | TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */ |
| 3058 | }; |
| 3059 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3060 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3061 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3062 | /* Requirements for changing the default keymaps: |
| 3063 | * |
| 3064 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 3065 | * good reasons. Do not change them unless you have deep |
| 3066 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 3067 | * the various ThinkPad models. The driver behaves |
| 3068 | * differently for KEY_RESERVED: such keys have their |
| 3069 | * hot key mask *unset* in mask_recommended, and also |
| 3070 | * in the initial hot key mask programmed into the |
| 3071 | * firmware at driver load time, which means the firm- |
| 3072 | * ware may react very differently if you change them to |
| 3073 | * something else; |
| 3074 | * |
| 3075 | * 2. You must be subscribed to the linux-thinkpad and |
| 3076 | * ibm-acpi-devel mailing lists, and you should read the |
| 3077 | * list archives since 2007 if you want to change the |
| 3078 | * keymaps. This requirement exists so that you will |
| 3079 | * know the past history of problems with the thinkpad- |
| 3080 | * acpi driver keymaps, and also that you will be |
| 3081 | * listening to any bug reports; |
| 3082 | * |
| 3083 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 3084 | * for merging, *ever*. Send them to the linux-acpi |
| 3085 | * mailinglist for comments. Merging is to be done only |
| 3086 | * through acpi-test and the ACPI maintainer. |
| 3087 | * |
| 3088 | * If the above is too much to ask, don't change the keymap. |
| 3089 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 3090 | */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3091 | static u16 ibm_keycode_map[] __initdata = { |
| 3092 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 3093 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
| 3094 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 3095 | 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] | 3096 | |
| 3097 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3098 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3099 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3100 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3101 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3102 | /* brightness: firmware always reacts to them */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3103 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3104 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3105 | |
| 3106 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3107 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3108 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3109 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3110 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3111 | |
| 3112 | /* Volume: firmware always react to it and reprograms |
| 3113 | * the built-in *extra* mixer. Never map it to control |
| 3114 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3115 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3116 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3117 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3118 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3119 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3120 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3121 | /* (assignments unknown, please report if found) */ |
| 3122 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3123 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3124 | }; |
| 3125 | static u16 lenovo_keycode_map[] __initdata = { |
| 3126 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 3127 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
| 3128 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 3129 | 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] | 3130 | |
| 3131 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3132 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3133 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3134 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3135 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3136 | /* These should be enabled --only-- when ACPI video |
| 3137 | * is disabled (i.e. in "vendor" mode), and are handled |
| 3138 | * in a special way by the init code */ |
| 3139 | KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ |
| 3140 | KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3141 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3142 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3143 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3144 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3145 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3146 | |
| 3147 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 3148 | * react to it and reprograms the built-in *extra* mixer. |
| 3149 | * Never map it to control another mixer by default. |
| 3150 | * |
| 3151 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 3152 | * these over the regular keyboard, so these are no-ops, |
| 3153 | * but there are still weird bugs re. MUTE, so do not |
| 3154 | * change unless you get test reports from all Lenovo |
| 3155 | * models. May cause the BIOS to interfere with the |
| 3156 | * HDA mixer. |
| 3157 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3158 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3159 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3160 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3161 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3162 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3163 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3164 | /* (assignments unknown, please report if found) */ |
| 3165 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3166 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3167 | }; |
| 3168 | |
| 3169 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) |
| 3170 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) |
| 3171 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) |
| 3172 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3173 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3174 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 3175 | int hkeyv; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3176 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3177 | unsigned long quirks; |
| 3178 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3179 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3180 | "initializing hotkey subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3181 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3182 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3183 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 3184 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3185 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3186 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3187 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3188 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3189 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 3190 | mutex_init(&hotkey_thread_mutex); |
| 3191 | mutex_init(&hotkey_thread_data_mutex); |
| 3192 | #endif |
| 3193 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3194 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3195 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3196 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3197 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3198 | "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3199 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3200 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3201 | if (!tp_features.hotkey) |
| 3202 | return 1; |
| 3203 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3204 | quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, |
| 3205 | ARRAY_SIZE(tpacpi_hotkey_qtable)); |
| 3206 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3207 | tpacpi_disable_brightness_delay(); |
| 3208 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3209 | /* MUST have enough space for all attributes to be added to |
| 3210 | * hotkey_dev_attributes */ |
| 3211 | hotkey_dev_attributes = create_attr_set( |
| 3212 | ARRAY_SIZE(hotkey_attributes) + 2, |
| 3213 | NULL); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3214 | if (!hotkey_dev_attributes) |
| 3215 | return -ENOMEM; |
| 3216 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 3217 | hotkey_attributes, |
| 3218 | ARRAY_SIZE(hotkey_attributes)); |
| 3219 | if (res) |
| 3220 | goto err_exit; |
| 3221 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3222 | /* 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] | 3223 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 3224 | for HKEY interface version 0x100 */ |
| 3225 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 3226 | if ((hkeyv >> 8) != 1) { |
| 3227 | printk(TPACPI_ERR "unknown version of the " |
| 3228 | "HKEY interface: 0x%x\n", hkeyv); |
| 3229 | printk(TPACPI_ERR "please report this to %s\n", |
| 3230 | TPACPI_MAIL); |
| 3231 | } else { |
| 3232 | /* |
| 3233 | * MHKV 0x100 in A31, R40, R40e, |
| 3234 | * T4x, X31, and later |
| 3235 | */ |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3236 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3237 | "firmware HKEY interface version: 0x%x\n", |
| 3238 | hkeyv); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3239 | |
| 3240 | /* Paranoia check AND init hotkey_all_mask */ |
| 3241 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
| 3242 | "MHKA", "qd")) { |
| 3243 | printk(TPACPI_ERR |
| 3244 | "missing MHKA handler, " |
| 3245 | "please report this to %s\n", |
| 3246 | TPACPI_MAIL); |
| 3247 | /* Fallback: pre-init for FN+F3,F4,F12 */ |
| 3248 | hotkey_all_mask = 0x080cU; |
| 3249 | } else { |
| 3250 | tp_features.hotkey_mask = 1; |
| 3251 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3252 | } |
| 3253 | } |
| 3254 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3255 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3256 | "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3257 | str_supported(tp_features.hotkey_mask)); |
| 3258 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3259 | /* Init hotkey_all_mask if not initialized yet */ |
| 3260 | if (!tp_features.hotkey_mask && !hotkey_all_mask && |
| 3261 | (quirks & TPACPI_HK_Q_INIMASK)) |
| 3262 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3263 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3264 | /* Init hotkey_acpi_mask and hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3265 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3266 | /* hotkey_source_mask *must* be zero for |
| 3267 | * the first hotkey_mask_get to return hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3268 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3269 | if (res) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3270 | goto err_exit; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3271 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3272 | hotkey_orig_mask = hotkey_acpi_mask; |
| 3273 | } else { |
| 3274 | hotkey_orig_mask = hotkey_all_mask; |
| 3275 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3276 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3277 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3278 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3279 | if (dbg_wlswemul) { |
| 3280 | tp_features.hotkey_wlsw = 1; |
| 3281 | printk(TPACPI_INFO |
| 3282 | "radio switch emulation enabled\n"); |
| 3283 | } else |
| 3284 | #endif |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3285 | /* Not all thinkpads have a hardware radio switch */ |
| 3286 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 3287 | tp_features.hotkey_wlsw = 1; |
| 3288 | printk(TPACPI_INFO |
| 3289 | "radio switch found; radios are %s\n", |
| 3290 | enabled(status, 0)); |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3291 | } |
| 3292 | if (tp_features.hotkey_wlsw) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3293 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3294 | &dev_attr_hotkey_radio_sw.attr); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3295 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3296 | /* For X41t, X60t, X61t Tablets... */ |
| 3297 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 3298 | tp_features.hotkey_tablet = 1; |
| 3299 | printk(TPACPI_INFO |
| 3300 | "possible tablet mode switch found; " |
| 3301 | "ThinkPad in %s mode\n", |
| 3302 | (status & TP_HOTKEY_TABLET_MASK)? |
| 3303 | "tablet" : "laptop"); |
| 3304 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3305 | &dev_attr_hotkey_tablet_mode.attr); |
| 3306 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3307 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3308 | if (!res) |
| 3309 | res = register_attr_set_with_sysfs( |
| 3310 | hotkey_dev_attributes, |
| 3311 | &tpacpi_pdev->dev.kobj); |
| 3312 | if (res) |
| 3313 | goto err_exit; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3314 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3315 | /* Set up key map */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3316 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3317 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 3318 | GFP_KERNEL); |
| 3319 | if (!hotkey_keycode_map) { |
| 3320 | printk(TPACPI_ERR |
| 3321 | "failed to allocate memory for key map\n"); |
| 3322 | res = -ENOMEM; |
| 3323 | goto err_exit; |
| 3324 | } |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3325 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3326 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3327 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3328 | "using Lenovo default hot key map\n"); |
| 3329 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, |
| 3330 | TPACPI_HOTKEY_MAP_SIZE); |
| 3331 | } else { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3332 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3333 | "using IBM default hot key map\n"); |
| 3334 | memcpy(hotkey_keycode_map, &ibm_keycode_map, |
| 3335 | TPACPI_HOTKEY_MAP_SIZE); |
| 3336 | } |
| 3337 | |
| 3338 | set_bit(EV_KEY, tpacpi_inputdev->evbit); |
| 3339 | set_bit(EV_MSC, tpacpi_inputdev->evbit); |
| 3340 | set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); |
| 3341 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 3342 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 3343 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 3344 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
| 3345 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
| 3346 | set_bit(hotkey_keycode_map[i], |
| 3347 | tpacpi_inputdev->keybit); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3348 | } else { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3349 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 3350 | hotkey_reserved_mask |= 1 << i; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3351 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3352 | } |
| 3353 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3354 | if (tp_features.hotkey_wlsw) { |
| 3355 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 3356 | set_bit(SW_RFKILL_ALL, tpacpi_inputdev->swbit); |
| 3357 | } |
| 3358 | if (tp_features.hotkey_tablet) { |
| 3359 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 3360 | set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3361 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3362 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3363 | /* Do not issue duplicate brightness change events to |
| 3364 | * userspace */ |
| 3365 | if (!tp_features.bright_acpimode) |
| 3366 | /* update bright_acpimode... */ |
| 3367 | tpacpi_check_std_acpi_brightness_support(); |
| 3368 | |
Henrique de Moraes Holschuh | 8bf3d4c | 2009-05-30 13:25:09 -0300 | [diff] [blame] | 3369 | if (tp_features.bright_acpimode && acpi_video_backlight_support()) { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3370 | printk(TPACPI_INFO |
| 3371 | "This ThinkPad has standard ACPI backlight " |
| 3372 | "brightness control, supported by the ACPI " |
| 3373 | "video driver\n"); |
| 3374 | printk(TPACPI_NOTICE |
| 3375 | "Disabling thinkpad-acpi brightness events " |
| 3376 | "by default...\n"); |
| 3377 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3378 | /* Disable brightness up/down on Lenovo thinkpads when |
| 3379 | * ACPI is handling them, otherwise it is plain impossible |
| 3380 | * for userspace to do something even remotely sane */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3381 | hotkey_reserved_mask |= |
| 3382 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 3383 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3384 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 3385 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3386 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3387 | |
Henrique de Moraes Holschuh | 230d8cf25 | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3388 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3389 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 3390 | & ~hotkey_all_mask |
| 3391 | & ~hotkey_reserved_mask; |
Henrique de Moraes Holschuh | 230d8cf25 | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3392 | |
| 3393 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3394 | "hotkey source mask 0x%08x, polling freq %u\n", |
| 3395 | hotkey_source_mask, hotkey_poll_freq); |
| 3396 | #endif |
| 3397 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3398 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3399 | "enabling firmware HKEY event interface...\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3400 | res = hotkey_status_set(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3401 | if (res) { |
| 3402 | hotkey_exit(); |
| 3403 | return res; |
| 3404 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3405 | res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask) |
| 3406 | | hotkey_driver_mask) |
| 3407 | & ~hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3408 | if (res < 0 && res != -ENXIO) { |
| 3409 | hotkey_exit(); |
| 3410 | return res; |
| 3411 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3412 | hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask) |
| 3413 | & ~hotkey_reserved_mask; |
| 3414 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3415 | "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n", |
| 3416 | hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3417 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3418 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3419 | "legacy ibm/hotkey event reporting over procfs %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3420 | (hotkey_report_mode < 2) ? |
| 3421 | "enabled" : "disabled"); |
| 3422 | |
| 3423 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 3424 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 3425 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3426 | hotkey_poll_setup_safe(true); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3427 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3428 | tpacpi_input_send_tabletsw(); |
| 3429 | |
| 3430 | return 0; |
| 3431 | |
| 3432 | err_exit: |
| 3433 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3434 | hotkey_dev_attributes = NULL; |
| 3435 | |
| 3436 | return (res < 0)? res : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3437 | } |
| 3438 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3439 | static bool hotkey_notify_hotkey(const u32 hkey, |
| 3440 | bool *send_acpi_ev, |
| 3441 | bool *ignore_acpi_ev) |
| 3442 | { |
| 3443 | /* 0x1000-0x1FFF: key presses */ |
| 3444 | unsigned int scancode = hkey & 0xfff; |
| 3445 | *send_acpi_ev = true; |
| 3446 | *ignore_acpi_ev = false; |
| 3447 | |
| 3448 | if (scancode > 0 && scancode < 0x21) { |
| 3449 | scancode--; |
| 3450 | if (!(hotkey_source_mask & (1 << scancode))) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3451 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3452 | *send_acpi_ev = false; |
| 3453 | } else { |
| 3454 | *ignore_acpi_ev = true; |
| 3455 | } |
| 3456 | return true; |
| 3457 | } |
| 3458 | return false; |
| 3459 | } |
| 3460 | |
| 3461 | static bool hotkey_notify_wakeup(const u32 hkey, |
| 3462 | bool *send_acpi_ev, |
| 3463 | bool *ignore_acpi_ev) |
| 3464 | { |
| 3465 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3466 | *send_acpi_ev = true; |
| 3467 | *ignore_acpi_ev = false; |
| 3468 | |
| 3469 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3470 | case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */ |
| 3471 | case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3472 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 3473 | *ignore_acpi_ev = true; |
| 3474 | break; |
| 3475 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3476 | case TP_HKEY_EV_WKUP_S3_BAYEJ: /* suspend, bay eject */ |
| 3477 | case TP_HKEY_EV_WKUP_S4_BAYEJ: /* hibernation, bay eject */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3478 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 3479 | *ignore_acpi_ev = true; |
| 3480 | break; |
| 3481 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3482 | case TP_HKEY_EV_WKUP_S3_BATLOW: /* Battery on critical low level/S3 */ |
| 3483 | 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] | 3484 | printk(TPACPI_ALERT |
| 3485 | "EMERGENCY WAKEUP: battery almost empty\n"); |
| 3486 | /* how to auto-heal: */ |
| 3487 | /* 2313: woke up from S3, go to S4/S5 */ |
| 3488 | /* 2413: woke up from S4, go to S5 */ |
| 3489 | break; |
| 3490 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3491 | default: |
| 3492 | return false; |
| 3493 | } |
| 3494 | |
| 3495 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
| 3496 | printk(TPACPI_INFO |
| 3497 | "woke up due to a hot-unplug " |
| 3498 | "request...\n"); |
| 3499 | hotkey_wakeup_reason_notify_change(); |
| 3500 | } |
| 3501 | return true; |
| 3502 | } |
| 3503 | |
| 3504 | static bool hotkey_notify_usrevent(const u32 hkey, |
| 3505 | bool *send_acpi_ev, |
| 3506 | bool *ignore_acpi_ev) |
| 3507 | { |
| 3508 | /* 0x5000-0x5FFF: human interface helpers */ |
| 3509 | *send_acpi_ev = true; |
| 3510 | *ignore_acpi_ev = false; |
| 3511 | |
| 3512 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3513 | case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */ |
| 3514 | 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] | 3515 | return true; |
| 3516 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3517 | case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */ |
| 3518 | case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3519 | tpacpi_input_send_tabletsw(); |
| 3520 | hotkey_tablet_mode_notify_change(); |
| 3521 | *send_acpi_ev = false; |
| 3522 | return true; |
| 3523 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3524 | case TP_HKEY_EV_LID_CLOSE: /* Lid closed */ |
| 3525 | case TP_HKEY_EV_LID_OPEN: /* Lid opened */ |
| 3526 | case TP_HKEY_EV_BRGHT_CHANGED: /* brightness changed */ |
Henrique de Moraes Holschuh | 176dd98 | 2009-09-20 14:09:24 -0300 | [diff] [blame] | 3527 | /* do not propagate these events */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3528 | *ignore_acpi_ev = true; |
| 3529 | return true; |
| 3530 | |
| 3531 | default: |
| 3532 | return false; |
| 3533 | } |
| 3534 | } |
| 3535 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3536 | static bool hotkey_notify_thermal(const u32 hkey, |
| 3537 | bool *send_acpi_ev, |
| 3538 | bool *ignore_acpi_ev) |
| 3539 | { |
| 3540 | /* 0x6000-0x6FFF: thermal alarms */ |
| 3541 | *send_acpi_ev = true; |
| 3542 | *ignore_acpi_ev = false; |
| 3543 | |
| 3544 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3545 | case TP_HKEY_EV_ALARM_BAT_HOT: |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3546 | printk(TPACPI_CRIT |
| 3547 | "THERMAL ALARM: battery is too hot!\n"); |
| 3548 | /* recommended action: warn user through gui */ |
| 3549 | return true; |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3550 | case TP_HKEY_EV_ALARM_BAT_XHOT: |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3551 | printk(TPACPI_ALERT |
| 3552 | "THERMAL EMERGENCY: battery is extremely hot!\n"); |
| 3553 | /* recommended action: immediate sleep/hibernate */ |
| 3554 | return true; |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3555 | case TP_HKEY_EV_ALARM_SENSOR_HOT: |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3556 | printk(TPACPI_CRIT |
| 3557 | "THERMAL ALARM: " |
| 3558 | "a sensor reports something is too hot!\n"); |
| 3559 | /* recommended action: warn user through gui, that */ |
| 3560 | /* some internal component is too hot */ |
| 3561 | return true; |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3562 | case TP_HKEY_EV_ALARM_SENSOR_XHOT: |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3563 | printk(TPACPI_ALERT |
| 3564 | "THERMAL EMERGENCY: " |
| 3565 | "a sensor reports something is extremely hot!\n"); |
| 3566 | /* recommended action: immediate sleep/hibernate */ |
| 3567 | return true; |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3568 | case TP_HKEY_EV_THM_TABLE_CHANGED: |
Henrique de Moraes Holschuh | 54926ce | 2009-01-11 03:01:09 -0200 | [diff] [blame] | 3569 | printk(TPACPI_INFO |
| 3570 | "EC reports that Thermal Table has changed\n"); |
| 3571 | /* recommended action: do nothing, we don't have |
| 3572 | * Lenovo ATM information */ |
| 3573 | return true; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3574 | default: |
| 3575 | printk(TPACPI_ALERT |
| 3576 | "THERMAL ALERT: unknown thermal alarm received\n"); |
| 3577 | return false; |
| 3578 | } |
| 3579 | } |
| 3580 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3581 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 3582 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3583 | u32 hkey; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3584 | bool send_acpi_ev; |
| 3585 | bool ignore_acpi_ev; |
| 3586 | bool known_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3587 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3588 | if (event != 0x80) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3589 | printk(TPACPI_ERR |
| 3590 | "unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3591 | /* 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] | 3592 | acpi_bus_generate_netlink_event( |
| 3593 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3594 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3595 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3596 | return; |
| 3597 | } |
| 3598 | |
| 3599 | while (1) { |
| 3600 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3601 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3602 | return; |
| 3603 | } |
| 3604 | |
| 3605 | if (hkey == 0) { |
| 3606 | /* queue empty */ |
| 3607 | return; |
| 3608 | } |
| 3609 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3610 | send_acpi_ev = true; |
| 3611 | ignore_acpi_ev = false; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3612 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3613 | switch (hkey >> 12) { |
| 3614 | case 1: |
| 3615 | /* 0x1000-0x1FFF: key presses */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3616 | known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev, |
| 3617 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3618 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3619 | case 2: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3620 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3621 | known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev, |
| 3622 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3623 | break; |
| 3624 | case 3: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3625 | /* 0x3000-0x3FFF: bay-related wakeups */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3626 | if (hkey == TP_HKEY_EV_BAYEJ_ACK) { |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3627 | hotkey_autosleep_ack = 1; |
| 3628 | printk(TPACPI_INFO |
| 3629 | "bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3630 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3631 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3632 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3633 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3634 | } |
| 3635 | break; |
| 3636 | case 4: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3637 | /* 0x4000-0x4FFF: dock-related wakeups */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3638 | if (hkey == TP_HKEY_EV_UNDOCK_ACK) { |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3639 | hotkey_autosleep_ack = 1; |
| 3640 | printk(TPACPI_INFO |
| 3641 | "undocked\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3642 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3643 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3644 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3645 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3646 | } |
| 3647 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3648 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 3649 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3650 | known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev, |
| 3651 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3652 | break; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3653 | case 6: |
| 3654 | /* 0x6000-0x6FFF: thermal alarms */ |
| 3655 | known_ev = hotkey_notify_thermal(hkey, &send_acpi_ev, |
| 3656 | &ignore_acpi_ev); |
| 3657 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3658 | case 7: |
| 3659 | /* 0x7000-0x7FFF: misc */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3660 | if (tp_features.hotkey_wlsw && |
| 3661 | hkey == TP_HKEY_EV_RFKILL_CHANGED) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3662 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3663 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3664 | known_ev = true; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3665 | break; |
| 3666 | } |
| 3667 | /* fallthrough to default */ |
| 3668 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3669 | known_ev = false; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3670 | } |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3671 | if (!known_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3672 | printk(TPACPI_NOTICE |
| 3673 | "unhandled HKEY event 0x%04x\n", hkey); |
Henrique de Moraes Holschuh | cb42935 | 2009-01-11 03:01:07 -0200 | [diff] [blame] | 3674 | printk(TPACPI_NOTICE |
| 3675 | "please report the conditions when this " |
| 3676 | "event happened to %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3677 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3678 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3679 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3680 | if (!ignore_acpi_ev && |
| 3681 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 3682 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 3683 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3684 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3685 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3686 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3687 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3688 | acpi_bus_generate_netlink_event( |
| 3689 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3690 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3691 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3692 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3693 | } |
| 3694 | } |
| 3695 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3696 | static void hotkey_suspend(pm_message_t state) |
| 3697 | { |
| 3698 | /* Do these on suspend, we get the events on early resume! */ |
| 3699 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 3700 | hotkey_autosleep_ack = 0; |
| 3701 | } |
| 3702 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3703 | static void hotkey_resume(void) |
| 3704 | { |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3705 | tpacpi_disable_brightness_delay(); |
| 3706 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3707 | if (hotkey_status_set(true) < 0 || |
| 3708 | hotkey_mask_set(hotkey_acpi_mask) < 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3709 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3710 | "error while attempting to reset the event " |
| 3711 | "firmware interface\n"); |
| 3712 | |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3713 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3714 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3715 | hotkey_wakeup_reason_notify_change(); |
| 3716 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3717 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3718 | } |
| 3719 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3720 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3721 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3723 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | int len = 0; |
| 3725 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3726 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3727 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3728 | return len; |
| 3729 | } |
| 3730 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3731 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3732 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3733 | res = hotkey_status_get(&status); |
| 3734 | if (!res) |
| 3735 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3736 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3737 | if (res) |
| 3738 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | |
| 3740 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3741 | if (hotkey_all_mask) { |
| 3742 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_user_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | len += sprintf(p + len, |
| 3744 | "commands:\tenable, disable, reset, <mask>\n"); |
| 3745 | } else { |
| 3746 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 3747 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 3748 | } |
| 3749 | |
| 3750 | return len; |
| 3751 | } |
| 3752 | |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3753 | static void hotkey_enabledisable_warn(bool enable) |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3754 | { |
| 3755 | tpacpi_log_usertask("procfs hotkey enable/disable"); |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3756 | if (!WARN((tpacpi_lifecycle == TPACPI_LIFE_RUNNING || !enable), |
| 3757 | TPACPI_WARN |
| 3758 | "hotkey enable/disable functionality has been " |
| 3759 | "removed from the driver. Hotkeys are always " |
| 3760 | "enabled\n")) |
| 3761 | printk(TPACPI_ERR |
| 3762 | "Please remove the hotkey=enable module " |
| 3763 | "parameter, it is deprecated. Hotkeys are always " |
| 3764 | "enabled\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3765 | } |
| 3766 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3767 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3769 | int res; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3770 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3773 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | return -ENODEV; |
| 3775 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3776 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3777 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3778 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3779 | mask = hotkey_user_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3780 | |
| 3781 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | while ((cmd = next_cmd(&buf))) { |
| 3783 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3784 | hotkey_enabledisable_warn(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3786 | hotkey_enabledisable_warn(0); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3787 | res = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | } else if (strlencmp(cmd, "reset") == 0) { |
Henrique de Moraes Holschuh | 20c9aa4 | 2009-09-12 15:22:16 -0300 | [diff] [blame] | 3789 | mask = (hotkey_all_mask | hotkey_source_mask) |
| 3790 | & ~hotkey_reserved_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 3792 | /* mask set */ |
| 3793 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 3794 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3795 | } else { |
| 3796 | res = -EINVAL; |
| 3797 | goto errexit; |
| 3798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | } |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3800 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3801 | if (!res) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3802 | tpacpi_disclose_usertask("procfs hotkey", |
| 3803 | "set mask to 0x%08x\n", mask); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3804 | res = hotkey_user_mask_set(mask); |
| 3805 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3807 | errexit: |
| 3808 | mutex_unlock(&hotkey_mutex); |
| 3809 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3810 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3812 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3813 | {TPACPI_ACPI_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3814 | {"", 0}, |
| 3815 | }; |
| 3816 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3817 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3818 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3819 | .notify = hotkey_notify, |
| 3820 | .handle = &hkey_handle, |
| 3821 | .type = ACPI_DEVICE_NOTIFY, |
| 3822 | }; |
| 3823 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3824 | static struct ibm_struct hotkey_driver_data = { |
| 3825 | .name = "hotkey", |
| 3826 | .read = hotkey_read, |
| 3827 | .write = hotkey_write, |
| 3828 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3829 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3830 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3831 | .acpi = &ibm_hotkey_acpidriver, |
| 3832 | }; |
| 3833 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3834 | /************************************************************************* |
| 3835 | * Bluetooth subdriver |
| 3836 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3838 | enum { |
| 3839 | /* ACPI GBDC/SBDC bits */ |
| 3840 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 3841 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3842 | TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: |
| 3843 | off / last state */ |
| 3844 | }; |
| 3845 | |
| 3846 | enum { |
| 3847 | /* ACPI \BLTH commands */ |
| 3848 | TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */ |
| 3849 | TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */ |
| 3850 | TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */ |
| 3851 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */ |
| 3852 | 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] | 3853 | }; |
| 3854 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3855 | #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" |
| 3856 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3857 | static void bluetooth_suspend(pm_message_t state) |
| 3858 | { |
| 3859 | /* Try to make sure radio will resume powered off */ |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3860 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 3861 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME)) |
| 3862 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3863 | "bluetooth power down on resume request failed\n"); |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3864 | } |
| 3865 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3866 | static int bluetooth_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3867 | { |
| 3868 | int status; |
| 3869 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3870 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3871 | if (dbg_bluetoothemul) |
| 3872 | return (tpacpi_bluetooth_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3873 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3874 | #endif |
| 3875 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3876 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 3877 | return -EIO; |
| 3878 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3879 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3880 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3881 | } |
| 3882 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3883 | static int bluetooth_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3884 | { |
| 3885 | int status; |
| 3886 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3887 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3888 | "will attempt to %s bluetooth\n", |
| 3889 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3890 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3891 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3892 | if (dbg_bluetoothemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3893 | tpacpi_bluetooth_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3894 | return 0; |
| 3895 | } |
| 3896 | #endif |
| 3897 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3898 | /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */ |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3899 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3900 | status = TP_ACPI_BLUETOOTH_RADIOSSW; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3901 | else |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3902 | status = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3903 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3904 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 3905 | return -EIO; |
| 3906 | |
| 3907 | return 0; |
| 3908 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3909 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3910 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 3911 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 3912 | struct device_attribute *attr, |
| 3913 | char *buf) |
| 3914 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3915 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3916 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 3920 | struct device_attribute *attr, |
| 3921 | const char *buf, size_t count) |
| 3922 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3923 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3924 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3925 | } |
| 3926 | |
| 3927 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 3928 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3929 | bluetooth_enable_show, bluetooth_enable_store); |
| 3930 | |
| 3931 | /* --------------------------------------------------------------------- */ |
| 3932 | |
| 3933 | static struct attribute *bluetooth_attributes[] = { |
| 3934 | &dev_attr_bluetooth_enable.attr, |
| 3935 | NULL |
| 3936 | }; |
| 3937 | |
| 3938 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3939 | .attrs = bluetooth_attributes, |
| 3940 | }; |
| 3941 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3942 | static const struct tpacpi_rfk_ops bluetooth_tprfk_ops = { |
| 3943 | .get_status = bluetooth_get_status, |
| 3944 | .set_status = bluetooth_set_status, |
| 3945 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3946 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3947 | static void bluetooth_shutdown(void) |
| 3948 | { |
| 3949 | /* Order firmware to save current state to NVRAM */ |
| 3950 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 3951 | TP_ACPI_BLTH_SAVE_STATE)) |
| 3952 | printk(TPACPI_NOTICE |
| 3953 | "failed to save bluetooth state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3954 | else |
| 3955 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3956 | "bluestooth state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3957 | } |
| 3958 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3959 | static void bluetooth_exit(void) |
| 3960 | { |
| 3961 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 3962 | &bluetooth_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3963 | |
| 3964 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
| 3965 | |
| 3966 | bluetooth_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3967 | } |
| 3968 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3969 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3971 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3972 | int status = 0; |
| 3973 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3974 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3975 | "initializing bluetooth subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3976 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3977 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3978 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3979 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 3980 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3981 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3982 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3984 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3985 | "bluetooth is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3986 | str_supported(tp_features.bluetooth), |
| 3987 | status); |
| 3988 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3989 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3990 | if (dbg_bluetoothemul) { |
| 3991 | tp_features.bluetooth = 1; |
| 3992 | printk(TPACPI_INFO |
| 3993 | "bluetooth switch emulation enabled\n"); |
| 3994 | } else |
| 3995 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3996 | if (tp_features.bluetooth && |
| 3997 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 3998 | /* no bluetooth hardware present in system */ |
| 3999 | tp_features.bluetooth = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4000 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4001 | "bluetooth hardware not installed\n"); |
| 4002 | } |
| 4003 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4004 | if (!tp_features.bluetooth) |
| 4005 | return 1; |
| 4006 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4007 | res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 4008 | &bluetooth_tprfk_ops, |
| 4009 | RFKILL_TYPE_BLUETOOTH, |
| 4010 | TPACPI_RFK_BLUETOOTH_SW_NAME, |
| 4011 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4012 | if (res) |
| 4013 | return res; |
| 4014 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4015 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4016 | &bluetooth_attr_group); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4017 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4018 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4019 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4020 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4021 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4022 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | } |
| 4024 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4025 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4026 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4028 | return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | } |
| 4030 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4031 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4033 | return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | } |
| 4035 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4036 | static struct ibm_struct bluetooth_driver_data = { |
| 4037 | .name = "bluetooth", |
| 4038 | .read = bluetooth_read, |
| 4039 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4040 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4041 | .suspend = bluetooth_suspend, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4042 | .shutdown = bluetooth_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4043 | }; |
| 4044 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4045 | /************************************************************************* |
| 4046 | * Wan subdriver |
| 4047 | */ |
| 4048 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4049 | enum { |
| 4050 | /* ACPI GWAN/SWAN bits */ |
| 4051 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 4052 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4053 | TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: |
| 4054 | off / last state */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4055 | }; |
| 4056 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4057 | #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" |
| 4058 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4059 | static void wan_suspend(pm_message_t state) |
| 4060 | { |
| 4061 | /* Try to make sure radio will resume powered off */ |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4062 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "qvd", |
| 4063 | TP_ACPI_WGSV_PWR_OFF_ON_RESUME)) |
| 4064 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 4065 | "WWAN power down on resume request failed\n"); |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4066 | } |
| 4067 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4068 | static int wan_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4069 | { |
| 4070 | int status; |
| 4071 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4072 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4073 | if (dbg_wwanemul) |
| 4074 | return (tpacpi_wwan_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4075 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4076 | #endif |
| 4077 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4078 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 4079 | return -EIO; |
| 4080 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4081 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4082 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4083 | } |
| 4084 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4085 | static int wan_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4086 | { |
| 4087 | int status; |
| 4088 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4089 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4090 | "will attempt to %s wwan\n", |
| 4091 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4092 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4093 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4094 | if (dbg_wwanemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4095 | tpacpi_wwan_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4096 | return 0; |
| 4097 | } |
| 4098 | #endif |
| 4099 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4100 | /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */ |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4101 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4102 | status = TP_ACPI_WANCARD_RADIOSSW; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4103 | else |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4104 | status = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4105 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4106 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 4107 | return -EIO; |
| 4108 | |
| 4109 | return 0; |
| 4110 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4111 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4112 | /* sysfs wan enable ---------------------------------------------------- */ |
| 4113 | static ssize_t wan_enable_show(struct device *dev, |
| 4114 | struct device_attribute *attr, |
| 4115 | char *buf) |
| 4116 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4117 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID, |
| 4118 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4119 | } |
| 4120 | |
| 4121 | static ssize_t wan_enable_store(struct device *dev, |
| 4122 | struct device_attribute *attr, |
| 4123 | const char *buf, size_t count) |
| 4124 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4125 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID, |
| 4126 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 4130 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4131 | wan_enable_show, wan_enable_store); |
| 4132 | |
| 4133 | /* --------------------------------------------------------------------- */ |
| 4134 | |
| 4135 | static struct attribute *wan_attributes[] = { |
| 4136 | &dev_attr_wan_enable.attr, |
| 4137 | NULL |
| 4138 | }; |
| 4139 | |
| 4140 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4141 | .attrs = wan_attributes, |
| 4142 | }; |
| 4143 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4144 | static const struct tpacpi_rfk_ops wan_tprfk_ops = { |
| 4145 | .get_status = wan_get_status, |
| 4146 | .set_status = wan_set_status, |
| 4147 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4148 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4149 | static void wan_shutdown(void) |
| 4150 | { |
| 4151 | /* Order firmware to save current state to NVRAM */ |
| 4152 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd", |
| 4153 | TP_ACPI_WGSV_SAVE_STATE)) |
| 4154 | printk(TPACPI_NOTICE |
| 4155 | "failed to save WWAN state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4156 | else |
| 4157 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 4158 | "WWAN state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4159 | } |
| 4160 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4161 | static void wan_exit(void) |
| 4162 | { |
| 4163 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 4164 | &wan_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4165 | |
| 4166 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
| 4167 | |
| 4168 | wan_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4169 | } |
| 4170 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4171 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4172 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4173 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4174 | int status = 0; |
| 4175 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4176 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4177 | "initializing wan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4178 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4179 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4180 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4181 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4182 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4183 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4184 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4185 | "wan is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4186 | str_supported(tp_features.wan), |
| 4187 | status); |
| 4188 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4189 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4190 | if (dbg_wwanemul) { |
| 4191 | tp_features.wan = 1; |
| 4192 | printk(TPACPI_INFO |
| 4193 | "wwan switch emulation enabled\n"); |
| 4194 | } else |
| 4195 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4196 | if (tp_features.wan && |
| 4197 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 4198 | /* no wan hardware present in system */ |
| 4199 | tp_features.wan = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4200 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4201 | "wan hardware not installed\n"); |
| 4202 | } |
| 4203 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4204 | if (!tp_features.wan) |
| 4205 | return 1; |
| 4206 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4207 | res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, |
| 4208 | &wan_tprfk_ops, |
| 4209 | RFKILL_TYPE_WWAN, |
| 4210 | TPACPI_RFK_WWAN_SW_NAME, |
| 4211 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4212 | if (res) |
| 4213 | return res; |
| 4214 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4215 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4216 | &wan_attr_group); |
| 4217 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4218 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4219 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4220 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4221 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4222 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4223 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4224 | } |
| 4225 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4226 | /* procfs -------------------------------------------------------------- */ |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4227 | static int wan_read(char *p) |
| 4228 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4229 | return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID, p); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | static int wan_write(char *buf) |
| 4233 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4234 | return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID, buf); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4235 | } |
| 4236 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4237 | static struct ibm_struct wan_driver_data = { |
| 4238 | .name = "wan", |
| 4239 | .read = wan_read, |
| 4240 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4241 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4242 | .suspend = wan_suspend, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4243 | .shutdown = wan_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4244 | }; |
| 4245 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4246 | /************************************************************************* |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4247 | * UWB subdriver |
| 4248 | */ |
| 4249 | |
| 4250 | enum { |
| 4251 | /* ACPI GUWB/SUWB bits */ |
| 4252 | TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */ |
| 4253 | TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */ |
| 4254 | }; |
| 4255 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4256 | #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" |
| 4257 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4258 | static int uwb_get_status(void) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4259 | { |
| 4260 | int status; |
| 4261 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4262 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4263 | if (dbg_uwbemul) |
| 4264 | return (tpacpi_uwb_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4265 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4266 | #endif |
| 4267 | |
| 4268 | if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) |
| 4269 | return -EIO; |
| 4270 | |
| 4271 | return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4272 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4273 | } |
| 4274 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4275 | static int uwb_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4276 | { |
| 4277 | int status; |
| 4278 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4279 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4280 | "will attempt to %s UWB\n", |
| 4281 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4282 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4283 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4284 | if (dbg_uwbemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4285 | tpacpi_uwb_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4286 | return 0; |
| 4287 | } |
| 4288 | #endif |
| 4289 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4290 | if (state == TPACPI_RFK_RADIO_ON) |
| 4291 | status = TP_ACPI_UWB_RADIOSSW; |
| 4292 | else |
| 4293 | status = 0; |
| 4294 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4295 | if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) |
| 4296 | return -EIO; |
| 4297 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4298 | return 0; |
| 4299 | } |
| 4300 | |
| 4301 | /* --------------------------------------------------------------------- */ |
| 4302 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4303 | static const struct tpacpi_rfk_ops uwb_tprfk_ops = { |
| 4304 | .get_status = uwb_get_status, |
| 4305 | .set_status = uwb_set_status, |
| 4306 | }; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4307 | |
| 4308 | static void uwb_exit(void) |
| 4309 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4310 | tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4311 | } |
| 4312 | |
| 4313 | static int __init uwb_init(struct ibm_init_struct *iibm) |
| 4314 | { |
| 4315 | int res; |
| 4316 | int status = 0; |
| 4317 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4318 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4319 | "initializing uwb subdriver\n"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4320 | |
| 4321 | TPACPI_ACPIHANDLE_INIT(hkey); |
| 4322 | |
| 4323 | tp_features.uwb = hkey_handle && |
| 4324 | acpi_evalf(hkey_handle, &status, "GUWB", "qd"); |
| 4325 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4326 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4327 | "uwb is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4328 | str_supported(tp_features.uwb), |
| 4329 | status); |
| 4330 | |
| 4331 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4332 | if (dbg_uwbemul) { |
| 4333 | tp_features.uwb = 1; |
| 4334 | printk(TPACPI_INFO |
| 4335 | "uwb switch emulation enabled\n"); |
| 4336 | } else |
| 4337 | #endif |
| 4338 | if (tp_features.uwb && |
| 4339 | !(status & TP_ACPI_UWB_HWPRESENT)) { |
| 4340 | /* no uwb hardware present in system */ |
| 4341 | tp_features.uwb = 0; |
| 4342 | dbg_printk(TPACPI_DBG_INIT, |
| 4343 | "uwb hardware not installed\n"); |
| 4344 | } |
| 4345 | |
| 4346 | if (!tp_features.uwb) |
| 4347 | return 1; |
| 4348 | |
| 4349 | res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4350 | &uwb_tprfk_ops, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4351 | RFKILL_TYPE_UWB, |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4352 | TPACPI_RFK_UWB_SW_NAME, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4353 | false); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4354 | return res; |
| 4355 | } |
| 4356 | |
| 4357 | static struct ibm_struct uwb_driver_data = { |
| 4358 | .name = "uwb", |
| 4359 | .exit = uwb_exit, |
| 4360 | .flags.experimental = 1, |
| 4361 | }; |
| 4362 | |
| 4363 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4364 | * Video subdriver |
| 4365 | */ |
| 4366 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4367 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 4368 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4369 | enum video_access_mode { |
| 4370 | TPACPI_VIDEO_NONE = 0, |
| 4371 | TPACPI_VIDEO_570, /* 570 */ |
| 4372 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 4373 | TPACPI_VIDEO_NEW, /* all others */ |
| 4374 | }; |
| 4375 | |
| 4376 | enum { /* video status flags, based on VIDEO_570 */ |
| 4377 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 4378 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 4379 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 4380 | }; |
| 4381 | |
| 4382 | enum { /* TPACPI_VIDEO_570 constants */ |
| 4383 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 4384 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 4385 | * video_status_flags */ |
| 4386 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 4387 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 4388 | }; |
| 4389 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4390 | static enum video_access_mode video_supported; |
| 4391 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4392 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4393 | static int video_autosw_get(void); |
| 4394 | static int video_autosw_set(int enable); |
| 4395 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4396 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4397 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4398 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4400 | int ivga; |
| 4401 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4402 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 4403 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4404 | TPACPI_ACPIHANDLE_INIT(vid); |
| 4405 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4406 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4407 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 4408 | /* G41, assume IVGA doesn't change */ |
| 4409 | vid_handle = vid2_handle; |
| 4410 | |
| 4411 | if (!vid_handle) |
| 4412 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4413 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4414 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 4415 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4416 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4417 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 4418 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4419 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4420 | else |
| 4421 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4422 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4424 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 4425 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 4426 | video_supported); |
| 4427 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4428 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | } |
| 4430 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4431 | static void video_exit(void) |
| 4432 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4433 | dbg_printk(TPACPI_DBG_EXIT, |
| 4434 | "restoring original video autoswitch mode\n"); |
| 4435 | if (video_autosw_set(video_orig_autosw)) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4436 | printk(TPACPI_ERR "error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4437 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4438 | } |
| 4439 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4440 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | { |
| 4442 | int status = 0; |
| 4443 | int i; |
| 4444 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4445 | switch (video_supported) { |
| 4446 | case TPACPI_VIDEO_570: |
| 4447 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 4448 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 4449 | return -EIO; |
| 4450 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 4451 | break; |
| 4452 | case TPACPI_VIDEO_770: |
| 4453 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4454 | return -EIO; |
| 4455 | if (i) |
| 4456 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4457 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4458 | return -EIO; |
| 4459 | if (i) |
| 4460 | status |= TP_ACPI_VIDEO_S_CRT; |
| 4461 | break; |
| 4462 | case TPACPI_VIDEO_NEW: |
| 4463 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 4464 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4465 | return -EIO; |
| 4466 | if (i) |
| 4467 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4469 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 4470 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4471 | return -EIO; |
| 4472 | if (i) |
| 4473 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4474 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 4475 | return -EIO; |
| 4476 | if (i) |
| 4477 | status |= TP_ACPI_VIDEO_S_DVI; |
| 4478 | break; |
| 4479 | default: |
| 4480 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4481 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | |
| 4483 | return status; |
| 4484 | } |
| 4485 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4486 | static int video_outputsw_set(int status) |
| 4487 | { |
| 4488 | int autosw; |
| 4489 | int res = 0; |
| 4490 | |
| 4491 | switch (video_supported) { |
| 4492 | case TPACPI_VIDEO_570: |
| 4493 | res = acpi_evalf(NULL, NULL, |
| 4494 | "\\_SB.PHS2", "vdd", |
| 4495 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 4496 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 4497 | break; |
| 4498 | case TPACPI_VIDEO_770: |
| 4499 | autosw = video_autosw_get(); |
| 4500 | if (autosw < 0) |
| 4501 | return autosw; |
| 4502 | |
| 4503 | res = video_autosw_set(1); |
| 4504 | if (res) |
| 4505 | return res; |
| 4506 | res = acpi_evalf(vid_handle, NULL, |
| 4507 | "ASWT", "vdd", status * 0x100, 0); |
| 4508 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4509 | printk(TPACPI_ERR |
| 4510 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4511 | return -EIO; |
| 4512 | } |
| 4513 | break; |
| 4514 | case TPACPI_VIDEO_NEW: |
| 4515 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4516 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4517 | break; |
| 4518 | default: |
| 4519 | return -ENOSYS; |
| 4520 | } |
| 4521 | |
| 4522 | return (res)? 0 : -EIO; |
| 4523 | } |
| 4524 | |
| 4525 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4527 | int autosw = 0; |
| 4528 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4529 | switch (video_supported) { |
| 4530 | case TPACPI_VIDEO_570: |
| 4531 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 4532 | return -EIO; |
| 4533 | break; |
| 4534 | case TPACPI_VIDEO_770: |
| 4535 | case TPACPI_VIDEO_NEW: |
| 4536 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 4537 | return -EIO; |
| 4538 | break; |
| 4539 | default: |
| 4540 | return -ENOSYS; |
| 4541 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4542 | |
| 4543 | return autosw & 1; |
| 4544 | } |
| 4545 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4546 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4547 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4548 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4549 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4550 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4551 | } |
| 4552 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4553 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4554 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4555 | int autosw = video_autosw_get(); |
| 4556 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4557 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4558 | if (autosw < 0) |
| 4559 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4560 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4561 | switch (video_supported) { |
| 4562 | case TPACPI_VIDEO_570: |
| 4563 | res = video_autosw_set(1); |
| 4564 | if (res) |
| 4565 | return res; |
| 4566 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 4567 | break; |
| 4568 | case TPACPI_VIDEO_770: |
| 4569 | case TPACPI_VIDEO_NEW: |
| 4570 | res = video_autosw_set(1); |
| 4571 | if (res) |
| 4572 | return res; |
| 4573 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 4574 | break; |
| 4575 | default: |
| 4576 | return -ENOSYS; |
| 4577 | } |
| 4578 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4579 | printk(TPACPI_ERR |
| 4580 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4581 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4582 | } |
| 4583 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4584 | return (res)? 0 : -EIO; |
| 4585 | } |
| 4586 | |
| 4587 | static int video_expand_toggle(void) |
| 4588 | { |
| 4589 | switch (video_supported) { |
| 4590 | case TPACPI_VIDEO_570: |
| 4591 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 4592 | 0 : -EIO; |
| 4593 | case TPACPI_VIDEO_770: |
| 4594 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 4595 | 0 : -EIO; |
| 4596 | case TPACPI_VIDEO_NEW: |
| 4597 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 4598 | 0 : -EIO; |
| 4599 | default: |
| 4600 | return -ENOSYS; |
| 4601 | } |
| 4602 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4603 | } |
| 4604 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4605 | static int video_read(char *p) |
| 4606 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4607 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4608 | int len = 0; |
| 4609 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4610 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4611 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4612 | return len; |
| 4613 | } |
| 4614 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4615 | status = video_outputsw_get(); |
| 4616 | if (status < 0) |
| 4617 | return status; |
| 4618 | |
| 4619 | autosw = video_autosw_get(); |
| 4620 | if (autosw < 0) |
| 4621 | return autosw; |
| 4622 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4623 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 4624 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 4625 | len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1)); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4626 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4627 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 4628 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 4629 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 4630 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4631 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4632 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 4633 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 4634 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 4635 | |
| 4636 | return len; |
| 4637 | } |
| 4638 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4639 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | { |
| 4641 | char *cmd; |
| 4642 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4643 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4645 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4646 | return -ENODEV; |
| 4647 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4648 | enable = 0; |
| 4649 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4650 | |
| 4651 | while ((cmd = next_cmd(&buf))) { |
| 4652 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4653 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4655 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4657 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4659 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4660 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4661 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4662 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4663 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4664 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4665 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4667 | res = video_autosw_set(1); |
| 4668 | if (res) |
| 4669 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4671 | res = video_autosw_set(0); |
| 4672 | if (res) |
| 4673 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4675 | res = video_outputsw_cycle(); |
| 4676 | if (res) |
| 4677 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4679 | res = video_expand_toggle(); |
| 4680 | if (res) |
| 4681 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | } else |
| 4683 | return -EINVAL; |
| 4684 | } |
| 4685 | |
| 4686 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4687 | status = video_outputsw_get(); |
| 4688 | if (status < 0) |
| 4689 | return status; |
| 4690 | res = video_outputsw_set((status & ~disable) | enable); |
| 4691 | if (res) |
| 4692 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4693 | } |
| 4694 | |
| 4695 | return 0; |
| 4696 | } |
| 4697 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4698 | static struct ibm_struct video_driver_data = { |
| 4699 | .name = "video", |
| 4700 | .read = video_read, |
| 4701 | .write = video_write, |
| 4702 | .exit = video_exit, |
| 4703 | }; |
| 4704 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4705 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 4706 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4707 | /************************************************************************* |
| 4708 | * Light (thinklight) subdriver |
| 4709 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4711 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 4712 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4713 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4714 | static int light_get_status(void) |
| 4715 | { |
| 4716 | int status = 0; |
| 4717 | |
| 4718 | if (tp_features.light_status) { |
| 4719 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 4720 | return -EIO; |
| 4721 | return (!!status); |
| 4722 | } |
| 4723 | |
| 4724 | return -ENXIO; |
| 4725 | } |
| 4726 | |
| 4727 | static int light_set_status(int status) |
| 4728 | { |
| 4729 | int rc; |
| 4730 | |
| 4731 | if (tp_features.light) { |
| 4732 | if (cmos_handle) { |
| 4733 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", |
| 4734 | (status)? |
| 4735 | TP_CMOS_THINKLIGHT_ON : |
| 4736 | TP_CMOS_THINKLIGHT_OFF); |
| 4737 | } else { |
| 4738 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", |
| 4739 | (status)? 1 : 0); |
| 4740 | } |
| 4741 | return (rc)? 0 : -EIO; |
| 4742 | } |
| 4743 | |
| 4744 | return -ENXIO; |
| 4745 | } |
| 4746 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4747 | static void light_set_status_worker(struct work_struct *work) |
| 4748 | { |
| 4749 | struct tpacpi_led_classdev *data = |
| 4750 | container_of(work, struct tpacpi_led_classdev, work); |
| 4751 | |
| 4752 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4753 | light_set_status((data->new_state != TPACPI_LED_OFF)); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4754 | } |
| 4755 | |
| 4756 | static void light_sysfs_set(struct led_classdev *led_cdev, |
| 4757 | enum led_brightness brightness) |
| 4758 | { |
| 4759 | struct tpacpi_led_classdev *data = |
| 4760 | container_of(led_cdev, |
| 4761 | struct tpacpi_led_classdev, |
| 4762 | led_classdev); |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4763 | data->new_state = (brightness != LED_OFF) ? |
| 4764 | TPACPI_LED_ON : TPACPI_LED_OFF; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4765 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4766 | } |
| 4767 | |
| 4768 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) |
| 4769 | { |
| 4770 | return (light_get_status() == 1)? LED_FULL : LED_OFF; |
| 4771 | } |
| 4772 | |
| 4773 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { |
| 4774 | .led_classdev = { |
| 4775 | .name = "tpacpi::thinklight", |
| 4776 | .brightness_set = &light_sysfs_set, |
| 4777 | .brightness_get = &light_sysfs_get, |
| 4778 | } |
| 4779 | }; |
| 4780 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4781 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4783 | int rc; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4784 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4785 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 4786 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4787 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 4788 | TPACPI_ACPIHANDLE_INIT(lght); |
| 4789 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4790 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4791 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4792 | /* 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] | 4793 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4794 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4795 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4796 | /* light status not supported on |
| 4797 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4798 | tp_features.light_status = |
| 4799 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4801 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
| 4802 | str_supported(tp_features.light), |
| 4803 | str_supported(tp_features.light_status)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4804 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4805 | if (!tp_features.light) |
| 4806 | return 1; |
| 4807 | |
| 4808 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 4809 | &tpacpi_led_thinklight.led_classdev); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4810 | |
| 4811 | if (rc < 0) { |
| 4812 | tp_features.light = 0; |
| 4813 | tp_features.light_status = 0; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4814 | } else { |
| 4815 | rc = 0; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4816 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4817 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4818 | return rc; |
| 4819 | } |
| 4820 | |
| 4821 | static void light_exit(void) |
| 4822 | { |
| 4823 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); |
| 4824 | if (work_pending(&tpacpi_led_thinklight.work)) |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4825 | flush_workqueue(tpacpi_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | } |
| 4827 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4828 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4829 | { |
| 4830 | int len = 0; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4831 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4833 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4834 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4835 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4836 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 4837 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 4838 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4839 | status = light_get_status(); |
| 4840 | if (status < 0) |
| 4841 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4843 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 4844 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | |
| 4846 | return len; |
| 4847 | } |
| 4848 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4849 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4852 | int newstatus = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4853 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4854 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4855 | return -ENODEV; |
| 4856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | while ((cmd = next_cmd(&buf))) { |
| 4858 | if (strlencmp(cmd, "on") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4859 | newstatus = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | } else if (strlencmp(cmd, "off") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4861 | newstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | } else |
| 4863 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | } |
| 4865 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4866 | return light_set_status(newstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 | } |
| 4868 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4869 | static struct ibm_struct light_driver_data = { |
| 4870 | .name = "light", |
| 4871 | .read = light_read, |
| 4872 | .write = light_write, |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4873 | .exit = light_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4874 | }; |
| 4875 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4876 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4877 | * CMOS subdriver |
| 4878 | */ |
| 4879 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4880 | /* sysfs cmos_command -------------------------------------------------- */ |
| 4881 | static ssize_t cmos_command_store(struct device *dev, |
| 4882 | struct device_attribute *attr, |
| 4883 | const char *buf, size_t count) |
| 4884 | { |
| 4885 | unsigned long cmos_cmd; |
| 4886 | int res; |
| 4887 | |
| 4888 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 4889 | return -EINVAL; |
| 4890 | |
| 4891 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4892 | return (res)? res : count; |
| 4893 | } |
| 4894 | |
| 4895 | static struct device_attribute dev_attr_cmos_command = |
| 4896 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 4897 | |
| 4898 | /* --------------------------------------------------------------------- */ |
| 4899 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4900 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4901 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4902 | int res; |
| 4903 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4904 | vdbg_printk(TPACPI_DBG_INIT, |
| 4905 | "initializing cmos commands subdriver\n"); |
| 4906 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4907 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4908 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4909 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 4910 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4911 | |
| 4912 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4913 | if (res) |
| 4914 | return res; |
| 4915 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4916 | return (cmos_handle)? 0 : 1; |
| 4917 | } |
| 4918 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4919 | static void cmos_exit(void) |
| 4920 | { |
| 4921 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4922 | } |
| 4923 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4924 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | { |
| 4926 | int len = 0; |
| 4927 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4928 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4929 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | if (!cmos_handle) |
| 4931 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4932 | else { |
| 4933 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4934 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4935 | } |
| 4936 | |
| 4937 | return len; |
| 4938 | } |
| 4939 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4940 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | { |
| 4942 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4943 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | |
| 4945 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4946 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 4947 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | /* cmos_cmd set */ |
| 4949 | } else |
| 4950 | return -EINVAL; |
| 4951 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4952 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4953 | if (res) |
| 4954 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4958 | } |
| 4959 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4960 | static struct ibm_struct cmos_driver_data = { |
| 4961 | .name = "cmos", |
| 4962 | .read = cmos_read, |
| 4963 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4964 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4965 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4966 | |
| 4967 | /************************************************************************* |
| 4968 | * LED subdriver |
| 4969 | */ |
| 4970 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4971 | enum led_access_mode { |
| 4972 | TPACPI_LED_NONE = 0, |
| 4973 | TPACPI_LED_570, /* 570 */ |
| 4974 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 4975 | TPACPI_LED_NEW, /* all others */ |
| 4976 | }; |
| 4977 | |
| 4978 | enum { /* For TPACPI_LED_OLD */ |
| 4979 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 4980 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 4981 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 4982 | }; |
| 4983 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4984 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4985 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4986 | TPACPI_HANDLE(led, ec, "SLED", /* 570 */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4987 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */ |
| 4988 | /* T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4989 | "LED", /* all others */ |
| 4990 | ); /* R30, R31 */ |
| 4991 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4992 | #define TPACPI_LED_NUMLEDS 16 |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4993 | static struct tpacpi_led_classdev *tpacpi_leds; |
| 4994 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; |
Harvey Harrison | e3aa51f | 2008-05-29 17:51:57 -0700 | [diff] [blame] | 4995 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4996 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
| 4997 | "tpacpi::power", |
| 4998 | "tpacpi:orange:batt", |
| 4999 | "tpacpi:green:batt", |
| 5000 | "tpacpi::dock_active", |
| 5001 | "tpacpi::bay_active", |
| 5002 | "tpacpi::dock_batt", |
| 5003 | "tpacpi::unknown_led", |
| 5004 | "tpacpi::standby", |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5005 | "tpacpi::dock_status1", |
| 5006 | "tpacpi::dock_status2", |
| 5007 | "tpacpi::unknown_led2", |
| 5008 | "tpacpi::unknown_led3", |
| 5009 | "tpacpi::thinkvantage", |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5010 | }; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5011 | #define TPACPI_SAFE_LEDS 0x1081U |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5012 | |
| 5013 | static inline bool tpacpi_is_led_restricted(const unsigned int led) |
| 5014 | { |
| 5015 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
| 5016 | return false; |
| 5017 | #else |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5018 | return (1U & (TPACPI_SAFE_LEDS >> led)) == 0; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5019 | #endif |
| 5020 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5021 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5022 | static int led_get_status(const unsigned int led) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5023 | { |
| 5024 | int status; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5025 | enum led_status_t led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5026 | |
| 5027 | switch (led_supported) { |
| 5028 | case TPACPI_LED_570: |
| 5029 | if (!acpi_evalf(ec_handle, |
| 5030 | &status, "GLED", "dd", 1 << led)) |
| 5031 | return -EIO; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5032 | led_s = (status == 0)? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5033 | TPACPI_LED_OFF : |
| 5034 | ((status == 1)? |
| 5035 | TPACPI_LED_ON : |
| 5036 | TPACPI_LED_BLINK); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5037 | tpacpi_led_state_cache[led] = led_s; |
| 5038 | return led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5039 | default: |
| 5040 | return -ENXIO; |
| 5041 | } |
| 5042 | |
| 5043 | /* not reached */ |
| 5044 | } |
| 5045 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5046 | static int led_set_status(const unsigned int led, |
| 5047 | const enum led_status_t ledstatus) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5048 | { |
| 5049 | /* off, on, blink. Index is led_status_t */ |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5050 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
| 5051 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5052 | |
| 5053 | int rc = 0; |
| 5054 | |
| 5055 | switch (led_supported) { |
| 5056 | case TPACPI_LED_570: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5057 | /* 570 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5058 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5059 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5060 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5061 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5062 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5063 | (1 << led), led_sled_arg1[ledstatus])) |
| 5064 | rc = -EIO; |
| 5065 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5066 | case TPACPI_LED_OLD: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5067 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5068 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5069 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5070 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5071 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5072 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
| 5073 | if (rc >= 0) |
| 5074 | rc = ec_write(TPACPI_LED_EC_HLBL, |
| 5075 | (ledstatus == TPACPI_LED_BLINK) << led); |
| 5076 | if (rc >= 0) |
| 5077 | rc = ec_write(TPACPI_LED_EC_HLCL, |
| 5078 | (ledstatus != TPACPI_LED_OFF) << led); |
| 5079 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5080 | case TPACPI_LED_NEW: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5081 | /* all others */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5082 | if (unlikely(led >= TPACPI_LED_NUMLEDS)) |
| 5083 | return -EINVAL; |
| 5084 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5085 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5086 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5087 | led, led_led_arg1[ledstatus])) |
| 5088 | rc = -EIO; |
| 5089 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5090 | default: |
| 5091 | rc = -ENXIO; |
| 5092 | } |
| 5093 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5094 | if (!rc) |
| 5095 | tpacpi_led_state_cache[led] = ledstatus; |
| 5096 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5097 | return rc; |
| 5098 | } |
| 5099 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5100 | static void led_set_status_worker(struct work_struct *work) |
| 5101 | { |
| 5102 | struct tpacpi_led_classdev *data = |
| 5103 | container_of(work, struct tpacpi_led_classdev, work); |
| 5104 | |
| 5105 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5106 | led_set_status(data->led, data->new_state); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5107 | } |
| 5108 | |
| 5109 | static void led_sysfs_set(struct led_classdev *led_cdev, |
| 5110 | enum led_brightness brightness) |
| 5111 | { |
| 5112 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5113 | struct tpacpi_led_classdev, led_classdev); |
| 5114 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5115 | if (brightness == LED_OFF) |
| 5116 | data->new_state = TPACPI_LED_OFF; |
| 5117 | else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) |
| 5118 | data->new_state = TPACPI_LED_ON; |
| 5119 | else |
| 5120 | data->new_state = TPACPI_LED_BLINK; |
| 5121 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5122 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, |
| 5126 | unsigned long *delay_on, unsigned long *delay_off) |
| 5127 | { |
| 5128 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5129 | struct tpacpi_led_classdev, led_classdev); |
| 5130 | |
| 5131 | /* Can we choose the flash rate? */ |
| 5132 | if (*delay_on == 0 && *delay_off == 0) { |
| 5133 | /* yes. set them to the hardware blink rate (1 Hz) */ |
| 5134 | *delay_on = 500; /* ms */ |
| 5135 | *delay_off = 500; /* ms */ |
| 5136 | } else if ((*delay_on != 500) || (*delay_off != 500)) |
| 5137 | return -EINVAL; |
| 5138 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5139 | data->new_state = TPACPI_LED_BLINK; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5140 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5141 | |
| 5142 | return 0; |
| 5143 | } |
| 5144 | |
| 5145 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) |
| 5146 | { |
| 5147 | int rc; |
| 5148 | |
| 5149 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5150 | struct tpacpi_led_classdev, led_classdev); |
| 5151 | |
| 5152 | rc = led_get_status(data->led); |
| 5153 | |
| 5154 | if (rc == TPACPI_LED_OFF || rc < 0) |
| 5155 | rc = LED_OFF; /* no error handling in led class :( */ |
| 5156 | else |
| 5157 | rc = LED_FULL; |
| 5158 | |
| 5159 | return rc; |
| 5160 | } |
| 5161 | |
| 5162 | static void led_exit(void) |
| 5163 | { |
| 5164 | unsigned int i; |
| 5165 | |
| 5166 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 5167 | if (tpacpi_leds[i].led_classdev.name) |
| 5168 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); |
| 5169 | } |
| 5170 | |
| 5171 | kfree(tpacpi_leds); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5172 | } |
| 5173 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5174 | static int __init tpacpi_init_led(unsigned int led) |
| 5175 | { |
| 5176 | int rc; |
| 5177 | |
| 5178 | tpacpi_leds[led].led = led; |
| 5179 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5180 | /* LEDs with no name don't get registered */ |
| 5181 | if (!tpacpi_led_names[led]) |
| 5182 | return 0; |
| 5183 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5184 | tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set; |
| 5185 | tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set; |
| 5186 | if (led_supported == TPACPI_LED_570) |
| 5187 | tpacpi_leds[led].led_classdev.brightness_get = |
| 5188 | &led_sysfs_get; |
| 5189 | |
| 5190 | tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led]; |
| 5191 | |
| 5192 | INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker); |
| 5193 | |
| 5194 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 5195 | &tpacpi_leds[led].led_classdev); |
| 5196 | if (rc < 0) |
| 5197 | tpacpi_leds[led].led_classdev.name = NULL; |
| 5198 | |
| 5199 | return rc; |
| 5200 | } |
| 5201 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5202 | static const struct tpacpi_quirk led_useful_qtable[] __initconst = { |
| 5203 | TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */ |
| 5204 | TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */ |
| 5205 | TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */ |
| 5206 | |
| 5207 | TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */ |
| 5208 | TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */ |
| 5209 | TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */ |
| 5210 | TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */ |
| 5211 | TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */ |
| 5212 | TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */ |
| 5213 | TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */ |
| 5214 | TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */ |
| 5215 | |
| 5216 | TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */ |
| 5217 | TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */ |
| 5218 | TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */ |
| 5219 | TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */ |
| 5220 | TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */ |
| 5221 | |
| 5222 | TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */ |
| 5223 | TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */ |
| 5224 | TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */ |
| 5225 | TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */ |
| 5226 | |
| 5227 | /* (1) - may have excess leds enabled on MSB */ |
| 5228 | |
| 5229 | /* Defaults (order matters, keep last, don't reorder!) */ |
| 5230 | { /* Lenovo */ |
| 5231 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 5232 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5233 | .quirks = 0x1fffU, |
| 5234 | }, |
| 5235 | { /* IBM ThinkPads with no EC version string */ |
| 5236 | .vendor = PCI_VENDOR_ID_IBM, |
| 5237 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_UNKNOWN, |
| 5238 | .quirks = 0x00ffU, |
| 5239 | }, |
| 5240 | { /* IBM ThinkPads with EC version string */ |
| 5241 | .vendor = PCI_VENDOR_ID_IBM, |
| 5242 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5243 | .quirks = 0x00bfU, |
| 5244 | }, |
| 5245 | }; |
| 5246 | |
| 5247 | #undef TPACPI_LEDQ_IBM |
| 5248 | #undef TPACPI_LEDQ_LNV |
| 5249 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5250 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5251 | { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5252 | unsigned int i; |
| 5253 | int rc; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5254 | unsigned long useful_leds; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5255 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5256 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 5257 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5258 | TPACPI_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5259 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5260 | if (!led_handle) |
| 5261 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5262 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5263 | else if (strlencmp(led_path, "SLED") == 0) |
| 5264 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5265 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5266 | else if (strlencmp(led_path, "SYSL") == 0) |
| 5267 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5268 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5269 | else |
| 5270 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5271 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5272 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5273 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 5274 | str_supported(led_supported), led_supported); |
| 5275 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5276 | if (led_supported == TPACPI_LED_NONE) |
| 5277 | return 1; |
| 5278 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5279 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
| 5280 | GFP_KERNEL); |
| 5281 | if (!tpacpi_leds) { |
| 5282 | printk(TPACPI_ERR "Out of memory for LED data\n"); |
| 5283 | return -ENOMEM; |
| 5284 | } |
| 5285 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5286 | useful_leds = tpacpi_check_quirks(led_useful_qtable, |
| 5287 | ARRAY_SIZE(led_useful_qtable)); |
| 5288 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5289 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5290 | if (!tpacpi_is_led_restricted(i) && |
| 5291 | test_bit(i, &useful_leds)) { |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5292 | rc = tpacpi_init_led(i); |
| 5293 | if (rc < 0) { |
| 5294 | led_exit(); |
| 5295 | return rc; |
| 5296 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5297 | } |
| 5298 | } |
| 5299 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5300 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5301 | printk(TPACPI_NOTICE |
| 5302 | "warning: userspace override of important " |
| 5303 | "firmware LEDs is enabled\n"); |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5304 | #endif |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5305 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5306 | } |
| 5307 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5308 | #define str_led_status(s) \ |
| 5309 | ((s) == TPACPI_LED_OFF ? "off" : \ |
| 5310 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5311 | |
| 5312 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5313 | { |
| 5314 | int len = 0; |
| 5315 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5316 | if (!led_supported) { |
| 5317 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5318 | return len; |
| 5319 | } |
| 5320 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 5321 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5322 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5323 | /* 570 */ |
| 5324 | int i, status; |
| 5325 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5326 | status = led_get_status(i); |
| 5327 | if (status < 0) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5328 | return -EIO; |
| 5329 | len += sprintf(p + len, "%d:\t\t%s\n", |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5330 | i, str_led_status(status)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5331 | } |
| 5332 | } |
| 5333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5334 | len += sprintf(p + len, "commands:\t" |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5335 | "<led> on, <led> off, <led> blink (<led> is 0-15)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5336 | |
| 5337 | return len; |
| 5338 | } |
| 5339 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5340 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5341 | { |
| 5342 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5343 | int led, rc; |
| 5344 | enum led_status_t s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5345 | |
| 5346 | if (!led_supported) |
| 5347 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5348 | |
| 5349 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5350 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5351 | return -EINVAL; |
| 5352 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5353 | if (strstr(cmd, "off")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5354 | s = TPACPI_LED_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5355 | } else if (strstr(cmd, "on")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5356 | s = TPACPI_LED_ON; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5357 | } else if (strstr(cmd, "blink")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5358 | s = TPACPI_LED_BLINK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5359 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5360 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5361 | } |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5362 | |
| 5363 | rc = led_set_status(led, s); |
| 5364 | if (rc < 0) |
| 5365 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5369 | } |
| 5370 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5371 | static struct ibm_struct led_driver_data = { |
| 5372 | .name = "led", |
| 5373 | .read = led_read, |
| 5374 | .write = led_write, |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5375 | .exit = led_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5376 | }; |
| 5377 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5378 | /************************************************************************* |
| 5379 | * Beep subdriver |
| 5380 | */ |
| 5381 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5382 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5383 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5384 | #define TPACPI_BEEP_Q1 0x0001 |
| 5385 | |
| 5386 | static const struct tpacpi_quirk beep_quirk_table[] __initconst = { |
| 5387 | TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1), /* 570 */ |
| 5388 | TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */ |
| 5389 | }; |
| 5390 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5391 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5392 | { |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5393 | unsigned long quirks; |
| 5394 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5395 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 5396 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5397 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5398 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5399 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 5400 | str_supported(beep_handle != NULL)); |
| 5401 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5402 | quirks = tpacpi_check_quirks(beep_quirk_table, |
| 5403 | ARRAY_SIZE(beep_quirk_table)); |
| 5404 | |
| 5405 | tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); |
| 5406 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5407 | return (beep_handle)? 0 : 1; |
| 5408 | } |
| 5409 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5410 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5411 | { |
| 5412 | int len = 0; |
| 5413 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5414 | if (!beep_handle) |
| 5415 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5416 | else { |
| 5417 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 5418 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 5419 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5420 | |
| 5421 | return len; |
| 5422 | } |
| 5423 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5424 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5425 | { |
| 5426 | char *cmd; |
| 5427 | int beep_cmd; |
| 5428 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5429 | if (!beep_handle) |
| 5430 | return -ENODEV; |
| 5431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5432 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5433 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 5434 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5435 | /* beep_cmd set */ |
| 5436 | } else |
| 5437 | return -EINVAL; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5438 | if (tp_features.beep_needs_two_args) { |
| 5439 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", |
| 5440 | beep_cmd, 0)) |
| 5441 | return -EIO; |
| 5442 | } else { |
| 5443 | if (!acpi_evalf(beep_handle, NULL, NULL, "vd", |
| 5444 | beep_cmd)) |
| 5445 | return -EIO; |
| 5446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5450 | } |
| 5451 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5452 | static struct ibm_struct beep_driver_data = { |
| 5453 | .name = "beep", |
| 5454 | .read = beep_read, |
| 5455 | .write = beep_write, |
| 5456 | }; |
| 5457 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5458 | /************************************************************************* |
| 5459 | * Thermal subdriver |
| 5460 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5461 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5462 | enum thermal_access_mode { |
| 5463 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 5464 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 5465 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 5466 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 5467 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 5468 | }; |
| 5469 | |
| 5470 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 5471 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 5472 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 5473 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
| 5474 | }; |
| 5475 | |
| 5476 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 5477 | struct ibm_thermal_sensors_struct { |
| 5478 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 5479 | }; |
| 5480 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5481 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5482 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5483 | /* idx is zero-based */ |
| 5484 | static int thermal_get_sensor(int idx, s32 *value) |
| 5485 | { |
| 5486 | int t; |
| 5487 | s8 tmp; |
| 5488 | char tmpi[5]; |
| 5489 | |
| 5490 | t = TP_EC_THERMAL_TMP0; |
| 5491 | |
| 5492 | switch (thermal_read_mode) { |
| 5493 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 5494 | case TPACPI_THERMAL_TPEC_16: |
| 5495 | if (idx >= 8 && idx <= 15) { |
| 5496 | t = TP_EC_THERMAL_TMP8; |
| 5497 | idx -= 8; |
| 5498 | } |
| 5499 | /* fallthrough */ |
| 5500 | #endif |
| 5501 | case TPACPI_THERMAL_TPEC_8: |
| 5502 | if (idx <= 7) { |
| 5503 | if (!acpi_ec_read(t + idx, &tmp)) |
| 5504 | return -EIO; |
| 5505 | *value = tmp * 1000; |
| 5506 | return 0; |
| 5507 | } |
| 5508 | break; |
| 5509 | |
| 5510 | case TPACPI_THERMAL_ACPI_UPDT: |
| 5511 | if (idx <= 7) { |
| 5512 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5513 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 5514 | return -EIO; |
| 5515 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5516 | return -EIO; |
| 5517 | *value = (t - 2732) * 100; |
| 5518 | return 0; |
| 5519 | } |
| 5520 | break; |
| 5521 | |
| 5522 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5523 | if (idx <= 7) { |
| 5524 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5525 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5526 | return -EIO; |
| 5527 | if (t > 127 || t < -127) |
| 5528 | t = TP_EC_THERMAL_TMP_NA; |
| 5529 | *value = t * 1000; |
| 5530 | return 0; |
| 5531 | } |
| 5532 | break; |
| 5533 | |
| 5534 | case TPACPI_THERMAL_NONE: |
| 5535 | default: |
| 5536 | return -ENOSYS; |
| 5537 | } |
| 5538 | |
| 5539 | return -EINVAL; |
| 5540 | } |
| 5541 | |
| 5542 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 5543 | { |
| 5544 | int res, i; |
| 5545 | int n; |
| 5546 | |
| 5547 | n = 8; |
| 5548 | i = 0; |
| 5549 | |
| 5550 | if (!s) |
| 5551 | return -EINVAL; |
| 5552 | |
| 5553 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 5554 | n = 16; |
| 5555 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5556 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5557 | res = thermal_get_sensor(i, &s->temp[i]); |
| 5558 | if (res) |
| 5559 | return res; |
| 5560 | } |
| 5561 | |
| 5562 | return n; |
| 5563 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5564 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5565 | /* sysfs temp##_input -------------------------------------------------- */ |
| 5566 | |
| 5567 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 5568 | struct device_attribute *attr, |
| 5569 | char *buf) |
| 5570 | { |
| 5571 | struct sensor_device_attribute *sensor_attr = |
| 5572 | to_sensor_dev_attr(attr); |
| 5573 | int idx = sensor_attr->index; |
| 5574 | s32 value; |
| 5575 | int res; |
| 5576 | |
| 5577 | res = thermal_get_sensor(idx, &value); |
| 5578 | if (res) |
| 5579 | return res; |
| 5580 | if (value == TP_EC_THERMAL_TMP_NA * 1000) |
| 5581 | return -ENXIO; |
| 5582 | |
| 5583 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 5584 | } |
| 5585 | |
| 5586 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5587 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 5588 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5589 | |
| 5590 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 5591 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 5592 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 5593 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 5594 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 5595 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 5596 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 5597 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 5598 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 5599 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 5600 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 5601 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 5602 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 5603 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 5604 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 5605 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 5606 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 5607 | }; |
| 5608 | |
| 5609 | #define THERMAL_ATTRS(X) \ |
| 5610 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 5611 | |
| 5612 | static struct attribute *thermal_temp_input_attr[] = { |
| 5613 | THERMAL_ATTRS(8), |
| 5614 | THERMAL_ATTRS(9), |
| 5615 | THERMAL_ATTRS(10), |
| 5616 | THERMAL_ATTRS(11), |
| 5617 | THERMAL_ATTRS(12), |
| 5618 | THERMAL_ATTRS(13), |
| 5619 | THERMAL_ATTRS(14), |
| 5620 | THERMAL_ATTRS(15), |
| 5621 | THERMAL_ATTRS(0), |
| 5622 | THERMAL_ATTRS(1), |
| 5623 | THERMAL_ATTRS(2), |
| 5624 | THERMAL_ATTRS(3), |
| 5625 | THERMAL_ATTRS(4), |
| 5626 | THERMAL_ATTRS(5), |
| 5627 | THERMAL_ATTRS(6), |
| 5628 | THERMAL_ATTRS(7), |
| 5629 | NULL |
| 5630 | }; |
| 5631 | |
| 5632 | static const struct attribute_group thermal_temp_input16_group = { |
| 5633 | .attrs = thermal_temp_input_attr |
| 5634 | }; |
| 5635 | |
| 5636 | static const struct attribute_group thermal_temp_input8_group = { |
| 5637 | .attrs = &thermal_temp_input_attr[8] |
| 5638 | }; |
| 5639 | |
| 5640 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 5641 | #undef THERMAL_ATTRS |
| 5642 | |
| 5643 | /* --------------------------------------------------------------------- */ |
| 5644 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5645 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5646 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5647 | u8 t, ta1, ta2; |
| 5648 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5649 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5650 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5651 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5652 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 5653 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5654 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5655 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 5656 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5657 | /* |
| 5658 | * Direct EC access mode: sensors at registers |
| 5659 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 5660 | * non-implemented, thermal sensors return 0x80 when |
| 5661 | * not available |
| 5662 | */ |
| 5663 | |
| 5664 | ta1 = ta2 = 0; |
| 5665 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5666 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5667 | ta1 |= t; |
| 5668 | } else { |
| 5669 | ta1 = 0; |
| 5670 | break; |
| 5671 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5672 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5673 | ta2 |= t; |
| 5674 | } else { |
| 5675 | ta1 = 0; |
| 5676 | break; |
| 5677 | } |
| 5678 | } |
| 5679 | if (ta1 == 0) { |
| 5680 | /* This is sheer paranoia, but we handle it anyway */ |
| 5681 | if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5682 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5683 | "ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5684 | "falling back to ACPI TMPx access " |
| 5685 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5686 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5687 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5688 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5689 | "ThinkPad ACPI EC access misbehaving, " |
| 5690 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5691 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5692 | } |
| 5693 | } else { |
| 5694 | thermal_read_mode = |
| 5695 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5696 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5697 | } |
| 5698 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5699 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 5700 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5701 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5702 | } else { |
| 5703 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5704 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5705 | } |
| 5706 | } else { |
| 5707 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5708 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5709 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5710 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5711 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 5712 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 5713 | thermal_read_mode); |
| 5714 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5715 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5716 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5717 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5718 | &thermal_temp_input16_group); |
| 5719 | if (res) |
| 5720 | return res; |
| 5721 | break; |
| 5722 | case TPACPI_THERMAL_TPEC_8: |
| 5723 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5724 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5725 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5726 | &thermal_temp_input8_group); |
| 5727 | if (res) |
| 5728 | return res; |
| 5729 | break; |
| 5730 | case TPACPI_THERMAL_NONE: |
| 5731 | default: |
| 5732 | return 1; |
| 5733 | } |
| 5734 | |
| 5735 | return 0; |
| 5736 | } |
| 5737 | |
| 5738 | static void thermal_exit(void) |
| 5739 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5740 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5741 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5742 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5743 | &thermal_temp_input16_group); |
| 5744 | break; |
| 5745 | case TPACPI_THERMAL_TPEC_8: |
| 5746 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5747 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5748 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5749 | &thermal_temp_input16_group); |
| 5750 | break; |
| 5751 | case TPACPI_THERMAL_NONE: |
| 5752 | default: |
| 5753 | break; |
| 5754 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5755 | } |
| 5756 | |
| 5757 | static int thermal_read(char *p) |
| 5758 | { |
| 5759 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5760 | int n, i; |
| 5761 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5762 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5763 | n = thermal_get_sensors(&t); |
| 5764 | if (unlikely(n < 0)) |
| 5765 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5766 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5767 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5768 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5769 | if (n > 0) { |
| 5770 | for (i = 0; i < (n - 1); i++) |
| 5771 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 5772 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 5773 | } else |
| 5774 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5775 | |
| 5776 | return len; |
| 5777 | } |
| 5778 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5779 | static struct ibm_struct thermal_driver_data = { |
| 5780 | .name = "thermal", |
| 5781 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5782 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5783 | }; |
| 5784 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5785 | /************************************************************************* |
| 5786 | * EC Dump subdriver |
| 5787 | */ |
| 5788 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5789 | static u8 ecdump_regs[256]; |
| 5790 | |
| 5791 | static int ecdump_read(char *p) |
| 5792 | { |
| 5793 | int len = 0; |
| 5794 | int i, j; |
| 5795 | u8 v; |
| 5796 | |
| 5797 | len += sprintf(p + len, "EC " |
| 5798 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 5799 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 5800 | for (i = 0; i < 256; i += 16) { |
| 5801 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 5802 | for (j = 0; j < 16; j++) { |
| 5803 | if (!acpi_ec_read(i + j, &v)) |
| 5804 | break; |
| 5805 | if (v != ecdump_regs[i + j]) |
| 5806 | len += sprintf(p + len, " *%02x", v); |
| 5807 | else |
| 5808 | len += sprintf(p + len, " %02x", v); |
| 5809 | ecdump_regs[i + j] = v; |
| 5810 | } |
| 5811 | len += sprintf(p + len, "\n"); |
| 5812 | if (j != 16) |
| 5813 | break; |
| 5814 | } |
| 5815 | |
| 5816 | /* These are way too dangerous to advertise openly... */ |
| 5817 | #if 0 |
| 5818 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 5819 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 5820 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 5821 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 5822 | #endif |
| 5823 | return len; |
| 5824 | } |
| 5825 | |
| 5826 | static int ecdump_write(char *buf) |
| 5827 | { |
| 5828 | char *cmd; |
| 5829 | int i, v; |
| 5830 | |
| 5831 | while ((cmd = next_cmd(&buf))) { |
| 5832 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 5833 | /* i and v set */ |
| 5834 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 5835 | /* i and v set */ |
| 5836 | } else |
| 5837 | return -EINVAL; |
| 5838 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 5839 | if (!acpi_ec_write(i, v)) |
| 5840 | return -EIO; |
| 5841 | } else |
| 5842 | return -EINVAL; |
| 5843 | } |
| 5844 | |
| 5845 | return 0; |
| 5846 | } |
| 5847 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5848 | static struct ibm_struct ecdump_driver_data = { |
| 5849 | .name = "ecdump", |
| 5850 | .read = ecdump_read, |
| 5851 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5852 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5853 | }; |
| 5854 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5855 | /************************************************************************* |
| 5856 | * Backlight/brightness subdriver |
| 5857 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 5858 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5859 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 5860 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5861 | /* |
| 5862 | * ThinkPads can read brightness from two places: EC HBRV (0x31), or |
| 5863 | * CMOS NVRAM byte 0x5E, bits 0-3. |
| 5864 | * |
| 5865 | * EC HBRV (0x31) has the following layout |
| 5866 | * Bit 7: unknown function |
| 5867 | * Bit 6: unknown function |
| 5868 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 5869 | * Bit 4: must be set to zero to avoid problems |
| 5870 | * Bit 3-0: backlight brightness level |
| 5871 | * |
| 5872 | * brightness_get_raw returns status data in the HBRV layout |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 5873 | * |
| 5874 | * WARNING: The X61 has been verified to use HBRV for something else, so |
| 5875 | * this should be used _only_ on IBM ThinkPads, and maybe with some careful |
| 5876 | * testing on the very early *60 Lenovo models... |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5877 | */ |
| 5878 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5879 | enum { |
| 5880 | TP_EC_BACKLIGHT = 0x31, |
| 5881 | |
| 5882 | /* TP_EC_BACKLIGHT bitmasks */ |
| 5883 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 5884 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 5885 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 5886 | }; |
| 5887 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5888 | enum tpacpi_brightness_access_mode { |
| 5889 | TPACPI_BRGHT_MODE_AUTO = 0, /* Not implemented yet */ |
| 5890 | TPACPI_BRGHT_MODE_EC, /* EC control */ |
| 5891 | TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */ |
| 5892 | TPACPI_BRGHT_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 5893 | TPACPI_BRGHT_MODE_MAX |
| 5894 | }; |
| 5895 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5896 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5897 | |
| 5898 | static enum tpacpi_brightness_access_mode brightness_mode = |
| 5899 | TPACPI_BRGHT_MODE_MAX; |
| 5900 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5901 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 5902 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5903 | static struct mutex brightness_mutex; |
| 5904 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5905 | /* NVRAM brightness access, |
| 5906 | * call with brightness_mutex held! */ |
| 5907 | static unsigned int tpacpi_brightness_nvram_get(void) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5908 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5909 | u8 lnvram; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5910 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5911 | lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 5912 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5913 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 5914 | lnvram &= (tp_features.bright_16levels) ? 0x0f : 0x07; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5915 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5916 | return lnvram; |
| 5917 | } |
| 5918 | |
| 5919 | static void tpacpi_brightness_checkpoint_nvram(void) |
| 5920 | { |
| 5921 | u8 lec = 0; |
| 5922 | u8 b_nvram; |
| 5923 | |
| 5924 | if (brightness_mode != TPACPI_BRGHT_MODE_ECNVRAM) |
| 5925 | return; |
| 5926 | |
| 5927 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5928 | "trying to checkpoint backlight level to NVRAM...\n"); |
| 5929 | |
| 5930 | if (mutex_lock_killable(&brightness_mutex) < 0) |
| 5931 | return; |
| 5932 | |
| 5933 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5934 | goto unlock; |
| 5935 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
| 5936 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 5937 | |
| 5938 | if (lec != ((b_nvram & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5939 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS)) { |
| 5940 | /* NVRAM needs update */ |
| 5941 | b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS << |
| 5942 | TP_NVRAM_POS_LEVEL_BRIGHTNESS); |
| 5943 | b_nvram |= lec; |
| 5944 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_BRIGHTNESS); |
| 5945 | dbg_printk(TPACPI_DBG_BRGHT, |
| 5946 | "updated NVRAM backlight level to %u (0x%02x)\n", |
| 5947 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5948 | } else |
| 5949 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5950 | "NVRAM backlight level already is %u (0x%02x)\n", |
| 5951 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5952 | |
| 5953 | unlock: |
| 5954 | mutex_unlock(&brightness_mutex); |
| 5955 | } |
| 5956 | |
| 5957 | |
| 5958 | /* call with brightness_mutex held! */ |
| 5959 | static int tpacpi_brightness_get_raw(int *status) |
| 5960 | { |
| 5961 | u8 lec = 0; |
| 5962 | |
| 5963 | switch (brightness_mode) { |
| 5964 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 5965 | *status = tpacpi_brightness_nvram_get(); |
| 5966 | return 0; |
| 5967 | case TPACPI_BRGHT_MODE_EC: |
| 5968 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 5969 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 5970 | return -EIO; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5971 | *status = lec; |
| 5972 | return 0; |
| 5973 | default: |
| 5974 | return -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5975 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5976 | } |
| 5977 | |
| 5978 | /* call with brightness_mutex held! */ |
| 5979 | /* do NOT call with illegal backlight level value */ |
| 5980 | static int tpacpi_brightness_set_ec(unsigned int value) |
| 5981 | { |
| 5982 | u8 lec = 0; |
| 5983 | |
| 5984 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5985 | return -EIO; |
| 5986 | |
| 5987 | if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT, |
| 5988 | (lec & TP_EC_BACKLIGHT_CMDMSK) | |
| 5989 | (value & TP_EC_BACKLIGHT_LVLMSK)))) |
| 5990 | return -EIO; |
| 5991 | |
| 5992 | return 0; |
| 5993 | } |
| 5994 | |
| 5995 | /* call with brightness_mutex held! */ |
| 5996 | static int tpacpi_brightness_set_ucmsstep(unsigned int value) |
| 5997 | { |
| 5998 | int cmos_cmd, inc; |
| 5999 | unsigned int current_value, i; |
| 6000 | |
| 6001 | current_value = tpacpi_brightness_nvram_get(); |
| 6002 | |
| 6003 | if (value == current_value) |
| 6004 | return 0; |
| 6005 | |
| 6006 | cmos_cmd = (value > current_value) ? |
| 6007 | TP_CMOS_BRIGHTNESS_UP : |
| 6008 | TP_CMOS_BRIGHTNESS_DOWN; |
| 6009 | inc = (value > current_value) ? 1 : -1; |
| 6010 | |
| 6011 | for (i = current_value; i != value; i += inc) |
| 6012 | if (issue_thinkpad_cmos_command(cmos_cmd)) |
| 6013 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6014 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6015 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6016 | } |
| 6017 | |
| 6018 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6019 | static int brightness_set(unsigned int value) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6020 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6021 | int res; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6022 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6023 | if (value > ((tp_features.bright_16levels)? 15 : 7) || |
| 6024 | value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6025 | return -EINVAL; |
| 6026 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6027 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 6028 | "set backlight level to %d\n", value); |
| 6029 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6030 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6031 | if (res < 0) |
| 6032 | return res; |
| 6033 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6034 | switch (brightness_mode) { |
| 6035 | case TPACPI_BRGHT_MODE_EC: |
| 6036 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 6037 | res = tpacpi_brightness_set_ec(value); |
| 6038 | break; |
| 6039 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 6040 | res = tpacpi_brightness_set_ucmsstep(value); |
| 6041 | break; |
| 6042 | default: |
| 6043 | res = -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6044 | } |
| 6045 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6046 | mutex_unlock(&brightness_mutex); |
| 6047 | return res; |
| 6048 | } |
| 6049 | |
| 6050 | /* sysfs backlight class ----------------------------------------------- */ |
| 6051 | |
| 6052 | static int brightness_update_status(struct backlight_device *bd) |
| 6053 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6054 | unsigned int level = |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6055 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 6056 | bd->props.power == FB_BLANK_UNBLANK) ? |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6057 | bd->props.brightness : 0; |
| 6058 | |
| 6059 | dbg_printk(TPACPI_DBG_BRGHT, |
| 6060 | "backlight: attempt to set level to %d\n", |
| 6061 | level); |
| 6062 | |
| 6063 | /* it is the backlight class's job (caller) to handle |
| 6064 | * EINTR and other errors properly */ |
| 6065 | return brightness_set(level); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6066 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 6067 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6068 | static int brightness_get(struct backlight_device *bd) |
| 6069 | { |
| 6070 | int status, res; |
| 6071 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6072 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6073 | if (res < 0) |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6074 | return 0; |
| 6075 | |
| 6076 | res = tpacpi_brightness_get_raw(&status); |
| 6077 | |
| 6078 | mutex_unlock(&brightness_mutex); |
| 6079 | |
| 6080 | if (res < 0) |
| 6081 | return 0; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6082 | |
| 6083 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 6084 | } |
| 6085 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6086 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6087 | .get_brightness = brightness_get, |
| 6088 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6089 | }; |
| 6090 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6091 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6092 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6093 | /* |
| 6094 | * These are only useful for models that have only one possibility |
| 6095 | * of GPU. If the BIOS model handles both ATI and Intel, don't use |
| 6096 | * these quirks. |
| 6097 | */ |
| 6098 | #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */ |
| 6099 | #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */ |
| 6100 | #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */ |
| 6101 | |
| 6102 | static const struct tpacpi_quirk brightness_quirk_table[] __initconst = { |
| 6103 | /* Models with ATI GPUs known to require ECNVRAM mode */ |
| 6104 | TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */ |
| 6105 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6106 | /* Models with ATI GPUs that can use ECNVRAM */ |
| 6107 | TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6108 | TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6109 | TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6110 | TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6111 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6112 | /* Models with Intel Extreme Graphics 2 */ |
| 6113 | TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6114 | TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_NOEC), |
| 6115 | TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_NOEC), |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6116 | |
| 6117 | /* Models with Intel GMA900 */ |
| 6118 | TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC), /* T43, R52 */ |
| 6119 | TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC), /* X41 */ |
| 6120 | TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC), /* X41 Tablet */ |
| 6121 | }; |
| 6122 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6123 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6124 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6125 | int b; |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6126 | unsigned long quirks; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6127 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6128 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 6129 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6130 | mutex_init(&brightness_mutex); |
| 6131 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6132 | quirks = tpacpi_check_quirks(brightness_quirk_table, |
| 6133 | ARRAY_SIZE(brightness_quirk_table)); |
| 6134 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6135 | /* |
| 6136 | * We always attempt to detect acpi support, so as to switch |
| 6137 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 6138 | * going to publish a backlight interface |
| 6139 | */ |
| 6140 | b = tpacpi_check_std_acpi_brightness_support(); |
| 6141 | if (b > 0) { |
Thomas Renninger | 2dba1b5 | 2008-08-01 17:38:03 +0200 | [diff] [blame] | 6142 | |
| 6143 | if (acpi_video_backlight_support()) { |
| 6144 | if (brightness_enable > 1) { |
| 6145 | printk(TPACPI_NOTICE |
| 6146 | "Standard ACPI backlight interface " |
| 6147 | "available, not loading native one.\n"); |
| 6148 | return 1; |
| 6149 | } else if (brightness_enable == 1) { |
| 6150 | printk(TPACPI_NOTICE |
| 6151 | "Backlight control force enabled, even if standard " |
| 6152 | "ACPI backlight interface is available\n"); |
| 6153 | } |
| 6154 | } else { |
| 6155 | if (brightness_enable > 1) { |
| 6156 | printk(TPACPI_NOTICE |
| 6157 | "Standard ACPI backlight interface not " |
| 6158 | "available, thinkpad_acpi native " |
| 6159 | "brightness control enabled\n"); |
| 6160 | } |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 6161 | } |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6162 | } |
| 6163 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6164 | if (!brightness_enable) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6165 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6166 | "brightness support disabled by " |
| 6167 | "module parameter\n"); |
| 6168 | return 1; |
| 6169 | } |
| 6170 | |
| 6171 | if (b > 16) { |
| 6172 | printk(TPACPI_ERR |
| 6173 | "Unsupported brightness interface, " |
| 6174 | "please contact %s\n", TPACPI_MAIL); |
| 6175 | return 1; |
| 6176 | } |
| 6177 | if (b == 16) |
| 6178 | tp_features.bright_16levels = 1; |
| 6179 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6180 | /* |
| 6181 | * Check for module parameter bogosity, note that we |
| 6182 | * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be |
| 6183 | * able to detect "unspecified" |
| 6184 | */ |
| 6185 | if (brightness_mode > TPACPI_BRGHT_MODE_MAX) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6186 | return -EINVAL; |
| 6187 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6188 | /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */ |
| 6189 | if (brightness_mode == TPACPI_BRGHT_MODE_AUTO || |
| 6190 | brightness_mode == TPACPI_BRGHT_MODE_MAX) { |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6191 | if (quirks & TPACPI_BRGHT_Q_EC) |
| 6192 | brightness_mode = TPACPI_BRGHT_MODE_ECNVRAM; |
| 6193 | else |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6194 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
| 6195 | |
| 6196 | dbg_printk(TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6197 | "driver auto-selected brightness_mode=%d\n", |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6198 | brightness_mode); |
| 6199 | } |
| 6200 | |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 6201 | /* Safety */ |
| 6202 | if (thinkpad_id.vendor != PCI_VENDOR_ID_IBM && |
| 6203 | (brightness_mode == TPACPI_BRGHT_MODE_ECNVRAM || |
| 6204 | brightness_mode == TPACPI_BRGHT_MODE_EC)) |
| 6205 | return -EINVAL; |
| 6206 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6207 | if (tpacpi_brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6208 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6209 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6210 | if (tp_features.bright_16levels) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6211 | printk(TPACPI_INFO |
| 6212 | "detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6213 | |
Henrique de Moraes Holschuh | 7d5a015 | 2007-04-24 11:48:20 -0300 | [diff] [blame] | 6214 | ibm_backlight_device = backlight_device_register( |
| 6215 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
| 6216 | &ibm_backlight_data); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6217 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6218 | int rc = PTR_ERR(ibm_backlight_device); |
| 6219 | ibm_backlight_device = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6220 | printk(TPACPI_ERR "Could not register backlight device\n"); |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6221 | return rc; |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6222 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6223 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6224 | "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6225 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6226 | if (quirks & TPACPI_BRGHT_Q_ASK) { |
| 6227 | printk(TPACPI_NOTICE |
| 6228 | "brightness: will use unverified default: " |
| 6229 | "brightness_mode=%d\n", brightness_mode); |
| 6230 | printk(TPACPI_NOTICE |
| 6231 | "brightness: please report to %s whether it works well " |
| 6232 | "or not on your ThinkPad\n", TPACPI_MAIL); |
| 6233 | } |
| 6234 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6235 | ibm_backlight_device->props.max_brightness = |
| 6236 | (tp_features.bright_16levels)? 15 : 7; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6237 | ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6238 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6239 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6240 | return 0; |
| 6241 | } |
| 6242 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6243 | static void brightness_suspend(pm_message_t state) |
| 6244 | { |
| 6245 | tpacpi_brightness_checkpoint_nvram(); |
| 6246 | } |
| 6247 | |
| 6248 | static void brightness_shutdown(void) |
| 6249 | { |
| 6250 | tpacpi_brightness_checkpoint_nvram(); |
| 6251 | } |
| 6252 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6253 | static void brightness_exit(void) |
| 6254 | { |
| 6255 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6256 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6257 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6258 | backlight_device_unregister(ibm_backlight_device); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6259 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6260 | |
| 6261 | tpacpi_brightness_checkpoint_nvram(); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6262 | } |
| 6263 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6264 | static int brightness_read(char *p) |
| 6265 | { |
| 6266 | int len = 0; |
| 6267 | int level; |
| 6268 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6269 | level = brightness_get(NULL); |
| 6270 | if (level < 0) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6271 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 6272 | } else { |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6273 | len += sprintf(p + len, "level:\t\t%d\n", level); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6274 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 6275 | len += sprintf(p + len, "commands:\tlevel <level>" |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6276 | " (<level> is 0-%d)\n", |
| 6277 | (tp_features.bright_16levels) ? 15 : 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6278 | } |
| 6279 | |
| 6280 | return len; |
| 6281 | } |
| 6282 | |
| 6283 | static int brightness_write(char *buf) |
| 6284 | { |
| 6285 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6286 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6287 | char *cmd; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6288 | int max_level = (tp_features.bright_16levels) ? 15 : 7; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6289 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6290 | level = brightness_get(NULL); |
| 6291 | if (level < 0) |
| 6292 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6293 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6294 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6295 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6296 | if (level < max_level) |
| 6297 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6298 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6299 | if (level > 0) |
| 6300 | level--; |
| 6301 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
| 6302 | level >= 0 && level <= max_level) { |
| 6303 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6304 | } else |
| 6305 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6306 | } |
| 6307 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6308 | tpacpi_disclose_usertask("procfs brightness", |
| 6309 | "set level to %d\n", level); |
| 6310 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6311 | /* |
| 6312 | * Now we know what the final level should be, so we try to set it. |
| 6313 | * Doing it this way makes the syscall restartable in case of EINTR |
| 6314 | */ |
| 6315 | rc = brightness_set(level); |
| 6316 | return (rc == -EINTR)? ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6317 | } |
| 6318 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6319 | static struct ibm_struct brightness_driver_data = { |
| 6320 | .name = "brightness", |
| 6321 | .read = brightness_read, |
| 6322 | .write = brightness_write, |
| 6323 | .exit = brightness_exit, |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6324 | .suspend = brightness_suspend, |
| 6325 | .shutdown = brightness_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6326 | }; |
| 6327 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6328 | /************************************************************************* |
| 6329 | * Volume subdriver |
| 6330 | */ |
| 6331 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6332 | static int volume_offset = 0x30; |
| 6333 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6334 | static int volume_read(char *p) |
| 6335 | { |
| 6336 | int len = 0; |
| 6337 | u8 level; |
| 6338 | |
| 6339 | if (!acpi_ec_read(volume_offset, &level)) { |
| 6340 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 6341 | } else { |
| 6342 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 6343 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 6344 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 6345 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 6346 | " (<level> is 0-15)\n"); |
| 6347 | } |
| 6348 | |
| 6349 | return len; |
| 6350 | } |
| 6351 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6352 | static int volume_write(char *buf) |
| 6353 | { |
| 6354 | int cmos_cmd, inc, i; |
| 6355 | u8 level, mute; |
| 6356 | int new_level, new_mute; |
| 6357 | char *cmd; |
| 6358 | |
| 6359 | while ((cmd = next_cmd(&buf))) { |
| 6360 | if (!acpi_ec_read(volume_offset, &level)) |
| 6361 | return -EIO; |
| 6362 | new_mute = mute = level & 0x40; |
| 6363 | new_level = level = level & 0xf; |
| 6364 | |
| 6365 | if (strlencmp(cmd, "up") == 0) { |
| 6366 | if (mute) |
| 6367 | new_mute = 0; |
| 6368 | else |
| 6369 | new_level = level == 15 ? 15 : level + 1; |
| 6370 | } else if (strlencmp(cmd, "down") == 0) { |
| 6371 | if (mute) |
| 6372 | new_mute = 0; |
| 6373 | else |
| 6374 | new_level = level == 0 ? 0 : level - 1; |
| 6375 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 6376 | new_level >= 0 && new_level <= 15) { |
| 6377 | /* new_level set */ |
| 6378 | } else if (strlencmp(cmd, "mute") == 0) { |
| 6379 | new_mute = 0x40; |
| 6380 | } else |
| 6381 | return -EINVAL; |
| 6382 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6383 | if (new_level != level) { |
| 6384 | /* mute doesn't change */ |
| 6385 | |
| 6386 | cmos_cmd = (new_level > level) ? |
| 6387 | TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6388 | inc = new_level > level ? 1 : -1; |
| 6389 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6390 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6391 | !acpi_ec_write(volume_offset, level))) |
| 6392 | return -EIO; |
| 6393 | |
| 6394 | for (i = level; i != new_level; i += inc) |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6395 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6396 | !acpi_ec_write(volume_offset, i + inc)) |
| 6397 | return -EIO; |
| 6398 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6399 | if (mute && |
| 6400 | (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
| 6401 | !acpi_ec_write(volume_offset, new_level + mute))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6402 | return -EIO; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6403 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6404 | } |
| 6405 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6406 | if (new_mute != mute) { |
| 6407 | /* level doesn't change */ |
| 6408 | |
| 6409 | cmos_cmd = (new_mute) ? |
| 6410 | TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6411 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6412 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6413 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 6414 | return -EIO; |
| 6415 | } |
| 6416 | } |
| 6417 | |
| 6418 | return 0; |
| 6419 | } |
| 6420 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6421 | static struct ibm_struct volume_driver_data = { |
| 6422 | .name = "volume", |
| 6423 | .read = volume_read, |
| 6424 | .write = volume_write, |
| 6425 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6426 | |
| 6427 | /************************************************************************* |
| 6428 | * Fan subdriver |
| 6429 | */ |
| 6430 | |
| 6431 | /* |
| 6432 | * FAN ACCESS MODES |
| 6433 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6434 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6435 | * ACPI GFAN method: returns fan level |
| 6436 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6437 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6438 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6439 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6440 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6441 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 6442 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6443 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 6444 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6445 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6446 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6447 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 6448 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6449 | * |
| 6450 | * Fan speed changes of any sort (including those caused by the |
| 6451 | * disengaged mode) are usually done slowly by the firmware as the |
| 6452 | * maximum ammount of fan duty cycle change per second seems to be |
| 6453 | * limited. |
| 6454 | * |
| 6455 | * Reading is not available if GFAN exists. |
| 6456 | * Writing is not available if SFAN exists. |
| 6457 | * |
| 6458 | * Bits |
| 6459 | * 7 automatic mode engaged; |
| 6460 | * (default operation mode of the ThinkPad) |
| 6461 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6462 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6463 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6464 | * the tachometer while the fan controller ramps up |
| 6465 | * the speed (which can take up to a few *minutes*). |
| 6466 | * Speeds up fan to 100% duty-cycle, which is far above |
| 6467 | * the standard RPM levels. It is not impossible that |
| 6468 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6469 | * 5-3 unused in some models. Extra bits for fan level |
| 6470 | * in others, but still useless as all values above |
| 6471 | * 7 map to the same speed as level 7 in these models. |
| 6472 | * 2-0 fan level (0..7 usually) |
| 6473 | * 0x00 = stop |
| 6474 | * 0x07 = max (set when temperatures critical) |
| 6475 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6476 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6477 | * |
| 6478 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 6479 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 6480 | * does so, its initial value is meaningless (0x07). |
| 6481 | * |
| 6482 | * For firmware bugs, refer to: |
| 6483 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 6484 | * |
| 6485 | * ---- |
| 6486 | * |
| 6487 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 6488 | * Main fan tachometer reading (in RPM) |
| 6489 | * |
| 6490 | * This register is present on all ThinkPads with a new-style EC, and |
| 6491 | * it is known not to be present on the A21m/e, and T22, as there is |
| 6492 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 6493 | * ThinkPads from this same time period (and earlier) probably lack the |
| 6494 | * tachometer as well. |
| 6495 | * |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 6496 | * 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] | 6497 | * was never fixed by IBM to report the EC firmware version string |
| 6498 | * probably support the tachometer (like the early X models), so |
| 6499 | * detecting it is quite hard. We need more data to know for sure. |
| 6500 | * |
| 6501 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 6502 | * might result. |
| 6503 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6504 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 6505 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6506 | * |
| 6507 | * For firmware bugs, refer to: |
| 6508 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 6509 | * |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6510 | * ---- |
| 6511 | * |
| 6512 | * ThinkPad EC register 0x31 bit 0 (only on select models) |
| 6513 | * |
| 6514 | * When bit 0 of EC register 0x31 is zero, the tachometer registers |
| 6515 | * show the speed of the main fan. When bit 0 of EC register 0x31 |
| 6516 | * is one, the tachometer registers show the speed of the auxiliary |
| 6517 | * fan. |
| 6518 | * |
| 6519 | * Fan control seems to affect both fans, regardless of the state |
| 6520 | * of this bit. |
| 6521 | * |
| 6522 | * So far, only the firmware for the X60/X61 non-tablet versions |
| 6523 | * seem to support this (firmware TP-7M). |
| 6524 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6525 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6526 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 6527 | * |
| 6528 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 6529 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 6530 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 6531 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 6532 | * |
| 6533 | * The speeds are stored on handles |
| 6534 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 6535 | * |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame^] | 6536 | * There are three default speed sets, accessible as handles: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6537 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 6538 | * |
| 6539 | * ACPI DSDT switches which set is in use depending on various |
| 6540 | * factors. |
| 6541 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6542 | * 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] | 6543 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 6544 | * but the ACPI tables just mention level 7. |
| 6545 | */ |
| 6546 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6547 | enum { /* Fan control constants */ |
| 6548 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 6549 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 6550 | * 0x84 must be read before 0x85 */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6551 | fan_select_offset = 0x31, /* EC register 0x31 (Firmware 7M) |
| 6552 | bit 0 selects which fan is active */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6553 | |
| 6554 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 6555 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 6556 | |
| 6557 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 6558 | }; |
| 6559 | |
| 6560 | enum fan_status_access_mode { |
| 6561 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 6562 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 6563 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 6564 | }; |
| 6565 | |
| 6566 | enum fan_control_access_mode { |
| 6567 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 6568 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 6569 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 6570 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 6571 | }; |
| 6572 | |
| 6573 | enum fan_control_commands { |
| 6574 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 6575 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 6576 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 6577 | * and also watchdog cmd */ |
| 6578 | }; |
| 6579 | |
| 6580 | static int fan_control_allowed; |
| 6581 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6582 | static enum fan_status_access_mode fan_status_access_mode; |
| 6583 | static enum fan_control_access_mode fan_control_access_mode; |
| 6584 | static enum fan_control_commands fan_control_commands; |
| 6585 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6586 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6587 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 6588 | static u8 fan_control_resume_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6589 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6590 | |
| 6591 | static struct mutex fan_mutex; |
| 6592 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6593 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 6594 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6595 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6596 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 6597 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6598 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 6599 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6600 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6601 | "JFNS", /* 770x-JL */ |
| 6602 | ); /* all others */ |
| 6603 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6604 | /* |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6605 | * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the |
| 6606 | * HFSP register at boot, so it contains 0x07 but the Thinkpad could |
| 6607 | * be in auto mode (0x80). |
| 6608 | * |
| 6609 | * This is corrected by any write to HFSP either by the driver, or |
| 6610 | * by the firmware. |
| 6611 | * |
| 6612 | * We assume 0x07 really means auto mode while this quirk is active, |
| 6613 | * as this is far more likely than the ThinkPad being in level 7, |
| 6614 | * which is only used by the firmware during thermal emergencies. |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6615 | * |
| 6616 | * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52), |
| 6617 | * TP-70 (T43, R52), which are known to be buggy. |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6618 | */ |
| 6619 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6620 | static void fan_quirk1_setup(void) |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6621 | { |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6622 | if (fan_control_initial_status == 0x07) { |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6623 | printk(TPACPI_NOTICE |
| 6624 | "fan_init: initial fan status is unknown, " |
| 6625 | "assuming it is in auto mode\n"); |
| 6626 | tp_features.fan_ctrl_status_undef = 1; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6627 | } |
| 6628 | } |
| 6629 | |
| 6630 | static void fan_quirk1_handle(u8 *fan_status) |
| 6631 | { |
| 6632 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 6633 | if (*fan_status != fan_control_initial_status) { |
| 6634 | /* something changed the HFSP regisnter since |
| 6635 | * driver init time, so it is not undefined |
| 6636 | * anymore */ |
| 6637 | tp_features.fan_ctrl_status_undef = 0; |
| 6638 | } else { |
| 6639 | /* Return most likely status. In fact, it |
| 6640 | * might be the only possible status */ |
| 6641 | *fan_status = TP_EC_FAN_AUTO; |
| 6642 | } |
| 6643 | } |
| 6644 | } |
| 6645 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6646 | /* Select main fan on X60/X61, NOOP on others */ |
| 6647 | static bool fan_select_fan1(void) |
| 6648 | { |
| 6649 | if (tp_features.second_fan) { |
| 6650 | u8 val; |
| 6651 | |
| 6652 | if (ec_read(fan_select_offset, &val) < 0) |
| 6653 | return false; |
| 6654 | val &= 0xFEU; |
| 6655 | if (ec_write(fan_select_offset, val) < 0) |
| 6656 | return false; |
| 6657 | } |
| 6658 | return true; |
| 6659 | } |
| 6660 | |
| 6661 | /* Select secondary fan on X60/X61 */ |
| 6662 | static bool fan_select_fan2(void) |
| 6663 | { |
| 6664 | u8 val; |
| 6665 | |
| 6666 | if (!tp_features.second_fan) |
| 6667 | return false; |
| 6668 | |
| 6669 | if (ec_read(fan_select_offset, &val) < 0) |
| 6670 | return false; |
| 6671 | val |= 0x01U; |
| 6672 | if (ec_write(fan_select_offset, val) < 0) |
| 6673 | return false; |
| 6674 | |
| 6675 | return true; |
| 6676 | } |
| 6677 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6678 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6679 | * Call with fan_mutex held |
| 6680 | */ |
| 6681 | static void fan_update_desired_level(u8 status) |
| 6682 | { |
| 6683 | if ((status & |
| 6684 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 6685 | if (status > 7) |
| 6686 | fan_control_desired_level = 7; |
| 6687 | else |
| 6688 | fan_control_desired_level = status; |
| 6689 | } |
| 6690 | } |
| 6691 | |
| 6692 | static int fan_get_status(u8 *status) |
| 6693 | { |
| 6694 | u8 s; |
| 6695 | |
| 6696 | /* TODO: |
| 6697 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 6698 | |
| 6699 | switch (fan_status_access_mode) { |
| 6700 | case TPACPI_FAN_RD_ACPI_GFAN: |
| 6701 | /* 570, 600e/x, 770e, 770x */ |
| 6702 | |
| 6703 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
| 6704 | return -EIO; |
| 6705 | |
| 6706 | if (likely(status)) |
| 6707 | *status = s & 0x07; |
| 6708 | |
| 6709 | break; |
| 6710 | |
| 6711 | case TPACPI_FAN_RD_TPEC: |
| 6712 | /* all except 570, 600e/x, 770e, 770x */ |
| 6713 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 6714 | return -EIO; |
| 6715 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6716 | if (likely(status)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6717 | *status = s; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6718 | fan_quirk1_handle(status); |
| 6719 | } |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6720 | |
| 6721 | break; |
| 6722 | |
| 6723 | default: |
| 6724 | return -ENXIO; |
| 6725 | } |
| 6726 | |
| 6727 | return 0; |
| 6728 | } |
| 6729 | |
| 6730 | static int fan_get_status_safe(u8 *status) |
| 6731 | { |
| 6732 | int rc; |
| 6733 | u8 s; |
| 6734 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6735 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6736 | return -ERESTARTSYS; |
| 6737 | rc = fan_get_status(&s); |
| 6738 | if (!rc) |
| 6739 | fan_update_desired_level(s); |
| 6740 | mutex_unlock(&fan_mutex); |
| 6741 | |
| 6742 | if (status) |
| 6743 | *status = s; |
| 6744 | |
| 6745 | return rc; |
| 6746 | } |
| 6747 | |
| 6748 | static int fan_get_speed(unsigned int *speed) |
| 6749 | { |
| 6750 | u8 hi, lo; |
| 6751 | |
| 6752 | switch (fan_status_access_mode) { |
| 6753 | case TPACPI_FAN_RD_TPEC: |
| 6754 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6755 | if (unlikely(!fan_select_fan1())) |
| 6756 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6757 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 6758 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 6759 | return -EIO; |
| 6760 | |
| 6761 | if (likely(speed)) |
| 6762 | *speed = (hi << 8) | lo; |
| 6763 | |
| 6764 | break; |
| 6765 | |
| 6766 | default: |
| 6767 | return -ENXIO; |
| 6768 | } |
| 6769 | |
| 6770 | return 0; |
| 6771 | } |
| 6772 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6773 | static int fan2_get_speed(unsigned int *speed) |
| 6774 | { |
| 6775 | u8 hi, lo; |
| 6776 | bool rc; |
| 6777 | |
| 6778 | switch (fan_status_access_mode) { |
| 6779 | case TPACPI_FAN_RD_TPEC: |
| 6780 | /* all except 570, 600e/x, 770e, 770x */ |
| 6781 | if (unlikely(!fan_select_fan2())) |
| 6782 | return -EIO; |
| 6783 | rc = !acpi_ec_read(fan_rpm_offset, &lo) || |
| 6784 | !acpi_ec_read(fan_rpm_offset + 1, &hi); |
| 6785 | fan_select_fan1(); /* play it safe */ |
| 6786 | if (rc) |
| 6787 | return -EIO; |
| 6788 | |
| 6789 | if (likely(speed)) |
| 6790 | *speed = (hi << 8) | lo; |
| 6791 | |
| 6792 | break; |
| 6793 | |
| 6794 | default: |
| 6795 | return -ENXIO; |
| 6796 | } |
| 6797 | |
| 6798 | return 0; |
| 6799 | } |
| 6800 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6801 | static int fan_set_level(int level) |
| 6802 | { |
| 6803 | if (!fan_control_allowed) |
| 6804 | return -EPERM; |
| 6805 | |
| 6806 | switch (fan_control_access_mode) { |
| 6807 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6808 | if (level >= 0 && level <= 7) { |
| 6809 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 6810 | return -EIO; |
| 6811 | } else |
| 6812 | return -EINVAL; |
| 6813 | break; |
| 6814 | |
| 6815 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6816 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 6817 | if (!(level & TP_EC_FAN_AUTO) && |
| 6818 | !(level & TP_EC_FAN_FULLSPEED) && |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6819 | ((level < 0) || (level > 7))) |
| 6820 | return -EINVAL; |
| 6821 | |
| 6822 | /* safety net should the EC not support AUTO |
| 6823 | * or FULLSPEED mode bits and just ignore them */ |
| 6824 | if (level & TP_EC_FAN_FULLSPEED) |
| 6825 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 6826 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6827 | level |= 4; /* safety min speed 4 */ |
| 6828 | |
| 6829 | if (!acpi_ec_write(fan_status_offset, level)) |
| 6830 | return -EIO; |
| 6831 | else |
| 6832 | tp_features.fan_ctrl_status_undef = 0; |
| 6833 | break; |
| 6834 | |
| 6835 | default: |
| 6836 | return -ENXIO; |
| 6837 | } |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6838 | |
| 6839 | vdbg_printk(TPACPI_DBG_FAN, |
| 6840 | "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] | 6841 | return 0; |
| 6842 | } |
| 6843 | |
| 6844 | static int fan_set_level_safe(int level) |
| 6845 | { |
| 6846 | int rc; |
| 6847 | |
| 6848 | if (!fan_control_allowed) |
| 6849 | return -EPERM; |
| 6850 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6851 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6852 | return -ERESTARTSYS; |
| 6853 | |
| 6854 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 6855 | level = fan_control_desired_level; |
| 6856 | |
| 6857 | rc = fan_set_level(level); |
| 6858 | if (!rc) |
| 6859 | fan_update_desired_level(level); |
| 6860 | |
| 6861 | mutex_unlock(&fan_mutex); |
| 6862 | return rc; |
| 6863 | } |
| 6864 | |
| 6865 | static int fan_set_enable(void) |
| 6866 | { |
| 6867 | u8 s; |
| 6868 | int rc; |
| 6869 | |
| 6870 | if (!fan_control_allowed) |
| 6871 | return -EPERM; |
| 6872 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6873 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6874 | return -ERESTARTSYS; |
| 6875 | |
| 6876 | switch (fan_control_access_mode) { |
| 6877 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6878 | case TPACPI_FAN_WR_TPEC: |
| 6879 | rc = fan_get_status(&s); |
| 6880 | if (rc < 0) |
| 6881 | break; |
| 6882 | |
| 6883 | /* Don't go out of emergency fan mode */ |
| 6884 | if (s != 7) { |
| 6885 | s &= 0x07; |
| 6886 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 6887 | } |
| 6888 | |
| 6889 | if (!acpi_ec_write(fan_status_offset, s)) |
| 6890 | rc = -EIO; |
| 6891 | else { |
| 6892 | tp_features.fan_ctrl_status_undef = 0; |
| 6893 | rc = 0; |
| 6894 | } |
| 6895 | break; |
| 6896 | |
| 6897 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6898 | rc = fan_get_status(&s); |
| 6899 | if (rc < 0) |
| 6900 | break; |
| 6901 | |
| 6902 | s &= 0x07; |
| 6903 | |
| 6904 | /* Set fan to at least level 4 */ |
| 6905 | s |= 4; |
| 6906 | |
| 6907 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6908 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6909 | else |
| 6910 | rc = 0; |
| 6911 | break; |
| 6912 | |
| 6913 | default: |
| 6914 | rc = -ENXIO; |
| 6915 | } |
| 6916 | |
| 6917 | mutex_unlock(&fan_mutex); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6918 | |
| 6919 | if (!rc) |
| 6920 | vdbg_printk(TPACPI_DBG_FAN, |
| 6921 | "fan control: set fan control register to 0x%02x\n", |
| 6922 | s); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6923 | return rc; |
| 6924 | } |
| 6925 | |
| 6926 | static int fan_set_disable(void) |
| 6927 | { |
| 6928 | int rc; |
| 6929 | |
| 6930 | if (!fan_control_allowed) |
| 6931 | return -EPERM; |
| 6932 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6933 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6934 | return -ERESTARTSYS; |
| 6935 | |
| 6936 | rc = 0; |
| 6937 | switch (fan_control_access_mode) { |
| 6938 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6939 | case TPACPI_FAN_WR_TPEC: |
| 6940 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 6941 | rc = -EIO; |
| 6942 | else { |
| 6943 | fan_control_desired_level = 0; |
| 6944 | tp_features.fan_ctrl_status_undef = 0; |
| 6945 | } |
| 6946 | break; |
| 6947 | |
| 6948 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6949 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 6950 | rc = -EIO; |
| 6951 | else |
| 6952 | fan_control_desired_level = 0; |
| 6953 | break; |
| 6954 | |
| 6955 | default: |
| 6956 | rc = -ENXIO; |
| 6957 | } |
| 6958 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6959 | if (!rc) |
| 6960 | vdbg_printk(TPACPI_DBG_FAN, |
| 6961 | "fan control: set fan control register to 0\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6962 | |
| 6963 | mutex_unlock(&fan_mutex); |
| 6964 | return rc; |
| 6965 | } |
| 6966 | |
| 6967 | static int fan_set_speed(int speed) |
| 6968 | { |
| 6969 | int rc; |
| 6970 | |
| 6971 | if (!fan_control_allowed) |
| 6972 | return -EPERM; |
| 6973 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6974 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6975 | return -ERESTARTSYS; |
| 6976 | |
| 6977 | rc = 0; |
| 6978 | switch (fan_control_access_mode) { |
| 6979 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6980 | if (speed >= 0 && speed <= 65535) { |
| 6981 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 6982 | speed, speed, speed)) |
| 6983 | rc = -EIO; |
| 6984 | } else |
| 6985 | rc = -EINVAL; |
| 6986 | break; |
| 6987 | |
| 6988 | default: |
| 6989 | rc = -ENXIO; |
| 6990 | } |
| 6991 | |
| 6992 | mutex_unlock(&fan_mutex); |
| 6993 | return rc; |
| 6994 | } |
| 6995 | |
| 6996 | static void fan_watchdog_reset(void) |
| 6997 | { |
| 6998 | static int fan_watchdog_active; |
| 6999 | |
| 7000 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 7001 | return; |
| 7002 | |
| 7003 | if (fan_watchdog_active) |
| 7004 | cancel_delayed_work(&fan_watchdog_task); |
| 7005 | |
| 7006 | if (fan_watchdog_maxinterval > 0 && |
| 7007 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
| 7008 | fan_watchdog_active = 1; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7009 | if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task, |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7010 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 7011 | * 1000))) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7012 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7013 | "failed to queue the fan watchdog, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7014 | "watchdog will not trigger\n"); |
| 7015 | } |
| 7016 | } else |
| 7017 | fan_watchdog_active = 0; |
| 7018 | } |
| 7019 | |
| 7020 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 7021 | { |
| 7022 | int rc; |
| 7023 | |
| 7024 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 7025 | return; |
| 7026 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7027 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7028 | rc = fan_set_enable(); |
| 7029 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7030 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7031 | "will try again later...\n", -rc); |
| 7032 | /* reschedule for later */ |
| 7033 | fan_watchdog_reset(); |
| 7034 | } |
| 7035 | } |
| 7036 | |
| 7037 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7038 | * SYSFS fan layout: hwmon compatible (device) |
| 7039 | * |
| 7040 | * pwm*_enable: |
| 7041 | * 0: "disengaged" mode |
| 7042 | * 1: manual mode |
| 7043 | * 2: native EC "auto" mode (recommended, hardware default) |
| 7044 | * |
| 7045 | * pwm*: set speed in manual mode, ignored otherwise. |
| 7046 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 7047 | * interpolation. |
| 7048 | * |
| 7049 | * fan*_input: tachometer reading, RPM |
| 7050 | * |
| 7051 | * |
| 7052 | * SYSFS fan layout: extensions |
| 7053 | * |
| 7054 | * fan_watchdog (driver): |
| 7055 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 7056 | */ |
| 7057 | |
| 7058 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 7059 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 7060 | struct device_attribute *attr, |
| 7061 | char *buf) |
| 7062 | { |
| 7063 | int res, mode; |
| 7064 | u8 status; |
| 7065 | |
| 7066 | res = fan_get_status_safe(&status); |
| 7067 | if (res) |
| 7068 | return res; |
| 7069 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7070 | if (status & TP_EC_FAN_FULLSPEED) { |
| 7071 | mode = 0; |
| 7072 | } else if (status & TP_EC_FAN_AUTO) { |
| 7073 | mode = 2; |
| 7074 | } else |
| 7075 | mode = 1; |
| 7076 | |
| 7077 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 7078 | } |
| 7079 | |
| 7080 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 7081 | struct device_attribute *attr, |
| 7082 | const char *buf, size_t count) |
| 7083 | { |
| 7084 | unsigned long t; |
| 7085 | int res, level; |
| 7086 | |
| 7087 | if (parse_strtoul(buf, 2, &t)) |
| 7088 | return -EINVAL; |
| 7089 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7090 | tpacpi_disclose_usertask("hwmon pwm1_enable", |
| 7091 | "set fan mode to %lu\n", t); |
| 7092 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7093 | switch (t) { |
| 7094 | case 0: |
| 7095 | level = TP_EC_FAN_FULLSPEED; |
| 7096 | break; |
| 7097 | case 1: |
| 7098 | level = TPACPI_FAN_LAST_LEVEL; |
| 7099 | break; |
| 7100 | case 2: |
| 7101 | level = TP_EC_FAN_AUTO; |
| 7102 | break; |
| 7103 | case 3: |
| 7104 | /* reserved for software-controlled auto mode */ |
| 7105 | return -ENOSYS; |
| 7106 | default: |
| 7107 | return -EINVAL; |
| 7108 | } |
| 7109 | |
| 7110 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 7111 | if (res == -ENXIO) |
| 7112 | return -EINVAL; |
| 7113 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7114 | return res; |
| 7115 | |
| 7116 | fan_watchdog_reset(); |
| 7117 | |
| 7118 | return count; |
| 7119 | } |
| 7120 | |
| 7121 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 7122 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 7123 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 7124 | |
| 7125 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 7126 | static ssize_t fan_pwm1_show(struct device *dev, |
| 7127 | struct device_attribute *attr, |
| 7128 | char *buf) |
| 7129 | { |
| 7130 | int res; |
| 7131 | u8 status; |
| 7132 | |
| 7133 | res = fan_get_status_safe(&status); |
| 7134 | if (res) |
| 7135 | return res; |
| 7136 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7137 | if ((status & |
| 7138 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 7139 | status = fan_control_desired_level; |
| 7140 | |
| 7141 | if (status > 7) |
| 7142 | status = 7; |
| 7143 | |
| 7144 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 7145 | } |
| 7146 | |
| 7147 | static ssize_t fan_pwm1_store(struct device *dev, |
| 7148 | struct device_attribute *attr, |
| 7149 | const char *buf, size_t count) |
| 7150 | { |
| 7151 | unsigned long s; |
| 7152 | int rc; |
| 7153 | u8 status, newlevel; |
| 7154 | |
| 7155 | if (parse_strtoul(buf, 255, &s)) |
| 7156 | return -EINVAL; |
| 7157 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7158 | tpacpi_disclose_usertask("hwmon pwm1", |
| 7159 | "set fan speed to %lu\n", s); |
| 7160 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7161 | /* scale down from 0-255 to 0-7 */ |
| 7162 | newlevel = (s >> 5) & 0x07; |
| 7163 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7164 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 7165 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7166 | |
| 7167 | rc = fan_get_status(&status); |
| 7168 | if (!rc && (status & |
| 7169 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 7170 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 7171 | if (rc == -ENXIO) |
| 7172 | rc = -EINVAL; |
| 7173 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7174 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 7175 | fan_watchdog_reset(); |
| 7176 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7177 | } |
| 7178 | |
| 7179 | mutex_unlock(&fan_mutex); |
| 7180 | return (rc)? rc : count; |
| 7181 | } |
| 7182 | |
| 7183 | static struct device_attribute dev_attr_fan_pwm1 = |
| 7184 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 7185 | fan_pwm1_show, fan_pwm1_store); |
| 7186 | |
| 7187 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 7188 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 7189 | struct device_attribute *attr, |
| 7190 | char *buf) |
| 7191 | { |
| 7192 | int res; |
| 7193 | unsigned int speed; |
| 7194 | |
| 7195 | res = fan_get_speed(&speed); |
| 7196 | if (res < 0) |
| 7197 | return res; |
| 7198 | |
| 7199 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7200 | } |
| 7201 | |
| 7202 | static struct device_attribute dev_attr_fan_fan1_input = |
| 7203 | __ATTR(fan1_input, S_IRUGO, |
| 7204 | fan_fan1_input_show, NULL); |
| 7205 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7206 | /* sysfs fan fan2_input ------------------------------------------------ */ |
| 7207 | static ssize_t fan_fan2_input_show(struct device *dev, |
| 7208 | struct device_attribute *attr, |
| 7209 | char *buf) |
| 7210 | { |
| 7211 | int res; |
| 7212 | unsigned int speed; |
| 7213 | |
| 7214 | res = fan2_get_speed(&speed); |
| 7215 | if (res < 0) |
| 7216 | return res; |
| 7217 | |
| 7218 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7219 | } |
| 7220 | |
| 7221 | static struct device_attribute dev_attr_fan_fan2_input = |
| 7222 | __ATTR(fan2_input, S_IRUGO, |
| 7223 | fan_fan2_input_show, NULL); |
| 7224 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7225 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7226 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 7227 | char *buf) |
| 7228 | { |
| 7229 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 7230 | } |
| 7231 | |
| 7232 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 7233 | const char *buf, size_t count) |
| 7234 | { |
| 7235 | unsigned long t; |
| 7236 | |
| 7237 | if (parse_strtoul(buf, 120, &t)) |
| 7238 | return -EINVAL; |
| 7239 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7240 | if (!fan_control_allowed) |
| 7241 | return -EPERM; |
| 7242 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7243 | fan_watchdog_maxinterval = t; |
| 7244 | fan_watchdog_reset(); |
| 7245 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7246 | tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t); |
| 7247 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7248 | return count; |
| 7249 | } |
| 7250 | |
| 7251 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 7252 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 7253 | |
| 7254 | /* --------------------------------------------------------------------- */ |
| 7255 | static struct attribute *fan_attributes[] = { |
| 7256 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 7257 | &dev_attr_fan_fan1_input.attr, |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7258 | NULL, /* for fan2_input */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7259 | NULL |
| 7260 | }; |
| 7261 | |
| 7262 | static const struct attribute_group fan_attr_group = { |
| 7263 | .attrs = fan_attributes, |
| 7264 | }; |
| 7265 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7266 | #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */ |
| 7267 | #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] | 7268 | |
| 7269 | #define TPACPI_FAN_QI(__id1, __id2, __quirks) \ |
| 7270 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 7271 | .bios = TPACPI_MATCH_ANY, \ |
| 7272 | .ec = TPID(__id1, __id2), \ |
| 7273 | .quirks = __quirks } |
| 7274 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7275 | #define TPACPI_FAN_QL(__id1, __id2, __quirks) \ |
| 7276 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 7277 | .bios = TPACPI_MATCH_ANY, \ |
| 7278 | .ec = TPID(__id1, __id2), \ |
| 7279 | .quirks = __quirks } |
| 7280 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7281 | static const struct tpacpi_quirk fan_quirk_table[] __initconst = { |
| 7282 | TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1), |
| 7283 | TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1), |
| 7284 | TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1), |
| 7285 | TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1), |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7286 | TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN), |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7287 | }; |
| 7288 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7289 | #undef TPACPI_FAN_QL |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7290 | #undef TPACPI_FAN_QI |
| 7291 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7292 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7293 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7294 | int rc; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7295 | unsigned long quirks; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7296 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7297 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7298 | "initializing fan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7299 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 7300 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7301 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 7302 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7303 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7304 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 7305 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7306 | tp_features.second_fan = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7307 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7308 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7309 | TPACPI_ACPIHANDLE_INIT(fans); |
| 7310 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 7311 | TPACPI_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7312 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7313 | quirks = tpacpi_check_quirks(fan_quirk_table, |
| 7314 | ARRAY_SIZE(fan_quirk_table)); |
| 7315 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7316 | if (gfan_handle) { |
| 7317 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7318 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7319 | } else { |
| 7320 | /* all other ThinkPads: note that even old-style |
| 7321 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7322 | if (likely(acpi_ec_read(fan_status_offset, |
| 7323 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7324 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7325 | if (quirks & TPACPI_FAN_Q1) |
| 7326 | fan_quirk1_setup(); |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7327 | if (quirks & TPACPI_FAN_2FAN) { |
| 7328 | tp_features.second_fan = 1; |
| 7329 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7330 | "secondary fan support enabled\n"); |
| 7331 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7332 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7333 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7334 | "ThinkPad ACPI EC access misbehaving, " |
| 7335 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7336 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7337 | } |
| 7338 | } |
| 7339 | |
| 7340 | if (sfan_handle) { |
| 7341 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7342 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 7343 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7344 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7345 | } else { |
| 7346 | if (!gfan_handle) { |
| 7347 | /* gfan without sfan means no fan control */ |
| 7348 | /* all other models implement TP EC 0x2f control */ |
| 7349 | |
| 7350 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7351 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7352 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7353 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7354 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7355 | TPACPI_FAN_CMD_SPEED | |
| 7356 | TPACPI_FAN_CMD_LEVEL | |
| 7357 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7358 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7359 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7360 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7361 | TPACPI_FAN_CMD_LEVEL | |
| 7362 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7363 | } |
| 7364 | } |
| 7365 | } |
| 7366 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7367 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7368 | "fan is %s, modes %d, %d\n", |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7369 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 7370 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 7371 | fan_status_access_mode, fan_control_access_mode); |
| 7372 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7373 | /* fan control master switch */ |
| 7374 | if (!fan_control_allowed) { |
| 7375 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 7376 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7377 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7378 | "fan control features disabled by parameter\n"); |
| 7379 | } |
| 7380 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7381 | /* update fan_control_desired_level */ |
| 7382 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 7383 | fan_get_status_safe(NULL); |
| 7384 | |
| 7385 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 7386 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7387 | if (tp_features.second_fan) { |
| 7388 | /* attach second fan tachometer */ |
| 7389 | fan_attributes[ARRAY_SIZE(fan_attributes)-2] = |
| 7390 | &dev_attr_fan_fan2_input.attr; |
| 7391 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7392 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7393 | &fan_attr_group); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7394 | if (rc < 0) |
| 7395 | return rc; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 7396 | |
| 7397 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
| 7398 | &driver_attr_fan_watchdog); |
| 7399 | if (rc < 0) { |
| 7400 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
| 7401 | &fan_attr_group); |
| 7402 | return rc; |
| 7403 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7404 | return 0; |
| 7405 | } else |
| 7406 | return 1; |
| 7407 | } |
| 7408 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7409 | static void fan_exit(void) |
| 7410 | { |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7411 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7412 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7413 | |
| 7414 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7415 | 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] | 7416 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 7417 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7418 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7419 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7420 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7421 | } |
| 7422 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7423 | static void fan_suspend(pm_message_t state) |
| 7424 | { |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7425 | int rc; |
| 7426 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7427 | if (!fan_control_allowed) |
| 7428 | return; |
| 7429 | |
| 7430 | /* Store fan status in cache */ |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7431 | fan_control_resume_level = 0; |
| 7432 | rc = fan_get_status_safe(&fan_control_resume_level); |
| 7433 | if (rc < 0) |
| 7434 | printk(TPACPI_NOTICE |
| 7435 | "failed to read fan level for later " |
| 7436 | "restore during resume: %d\n", rc); |
| 7437 | |
| 7438 | /* if it is undefined, don't attempt to restore it. |
| 7439 | * KEEP THIS LAST */ |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7440 | if (tp_features.fan_ctrl_status_undef) |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7441 | fan_control_resume_level = 0; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7442 | } |
| 7443 | |
| 7444 | static void fan_resume(void) |
| 7445 | { |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7446 | u8 current_level = 7; |
| 7447 | bool do_set = false; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7448 | int rc; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7449 | |
| 7450 | /* DSDT *always* updates status on resume */ |
| 7451 | tp_features.fan_ctrl_status_undef = 0; |
| 7452 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7453 | if (!fan_control_allowed || |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7454 | !fan_control_resume_level || |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7455 | (fan_get_status_safe(¤t_level) < 0)) |
| 7456 | return; |
| 7457 | |
| 7458 | switch (fan_control_access_mode) { |
| 7459 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7460 | /* never decrease fan level */ |
| 7461 | do_set = (fan_control_resume_level > current_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7462 | break; |
| 7463 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7464 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7465 | /* never decrease fan level, scale is: |
| 7466 | * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO |
| 7467 | * |
| 7468 | * We expect the firmware to set either 7 or AUTO, but we |
| 7469 | * handle FULLSPEED out of paranoia. |
| 7470 | * |
| 7471 | * So, we can safely only restore FULLSPEED or 7, anything |
| 7472 | * else could slow the fan. Restoring AUTO is useless, at |
| 7473 | * best that's exactly what the DSDT already set (it is the |
| 7474 | * slower it uses). |
| 7475 | * |
| 7476 | * Always keep in mind that the DSDT *will* have set the |
| 7477 | * fans to what the vendor supposes is the best level. We |
| 7478 | * muck with it only to speed the fan up. |
| 7479 | */ |
| 7480 | if (fan_control_resume_level != 7 && |
| 7481 | !(fan_control_resume_level & TP_EC_FAN_FULLSPEED)) |
| 7482 | return; |
| 7483 | else |
| 7484 | do_set = !(current_level & TP_EC_FAN_FULLSPEED) && |
| 7485 | (current_level != fan_control_resume_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7486 | break; |
| 7487 | default: |
| 7488 | return; |
| 7489 | } |
| 7490 | if (do_set) { |
| 7491 | printk(TPACPI_NOTICE |
| 7492 | "restoring fan level to 0x%02x\n", |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7493 | fan_control_resume_level); |
| 7494 | rc = fan_set_level_safe(fan_control_resume_level); |
| 7495 | if (rc < 0) |
| 7496 | printk(TPACPI_NOTICE |
| 7497 | "failed to restore fan level: %d\n", rc); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7498 | } |
| 7499 | } |
| 7500 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7501 | static int fan_read(char *p) |
| 7502 | { |
| 7503 | int len = 0; |
| 7504 | int rc; |
| 7505 | u8 status; |
| 7506 | unsigned int speed = 0; |
| 7507 | |
| 7508 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7509 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7510 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7511 | rc = fan_get_status_safe(&status); |
| 7512 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7513 | return rc; |
| 7514 | |
| 7515 | len += sprintf(p + len, "status:\t\t%s\n" |
| 7516 | "level:\t\t%d\n", |
| 7517 | (status != 0) ? "enabled" : "disabled", status); |
| 7518 | break; |
| 7519 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7520 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7521 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7522 | rc = fan_get_status_safe(&status); |
| 7523 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7524 | return rc; |
| 7525 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7526 | len += sprintf(p + len, "status:\t\t%s\n", |
| 7527 | (status != 0) ? "enabled" : "disabled"); |
| 7528 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7529 | rc = fan_get_speed(&speed); |
| 7530 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7531 | return rc; |
| 7532 | |
| 7533 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 7534 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7535 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7536 | /* Disengaged mode takes precedence */ |
| 7537 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7538 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7539 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 7540 | else |
| 7541 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 7542 | break; |
| 7543 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7544 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7545 | default: |
| 7546 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 7547 | } |
| 7548 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7549 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7550 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 7551 | |
| 7552 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7553 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7554 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 7555 | break; |
| 7556 | |
| 7557 | default: |
| 7558 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7559 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7560 | break; |
| 7561 | } |
| 7562 | } |
| 7563 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7564 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7565 | len += sprintf(p + len, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7566 | "commands:\twatchdog <timeout> (<timeout> " |
| 7567 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7568 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7569 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7570 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 7571 | " (<speed> is 0-65535)\n"); |
| 7572 | |
| 7573 | return len; |
| 7574 | } |
| 7575 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7576 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 7577 | { |
| 7578 | int level; |
| 7579 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7580 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7581 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7582 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7583 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7584 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7585 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7586 | return 0; |
| 7587 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7588 | *rc = fan_set_level_safe(level); |
| 7589 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7590 | printk(TPACPI_ERR "level command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7591 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7592 | else if (!*rc) |
| 7593 | tpacpi_disclose_usertask("procfs fan", |
| 7594 | "set level to %d\n", level); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7595 | |
| 7596 | return 1; |
| 7597 | } |
| 7598 | |
| 7599 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 7600 | { |
| 7601 | if (strlencmp(cmd, "enable") != 0) |
| 7602 | return 0; |
| 7603 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7604 | *rc = fan_set_enable(); |
| 7605 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7606 | printk(TPACPI_ERR "enable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7607 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7608 | else if (!*rc) |
| 7609 | tpacpi_disclose_usertask("procfs fan", "enable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7610 | |
| 7611 | return 1; |
| 7612 | } |
| 7613 | |
| 7614 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 7615 | { |
| 7616 | if (strlencmp(cmd, "disable") != 0) |
| 7617 | return 0; |
| 7618 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7619 | *rc = fan_set_disable(); |
| 7620 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7621 | printk(TPACPI_ERR "disable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7622 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7623 | else if (!*rc) |
| 7624 | tpacpi_disclose_usertask("procfs fan", "disable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7625 | |
| 7626 | return 1; |
| 7627 | } |
| 7628 | |
| 7629 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 7630 | { |
| 7631 | int speed; |
| 7632 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7633 | /* TODO: |
| 7634 | * Support speed <low> <medium> <high> ? */ |
| 7635 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7636 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 7637 | return 0; |
| 7638 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7639 | *rc = fan_set_speed(speed); |
| 7640 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7641 | printk(TPACPI_ERR "speed command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7642 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7643 | else if (!*rc) |
| 7644 | tpacpi_disclose_usertask("procfs fan", |
| 7645 | "set speed to %d\n", speed); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7646 | |
| 7647 | return 1; |
| 7648 | } |
| 7649 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7650 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 7651 | { |
| 7652 | int interval; |
| 7653 | |
| 7654 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 7655 | return 0; |
| 7656 | |
| 7657 | if (interval < 0 || interval > 120) |
| 7658 | *rc = -EINVAL; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7659 | else { |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7660 | fan_watchdog_maxinterval = interval; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7661 | tpacpi_disclose_usertask("procfs fan", |
| 7662 | "set watchdog timer to %d\n", |
| 7663 | interval); |
| 7664 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7665 | |
| 7666 | return 1; |
| 7667 | } |
| 7668 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7669 | static int fan_write(char *buf) |
| 7670 | { |
| 7671 | char *cmd; |
| 7672 | int rc = 0; |
| 7673 | |
| 7674 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7675 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7676 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7677 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7678 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7679 | fan_write_cmd_disable(cmd, &rc) || |
| 7680 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7681 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7682 | fan_write_cmd_speed(cmd, &rc)) |
| 7683 | ) |
| 7684 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7685 | else if (!rc) |
| 7686 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7687 | } |
| 7688 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7689 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7690 | } |
| 7691 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7692 | static struct ibm_struct fan_driver_data = { |
| 7693 | .name = "fan", |
| 7694 | .read = fan_read, |
| 7695 | .write = fan_write, |
| 7696 | .exit = fan_exit, |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7697 | .suspend = fan_suspend, |
| 7698 | .resume = fan_resume, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7699 | }; |
| 7700 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7701 | /**************************************************************************** |
| 7702 | **************************************************************************** |
| 7703 | * |
| 7704 | * Infrastructure |
| 7705 | * |
| 7706 | **************************************************************************** |
| 7707 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7708 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 7709 | /* |
| 7710 | * HKEY event callout for other subdrivers go here |
| 7711 | * (yes, it is ugly, but it is quick, safe, and gets the job done |
| 7712 | */ |
| 7713 | static void tpacpi_driver_event(const unsigned int hkey_event) |
| 7714 | { |
| 7715 | } |
| 7716 | |
| 7717 | |
| 7718 | |
| 7719 | static void hotkey_driver_event(const unsigned int scancode) |
| 7720 | { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 7721 | tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 7722 | } |
| 7723 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7724 | /* sysfs name ---------------------------------------------------------- */ |
| 7725 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 7726 | struct device_attribute *attr, |
| 7727 | char *buf) |
| 7728 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7729 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7730 | } |
| 7731 | |
| 7732 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 7733 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 7734 | |
| 7735 | /* --------------------------------------------------------------------- */ |
| 7736 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7737 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 7738 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7739 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7740 | /* |
| 7741 | * Module and infrastructure proble, init and exit handling |
| 7742 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7743 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7744 | static int force_load; |
| 7745 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7746 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7747 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7748 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7749 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7750 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7751 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7752 | } |
| 7753 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 7754 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7755 | static void ibm_exit(struct ibm_struct *ibm) |
| 7756 | { |
| 7757 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 7758 | |
| 7759 | list_del_init(&ibm->all_drivers); |
| 7760 | |
| 7761 | if (ibm->flags.acpi_notify_installed) { |
| 7762 | dbg_printk(TPACPI_DBG_EXIT, |
| 7763 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 7764 | BUG_ON(!ibm->acpi); |
| 7765 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 7766 | ibm->acpi->type, |
| 7767 | dispatch_acpi_notify); |
| 7768 | ibm->flags.acpi_notify_installed = 0; |
| 7769 | ibm->flags.acpi_notify_installed = 0; |
| 7770 | } |
| 7771 | |
| 7772 | if (ibm->flags.proc_created) { |
| 7773 | dbg_printk(TPACPI_DBG_EXIT, |
| 7774 | "%s: remove_proc_entry\n", ibm->name); |
| 7775 | remove_proc_entry(ibm->name, proc_dir); |
| 7776 | ibm->flags.proc_created = 0; |
| 7777 | } |
| 7778 | |
| 7779 | if (ibm->flags.acpi_driver_registered) { |
| 7780 | dbg_printk(TPACPI_DBG_EXIT, |
| 7781 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 7782 | BUG_ON(!ibm->acpi); |
| 7783 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 7784 | kfree(ibm->acpi->driver); |
| 7785 | ibm->acpi->driver = NULL; |
| 7786 | ibm->flags.acpi_driver_registered = 0; |
| 7787 | } |
| 7788 | |
| 7789 | if (ibm->flags.init_called && ibm->exit) { |
| 7790 | ibm->exit(); |
| 7791 | ibm->flags.init_called = 0; |
| 7792 | } |
| 7793 | |
| 7794 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 7795 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7796 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7797 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7798 | { |
| 7799 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7800 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7801 | struct proc_dir_entry *entry; |
| 7802 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7803 | BUG_ON(ibm == NULL); |
| 7804 | |
| 7805 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 7806 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7807 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7808 | return 0; |
| 7809 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7810 | dbg_printk(TPACPI_DBG_INIT, |
| 7811 | "probing for %s\n", ibm->name); |
| 7812 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7813 | if (iibm->init) { |
| 7814 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7815 | if (ret > 0) |
| 7816 | return 0; /* probe failed */ |
| 7817 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7818 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7819 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7820 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7821 | } |
| 7822 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7823 | if (ibm->acpi) { |
| 7824 | if (ibm->acpi->hid) { |
| 7825 | ret = register_tpacpi_subdriver(ibm); |
| 7826 | if (ret) |
| 7827 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7828 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7829 | |
| 7830 | if (ibm->acpi->notify) { |
| 7831 | ret = setup_acpi_notify(ibm); |
| 7832 | if (ret == -ENODEV) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7833 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7834 | ibm->name); |
| 7835 | ret = 0; |
| 7836 | goto err_out; |
| 7837 | } |
| 7838 | if (ret < 0) |
| 7839 | goto err_out; |
| 7840 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7841 | } |
| 7842 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7843 | dbg_printk(TPACPI_DBG_INIT, |
| 7844 | "%s installed\n", ibm->name); |
| 7845 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7846 | if (ibm->read) { |
| 7847 | entry = create_proc_entry(ibm->name, |
| 7848 | S_IFREG | S_IRUGO | S_IWUSR, |
| 7849 | proc_dir); |
| 7850 | if (!entry) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7851 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7852 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7853 | ret = -ENODEV; |
| 7854 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7855 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7856 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7857 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7858 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7859 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7860 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7861 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7862 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7863 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 7864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7865 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7866 | |
| 7867 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7868 | dbg_printk(TPACPI_DBG_INIT, |
| 7869 | "%s: at error exit path with result %d\n", |
| 7870 | ibm->name, ret); |
| 7871 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7872 | ibm_exit(ibm); |
| 7873 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7874 | } |
| 7875 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7876 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7877 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7878 | static bool __pure __init tpacpi_is_fw_digit(const char c) |
| 7879 | { |
| 7880 | return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); |
| 7881 | } |
| 7882 | |
| 7883 | /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */ |
| 7884 | static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, |
| 7885 | const char t) |
| 7886 | { |
| 7887 | return s && strlen(s) >= 8 && |
| 7888 | tpacpi_is_fw_digit(s[0]) && |
| 7889 | tpacpi_is_fw_digit(s[1]) && |
| 7890 | s[2] == t && s[3] == 'T' && |
| 7891 | tpacpi_is_fw_digit(s[4]) && |
| 7892 | tpacpi_is_fw_digit(s[5]) && |
| 7893 | s[6] == 'W' && s[7] == 'W'; |
| 7894 | } |
| 7895 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7896 | /* returns 0 - probe ok, or < 0 - probe error. |
| 7897 | * Probe ok doesn't mean thinkpad found. |
| 7898 | * On error, kfree() cleanup on tp->* is not performed, caller must do it */ |
| 7899 | static int __must_check __init get_thinkpad_model_data( |
| 7900 | struct thinkpad_id_data *tp) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7901 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 7902 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7903 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7904 | char const *s; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7905 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7906 | if (!tp) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7907 | return -EINVAL; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7908 | |
| 7909 | memset(tp, 0, sizeof(*tp)); |
| 7910 | |
| 7911 | if (dmi_name_in_vendors("IBM")) |
| 7912 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 7913 | else if (dmi_name_in_vendors("LENOVO")) |
| 7914 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 7915 | else |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7916 | return 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7917 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7918 | s = dmi_get_system_info(DMI_BIOS_VERSION); |
| 7919 | tp->bios_version_str = kstrdup(s, GFP_KERNEL); |
| 7920 | if (s && !tp->bios_version_str) |
| 7921 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7922 | |
| 7923 | /* Really ancient ThinkPad 240X will fail this, which is fine */ |
| 7924 | 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] | 7925 | return 0; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7926 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7927 | tp->bios_model = tp->bios_version_str[0] |
| 7928 | | (tp->bios_version_str[1] << 8); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7929 | tp->bios_release = (tp->bios_version_str[4] << 8) |
| 7930 | | tp->bios_version_str[5]; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7931 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7932 | /* |
| 7933 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 7934 | * X32 or newer, all Z series; Some models must have an |
| 7935 | * up-to-date BIOS or they will not be detected. |
| 7936 | * |
| 7937 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 7938 | */ |
| 7939 | 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] | 7940 | if (sscanf(dev->name, |
| 7941 | "IBM ThinkPad Embedded Controller -[%17c", |
| 7942 | ec_fw_string) == 1) { |
| 7943 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 7944 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7945 | |
| 7946 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7947 | if (!tp->ec_version_str) |
| 7948 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7949 | |
| 7950 | if (tpacpi_is_valid_fw_id(ec_fw_string, 'H')) { |
| 7951 | tp->ec_model = ec_fw_string[0] |
| 7952 | | (ec_fw_string[1] << 8); |
| 7953 | tp->ec_release = (ec_fw_string[4] << 8) |
| 7954 | | ec_fw_string[5]; |
| 7955 | } else { |
| 7956 | printk(TPACPI_NOTICE |
| 7957 | "ThinkPad firmware release %s " |
| 7958 | "doesn't match the known patterns\n", |
| 7959 | ec_fw_string); |
| 7960 | printk(TPACPI_NOTICE |
| 7961 | "please report this to %s\n", |
| 7962 | TPACPI_MAIL); |
| 7963 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7964 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7965 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7966 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7967 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7968 | s = dmi_get_system_info(DMI_PRODUCT_VERSION); |
| 7969 | if (s && !strnicmp(s, "ThinkPad", 8)) { |
| 7970 | tp->model_str = kstrdup(s, GFP_KERNEL); |
| 7971 | if (!tp->model_str) |
| 7972 | return -ENOMEM; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7973 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 7974 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7975 | s = dmi_get_system_info(DMI_PRODUCT_NAME); |
| 7976 | tp->nummodel_str = kstrdup(s, GFP_KERNEL); |
| 7977 | if (s && !tp->nummodel_str) |
| 7978 | return -ENOMEM; |
| 7979 | |
| 7980 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7981 | } |
| 7982 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7983 | static int __init probe_for_thinkpad(void) |
| 7984 | { |
| 7985 | int is_thinkpad; |
| 7986 | |
| 7987 | if (acpi_disabled) |
| 7988 | return -ENODEV; |
| 7989 | |
| 7990 | /* |
| 7991 | * 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] | 7992 | * 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] | 7993 | */ |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 7994 | is_thinkpad = (thinkpad_id.model_str != NULL) || |
| 7995 | (thinkpad_id.ec_model != 0) || |
| 7996 | tpacpi_is_fw_known(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7997 | |
| 7998 | /* ec is required because many other handles are relative to it */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7999 | TPACPI_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8000 | if (!ec_handle) { |
| 8001 | if (is_thinkpad) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8002 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8003 | "Not yet supported ThinkPad detected!\n"); |
| 8004 | return -ENODEV; |
| 8005 | } |
| 8006 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 8007 | if (!is_thinkpad && !force_load) |
| 8008 | return -ENODEV; |
| 8009 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8010 | return 0; |
| 8011 | } |
| 8012 | |
| 8013 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8014 | /* Module init, exit, parameters */ |
| 8015 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8016 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 8017 | { |
| 8018 | .init = thinkpad_acpi_driver_init, |
| 8019 | .data = &thinkpad_acpi_driver_data, |
| 8020 | }, |
| 8021 | { |
| 8022 | .init = hotkey_init, |
| 8023 | .data = &hotkey_driver_data, |
| 8024 | }, |
| 8025 | { |
| 8026 | .init = bluetooth_init, |
| 8027 | .data = &bluetooth_driver_data, |
| 8028 | }, |
| 8029 | { |
| 8030 | .init = wan_init, |
| 8031 | .data = &wan_driver_data, |
| 8032 | }, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8033 | { |
| 8034 | .init = uwb_init, |
| 8035 | .data = &uwb_driver_data, |
| 8036 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 8037 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8038 | { |
| 8039 | .init = video_init, |
| 8040 | .data = &video_driver_data, |
| 8041 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 8042 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8043 | { |
| 8044 | .init = light_init, |
| 8045 | .data = &light_driver_data, |
| 8046 | }, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8047 | { |
| 8048 | .init = cmos_init, |
| 8049 | .data = &cmos_driver_data, |
| 8050 | }, |
| 8051 | { |
| 8052 | .init = led_init, |
| 8053 | .data = &led_driver_data, |
| 8054 | }, |
| 8055 | { |
| 8056 | .init = beep_init, |
| 8057 | .data = &beep_driver_data, |
| 8058 | }, |
| 8059 | { |
| 8060 | .init = thermal_init, |
| 8061 | .data = &thermal_driver_data, |
| 8062 | }, |
| 8063 | { |
| 8064 | .data = &ecdump_driver_data, |
| 8065 | }, |
| 8066 | { |
| 8067 | .init = brightness_init, |
| 8068 | .data = &brightness_driver_data, |
| 8069 | }, |
| 8070 | { |
| 8071 | .data = &volume_driver_data, |
| 8072 | }, |
| 8073 | { |
| 8074 | .init = fan_init, |
| 8075 | .data = &fan_driver_data, |
| 8076 | }, |
| 8077 | }; |
| 8078 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8079 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 8080 | { |
| 8081 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8082 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8083 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 8084 | if (!kp || !kp->name || !val) |
| 8085 | return -EINVAL; |
| 8086 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8087 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 8088 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 8089 | WARN_ON(ibm == NULL); |
| 8090 | |
| 8091 | if (!ibm || !ibm->name) |
| 8092 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8093 | |
| 8094 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 8095 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8096 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8097 | strcpy(ibms_init[i].param, val); |
| 8098 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8099 | return 0; |
| 8100 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8101 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8102 | |
| 8103 | return -EINVAL; |
| 8104 | } |
| 8105 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8106 | module_param(experimental, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8107 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8108 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8109 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 8110 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8111 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 8112 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 8113 | module_param(force_load, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8114 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8115 | "Attempts to load the driver even on a " |
| 8116 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 8117 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 8118 | module_param_named(fan_control, fan_control_allowed, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8119 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8120 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8121 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 8122 | module_param_named(brightness_mode, brightness_mode, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8123 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8124 | "Selects brightness control strategy: " |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 8125 | "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 8126 | |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 8127 | module_param(brightness_enable, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8128 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8129 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 8130 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8131 | module_param(hotkey_report_mode, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8132 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8133 | "used for backwards compatibility with userspace, " |
| 8134 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8135 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8136 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8137 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 8138 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8139 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8140 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8141 | TPACPI_PARAM(hotkey); |
| 8142 | TPACPI_PARAM(bluetooth); |
| 8143 | TPACPI_PARAM(video); |
| 8144 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8145 | TPACPI_PARAM(cmos); |
| 8146 | TPACPI_PARAM(led); |
| 8147 | TPACPI_PARAM(beep); |
| 8148 | TPACPI_PARAM(ecdump); |
| 8149 | TPACPI_PARAM(brightness); |
| 8150 | TPACPI_PARAM(volume); |
| 8151 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8152 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8153 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 8154 | module_param(dbg_wlswemul, uint, 0); |
| 8155 | MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation"); |
| 8156 | module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0); |
| 8157 | MODULE_PARM_DESC(wlsw_state, |
| 8158 | "Initial state of the emulated WLSW switch"); |
| 8159 | |
| 8160 | module_param(dbg_bluetoothemul, uint, 0); |
| 8161 | MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation"); |
| 8162 | module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0); |
| 8163 | MODULE_PARM_DESC(bluetooth_state, |
| 8164 | "Initial state of the emulated bluetooth switch"); |
| 8165 | |
| 8166 | module_param(dbg_wwanemul, uint, 0); |
| 8167 | MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation"); |
| 8168 | module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0); |
| 8169 | MODULE_PARM_DESC(wwan_state, |
| 8170 | "Initial state of the emulated WWAN switch"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8171 | |
| 8172 | module_param(dbg_uwbemul, uint, 0); |
| 8173 | MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation"); |
| 8174 | module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0); |
| 8175 | MODULE_PARM_DESC(uwb_state, |
| 8176 | "Initial state of the emulated UWB switch"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8177 | #endif |
| 8178 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8179 | static void thinkpad_acpi_module_exit(void) |
| 8180 | { |
| 8181 | struct ibm_struct *ibm, *itmp; |
| 8182 | |
| 8183 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 8184 | |
| 8185 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 8186 | &tpacpi_all_drivers, |
| 8187 | all_drivers) { |
| 8188 | ibm_exit(ibm); |
| 8189 | } |
| 8190 | |
| 8191 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 8192 | |
| 8193 | if (tpacpi_inputdev) { |
| 8194 | if (tp_features.input_device_registered) |
| 8195 | input_unregister_device(tpacpi_inputdev); |
| 8196 | else |
| 8197 | input_free_device(tpacpi_inputdev); |
| 8198 | } |
| 8199 | |
| 8200 | if (tpacpi_hwmon) |
| 8201 | hwmon_device_unregister(tpacpi_hwmon); |
| 8202 | |
| 8203 | if (tp_features.sensors_pdev_attrs_registered) |
| 8204 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 8205 | &dev_attr_thinkpad_acpi_pdev_name); |
| 8206 | if (tpacpi_sensors_pdev) |
| 8207 | platform_device_unregister(tpacpi_sensors_pdev); |
| 8208 | if (tpacpi_pdev) |
| 8209 | platform_device_unregister(tpacpi_pdev); |
| 8210 | |
| 8211 | if (tp_features.sensors_pdrv_attrs_registered) |
| 8212 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 8213 | if (tp_features.platform_drv_attrs_registered) |
| 8214 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 8215 | |
| 8216 | if (tp_features.sensors_pdrv_registered) |
| 8217 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 8218 | |
| 8219 | if (tp_features.platform_drv_registered) |
| 8220 | platform_driver_unregister(&tpacpi_pdriver); |
| 8221 | |
| 8222 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8223 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8224 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8225 | if (tpacpi_wq) |
| 8226 | destroy_workqueue(tpacpi_wq); |
| 8227 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8228 | kfree(thinkpad_id.bios_version_str); |
| 8229 | kfree(thinkpad_id.ec_version_str); |
| 8230 | kfree(thinkpad_id.model_str); |
| 8231 | } |
| 8232 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 8233 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8234 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8235 | { |
| 8236 | int ret, i; |
| 8237 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 8238 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 8239 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8240 | /* Parameter checking */ |
| 8241 | if (hotkey_report_mode > 2) |
| 8242 | return -EINVAL; |
| 8243 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8244 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8245 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8246 | ret = get_thinkpad_model_data(&thinkpad_id); |
| 8247 | if (ret) { |
| 8248 | printk(TPACPI_ERR |
| 8249 | "unable to get DMI data: %d\n", ret); |
| 8250 | thinkpad_acpi_module_exit(); |
| 8251 | return ret; |
| 8252 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8253 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8254 | if (ret) { |
| 8255 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8256 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8258 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8259 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8260 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8261 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 8262 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8263 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8264 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
| 8265 | if (!tpacpi_wq) { |
| 8266 | thinkpad_acpi_module_exit(); |
| 8267 | return -ENOMEM; |
| 8268 | } |
| 8269 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8270 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8271 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8272 | printk(TPACPI_ERR |
| 8273 | "unable to create proc dir " TPACPI_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8274 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8275 | return -ENODEV; |
| 8276 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8277 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8278 | ret = platform_driver_register(&tpacpi_pdriver); |
| 8279 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8280 | printk(TPACPI_ERR |
| 8281 | "unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8282 | thinkpad_acpi_module_exit(); |
| 8283 | return ret; |
| 8284 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 8285 | tp_features.platform_drv_registered = 1; |
| 8286 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8287 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 8288 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8289 | printk(TPACPI_ERR |
| 8290 | "unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8291 | thinkpad_acpi_module_exit(); |
| 8292 | return ret; |
| 8293 | } |
| 8294 | tp_features.sensors_pdrv_registered = 1; |
| 8295 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8296 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8297 | if (!ret) { |
| 8298 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8299 | ret = tpacpi_create_driver_attributes( |
| 8300 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8301 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8302 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8303 | printk(TPACPI_ERR |
| 8304 | "unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8305 | thinkpad_acpi_module_exit(); |
| 8306 | return ret; |
| 8307 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8308 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8309 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8310 | |
| 8311 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8312 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8313 | NULL, 0); |
| 8314 | if (IS_ERR(tpacpi_pdev)) { |
| 8315 | ret = PTR_ERR(tpacpi_pdev); |
| 8316 | tpacpi_pdev = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8317 | printk(TPACPI_ERR "unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8318 | thinkpad_acpi_module_exit(); |
| 8319 | return ret; |
| 8320 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8321 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8322 | TPACPI_HWMON_DRVR_NAME, |
| 8323 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8324 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 8325 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 8326 | tpacpi_sensors_pdev = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8327 | printk(TPACPI_ERR |
| 8328 | "unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8329 | thinkpad_acpi_module_exit(); |
| 8330 | return ret; |
| 8331 | } |
| 8332 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 8333 | &dev_attr_thinkpad_acpi_pdev_name); |
| 8334 | if (ret) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8335 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8336 | "unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8337 | thinkpad_acpi_module_exit(); |
| 8338 | return ret; |
| 8339 | } |
| 8340 | tp_features.sensors_pdev_attrs_registered = 1; |
| 8341 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8342 | if (IS_ERR(tpacpi_hwmon)) { |
| 8343 | ret = PTR_ERR(tpacpi_hwmon); |
| 8344 | tpacpi_hwmon = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8345 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8346 | thinkpad_acpi_module_exit(); |
| 8347 | return ret; |
| 8348 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 8349 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8350 | tpacpi_inputdev = input_allocate_device(); |
| 8351 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8352 | printk(TPACPI_ERR "unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8353 | thinkpad_acpi_module_exit(); |
| 8354 | return -ENOMEM; |
| 8355 | } else { |
| 8356 | /* Prepare input device, but don't register */ |
| 8357 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8358 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8359 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 8360 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
| 8361 | thinkpad_id.vendor : |
| 8362 | PCI_VENDOR_ID_IBM; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8363 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 8364 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
| 8365 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8366 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 8367 | ret = ibm_init(&ibms_init[i]); |
| 8368 | if (ret >= 0 && *ibms_init[i].param) |
| 8369 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8370 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8371 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8372 | return ret; |
| 8373 | } |
| 8374 | } |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8375 | ret = input_register_device(tpacpi_inputdev); |
| 8376 | if (ret < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8377 | printk(TPACPI_ERR "unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8378 | thinkpad_acpi_module_exit(); |
| 8379 | return ret; |
| 8380 | } else { |
| 8381 | tp_features.input_device_registered = 1; |
| 8382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8383 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 8384 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8385 | return 0; |
| 8386 | } |
| 8387 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 8388 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 8389 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8390 | /* |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 8391 | * This will autoload the driver in almost every ThinkPad |
| 8392 | * in widespread use. |
| 8393 | * |
| 8394 | * Only _VERY_ old models, like the 240, 240x and 570 lack |
| 8395 | * the HKEY event interface. |
| 8396 | */ |
| 8397 | MODULE_DEVICE_TABLE(acpi, ibm_htk_device_ids); |
| 8398 | |
| 8399 | /* |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8400 | * DMI matching for module autoloading |
| 8401 | * |
| 8402 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 8403 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 8404 | * |
| 8405 | * Only models listed in thinkwiki will be supported, so add yours |
| 8406 | * if it is not there yet. |
| 8407 | */ |
| 8408 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
Mathieu Chouquet-Stringer | b36a50f | 2009-03-14 16:35:26 +0100 | [diff] [blame] | 8409 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*") |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8410 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8411 | /* Ancient thinkpad BIOSes have to be identified by |
| 8412 | * BIOS type or model number, and there are far less |
| 8413 | * BIOS types than model numbers... */ |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 8414 | IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8415 | |
Henrique de Moraes Holschuh | f68f53a | 2009-04-14 02:44:12 +0000 | [diff] [blame] | 8416 | MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>"); |
| 8417 | MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8418 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 8419 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8420 | MODULE_LICENSE("GPL"); |
| 8421 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8422 | module_init(thinkpad_acpi_module_init); |
| 8423 | module_exit(thinkpad_acpi_module_exit); |