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 | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 25 | #define TPACPI_SYSFS_VERSION 0x020600 |
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, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1683 | __eid, __ev1, __ev2) \ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1684 | { .vendor = (__v), \ |
| 1685 | .bios = TPID(__bid1, __bid2), \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1686 | .ec = __eid, \ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 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 | |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1693 | /* Outdated IBM BIOSes often lack the EC id string */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1694 | #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1695 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1696 | __bv1, __bv2, TPID(__id1, __id2), \ |
| 1697 | __ev1, __ev2), \ |
| 1698 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
| 1699 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ |
| 1700 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1701 | |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1702 | /* Outdated IBM BIOSes often lack the EC id string */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1703 | #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \ |
| 1704 | __eid1, __eid2, __ev1, __ev2) \ |
| 1705 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1706 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
| 1707 | __ev1, __ev2), \ |
| 1708 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
| 1709 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ |
| 1710 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1711 | |
| 1712 | #define TPV_QL0(__id1, __id2, __bv1, __bv2) \ |
| 1713 | TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2) |
| 1714 | |
| 1715 | #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1716 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1717 | __bv1, __bv2, TPID(__id1, __id2), \ |
| 1718 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1719 | |
| 1720 | #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \ |
| 1721 | __eid1, __eid2, __ev1, __ev2) \ |
| 1722 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1723 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
| 1724 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1725 | |
| 1726 | static const struct tpacpi_quirk tpacpi_bios_version_qtable[] __initconst = { |
| 1727 | /* Numeric models ------------------ */ |
| 1728 | /* FW MODEL BIOS VERS */ |
| 1729 | TPV_QI0('I', 'M', '6', '5'), /* 570 */ |
| 1730 | TPV_QI0('I', 'U', '2', '6'), /* 570E */ |
| 1731 | TPV_QI0('I', 'B', '5', '4'), /* 600 */ |
| 1732 | TPV_QI0('I', 'H', '4', '7'), /* 600E */ |
| 1733 | TPV_QI0('I', 'N', '3', '6'), /* 600E */ |
| 1734 | TPV_QI0('I', 'T', '5', '5'), /* 600X */ |
| 1735 | TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */ |
| 1736 | TPV_QI0('I', 'I', '4', '2'), /* 770X */ |
| 1737 | TPV_QI0('I', 'O', '2', '3'), /* 770Z */ |
| 1738 | |
| 1739 | /* A-series ------------------------- */ |
| 1740 | /* FW MODEL BIOS VERS EC VERS */ |
| 1741 | TPV_QI0('I', 'W', '5', '9'), /* A20m */ |
| 1742 | TPV_QI0('I', 'V', '6', '9'), /* A20p */ |
| 1743 | TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */ |
| 1744 | TPV_QI0('K', 'U', '3', '6'), /* A21e */ |
| 1745 | TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */ |
| 1746 | TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */ |
| 1747 | TPV_QI0('1', 'B', '1', '7'), /* A22e */ |
| 1748 | TPV_QI0('1', '3', '2', '0'), /* A22m */ |
| 1749 | TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */ |
| 1750 | TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */ |
| 1751 | TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */ |
| 1752 | |
| 1753 | /* G-series ------------------------- */ |
| 1754 | /* FW MODEL BIOS VERS */ |
| 1755 | TPV_QI0('1', 'T', 'A', '6'), /* G40 */ |
| 1756 | TPV_QI0('1', 'X', '5', '7'), /* G41 */ |
| 1757 | |
| 1758 | /* R-series, T-series --------------- */ |
| 1759 | /* FW MODEL BIOS VERS EC VERS */ |
| 1760 | TPV_QI0('1', 'C', 'F', '0'), /* R30 */ |
| 1761 | TPV_QI0('1', 'F', 'F', '1'), /* R31 */ |
| 1762 | TPV_QI0('1', 'M', '9', '7'), /* R32 */ |
| 1763 | TPV_QI0('1', 'O', '6', '1'), /* R40 */ |
| 1764 | TPV_QI0('1', 'P', '6', '5'), /* R40 */ |
| 1765 | TPV_QI0('1', 'S', '7', '0'), /* R40e */ |
| 1766 | TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51, |
| 1767 | T40/p, T41/p, T42/p (1) */ |
| 1768 | TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */ |
| 1769 | TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */ |
| 1770 | TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */ |
| 1771 | TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */ |
| 1772 | |
| 1773 | TPV_QI0('I', 'Y', '6', '1'), /* T20 */ |
| 1774 | TPV_QI0('K', 'Z', '3', '4'), /* T21 */ |
| 1775 | TPV_QI0('1', '6', '3', '2'), /* T22 */ |
| 1776 | TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */ |
| 1777 | TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */ |
| 1778 | TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */ |
| 1779 | |
| 1780 | TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */ |
| 1781 | TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */ |
Henrique de Moraes Holschuh | 90765c6 | 2009-12-09 01:36:23 +0000 | [diff] [blame] | 1782 | TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1783 | |
| 1784 | /* BIOS FW BIOS VERS EC FW EC VERS */ |
| 1785 | TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */ |
| 1786 | TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */ |
| 1787 | |
| 1788 | /* X-series ------------------------- */ |
| 1789 | /* FW MODEL BIOS VERS EC VERS */ |
| 1790 | TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */ |
| 1791 | TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */ |
| 1792 | TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */ |
| 1793 | TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */ |
| 1794 | TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */ |
| 1795 | TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */ |
| 1796 | TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */ |
| 1797 | |
Henrique de Moraes Holschuh | 90765c6 | 2009-12-09 01:36:23 +0000 | [diff] [blame] | 1798 | TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */ |
| 1799 | TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1800 | |
| 1801 | /* (0) - older versions lack DMI EC fw string and functionality */ |
| 1802 | /* (1) - older versions known to lack functionality */ |
| 1803 | }; |
| 1804 | |
| 1805 | #undef TPV_QL1 |
| 1806 | #undef TPV_QL0 |
| 1807 | #undef TPV_QI2 |
| 1808 | #undef TPV_QI1 |
| 1809 | #undef TPV_QI0 |
| 1810 | #undef TPV_Q_X |
| 1811 | #undef TPV_Q |
| 1812 | |
| 1813 | static void __init tpacpi_check_outdated_fw(void) |
| 1814 | { |
| 1815 | unsigned long fwvers; |
| 1816 | u16 ec_version, bios_version; |
| 1817 | |
| 1818 | fwvers = tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1819 | ARRAY_SIZE(tpacpi_bios_version_qtable)); |
| 1820 | |
| 1821 | if (!fwvers) |
| 1822 | return; |
| 1823 | |
| 1824 | bios_version = fwvers & 0xffffU; |
| 1825 | ec_version = (fwvers >> 16) & 0xffffU; |
| 1826 | |
| 1827 | /* note that unknown versions are set to 0x0000 and we use that */ |
| 1828 | if ((bios_version > thinkpad_id.bios_release) || |
| 1829 | (ec_version > thinkpad_id.ec_release && |
| 1830 | ec_version != TPACPI_MATCH_ANY)) { |
| 1831 | /* |
| 1832 | * The changelogs would let us track down the exact |
| 1833 | * reason, but it is just too much of a pain to track |
| 1834 | * it. We only list BIOSes that are either really |
| 1835 | * broken, or really stable to begin with, so it is |
| 1836 | * best if the user upgrades the firmware anyway. |
| 1837 | */ |
| 1838 | printk(TPACPI_WARN |
| 1839 | "WARNING: Outdated ThinkPad BIOS/EC firmware\n"); |
| 1840 | printk(TPACPI_WARN |
| 1841 | "WARNING: This firmware may be missing critical bug " |
| 1842 | "fixes and/or important features\n"); |
| 1843 | } |
| 1844 | } |
| 1845 | |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1846 | static bool __init tpacpi_is_fw_known(void) |
| 1847 | { |
| 1848 | return tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1849 | ARRAY_SIZE(tpacpi_bios_version_qtable)) != 0; |
| 1850 | } |
| 1851 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1852 | /**************************************************************************** |
| 1853 | **************************************************************************** |
| 1854 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1855 | * Subdrivers |
| 1856 | * |
| 1857 | **************************************************************************** |
| 1858 | ****************************************************************************/ |
| 1859 | |
| 1860 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 1861 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1862 | */ |
| 1863 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1864 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1866 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 1867 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1869 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1870 | (thinkpad_id.bios_version_str) ? |
| 1871 | thinkpad_id.bios_version_str : "unknown", |
| 1872 | (thinkpad_id.ec_version_str) ? |
| 1873 | thinkpad_id.ec_version_str : "unknown"); |
| 1874 | |
| 1875 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1876 | printk(TPACPI_INFO "%s %s, model %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1877 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 1878 | "IBM" : ((thinkpad_id.vendor == |
| 1879 | PCI_VENDOR_ID_LENOVO) ? |
| 1880 | "Lenovo" : "Unknown vendor"), |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1881 | thinkpad_id.model_str, |
| 1882 | (thinkpad_id.nummodel_str) ? |
| 1883 | thinkpad_id.nummodel_str : "unknown"); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 1884 | |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1885 | tpacpi_check_outdated_fw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | return 0; |
| 1887 | } |
| 1888 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1889 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | { |
| 1891 | int len = 0; |
| 1892 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1893 | len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); |
| 1894 | len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | |
| 1896 | return len; |
| 1897 | } |
| 1898 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1899 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1900 | .name = "driver", |
| 1901 | .read = thinkpad_acpi_driver_read, |
| 1902 | }; |
| 1903 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1904 | /************************************************************************* |
| 1905 | * Hotkey subdriver |
| 1906 | */ |
| 1907 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1908 | /* |
| 1909 | * ThinkPad firmware event model |
| 1910 | * |
| 1911 | * The ThinkPad firmware has two main event interfaces: normal ACPI |
| 1912 | * notifications (which follow the ACPI standard), and a private event |
| 1913 | * interface. |
| 1914 | * |
| 1915 | * The private event interface also issues events for the hotkeys. As |
| 1916 | * the driver gained features, the event handling code ended up being |
| 1917 | * built around the hotkey subdriver. This will need to be refactored |
| 1918 | * to a more formal event API eventually. |
| 1919 | * |
| 1920 | * Some "hotkeys" are actually supposed to be used as event reports, |
| 1921 | * such as "brightness has changed", "volume has changed", depending on |
| 1922 | * the ThinkPad model and how the firmware is operating. |
| 1923 | * |
| 1924 | * Unlike other classes, hotkey-class events have mask/unmask control on |
| 1925 | * non-ancient firmware. However, how it behaves changes a lot with the |
| 1926 | * firmware model and version. |
| 1927 | */ |
| 1928 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1929 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1930 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1931 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1932 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1933 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1934 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1935 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1936 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1937 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1938 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1939 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1940 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1941 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1942 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1943 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1944 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1945 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1946 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1947 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1948 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1949 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1950 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1951 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1952 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1953 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1954 | }; |
| 1955 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1956 | enum { /* Keys/events available through NVRAM polling */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1957 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1958 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1959 | }; |
| 1960 | |
| 1961 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1962 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1963 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1964 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1965 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1966 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1967 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1968 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1969 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1970 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1971 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1972 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1973 | }; |
| 1974 | |
| 1975 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1976 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1977 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1978 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1979 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1980 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1981 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1982 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1983 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1984 | TP_ACPI_HKEY_MUTE_MASK, |
| 1985 | }; |
| 1986 | |
| 1987 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1988 | struct tp_nvram_state { |
| 1989 | u16 thinkpad_toggle:1; |
| 1990 | u16 zoom_toggle:1; |
| 1991 | u16 display_toggle:1; |
| 1992 | u16 thinklight_toggle:1; |
| 1993 | u16 hibernate_toggle:1; |
| 1994 | u16 displayexp_toggle:1; |
| 1995 | u16 display_state:1; |
| 1996 | u16 brightness_toggle:1; |
| 1997 | u16 volume_toggle:1; |
| 1998 | u16 mute:1; |
| 1999 | |
| 2000 | u8 brightness_level; |
| 2001 | u8 volume_level; |
| 2002 | }; |
| 2003 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2004 | /* kthread for the hotkey poller */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2005 | static struct task_struct *tpacpi_hotkey_task; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2006 | |
| 2007 | /* 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] | 2008 | static struct mutex hotkey_thread_mutex; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2009 | |
| 2010 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2011 | * Acquire mutex to write poller control variables as an |
| 2012 | * atomic block. |
| 2013 | * |
| 2014 | * Increment hotkey_config_change when changing them if you |
| 2015 | * want the kthread to forget old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2016 | * |
| 2017 | * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 2018 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2019 | static struct mutex hotkey_thread_data_mutex; |
| 2020 | static unsigned int hotkey_config_change; |
| 2021 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2022 | /* |
| 2023 | * hotkey poller control variables |
| 2024 | * |
| 2025 | * 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] | 2026 | * |
| 2027 | * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 2028 | * should be used only when the changes need to be taken as |
| 2029 | * a block, OR when one needs to force the kthread to forget |
| 2030 | * old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2031 | */ |
| 2032 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 2033 | static unsigned int hotkey_poll_freq = 10; /* Hz */ |
| 2034 | |
| 2035 | #define HOTKEY_CONFIG_CRITICAL_START \ |
| 2036 | do { \ |
| 2037 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 2038 | hotkey_config_change++; \ |
| 2039 | } while (0); |
| 2040 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 2041 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2042 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2043 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2044 | |
| 2045 | #define hotkey_source_mask 0U |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2046 | #define HOTKEY_CONFIG_CRITICAL_START |
| 2047 | #define HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2048 | |
| 2049 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2050 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2051 | static struct mutex hotkey_mutex; |
| 2052 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2053 | static enum { /* Reasons for waking up */ |
| 2054 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 2055 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 2056 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 2057 | } hotkey_wakeup_reason; |
| 2058 | |
| 2059 | static int hotkey_autosleep_ack; |
| 2060 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2061 | static u32 hotkey_orig_mask; /* events the BIOS had enabled */ |
| 2062 | static u32 hotkey_all_mask; /* all events supported in fw */ |
| 2063 | static u32 hotkey_reserved_mask; /* events better left disabled */ |
| 2064 | static u32 hotkey_driver_mask; /* events needed by the driver */ |
| 2065 | static u32 hotkey_user_mask; /* events visible to userspace */ |
| 2066 | static u32 hotkey_acpi_mask; /* events enabled in firmware */ |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2067 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 2068 | static unsigned int hotkey_report_mode; |
| 2069 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2070 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2071 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 2072 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2073 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2074 | static void tpacpi_driver_event(const unsigned int hkey_event); |
| 2075 | static void hotkey_driver_event(const unsigned int scancode); |
| 2076 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2077 | /* HKEY.MHKG() return bits */ |
| 2078 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 2079 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2080 | static int hotkey_get_wlsw(void) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2081 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2082 | int status; |
| 2083 | |
| 2084 | if (!tp_features.hotkey_wlsw) |
| 2085 | return -ENODEV; |
| 2086 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2087 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2088 | if (dbg_wlswemul) |
| 2089 | return (tpacpi_wlsw_emulstate) ? |
| 2090 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2091 | #endif |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2092 | |
| 2093 | if (!acpi_evalf(hkey_handle, &status, "WLSW", "d")) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2094 | return -EIO; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2095 | |
| 2096 | return (status) ? TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2097 | } |
| 2098 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2099 | static int hotkey_get_tablet_mode(int *status) |
| 2100 | { |
| 2101 | int s; |
| 2102 | |
| 2103 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 2104 | return -EIO; |
| 2105 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 2106 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 2107 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2108 | } |
| 2109 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2110 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2111 | * Reads current event mask from firmware, and updates |
| 2112 | * hotkey_acpi_mask accordingly. Also resets any bits |
| 2113 | * from hotkey_user_mask that are unavailable to be |
| 2114 | * delivered (shadow requirement of the userspace ABI). |
| 2115 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2116 | * Call with hotkey_mutex held |
| 2117 | */ |
| 2118 | static int hotkey_mask_get(void) |
| 2119 | { |
| 2120 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2121 | u32 m = 0; |
| 2122 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2123 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2124 | return -EIO; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2125 | |
| 2126 | hotkey_acpi_mask = m; |
| 2127 | } else { |
| 2128 | /* no mask support doesn't mean no event support... */ |
| 2129 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2130 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2131 | |
| 2132 | /* sync userspace-visible mask */ |
| 2133 | hotkey_user_mask &= (hotkey_acpi_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2134 | |
| 2135 | return 0; |
| 2136 | } |
| 2137 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2138 | void static hotkey_mask_warn_incomplete_mask(void) |
| 2139 | { |
| 2140 | /* log only what the user can fix... */ |
| 2141 | const u32 wantedmask = hotkey_driver_mask & |
| 2142 | ~(hotkey_acpi_mask | hotkey_source_mask) & |
| 2143 | (hotkey_all_mask | TPACPI_HKEY_NVRAM_KNOWN_MASK); |
| 2144 | |
| 2145 | if (wantedmask) |
| 2146 | printk(TPACPI_NOTICE |
| 2147 | "required events 0x%08x not enabled!\n", |
| 2148 | wantedmask); |
| 2149 | } |
| 2150 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2151 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2152 | * Set the firmware mask when supported |
| 2153 | * |
| 2154 | * Also calls hotkey_mask_get to update hotkey_acpi_mask. |
| 2155 | * |
| 2156 | * NOTE: does not set bits in hotkey_user_mask, but may reset them. |
| 2157 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2158 | * Call with hotkey_mutex held |
| 2159 | */ |
| 2160 | static int hotkey_mask_set(u32 mask) |
| 2161 | { |
| 2162 | int i; |
| 2163 | int rc = 0; |
| 2164 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2165 | const u32 fwmask = mask & ~hotkey_source_mask; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 2166 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2167 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2168 | for (i = 0; i < 32; i++) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2169 | if (!acpi_evalf(hkey_handle, |
| 2170 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2171 | !!(mask & (1 << i)))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2172 | rc = -EIO; |
| 2173 | break; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2174 | } |
| 2175 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2176 | } |
| 2177 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2178 | /* |
| 2179 | * We *must* make an inconditional call to hotkey_mask_get to |
| 2180 | * refresh hotkey_acpi_mask and update hotkey_user_mask |
| 2181 | * |
| 2182 | * Take the opportunity to also log when we cannot _enable_ |
| 2183 | * a given event. |
| 2184 | */ |
| 2185 | if (!hotkey_mask_get() && !rc && (fwmask & ~hotkey_acpi_mask)) { |
| 2186 | printk(TPACPI_NOTICE |
| 2187 | "asked for hotkey mask 0x%08x, but " |
| 2188 | "firmware forced it to 0x%08x\n", |
| 2189 | fwmask, hotkey_acpi_mask); |
| 2190 | } |
| 2191 | |
Henrique de Moraes Holschuh | 6b30eb7 | 2009-12-09 01:36:25 +0000 | [diff] [blame] | 2192 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING) |
| 2193 | hotkey_mask_warn_incomplete_mask(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2194 | |
| 2195 | return rc; |
| 2196 | } |
| 2197 | |
| 2198 | /* |
| 2199 | * Sets hotkey_user_mask and tries to set the firmware mask |
| 2200 | * |
| 2201 | * Call with hotkey_mutex held |
| 2202 | */ |
| 2203 | static int hotkey_user_mask_set(const u32 mask) |
| 2204 | { |
| 2205 | int rc; |
| 2206 | |
| 2207 | /* Give people a chance to notice they are doing something that |
| 2208 | * is bound to go boom on their users sooner or later */ |
| 2209 | if (!tp_warned.hotkey_mask_ff && |
| 2210 | (mask == 0xffff || mask == 0xffffff || |
| 2211 | mask == 0xffffffff)) { |
| 2212 | tp_warned.hotkey_mask_ff = 1; |
| 2213 | printk(TPACPI_NOTICE |
| 2214 | "setting the hotkey mask to 0x%08x is likely " |
| 2215 | "not the best way to go about it\n", mask); |
| 2216 | printk(TPACPI_NOTICE |
| 2217 | "please consider using the driver defaults, " |
| 2218 | "and refer to up-to-date thinkpad-acpi " |
| 2219 | "documentation\n"); |
| 2220 | } |
| 2221 | |
| 2222 | /* Try to enable what the user asked for, plus whatever we need. |
| 2223 | * this syncs everything but won't enable bits in hotkey_user_mask */ |
| 2224 | rc = hotkey_mask_set((mask | hotkey_driver_mask) & ~hotkey_source_mask); |
| 2225 | |
| 2226 | /* Enable the available bits in hotkey_user_mask */ |
| 2227 | hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask); |
| 2228 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2229 | return rc; |
| 2230 | } |
| 2231 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2232 | /* |
| 2233 | * Sets the driver hotkey mask. |
| 2234 | * |
| 2235 | * Can be called even if the hotkey subdriver is inactive |
| 2236 | */ |
| 2237 | static int tpacpi_hotkey_driver_mask_set(const u32 mask) |
| 2238 | { |
| 2239 | int rc; |
| 2240 | |
| 2241 | /* Do the right thing if hotkey_init has not been called yet */ |
| 2242 | if (!tp_features.hotkey) { |
| 2243 | hotkey_driver_mask = mask; |
| 2244 | return 0; |
| 2245 | } |
| 2246 | |
| 2247 | mutex_lock(&hotkey_mutex); |
| 2248 | |
| 2249 | HOTKEY_CONFIG_CRITICAL_START |
| 2250 | hotkey_driver_mask = mask; |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2251 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2252 | hotkey_source_mask |= (mask & ~hotkey_all_mask); |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2253 | #endif |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2254 | HOTKEY_CONFIG_CRITICAL_END |
| 2255 | |
| 2256 | rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) & |
| 2257 | ~hotkey_source_mask); |
| 2258 | mutex_unlock(&hotkey_mutex); |
| 2259 | |
| 2260 | return rc; |
| 2261 | } |
| 2262 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2263 | static int hotkey_status_get(int *status) |
| 2264 | { |
| 2265 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 2266 | return -EIO; |
| 2267 | |
| 2268 | return 0; |
| 2269 | } |
| 2270 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2271 | static int hotkey_status_set(bool enable) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2272 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2273 | 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] | 2274 | return -EIO; |
| 2275 | |
| 2276 | return 0; |
| 2277 | } |
| 2278 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2279 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2280 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2281 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2282 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2283 | if (tp_features.hotkey_tablet && |
| 2284 | !hotkey_get_tablet_mode(&state)) { |
| 2285 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2286 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2287 | input_report_switch(tpacpi_inputdev, |
| 2288 | SW_TABLET_MODE, !!state); |
| 2289 | input_sync(tpacpi_inputdev); |
| 2290 | |
| 2291 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2292 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2293 | } |
| 2294 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2295 | /* Do NOT call without validating scancode first */ |
| 2296 | static void tpacpi_input_send_key(const unsigned int scancode) |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2297 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2298 | const unsigned int keycode = hotkey_keycode_map[scancode]; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2299 | |
| 2300 | if (keycode != KEY_RESERVED) { |
| 2301 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2302 | |
| 2303 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 2304 | if (keycode == KEY_UNKNOWN) |
| 2305 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 2306 | scancode); |
| 2307 | input_sync(tpacpi_inputdev); |
| 2308 | |
| 2309 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 2310 | if (keycode == KEY_UNKNOWN) |
| 2311 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 2312 | scancode); |
| 2313 | input_sync(tpacpi_inputdev); |
| 2314 | |
| 2315 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2316 | } |
| 2317 | } |
| 2318 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2319 | /* Do NOT call without validating scancode first */ |
| 2320 | static void tpacpi_input_send_key_masked(const unsigned int scancode) |
| 2321 | { |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2322 | hotkey_driver_event(scancode); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2323 | if (hotkey_user_mask & (1 << scancode)) |
| 2324 | tpacpi_input_send_key(scancode); |
| 2325 | } |
| 2326 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2327 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2328 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 2329 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2330 | /* Do NOT call without validating scancode first */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2331 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 2332 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2333 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2334 | if (hotkey_report_mode < 2) { |
| 2335 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 2336 | 0x80, TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2337 | } |
| 2338 | } |
| 2339 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2340 | 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] | 2341 | { |
| 2342 | u8 d; |
| 2343 | |
| 2344 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 2345 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 2346 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 2347 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 2348 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 2349 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 2350 | } |
| 2351 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 2352 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 2353 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 2354 | } |
| 2355 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 2356 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 2357 | n->displayexp_toggle = |
| 2358 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 2359 | } |
| 2360 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 2361 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 2362 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 2363 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 2364 | n->brightness_toggle = |
| 2365 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 2366 | } |
| 2367 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 2368 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 2369 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 2370 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 2371 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 2372 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 2373 | } |
| 2374 | } |
| 2375 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2376 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
| 2377 | struct tp_nvram_state *newn, |
| 2378 | const u32 event_mask) |
| 2379 | { |
| 2380 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2381 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2382 | do { \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2383 | if ((event_mask & (1 << __scancode)) && \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2384 | oldn->__member != newn->__member) \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2385 | tpacpi_hotkey_send_key(__scancode); \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2386 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2387 | |
| 2388 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2389 | do { \ |
| 2390 | if (event_mask & (1 << __scancode)) \ |
| 2391 | tpacpi_hotkey_send_key(__scancode); \ |
| 2392 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2393 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2394 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 2395 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 2396 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 2397 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 2398 | |
| 2399 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 2400 | |
| 2401 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 2402 | |
| 2403 | /* handle volume */ |
| 2404 | if (oldn->volume_toggle != newn->volume_toggle) { |
| 2405 | if (oldn->mute != newn->mute) { |
| 2406 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2407 | } |
| 2408 | if (oldn->volume_level > newn->volume_level) { |
| 2409 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2410 | } else if (oldn->volume_level < newn->volume_level) { |
| 2411 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2412 | } else if (oldn->mute == newn->mute) { |
| 2413 | /* repeated key presses that didn't change state */ |
| 2414 | if (newn->mute) { |
| 2415 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2416 | } else if (newn->volume_level != 0) { |
| 2417 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2418 | } else { |
| 2419 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2420 | } |
| 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | /* handle brightness */ |
| 2425 | if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 2426 | if (oldn->brightness_level < newn->brightness_level) { |
| 2427 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2428 | } else if (oldn->brightness_level > newn->brightness_level) { |
| 2429 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2430 | } else { |
| 2431 | /* repeated key presses that didn't change state */ |
| 2432 | if (newn->brightness_level != 0) { |
| 2433 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2434 | } else { |
| 2435 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2436 | } |
| 2437 | } |
| 2438 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2439 | |
| 2440 | #undef TPACPI_COMPARE_KEY |
| 2441 | #undef TPACPI_MAY_SEND_KEY |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2442 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2443 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2444 | /* |
| 2445 | * Polling driver |
| 2446 | * |
| 2447 | * We track all events in hotkey_source_mask all the time, since |
| 2448 | * most of them are edge-based. We only issue those requested by |
| 2449 | * hotkey_user_mask or hotkey_driver_mask, though. |
| 2450 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2451 | static int hotkey_kthread(void *data) |
| 2452 | { |
| 2453 | struct tp_nvram_state s[2]; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2454 | u32 poll_mask, event_mask; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2455 | unsigned int si, so; |
| 2456 | unsigned long t; |
| 2457 | unsigned int change_detector, must_reset; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2458 | unsigned int poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2459 | |
| 2460 | mutex_lock(&hotkey_thread_mutex); |
| 2461 | |
| 2462 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 2463 | goto exit; |
| 2464 | |
| 2465 | set_freezable(); |
| 2466 | |
| 2467 | so = 0; |
| 2468 | si = 1; |
| 2469 | t = 0; |
| 2470 | |
| 2471 | /* Initial state for compares */ |
| 2472 | mutex_lock(&hotkey_thread_data_mutex); |
| 2473 | change_detector = hotkey_config_change; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2474 | poll_mask = hotkey_source_mask; |
| 2475 | event_mask = hotkey_source_mask & |
| 2476 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2477 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2478 | mutex_unlock(&hotkey_thread_data_mutex); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2479 | hotkey_read_nvram(&s[so], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2480 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2481 | while (!kthread_should_stop()) { |
| 2482 | if (t == 0) { |
| 2483 | if (likely(poll_freq)) |
| 2484 | t = 1000/poll_freq; |
| 2485 | else |
| 2486 | t = 100; /* should never happen... */ |
| 2487 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2488 | t = msleep_interruptible(t); |
| 2489 | if (unlikely(kthread_should_stop())) |
| 2490 | break; |
| 2491 | must_reset = try_to_freeze(); |
| 2492 | if (t > 0 && !must_reset) |
| 2493 | continue; |
| 2494 | |
| 2495 | mutex_lock(&hotkey_thread_data_mutex); |
| 2496 | if (must_reset || hotkey_config_change != change_detector) { |
| 2497 | /* forget old state on thaw or config change */ |
| 2498 | si = so; |
| 2499 | t = 0; |
| 2500 | change_detector = hotkey_config_change; |
| 2501 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2502 | poll_mask = hotkey_source_mask; |
| 2503 | event_mask = hotkey_source_mask & |
| 2504 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2505 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2506 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2507 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2508 | if (likely(poll_mask)) { |
| 2509 | hotkey_read_nvram(&s[si], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2510 | if (likely(si != so)) { |
| 2511 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2512 | event_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2513 | } |
| 2514 | } |
| 2515 | |
| 2516 | so = si; |
| 2517 | si ^= 1; |
| 2518 | } |
| 2519 | |
| 2520 | exit: |
| 2521 | mutex_unlock(&hotkey_thread_mutex); |
| 2522 | return 0; |
| 2523 | } |
| 2524 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2525 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2526 | static void hotkey_poll_stop_sync(void) |
| 2527 | { |
| 2528 | if (tpacpi_hotkey_task) { |
| 2529 | if (frozen(tpacpi_hotkey_task) || |
| 2530 | freezing(tpacpi_hotkey_task)) |
| 2531 | thaw_process(tpacpi_hotkey_task); |
| 2532 | |
| 2533 | kthread_stop(tpacpi_hotkey_task); |
| 2534 | tpacpi_hotkey_task = NULL; |
| 2535 | mutex_lock(&hotkey_thread_mutex); |
| 2536 | /* at this point, the thread did exit */ |
| 2537 | mutex_unlock(&hotkey_thread_mutex); |
| 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2542 | static void hotkey_poll_setup(bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2543 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2544 | const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask; |
| 2545 | 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] | 2546 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2547 | if (hotkey_poll_freq > 0 && |
| 2548 | (poll_driver_mask || |
| 2549 | (poll_user_mask && tpacpi_inputdev->users > 0))) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2550 | if (!tpacpi_hotkey_task) { |
| 2551 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 2552 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2553 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 2554 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2555 | printk(TPACPI_ERR |
| 2556 | "could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2557 | "for hotkey polling\n"); |
| 2558 | } |
| 2559 | } |
| 2560 | } else { |
| 2561 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2562 | if (may_warn && (poll_driver_mask || poll_user_mask) && |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2563 | hotkey_poll_freq == 0) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2564 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2565 | "hot keys 0x%08x and/or events 0x%08x " |
| 2566 | "require polling, which is currently " |
| 2567 | "disabled\n", |
| 2568 | poll_user_mask, poll_driver_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2569 | } |
| 2570 | } |
| 2571 | } |
| 2572 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2573 | static void hotkey_poll_setup_safe(bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2574 | { |
| 2575 | mutex_lock(&hotkey_mutex); |
| 2576 | hotkey_poll_setup(may_warn); |
| 2577 | mutex_unlock(&hotkey_mutex); |
| 2578 | } |
| 2579 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2580 | /* call with hotkey_mutex held */ |
| 2581 | static void hotkey_poll_set_freq(unsigned int freq) |
| 2582 | { |
| 2583 | if (!freq) |
| 2584 | hotkey_poll_stop_sync(); |
| 2585 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2586 | hotkey_poll_freq = freq; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2587 | } |
| 2588 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2589 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2590 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2591 | static void hotkey_poll_setup_safe(bool __unused) |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2592 | { |
| 2593 | } |
| 2594 | |
| 2595 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2596 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2597 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 2598 | { |
| 2599 | switch (tpacpi_lifecycle) { |
| 2600 | case TPACPI_LIFE_INIT: |
| 2601 | /* |
| 2602 | * hotkey_init will call hotkey_poll_setup_safe |
| 2603 | * at the appropriate moment |
| 2604 | */ |
| 2605 | return 0; |
| 2606 | case TPACPI_LIFE_EXITING: |
| 2607 | return -EBUSY; |
| 2608 | case TPACPI_LIFE_RUNNING: |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2609 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2610 | return 0; |
| 2611 | } |
| 2612 | |
| 2613 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 2614 | BUG(); |
| 2615 | return -EBUSY; |
| 2616 | } |
| 2617 | |
| 2618 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 2619 | { |
| 2620 | /* disable hotkey polling when possible */ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2621 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING && |
| 2622 | !(hotkey_source_mask & hotkey_driver_mask)) |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2623 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2624 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2625 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2626 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 2627 | static ssize_t hotkey_enable_show(struct device *dev, |
| 2628 | struct device_attribute *attr, |
| 2629 | char *buf) |
| 2630 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2631 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2632 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2633 | printk_deprecated_attribute("hotkey_enable", |
| 2634 | "Hotkey reporting is always enabled"); |
| 2635 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2636 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2637 | if (res) |
| 2638 | return res; |
| 2639 | |
| 2640 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 2641 | } |
| 2642 | |
| 2643 | static ssize_t hotkey_enable_store(struct device *dev, |
| 2644 | struct device_attribute *attr, |
| 2645 | const char *buf, size_t count) |
| 2646 | { |
| 2647 | unsigned long t; |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2648 | |
| 2649 | printk_deprecated_attribute("hotkey_enable", |
| 2650 | "Hotkeys can be disabled through hotkey_mask"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2651 | |
| 2652 | if (parse_strtoul(buf, 1, &t)) |
| 2653 | return -EINVAL; |
| 2654 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2655 | if (t == 0) |
| 2656 | return -EPERM; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2657 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2658 | return count; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2662 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2663 | hotkey_enable_show, hotkey_enable_store); |
| 2664 | |
| 2665 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 2666 | static ssize_t hotkey_mask_show(struct device *dev, |
| 2667 | struct device_attribute *attr, |
| 2668 | char *buf) |
| 2669 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2670 | 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] | 2671 | } |
| 2672 | |
| 2673 | static ssize_t hotkey_mask_store(struct device *dev, |
| 2674 | struct device_attribute *attr, |
| 2675 | const char *buf, size_t count) |
| 2676 | { |
| 2677 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2678 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2679 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2680 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2681 | return -EINVAL; |
| 2682 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2683 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2684 | return -ERESTARTSYS; |
| 2685 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2686 | res = hotkey_user_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2687 | |
| 2688 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2689 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2690 | #endif |
| 2691 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2692 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2693 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2694 | tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t); |
| 2695 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2696 | return (res) ? res : count; |
| 2697 | } |
| 2698 | |
| 2699 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2700 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2701 | hotkey_mask_show, hotkey_mask_store); |
| 2702 | |
| 2703 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 2704 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 2705 | struct device_attribute *attr, |
| 2706 | char *buf) |
| 2707 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2708 | return sprintf(buf, "0\n"); |
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_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2712 | __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] | 2713 | |
| 2714 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 2715 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 2716 | struct device_attribute *attr, |
| 2717 | char *buf) |
| 2718 | { |
Henrique de Moraes Holschuh | 06777be | 2009-09-12 15:22:15 -0300 | [diff] [blame] | 2719 | printk_deprecated_attribute("hotkey_bios_mask", |
| 2720 | "This attribute is useless."); |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2721 | 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] | 2722 | } |
| 2723 | |
| 2724 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2725 | __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] | 2726 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2727 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 2728 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 2729 | struct device_attribute *attr, |
| 2730 | char *buf) |
| 2731 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2732 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 2733 | hotkey_all_mask | hotkey_source_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_all_mask = |
| 2737 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 2738 | |
| 2739 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 2740 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 2741 | struct device_attribute *attr, |
| 2742 | char *buf) |
| 2743 | { |
| 2744 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2745 | (hotkey_all_mask | hotkey_source_mask) |
| 2746 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 2750 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 2751 | hotkey_recommended_mask_show, NULL); |
| 2752 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2753 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2754 | |
| 2755 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 2756 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 2757 | struct device_attribute *attr, |
| 2758 | char *buf) |
| 2759 | { |
| 2760 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 2761 | } |
| 2762 | |
| 2763 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 2764 | struct device_attribute *attr, |
| 2765 | const char *buf, size_t count) |
| 2766 | { |
| 2767 | unsigned long t; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2768 | u32 r_ev; |
| 2769 | int rc; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2770 | |
| 2771 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 2772 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 2773 | return -EINVAL; |
| 2774 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2775 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2776 | return -ERESTARTSYS; |
| 2777 | |
| 2778 | HOTKEY_CONFIG_CRITICAL_START |
| 2779 | hotkey_source_mask = t; |
| 2780 | HOTKEY_CONFIG_CRITICAL_END |
| 2781 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2782 | rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) & |
| 2783 | ~hotkey_source_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2784 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2785 | |
| 2786 | /* check if events needed by the driver got disabled */ |
| 2787 | r_ev = hotkey_driver_mask & ~(hotkey_acpi_mask & hotkey_all_mask) |
| 2788 | & ~hotkey_source_mask & TPACPI_HKEY_NVRAM_KNOWN_MASK; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2789 | |
| 2790 | mutex_unlock(&hotkey_mutex); |
| 2791 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2792 | if (rc < 0) |
| 2793 | printk(TPACPI_ERR "hotkey_source_mask: failed to update the" |
| 2794 | "firmware event mask!\n"); |
| 2795 | |
| 2796 | if (r_ev) |
| 2797 | printk(TPACPI_NOTICE "hotkey_source_mask: " |
| 2798 | "some important events were disabled: " |
| 2799 | "0x%04x\n", r_ev); |
| 2800 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2801 | tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); |
| 2802 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2803 | return (rc < 0) ? rc : count; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 2807 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 2808 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 2809 | |
| 2810 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 2811 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 2812 | struct device_attribute *attr, |
| 2813 | char *buf) |
| 2814 | { |
| 2815 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 2816 | } |
| 2817 | |
| 2818 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 2819 | struct device_attribute *attr, |
| 2820 | const char *buf, size_t count) |
| 2821 | { |
| 2822 | unsigned long t; |
| 2823 | |
| 2824 | if (parse_strtoul(buf, 25, &t)) |
| 2825 | return -EINVAL; |
| 2826 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2827 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2828 | return -ERESTARTSYS; |
| 2829 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2830 | hotkey_poll_set_freq(t); |
| 2831 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2832 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2833 | mutex_unlock(&hotkey_mutex); |
| 2834 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2835 | tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t); |
| 2836 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2837 | return count; |
| 2838 | } |
| 2839 | |
| 2840 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 2841 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 2842 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 2843 | |
| 2844 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2845 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2846 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2847 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 2848 | struct device_attribute *attr, |
| 2849 | char *buf) |
| 2850 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2851 | int res; |
| 2852 | res = hotkey_get_wlsw(); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2853 | if (res < 0) |
| 2854 | return res; |
| 2855 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2856 | /* Opportunistic update */ |
| 2857 | tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF)); |
| 2858 | |
| 2859 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2860 | (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 2864 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 2865 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2866 | static void hotkey_radio_sw_notify_change(void) |
| 2867 | { |
| 2868 | if (tp_features.hotkey_wlsw) |
| 2869 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2870 | "hotkey_radio_sw"); |
| 2871 | } |
| 2872 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2873 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 2874 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 2875 | struct device_attribute *attr, |
| 2876 | char *buf) |
| 2877 | { |
| 2878 | int res, s; |
| 2879 | res = hotkey_get_tablet_mode(&s); |
| 2880 | if (res < 0) |
| 2881 | return res; |
| 2882 | |
| 2883 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 2884 | } |
| 2885 | |
| 2886 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 2887 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 2888 | |
| 2889 | static void hotkey_tablet_mode_notify_change(void) |
| 2890 | { |
| 2891 | if (tp_features.hotkey_tablet) |
| 2892 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2893 | "hotkey_tablet_mode"); |
| 2894 | } |
| 2895 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2896 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 2897 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 2898 | struct device_attribute *attr, |
| 2899 | char *buf) |
| 2900 | { |
| 2901 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2902 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 2903 | } |
| 2904 | |
| 2905 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 2906 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 2907 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2908 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2909 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 2910 | struct device_attribute *attr, |
| 2911 | char *buf) |
| 2912 | { |
| 2913 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 2914 | } |
| 2915 | |
| 2916 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 2917 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 2918 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2919 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2920 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2921 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2922 | "wakeup_reason"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2926 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 2927 | struct device_attribute *attr, |
| 2928 | char *buf) |
| 2929 | { |
| 2930 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 2931 | } |
| 2932 | |
| 2933 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 2934 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 2935 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 2936 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2937 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2938 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2939 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2940 | "wakeup_hotunplug_complete"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2941 | } |
| 2942 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2943 | /* --------------------------------------------------------------------- */ |
| 2944 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2945 | static struct attribute *hotkey_attributes[] __initdata = { |
| 2946 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2947 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2948 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2949 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2950 | &dev_attr_hotkey_wakeup_reason.attr, |
| 2951 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2952 | &dev_attr_hotkey_mask.attr, |
| 2953 | &dev_attr_hotkey_all_mask.attr, |
| 2954 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2955 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2956 | &dev_attr_hotkey_source_mask.attr, |
| 2957 | &dev_attr_hotkey_poll_freq.attr, |
| 2958 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2959 | }; |
| 2960 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2961 | /* |
| 2962 | * Sync both the hw and sw blocking state of all switches |
| 2963 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2964 | static void tpacpi_send_radiosw_update(void) |
| 2965 | { |
| 2966 | int wlsw; |
| 2967 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2968 | /* |
| 2969 | * We must sync all rfkill controllers *before* issuing any |
| 2970 | * rfkill input events, or we will race the rfkill core input |
| 2971 | * handler. |
| 2972 | * |
| 2973 | * tpacpi_inputdev_send_mutex works as a syncronization point |
| 2974 | * for the above. |
| 2975 | * |
| 2976 | * We optimize to avoid numerous calls to hotkey_get_wlsw. |
| 2977 | */ |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 2978 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2979 | wlsw = hotkey_get_wlsw(); |
| 2980 | |
| 2981 | /* Sync hw blocking state first if it is hw-blocked */ |
| 2982 | if (wlsw == TPACPI_RFK_RADIO_OFF) |
| 2983 | tpacpi_rfk_update_hwblock_state(true); |
| 2984 | |
| 2985 | /* Sync sw blocking state */ |
| 2986 | tpacpi_rfk_update_swstate_all(); |
| 2987 | |
| 2988 | /* Sync hw blocking state last if it is hw-unblocked */ |
| 2989 | if (wlsw == TPACPI_RFK_RADIO_ON) |
| 2990 | tpacpi_rfk_update_hwblock_state(false); |
| 2991 | |
| 2992 | /* Issue rfkill input event for WLSW switch */ |
| 2993 | if (!(wlsw < 0)) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2994 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2995 | |
| 2996 | input_report_switch(tpacpi_inputdev, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2997 | SW_RFKILL_ALL, (wlsw > 0)); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2998 | input_sync(tpacpi_inputdev); |
| 2999 | |
| 3000 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 3001 | } |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3002 | |
| 3003 | /* |
| 3004 | * this can be unconditional, as we will poll state again |
| 3005 | * if userspace uses the notify to read data |
| 3006 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3007 | hotkey_radio_sw_notify_change(); |
| 3008 | } |
| 3009 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3010 | static void hotkey_exit(void) |
| 3011 | { |
| 3012 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3013 | mutex_lock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3014 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3015 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3016 | #endif |
| 3017 | |
| 3018 | if (hotkey_dev_attributes) |
| 3019 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3020 | |
| 3021 | kfree(hotkey_keycode_map); |
| 3022 | |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3023 | dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3024 | "restoring original HKEY status and mask\n"); |
| 3025 | /* yes, there is a bitwise or below, we want the |
| 3026 | * functions to be called even if one of them fail */ |
| 3027 | if (((tp_features.hotkey_mask && |
| 3028 | hotkey_mask_set(hotkey_orig_mask)) | |
| 3029 | hotkey_status_set(false)) != 0) |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3030 | printk(TPACPI_ERR |
| 3031 | "failed to restore hot key mask " |
| 3032 | "to BIOS defaults\n"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3033 | } |
| 3034 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3035 | static void __init hotkey_unmap(const unsigned int scancode) |
| 3036 | { |
| 3037 | if (hotkey_keycode_map[scancode] != KEY_RESERVED) { |
| 3038 | clear_bit(hotkey_keycode_map[scancode], |
| 3039 | tpacpi_inputdev->keybit); |
| 3040 | hotkey_keycode_map[scancode] = KEY_RESERVED; |
| 3041 | } |
| 3042 | } |
| 3043 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3044 | /* |
| 3045 | * HKEY quirks: |
| 3046 | * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12 |
| 3047 | */ |
| 3048 | |
| 3049 | #define TPACPI_HK_Q_INIMASK 0x0001 |
| 3050 | |
| 3051 | static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = { |
| 3052 | TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3053 | TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3054 | TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK), /* 770, 770E, 770ED */ |
| 3055 | TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK), /* A20m */ |
| 3056 | TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK), /* A20p */ |
| 3057 | TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK), /* A21e, A22e */ |
| 3058 | TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK), /* A21e */ |
| 3059 | TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK), /* A21m, A22m */ |
| 3060 | TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK), /* A21p, A22p */ |
| 3061 | TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK), /* A22e */ |
| 3062 | TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK), /* A22m */ |
| 3063 | TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK), /* A30/p (0) */ |
| 3064 | TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK), /* R30 */ |
| 3065 | TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK), /* R31 */ |
| 3066 | TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK), /* T20 */ |
| 3067 | TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK), /* T21 */ |
| 3068 | TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK), /* T22 */ |
| 3069 | TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK), /* X20, X21 */ |
| 3070 | TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */ |
| 3071 | }; |
| 3072 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3073 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3074 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3075 | /* Requirements for changing the default keymaps: |
| 3076 | * |
| 3077 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 3078 | * good reasons. Do not change them unless you have deep |
| 3079 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 3080 | * the various ThinkPad models. The driver behaves |
| 3081 | * differently for KEY_RESERVED: such keys have their |
| 3082 | * hot key mask *unset* in mask_recommended, and also |
| 3083 | * in the initial hot key mask programmed into the |
| 3084 | * firmware at driver load time, which means the firm- |
| 3085 | * ware may react very differently if you change them to |
| 3086 | * something else; |
| 3087 | * |
| 3088 | * 2. You must be subscribed to the linux-thinkpad and |
| 3089 | * ibm-acpi-devel mailing lists, and you should read the |
| 3090 | * list archives since 2007 if you want to change the |
| 3091 | * keymaps. This requirement exists so that you will |
| 3092 | * know the past history of problems with the thinkpad- |
| 3093 | * acpi driver keymaps, and also that you will be |
| 3094 | * listening to any bug reports; |
| 3095 | * |
| 3096 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 3097 | * for merging, *ever*. Send them to the linux-acpi |
| 3098 | * mailinglist for comments. Merging is to be done only |
| 3099 | * through acpi-test and the ACPI maintainer. |
| 3100 | * |
| 3101 | * If the above is too much to ask, don't change the keymap. |
| 3102 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 3103 | */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3104 | static u16 ibm_keycode_map[] __initdata = { |
| 3105 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 3106 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
| 3107 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 3108 | 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] | 3109 | |
| 3110 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3111 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3112 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3113 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3114 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3115 | /* brightness: firmware always reacts to them */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3116 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3117 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3118 | |
| 3119 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3120 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3121 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3122 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3123 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3124 | |
| 3125 | /* Volume: firmware always react to it and reprograms |
| 3126 | * the built-in *extra* mixer. Never map it to control |
| 3127 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3128 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3129 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3130 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3131 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3132 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3133 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3134 | /* (assignments unknown, please report if found) */ |
| 3135 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3136 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3137 | }; |
| 3138 | static u16 lenovo_keycode_map[] __initdata = { |
| 3139 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 3140 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
| 3141 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 3142 | 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] | 3143 | |
| 3144 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3145 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3146 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3147 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3148 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3149 | /* These should be enabled --only-- when ACPI video |
| 3150 | * is disabled (i.e. in "vendor" mode), and are handled |
| 3151 | * in a special way by the init code */ |
| 3152 | KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ |
| 3153 | KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3154 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3155 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3156 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3157 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3158 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3159 | |
| 3160 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 3161 | * react to it and reprograms the built-in *extra* mixer. |
| 3162 | * Never map it to control another mixer by default. |
| 3163 | * |
| 3164 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 3165 | * these over the regular keyboard, so these are no-ops, |
| 3166 | * but there are still weird bugs re. MUTE, so do not |
| 3167 | * change unless you get test reports from all Lenovo |
| 3168 | * models. May cause the BIOS to interfere with the |
| 3169 | * HDA mixer. |
| 3170 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3171 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3172 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3173 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3174 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3175 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3176 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3177 | /* (assignments unknown, please report if found) */ |
| 3178 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3179 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3180 | }; |
| 3181 | |
| 3182 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) |
| 3183 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) |
| 3184 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) |
| 3185 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3186 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3187 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 3188 | int hkeyv; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3189 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3190 | unsigned long quirks; |
| 3191 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3192 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3193 | "initializing hotkey subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3194 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3195 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3196 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 3197 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3198 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3199 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3200 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3201 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3202 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 3203 | mutex_init(&hotkey_thread_mutex); |
| 3204 | mutex_init(&hotkey_thread_data_mutex); |
| 3205 | #endif |
| 3206 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3207 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3208 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3209 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3210 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3211 | "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3212 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3213 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3214 | if (!tp_features.hotkey) |
| 3215 | return 1; |
| 3216 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3217 | quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, |
| 3218 | ARRAY_SIZE(tpacpi_hotkey_qtable)); |
| 3219 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3220 | tpacpi_disable_brightness_delay(); |
| 3221 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3222 | /* MUST have enough space for all attributes to be added to |
| 3223 | * hotkey_dev_attributes */ |
| 3224 | hotkey_dev_attributes = create_attr_set( |
| 3225 | ARRAY_SIZE(hotkey_attributes) + 2, |
| 3226 | NULL); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3227 | if (!hotkey_dev_attributes) |
| 3228 | return -ENOMEM; |
| 3229 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 3230 | hotkey_attributes, |
| 3231 | ARRAY_SIZE(hotkey_attributes)); |
| 3232 | if (res) |
| 3233 | goto err_exit; |
| 3234 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3235 | /* 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] | 3236 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 3237 | for HKEY interface version 0x100 */ |
| 3238 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 3239 | if ((hkeyv >> 8) != 1) { |
| 3240 | printk(TPACPI_ERR "unknown version of the " |
| 3241 | "HKEY interface: 0x%x\n", hkeyv); |
| 3242 | printk(TPACPI_ERR "please report this to %s\n", |
| 3243 | TPACPI_MAIL); |
| 3244 | } else { |
| 3245 | /* |
| 3246 | * MHKV 0x100 in A31, R40, R40e, |
| 3247 | * T4x, X31, and later |
| 3248 | */ |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3249 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3250 | "firmware HKEY interface version: 0x%x\n", |
| 3251 | hkeyv); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3252 | |
| 3253 | /* Paranoia check AND init hotkey_all_mask */ |
| 3254 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
| 3255 | "MHKA", "qd")) { |
| 3256 | printk(TPACPI_ERR |
| 3257 | "missing MHKA handler, " |
| 3258 | "please report this to %s\n", |
| 3259 | TPACPI_MAIL); |
| 3260 | /* Fallback: pre-init for FN+F3,F4,F12 */ |
| 3261 | hotkey_all_mask = 0x080cU; |
| 3262 | } else { |
| 3263 | tp_features.hotkey_mask = 1; |
| 3264 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3265 | } |
| 3266 | } |
| 3267 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3268 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3269 | "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3270 | str_supported(tp_features.hotkey_mask)); |
| 3271 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3272 | /* Init hotkey_all_mask if not initialized yet */ |
| 3273 | if (!tp_features.hotkey_mask && !hotkey_all_mask && |
| 3274 | (quirks & TPACPI_HK_Q_INIMASK)) |
| 3275 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3276 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3277 | /* Init hotkey_acpi_mask and hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3278 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3279 | /* hotkey_source_mask *must* be zero for |
| 3280 | * the first hotkey_mask_get to return hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3281 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3282 | if (res) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3283 | goto err_exit; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3284 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3285 | hotkey_orig_mask = hotkey_acpi_mask; |
| 3286 | } else { |
| 3287 | hotkey_orig_mask = hotkey_all_mask; |
| 3288 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3289 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3290 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3291 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3292 | if (dbg_wlswemul) { |
| 3293 | tp_features.hotkey_wlsw = 1; |
| 3294 | printk(TPACPI_INFO |
| 3295 | "radio switch emulation enabled\n"); |
| 3296 | } else |
| 3297 | #endif |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3298 | /* Not all thinkpads have a hardware radio switch */ |
| 3299 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 3300 | tp_features.hotkey_wlsw = 1; |
| 3301 | printk(TPACPI_INFO |
| 3302 | "radio switch found; radios are %s\n", |
| 3303 | enabled(status, 0)); |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3304 | } |
| 3305 | if (tp_features.hotkey_wlsw) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3306 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3307 | &dev_attr_hotkey_radio_sw.attr); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3308 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3309 | /* For X41t, X60t, X61t Tablets... */ |
| 3310 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 3311 | tp_features.hotkey_tablet = 1; |
| 3312 | printk(TPACPI_INFO |
| 3313 | "possible tablet mode switch found; " |
| 3314 | "ThinkPad in %s mode\n", |
| 3315 | (status & TP_HOTKEY_TABLET_MASK)? |
| 3316 | "tablet" : "laptop"); |
| 3317 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3318 | &dev_attr_hotkey_tablet_mode.attr); |
| 3319 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3320 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3321 | if (!res) |
| 3322 | res = register_attr_set_with_sysfs( |
| 3323 | hotkey_dev_attributes, |
| 3324 | &tpacpi_pdev->dev.kobj); |
| 3325 | if (res) |
| 3326 | goto err_exit; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3327 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3328 | /* Set up key map */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3329 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3330 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 3331 | GFP_KERNEL); |
| 3332 | if (!hotkey_keycode_map) { |
| 3333 | printk(TPACPI_ERR |
| 3334 | "failed to allocate memory for key map\n"); |
| 3335 | res = -ENOMEM; |
| 3336 | goto err_exit; |
| 3337 | } |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3338 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3339 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3340 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3341 | "using Lenovo default hot key map\n"); |
| 3342 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, |
| 3343 | TPACPI_HOTKEY_MAP_SIZE); |
| 3344 | } else { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3345 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3346 | "using IBM default hot key map\n"); |
| 3347 | memcpy(hotkey_keycode_map, &ibm_keycode_map, |
| 3348 | TPACPI_HOTKEY_MAP_SIZE); |
| 3349 | } |
| 3350 | |
| 3351 | set_bit(EV_KEY, tpacpi_inputdev->evbit); |
| 3352 | set_bit(EV_MSC, tpacpi_inputdev->evbit); |
| 3353 | set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); |
| 3354 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 3355 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 3356 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 3357 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
| 3358 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
| 3359 | set_bit(hotkey_keycode_map[i], |
| 3360 | tpacpi_inputdev->keybit); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3361 | } else { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3362 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 3363 | hotkey_reserved_mask |= 1 << i; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3364 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3365 | } |
| 3366 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3367 | if (tp_features.hotkey_wlsw) { |
| 3368 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 3369 | set_bit(SW_RFKILL_ALL, tpacpi_inputdev->swbit); |
| 3370 | } |
| 3371 | if (tp_features.hotkey_tablet) { |
| 3372 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 3373 | set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3374 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3375 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3376 | /* Do not issue duplicate brightness change events to |
| 3377 | * userspace */ |
| 3378 | if (!tp_features.bright_acpimode) |
| 3379 | /* update bright_acpimode... */ |
| 3380 | tpacpi_check_std_acpi_brightness_support(); |
| 3381 | |
Henrique de Moraes Holschuh | 8bf3d4c | 2009-05-30 13:25:09 -0300 | [diff] [blame] | 3382 | if (tp_features.bright_acpimode && acpi_video_backlight_support()) { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3383 | printk(TPACPI_INFO |
| 3384 | "This ThinkPad has standard ACPI backlight " |
| 3385 | "brightness control, supported by the ACPI " |
| 3386 | "video driver\n"); |
| 3387 | printk(TPACPI_NOTICE |
| 3388 | "Disabling thinkpad-acpi brightness events " |
| 3389 | "by default...\n"); |
| 3390 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3391 | /* Disable brightness up/down on Lenovo thinkpads when |
| 3392 | * ACPI is handling them, otherwise it is plain impossible |
| 3393 | * for userspace to do something even remotely sane */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3394 | hotkey_reserved_mask |= |
| 3395 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 3396 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3397 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 3398 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3399 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3400 | |
Henrique de Moraes Holschuh | 230d8cf | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3401 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3402 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 3403 | & ~hotkey_all_mask |
| 3404 | & ~hotkey_reserved_mask; |
Henrique de Moraes Holschuh | 230d8cf | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3405 | |
| 3406 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3407 | "hotkey source mask 0x%08x, polling freq %u\n", |
| 3408 | hotkey_source_mask, hotkey_poll_freq); |
| 3409 | #endif |
| 3410 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3411 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3412 | "enabling firmware HKEY event interface...\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3413 | res = hotkey_status_set(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3414 | if (res) { |
| 3415 | hotkey_exit(); |
| 3416 | return res; |
| 3417 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3418 | res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask) |
| 3419 | | hotkey_driver_mask) |
| 3420 | & ~hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3421 | if (res < 0 && res != -ENXIO) { |
| 3422 | hotkey_exit(); |
| 3423 | return res; |
| 3424 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3425 | hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask) |
| 3426 | & ~hotkey_reserved_mask; |
| 3427 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3428 | "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n", |
| 3429 | hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3430 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3431 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3432 | "legacy ibm/hotkey event reporting over procfs %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3433 | (hotkey_report_mode < 2) ? |
| 3434 | "enabled" : "disabled"); |
| 3435 | |
| 3436 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 3437 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 3438 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3439 | hotkey_poll_setup_safe(true); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3440 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3441 | tpacpi_input_send_tabletsw(); |
| 3442 | |
| 3443 | return 0; |
| 3444 | |
| 3445 | err_exit: |
| 3446 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3447 | hotkey_dev_attributes = NULL; |
| 3448 | |
| 3449 | return (res < 0)? res : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3450 | } |
| 3451 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3452 | static bool hotkey_notify_hotkey(const u32 hkey, |
| 3453 | bool *send_acpi_ev, |
| 3454 | bool *ignore_acpi_ev) |
| 3455 | { |
| 3456 | /* 0x1000-0x1FFF: key presses */ |
| 3457 | unsigned int scancode = hkey & 0xfff; |
| 3458 | *send_acpi_ev = true; |
| 3459 | *ignore_acpi_ev = false; |
| 3460 | |
| 3461 | if (scancode > 0 && scancode < 0x21) { |
| 3462 | scancode--; |
| 3463 | if (!(hotkey_source_mask & (1 << scancode))) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3464 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3465 | *send_acpi_ev = false; |
| 3466 | } else { |
| 3467 | *ignore_acpi_ev = true; |
| 3468 | } |
| 3469 | return true; |
| 3470 | } |
| 3471 | return false; |
| 3472 | } |
| 3473 | |
| 3474 | static bool hotkey_notify_wakeup(const u32 hkey, |
| 3475 | bool *send_acpi_ev, |
| 3476 | bool *ignore_acpi_ev) |
| 3477 | { |
| 3478 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3479 | *send_acpi_ev = true; |
| 3480 | *ignore_acpi_ev = false; |
| 3481 | |
| 3482 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3483 | case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */ |
| 3484 | case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3485 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 3486 | *ignore_acpi_ev = true; |
| 3487 | break; |
| 3488 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3489 | case TP_HKEY_EV_WKUP_S3_BAYEJ: /* suspend, bay eject */ |
| 3490 | case TP_HKEY_EV_WKUP_S4_BAYEJ: /* hibernation, bay eject */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3491 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 3492 | *ignore_acpi_ev = true; |
| 3493 | break; |
| 3494 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3495 | case TP_HKEY_EV_WKUP_S3_BATLOW: /* Battery on critical low level/S3 */ |
| 3496 | 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] | 3497 | printk(TPACPI_ALERT |
| 3498 | "EMERGENCY WAKEUP: battery almost empty\n"); |
| 3499 | /* how to auto-heal: */ |
| 3500 | /* 2313: woke up from S3, go to S4/S5 */ |
| 3501 | /* 2413: woke up from S4, go to S5 */ |
| 3502 | break; |
| 3503 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3504 | default: |
| 3505 | return false; |
| 3506 | } |
| 3507 | |
| 3508 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
| 3509 | printk(TPACPI_INFO |
| 3510 | "woke up due to a hot-unplug " |
| 3511 | "request...\n"); |
| 3512 | hotkey_wakeup_reason_notify_change(); |
| 3513 | } |
| 3514 | return true; |
| 3515 | } |
| 3516 | |
| 3517 | static bool hotkey_notify_usrevent(const u32 hkey, |
| 3518 | bool *send_acpi_ev, |
| 3519 | bool *ignore_acpi_ev) |
| 3520 | { |
| 3521 | /* 0x5000-0x5FFF: human interface helpers */ |
| 3522 | *send_acpi_ev = true; |
| 3523 | *ignore_acpi_ev = false; |
| 3524 | |
| 3525 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3526 | case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */ |
| 3527 | 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] | 3528 | return true; |
| 3529 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3530 | case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */ |
| 3531 | case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3532 | tpacpi_input_send_tabletsw(); |
| 3533 | hotkey_tablet_mode_notify_change(); |
| 3534 | *send_acpi_ev = false; |
| 3535 | return true; |
| 3536 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3537 | case TP_HKEY_EV_LID_CLOSE: /* Lid closed */ |
| 3538 | case TP_HKEY_EV_LID_OPEN: /* Lid opened */ |
| 3539 | case TP_HKEY_EV_BRGHT_CHANGED: /* brightness changed */ |
Henrique de Moraes Holschuh | 176dd98 | 2009-09-20 14:09:24 -0300 | [diff] [blame] | 3540 | /* do not propagate these events */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3541 | *ignore_acpi_ev = true; |
| 3542 | return true; |
| 3543 | |
| 3544 | default: |
| 3545 | return false; |
| 3546 | } |
| 3547 | } |
| 3548 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3549 | static bool hotkey_notify_thermal(const u32 hkey, |
| 3550 | bool *send_acpi_ev, |
| 3551 | bool *ignore_acpi_ev) |
| 3552 | { |
| 3553 | /* 0x6000-0x6FFF: thermal alarms */ |
| 3554 | *send_acpi_ev = true; |
| 3555 | *ignore_acpi_ev = false; |
| 3556 | |
| 3557 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3558 | case TP_HKEY_EV_ALARM_BAT_HOT: |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3559 | printk(TPACPI_CRIT |
| 3560 | "THERMAL ALARM: battery is too hot!\n"); |
| 3561 | /* recommended action: warn user through gui */ |
| 3562 | return true; |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3563 | case TP_HKEY_EV_ALARM_BAT_XHOT: |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3564 | printk(TPACPI_ALERT |
| 3565 | "THERMAL EMERGENCY: battery 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_ALARM_SENSOR_HOT: |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3569 | printk(TPACPI_CRIT |
| 3570 | "THERMAL ALARM: " |
| 3571 | "a sensor reports something is too hot!\n"); |
| 3572 | /* recommended action: warn user through gui, that */ |
| 3573 | /* some internal component is too hot */ |
| 3574 | return true; |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3575 | case TP_HKEY_EV_ALARM_SENSOR_XHOT: |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3576 | printk(TPACPI_ALERT |
| 3577 | "THERMAL EMERGENCY: " |
| 3578 | "a sensor reports something is extremely hot!\n"); |
| 3579 | /* recommended action: immediate sleep/hibernate */ |
| 3580 | return true; |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3581 | case TP_HKEY_EV_THM_TABLE_CHANGED: |
Henrique de Moraes Holschuh | 54926ce | 2009-01-11 03:01:09 -0200 | [diff] [blame] | 3582 | printk(TPACPI_INFO |
| 3583 | "EC reports that Thermal Table has changed\n"); |
| 3584 | /* recommended action: do nothing, we don't have |
| 3585 | * Lenovo ATM information */ |
| 3586 | return true; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3587 | default: |
| 3588 | printk(TPACPI_ALERT |
| 3589 | "THERMAL ALERT: unknown thermal alarm received\n"); |
| 3590 | return false; |
| 3591 | } |
| 3592 | } |
| 3593 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3594 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 3595 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3596 | u32 hkey; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3597 | bool send_acpi_ev; |
| 3598 | bool ignore_acpi_ev; |
| 3599 | bool known_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3600 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3601 | if (event != 0x80) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3602 | printk(TPACPI_ERR |
| 3603 | "unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3604 | /* 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] | 3605 | acpi_bus_generate_netlink_event( |
| 3606 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3607 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3608 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3609 | return; |
| 3610 | } |
| 3611 | |
| 3612 | while (1) { |
| 3613 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3614 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3615 | return; |
| 3616 | } |
| 3617 | |
| 3618 | if (hkey == 0) { |
| 3619 | /* queue empty */ |
| 3620 | return; |
| 3621 | } |
| 3622 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3623 | send_acpi_ev = true; |
| 3624 | ignore_acpi_ev = false; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3625 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3626 | switch (hkey >> 12) { |
| 3627 | case 1: |
| 3628 | /* 0x1000-0x1FFF: key presses */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3629 | known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev, |
| 3630 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3631 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3632 | case 2: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3633 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3634 | known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev, |
| 3635 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3636 | break; |
| 3637 | case 3: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3638 | /* 0x3000-0x3FFF: bay-related wakeups */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3639 | if (hkey == TP_HKEY_EV_BAYEJ_ACK) { |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3640 | hotkey_autosleep_ack = 1; |
| 3641 | printk(TPACPI_INFO |
| 3642 | "bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3643 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3644 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3645 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3646 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3647 | } |
| 3648 | break; |
| 3649 | case 4: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3650 | /* 0x4000-0x4FFF: dock-related wakeups */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3651 | if (hkey == TP_HKEY_EV_UNDOCK_ACK) { |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3652 | hotkey_autosleep_ack = 1; |
| 3653 | printk(TPACPI_INFO |
| 3654 | "undocked\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3655 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3656 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3657 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3658 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3659 | } |
| 3660 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3661 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 3662 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3663 | known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev, |
| 3664 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3665 | break; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3666 | case 6: |
| 3667 | /* 0x6000-0x6FFF: thermal alarms */ |
| 3668 | known_ev = hotkey_notify_thermal(hkey, &send_acpi_ev, |
| 3669 | &ignore_acpi_ev); |
| 3670 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3671 | case 7: |
| 3672 | /* 0x7000-0x7FFF: misc */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3673 | if (tp_features.hotkey_wlsw && |
| 3674 | hkey == TP_HKEY_EV_RFKILL_CHANGED) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3675 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3676 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3677 | known_ev = true; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3678 | break; |
| 3679 | } |
| 3680 | /* fallthrough to default */ |
| 3681 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3682 | known_ev = false; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3683 | } |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3684 | if (!known_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3685 | printk(TPACPI_NOTICE |
| 3686 | "unhandled HKEY event 0x%04x\n", hkey); |
Henrique de Moraes Holschuh | cb42935 | 2009-01-11 03:01:07 -0200 | [diff] [blame] | 3687 | printk(TPACPI_NOTICE |
| 3688 | "please report the conditions when this " |
| 3689 | "event happened to %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3690 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3691 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3692 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3693 | if (!ignore_acpi_ev && |
| 3694 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 3695 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 3696 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3697 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3698 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3699 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3700 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3701 | acpi_bus_generate_netlink_event( |
| 3702 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3703 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3704 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3705 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3706 | } |
| 3707 | } |
| 3708 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3709 | static void hotkey_suspend(pm_message_t state) |
| 3710 | { |
| 3711 | /* Do these on suspend, we get the events on early resume! */ |
| 3712 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 3713 | hotkey_autosleep_ack = 0; |
| 3714 | } |
| 3715 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3716 | static void hotkey_resume(void) |
| 3717 | { |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3718 | tpacpi_disable_brightness_delay(); |
| 3719 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3720 | if (hotkey_status_set(true) < 0 || |
| 3721 | hotkey_mask_set(hotkey_acpi_mask) < 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3722 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3723 | "error while attempting to reset the event " |
| 3724 | "firmware interface\n"); |
| 3725 | |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3726 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3727 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3728 | hotkey_wakeup_reason_notify_change(); |
| 3729 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3730 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3731 | } |
| 3732 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3733 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3734 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3736 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | int len = 0; |
| 3738 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3739 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3740 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3741 | return len; |
| 3742 | } |
| 3743 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3744 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3745 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3746 | res = hotkey_status_get(&status); |
| 3747 | if (!res) |
| 3748 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3749 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3750 | if (res) |
| 3751 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | |
| 3753 | 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] | 3754 | if (hotkey_all_mask) { |
| 3755 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_user_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | len += sprintf(p + len, |
| 3757 | "commands:\tenable, disable, reset, <mask>\n"); |
| 3758 | } else { |
| 3759 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 3760 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 3761 | } |
| 3762 | |
| 3763 | return len; |
| 3764 | } |
| 3765 | |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3766 | static void hotkey_enabledisable_warn(bool enable) |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3767 | { |
| 3768 | tpacpi_log_usertask("procfs hotkey enable/disable"); |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3769 | if (!WARN((tpacpi_lifecycle == TPACPI_LIFE_RUNNING || !enable), |
| 3770 | TPACPI_WARN |
| 3771 | "hotkey enable/disable functionality has been " |
| 3772 | "removed from the driver. Hotkeys are always " |
| 3773 | "enabled\n")) |
| 3774 | printk(TPACPI_ERR |
| 3775 | "Please remove the hotkey=enable module " |
| 3776 | "parameter, it is deprecated. Hotkeys are always " |
| 3777 | "enabled\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3778 | } |
| 3779 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3780 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3782 | int res; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3783 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3786 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | return -ENODEV; |
| 3788 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3789 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3790 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3791 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3792 | mask = hotkey_user_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3793 | |
| 3794 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | while ((cmd = next_cmd(&buf))) { |
| 3796 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3797 | hotkey_enabledisable_warn(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3799 | hotkey_enabledisable_warn(0); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3800 | res = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | } else if (strlencmp(cmd, "reset") == 0) { |
Henrique de Moraes Holschuh | 20c9aa4 | 2009-09-12 15:22:16 -0300 | [diff] [blame] | 3802 | mask = (hotkey_all_mask | hotkey_source_mask) |
| 3803 | & ~hotkey_reserved_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 3805 | /* mask set */ |
| 3806 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 3807 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3808 | } else { |
| 3809 | res = -EINVAL; |
| 3810 | goto errexit; |
| 3811 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | } |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3813 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3814 | if (!res) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3815 | tpacpi_disclose_usertask("procfs hotkey", |
| 3816 | "set mask to 0x%08x\n", mask); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3817 | res = hotkey_user_mask_set(mask); |
| 3818 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3820 | errexit: |
| 3821 | mutex_unlock(&hotkey_mutex); |
| 3822 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3823 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3825 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3826 | {TPACPI_ACPI_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3827 | {"", 0}, |
| 3828 | }; |
| 3829 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3830 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3831 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3832 | .notify = hotkey_notify, |
| 3833 | .handle = &hkey_handle, |
| 3834 | .type = ACPI_DEVICE_NOTIFY, |
| 3835 | }; |
| 3836 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3837 | static struct ibm_struct hotkey_driver_data = { |
| 3838 | .name = "hotkey", |
| 3839 | .read = hotkey_read, |
| 3840 | .write = hotkey_write, |
| 3841 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3842 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3843 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3844 | .acpi = &ibm_hotkey_acpidriver, |
| 3845 | }; |
| 3846 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3847 | /************************************************************************* |
| 3848 | * Bluetooth subdriver |
| 3849 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3851 | enum { |
| 3852 | /* ACPI GBDC/SBDC bits */ |
| 3853 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 3854 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3855 | TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: |
| 3856 | off / last state */ |
| 3857 | }; |
| 3858 | |
| 3859 | enum { |
| 3860 | /* ACPI \BLTH commands */ |
| 3861 | TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */ |
| 3862 | TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */ |
| 3863 | TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */ |
| 3864 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */ |
| 3865 | 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] | 3866 | }; |
| 3867 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3868 | #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" |
| 3869 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3870 | static int bluetooth_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3871 | { |
| 3872 | int status; |
| 3873 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3874 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3875 | if (dbg_bluetoothemul) |
| 3876 | return (tpacpi_bluetooth_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3877 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3878 | #endif |
| 3879 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3880 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 3881 | return -EIO; |
| 3882 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3883 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3884 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3885 | } |
| 3886 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3887 | static int bluetooth_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3888 | { |
| 3889 | int status; |
| 3890 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3891 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3892 | "will attempt to %s bluetooth\n", |
| 3893 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3894 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3895 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3896 | if (dbg_bluetoothemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3897 | tpacpi_bluetooth_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3898 | return 0; |
| 3899 | } |
| 3900 | #endif |
| 3901 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3902 | /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */ |
Henrique de Moraes Holschuh | 208b996 | 2009-12-09 01:36:22 +0000 | [diff] [blame] | 3903 | status = TP_ACPI_BLUETOOTH_RESUMECTRL; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3904 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 208b996 | 2009-12-09 01:36:22 +0000 | [diff] [blame] | 3905 | status |= TP_ACPI_BLUETOOTH_RADIOSSW; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3906 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3907 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 3908 | return -EIO; |
| 3909 | |
| 3910 | return 0; |
| 3911 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3912 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3913 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 3914 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 3915 | struct device_attribute *attr, |
| 3916 | char *buf) |
| 3917 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3918 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3919 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3920 | } |
| 3921 | |
| 3922 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 3923 | struct device_attribute *attr, |
| 3924 | const char *buf, size_t count) |
| 3925 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3926 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3927 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 3931 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3932 | bluetooth_enable_show, bluetooth_enable_store); |
| 3933 | |
| 3934 | /* --------------------------------------------------------------------- */ |
| 3935 | |
| 3936 | static struct attribute *bluetooth_attributes[] = { |
| 3937 | &dev_attr_bluetooth_enable.attr, |
| 3938 | NULL |
| 3939 | }; |
| 3940 | |
| 3941 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3942 | .attrs = bluetooth_attributes, |
| 3943 | }; |
| 3944 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3945 | static const struct tpacpi_rfk_ops bluetooth_tprfk_ops = { |
| 3946 | .get_status = bluetooth_get_status, |
| 3947 | .set_status = bluetooth_set_status, |
| 3948 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3949 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3950 | static void bluetooth_shutdown(void) |
| 3951 | { |
| 3952 | /* Order firmware to save current state to NVRAM */ |
| 3953 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 3954 | TP_ACPI_BLTH_SAVE_STATE)) |
| 3955 | printk(TPACPI_NOTICE |
| 3956 | "failed to save bluetooth state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3957 | else |
| 3958 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3959 | "bluestooth state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3960 | } |
| 3961 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3962 | static void bluetooth_exit(void) |
| 3963 | { |
| 3964 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 3965 | &bluetooth_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3966 | |
| 3967 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
| 3968 | |
| 3969 | bluetooth_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3970 | } |
| 3971 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3972 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3974 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3975 | int status = 0; |
| 3976 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3977 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3978 | "initializing bluetooth subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3979 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3980 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3981 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3982 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 3983 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3984 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3985 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3987 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3988 | "bluetooth is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3989 | str_supported(tp_features.bluetooth), |
| 3990 | status); |
| 3991 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3992 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3993 | if (dbg_bluetoothemul) { |
| 3994 | tp_features.bluetooth = 1; |
| 3995 | printk(TPACPI_INFO |
| 3996 | "bluetooth switch emulation enabled\n"); |
| 3997 | } else |
| 3998 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3999 | if (tp_features.bluetooth && |
| 4000 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 4001 | /* no bluetooth hardware present in system */ |
| 4002 | tp_features.bluetooth = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4003 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4004 | "bluetooth hardware not installed\n"); |
| 4005 | } |
| 4006 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4007 | if (!tp_features.bluetooth) |
| 4008 | return 1; |
| 4009 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4010 | res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 4011 | &bluetooth_tprfk_ops, |
| 4012 | RFKILL_TYPE_BLUETOOTH, |
| 4013 | TPACPI_RFK_BLUETOOTH_SW_NAME, |
| 4014 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4015 | if (res) |
| 4016 | return res; |
| 4017 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4018 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4019 | &bluetooth_attr_group); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4020 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4021 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4022 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4023 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4024 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4025 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | } |
| 4027 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4028 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4029 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4031 | return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4034 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4036 | return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | } |
| 4038 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4039 | static struct ibm_struct bluetooth_driver_data = { |
| 4040 | .name = "bluetooth", |
| 4041 | .read = bluetooth_read, |
| 4042 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4043 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4044 | .shutdown = bluetooth_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4045 | }; |
| 4046 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4047 | /************************************************************************* |
| 4048 | * Wan subdriver |
| 4049 | */ |
| 4050 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4051 | enum { |
| 4052 | /* ACPI GWAN/SWAN bits */ |
| 4053 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 4054 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4055 | TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: |
| 4056 | off / last state */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4057 | }; |
| 4058 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4059 | #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" |
| 4060 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4061 | static int wan_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4062 | { |
| 4063 | int status; |
| 4064 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4065 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4066 | if (dbg_wwanemul) |
| 4067 | return (tpacpi_wwan_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4068 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4069 | #endif |
| 4070 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4071 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 4072 | return -EIO; |
| 4073 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4074 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? |
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 | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4076 | } |
| 4077 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4078 | static int wan_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4079 | { |
| 4080 | int status; |
| 4081 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4082 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4083 | "will attempt to %s wwan\n", |
| 4084 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4085 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4086 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4087 | if (dbg_wwanemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4088 | tpacpi_wwan_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4089 | return 0; |
| 4090 | } |
| 4091 | #endif |
| 4092 | |
Henrique de Moraes Holschuh | 208b996 | 2009-12-09 01:36:22 +0000 | [diff] [blame] | 4093 | /* We make sure to set TP_ACPI_WANCARD_RESUMECTRL */ |
| 4094 | status = TP_ACPI_WANCARD_RESUMECTRL; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4095 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 208b996 | 2009-12-09 01:36:22 +0000 | [diff] [blame] | 4096 | status |= TP_ACPI_WANCARD_RADIOSSW; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4097 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4098 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 4099 | return -EIO; |
| 4100 | |
| 4101 | return 0; |
| 4102 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4103 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4104 | /* sysfs wan enable ---------------------------------------------------- */ |
| 4105 | static ssize_t wan_enable_show(struct device *dev, |
| 4106 | struct device_attribute *attr, |
| 4107 | char *buf) |
| 4108 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4109 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID, |
| 4110 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4111 | } |
| 4112 | |
| 4113 | static ssize_t wan_enable_store(struct device *dev, |
| 4114 | struct device_attribute *attr, |
| 4115 | const char *buf, size_t count) |
| 4116 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4117 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID, |
| 4118 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4119 | } |
| 4120 | |
| 4121 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 4122 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4123 | wan_enable_show, wan_enable_store); |
| 4124 | |
| 4125 | /* --------------------------------------------------------------------- */ |
| 4126 | |
| 4127 | static struct attribute *wan_attributes[] = { |
| 4128 | &dev_attr_wan_enable.attr, |
| 4129 | NULL |
| 4130 | }; |
| 4131 | |
| 4132 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4133 | .attrs = wan_attributes, |
| 4134 | }; |
| 4135 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4136 | static const struct tpacpi_rfk_ops wan_tprfk_ops = { |
| 4137 | .get_status = wan_get_status, |
| 4138 | .set_status = wan_set_status, |
| 4139 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4140 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4141 | static void wan_shutdown(void) |
| 4142 | { |
| 4143 | /* Order firmware to save current state to NVRAM */ |
| 4144 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd", |
| 4145 | TP_ACPI_WGSV_SAVE_STATE)) |
| 4146 | printk(TPACPI_NOTICE |
| 4147 | "failed to save WWAN state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4148 | else |
| 4149 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 4150 | "WWAN state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4151 | } |
| 4152 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4153 | static void wan_exit(void) |
| 4154 | { |
| 4155 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 4156 | &wan_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4157 | |
| 4158 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
| 4159 | |
| 4160 | wan_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4161 | } |
| 4162 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4163 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4164 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4165 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4166 | int status = 0; |
| 4167 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4168 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4169 | "initializing wan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4170 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4171 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4172 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4173 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4174 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 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 | "wan is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4178 | str_supported(tp_features.wan), |
| 4179 | status); |
| 4180 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4181 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4182 | if (dbg_wwanemul) { |
| 4183 | tp_features.wan = 1; |
| 4184 | printk(TPACPI_INFO |
| 4185 | "wwan switch emulation enabled\n"); |
| 4186 | } else |
| 4187 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4188 | if (tp_features.wan && |
| 4189 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 4190 | /* no wan hardware present in system */ |
| 4191 | tp_features.wan = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4192 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4193 | "wan hardware not installed\n"); |
| 4194 | } |
| 4195 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4196 | if (!tp_features.wan) |
| 4197 | return 1; |
| 4198 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4199 | res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, |
| 4200 | &wan_tprfk_ops, |
| 4201 | RFKILL_TYPE_WWAN, |
| 4202 | TPACPI_RFK_WWAN_SW_NAME, |
| 4203 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4204 | if (res) |
| 4205 | return res; |
| 4206 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4207 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4208 | &wan_attr_group); |
| 4209 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4210 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4211 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4212 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4213 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4214 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4215 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4216 | } |
| 4217 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4218 | /* procfs -------------------------------------------------------------- */ |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4219 | static int wan_read(char *p) |
| 4220 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4221 | return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID, p); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | static int wan_write(char *buf) |
| 4225 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4226 | return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID, buf); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4227 | } |
| 4228 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4229 | static struct ibm_struct wan_driver_data = { |
| 4230 | .name = "wan", |
| 4231 | .read = wan_read, |
| 4232 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4233 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4234 | .shutdown = wan_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4235 | }; |
| 4236 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4237 | /************************************************************************* |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4238 | * UWB subdriver |
| 4239 | */ |
| 4240 | |
| 4241 | enum { |
| 4242 | /* ACPI GUWB/SUWB bits */ |
| 4243 | TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */ |
| 4244 | TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */ |
| 4245 | }; |
| 4246 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4247 | #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" |
| 4248 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4249 | static int uwb_get_status(void) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4250 | { |
| 4251 | int status; |
| 4252 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4253 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4254 | if (dbg_uwbemul) |
| 4255 | return (tpacpi_uwb_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4256 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4257 | #endif |
| 4258 | |
| 4259 | if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) |
| 4260 | return -EIO; |
| 4261 | |
| 4262 | return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4263 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4264 | } |
| 4265 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4266 | static int uwb_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4267 | { |
| 4268 | int status; |
| 4269 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4270 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4271 | "will attempt to %s UWB\n", |
| 4272 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4273 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4274 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4275 | if (dbg_uwbemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4276 | tpacpi_uwb_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4277 | return 0; |
| 4278 | } |
| 4279 | #endif |
| 4280 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4281 | if (state == TPACPI_RFK_RADIO_ON) |
| 4282 | status = TP_ACPI_UWB_RADIOSSW; |
| 4283 | else |
| 4284 | status = 0; |
| 4285 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4286 | if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) |
| 4287 | return -EIO; |
| 4288 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4289 | return 0; |
| 4290 | } |
| 4291 | |
| 4292 | /* --------------------------------------------------------------------- */ |
| 4293 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4294 | static const struct tpacpi_rfk_ops uwb_tprfk_ops = { |
| 4295 | .get_status = uwb_get_status, |
| 4296 | .set_status = uwb_set_status, |
| 4297 | }; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4298 | |
| 4299 | static void uwb_exit(void) |
| 4300 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4301 | tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | static int __init uwb_init(struct ibm_init_struct *iibm) |
| 4305 | { |
| 4306 | int res; |
| 4307 | int status = 0; |
| 4308 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4309 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4310 | "initializing uwb subdriver\n"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4311 | |
| 4312 | TPACPI_ACPIHANDLE_INIT(hkey); |
| 4313 | |
| 4314 | tp_features.uwb = hkey_handle && |
| 4315 | acpi_evalf(hkey_handle, &status, "GUWB", "qd"); |
| 4316 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4317 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4318 | "uwb is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4319 | str_supported(tp_features.uwb), |
| 4320 | status); |
| 4321 | |
| 4322 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4323 | if (dbg_uwbemul) { |
| 4324 | tp_features.uwb = 1; |
| 4325 | printk(TPACPI_INFO |
| 4326 | "uwb switch emulation enabled\n"); |
| 4327 | } else |
| 4328 | #endif |
| 4329 | if (tp_features.uwb && |
| 4330 | !(status & TP_ACPI_UWB_HWPRESENT)) { |
| 4331 | /* no uwb hardware present in system */ |
| 4332 | tp_features.uwb = 0; |
| 4333 | dbg_printk(TPACPI_DBG_INIT, |
| 4334 | "uwb hardware not installed\n"); |
| 4335 | } |
| 4336 | |
| 4337 | if (!tp_features.uwb) |
| 4338 | return 1; |
| 4339 | |
| 4340 | res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4341 | &uwb_tprfk_ops, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4342 | RFKILL_TYPE_UWB, |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4343 | TPACPI_RFK_UWB_SW_NAME, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4344 | false); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4345 | return res; |
| 4346 | } |
| 4347 | |
| 4348 | static struct ibm_struct uwb_driver_data = { |
| 4349 | .name = "uwb", |
| 4350 | .exit = uwb_exit, |
| 4351 | .flags.experimental = 1, |
| 4352 | }; |
| 4353 | |
| 4354 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4355 | * Video subdriver |
| 4356 | */ |
| 4357 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4358 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 4359 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4360 | enum video_access_mode { |
| 4361 | TPACPI_VIDEO_NONE = 0, |
| 4362 | TPACPI_VIDEO_570, /* 570 */ |
| 4363 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 4364 | TPACPI_VIDEO_NEW, /* all others */ |
| 4365 | }; |
| 4366 | |
| 4367 | enum { /* video status flags, based on VIDEO_570 */ |
| 4368 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 4369 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 4370 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 4371 | }; |
| 4372 | |
| 4373 | enum { /* TPACPI_VIDEO_570 constants */ |
| 4374 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 4375 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 4376 | * video_status_flags */ |
| 4377 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 4378 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 4379 | }; |
| 4380 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4381 | static enum video_access_mode video_supported; |
| 4382 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4383 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4384 | static int video_autosw_get(void); |
| 4385 | static int video_autosw_set(int enable); |
| 4386 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4387 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4388 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4389 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4391 | int ivga; |
| 4392 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4393 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 4394 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4395 | TPACPI_ACPIHANDLE_INIT(vid); |
| 4396 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4397 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4398 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 4399 | /* G41, assume IVGA doesn't change */ |
| 4400 | vid_handle = vid2_handle; |
| 4401 | |
| 4402 | if (!vid_handle) |
| 4403 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4404 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4405 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 4406 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4407 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4408 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 4409 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4410 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4411 | else |
| 4412 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4413 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4415 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 4416 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 4417 | video_supported); |
| 4418 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4419 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4422 | static void video_exit(void) |
| 4423 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4424 | dbg_printk(TPACPI_DBG_EXIT, |
| 4425 | "restoring original video autoswitch mode\n"); |
| 4426 | if (video_autosw_set(video_orig_autosw)) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4427 | printk(TPACPI_ERR "error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4428 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4429 | } |
| 4430 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4431 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | { |
| 4433 | int status = 0; |
| 4434 | int i; |
| 4435 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4436 | switch (video_supported) { |
| 4437 | case TPACPI_VIDEO_570: |
| 4438 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 4439 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 4440 | return -EIO; |
| 4441 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 4442 | break; |
| 4443 | case TPACPI_VIDEO_770: |
| 4444 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4445 | return -EIO; |
| 4446 | if (i) |
| 4447 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4448 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4449 | return -EIO; |
| 4450 | if (i) |
| 4451 | status |= TP_ACPI_VIDEO_S_CRT; |
| 4452 | break; |
| 4453 | case TPACPI_VIDEO_NEW: |
| 4454 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 4455 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4456 | return -EIO; |
| 4457 | if (i) |
| 4458 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4460 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 4461 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4462 | return -EIO; |
| 4463 | if (i) |
| 4464 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4465 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 4466 | return -EIO; |
| 4467 | if (i) |
| 4468 | status |= TP_ACPI_VIDEO_S_DVI; |
| 4469 | break; |
| 4470 | default: |
| 4471 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4472 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | |
| 4474 | return status; |
| 4475 | } |
| 4476 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4477 | static int video_outputsw_set(int status) |
| 4478 | { |
| 4479 | int autosw; |
| 4480 | int res = 0; |
| 4481 | |
| 4482 | switch (video_supported) { |
| 4483 | case TPACPI_VIDEO_570: |
| 4484 | res = acpi_evalf(NULL, NULL, |
| 4485 | "\\_SB.PHS2", "vdd", |
| 4486 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 4487 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 4488 | break; |
| 4489 | case TPACPI_VIDEO_770: |
| 4490 | autosw = video_autosw_get(); |
| 4491 | if (autosw < 0) |
| 4492 | return autosw; |
| 4493 | |
| 4494 | res = video_autosw_set(1); |
| 4495 | if (res) |
| 4496 | return res; |
| 4497 | res = acpi_evalf(vid_handle, NULL, |
| 4498 | "ASWT", "vdd", status * 0x100, 0); |
| 4499 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4500 | printk(TPACPI_ERR |
| 4501 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4502 | return -EIO; |
| 4503 | } |
| 4504 | break; |
| 4505 | case TPACPI_VIDEO_NEW: |
| 4506 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4507 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4508 | break; |
| 4509 | default: |
| 4510 | return -ENOSYS; |
| 4511 | } |
| 4512 | |
| 4513 | return (res)? 0 : -EIO; |
| 4514 | } |
| 4515 | |
| 4516 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4518 | int autosw = 0; |
| 4519 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4520 | switch (video_supported) { |
| 4521 | case TPACPI_VIDEO_570: |
| 4522 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 4523 | return -EIO; |
| 4524 | break; |
| 4525 | case TPACPI_VIDEO_770: |
| 4526 | case TPACPI_VIDEO_NEW: |
| 4527 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 4528 | return -EIO; |
| 4529 | break; |
| 4530 | default: |
| 4531 | return -ENOSYS; |
| 4532 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4533 | |
| 4534 | return autosw & 1; |
| 4535 | } |
| 4536 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4537 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4538 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4539 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4540 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4541 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4542 | } |
| 4543 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4544 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4545 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4546 | int autosw = video_autosw_get(); |
| 4547 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4548 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4549 | if (autosw < 0) |
| 4550 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4551 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4552 | switch (video_supported) { |
| 4553 | case TPACPI_VIDEO_570: |
| 4554 | res = video_autosw_set(1); |
| 4555 | if (res) |
| 4556 | return res; |
| 4557 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 4558 | break; |
| 4559 | case TPACPI_VIDEO_770: |
| 4560 | case TPACPI_VIDEO_NEW: |
| 4561 | res = video_autosw_set(1); |
| 4562 | if (res) |
| 4563 | return res; |
| 4564 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 4565 | break; |
| 4566 | default: |
| 4567 | return -ENOSYS; |
| 4568 | } |
| 4569 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4570 | printk(TPACPI_ERR |
| 4571 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4572 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4573 | } |
| 4574 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4575 | return (res)? 0 : -EIO; |
| 4576 | } |
| 4577 | |
| 4578 | static int video_expand_toggle(void) |
| 4579 | { |
| 4580 | switch (video_supported) { |
| 4581 | case TPACPI_VIDEO_570: |
| 4582 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 4583 | 0 : -EIO; |
| 4584 | case TPACPI_VIDEO_770: |
| 4585 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 4586 | 0 : -EIO; |
| 4587 | case TPACPI_VIDEO_NEW: |
| 4588 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 4589 | 0 : -EIO; |
| 4590 | default: |
| 4591 | return -ENOSYS; |
| 4592 | } |
| 4593 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4594 | } |
| 4595 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4596 | static int video_read(char *p) |
| 4597 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4598 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4599 | int len = 0; |
| 4600 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4601 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4602 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4603 | return len; |
| 4604 | } |
| 4605 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4606 | status = video_outputsw_get(); |
| 4607 | if (status < 0) |
| 4608 | return status; |
| 4609 | |
| 4610 | autosw = video_autosw_get(); |
| 4611 | if (autosw < 0) |
| 4612 | return autosw; |
| 4613 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4614 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 4615 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 4616 | 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] | 4617 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4618 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 4619 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 4620 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 4621 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4622 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4623 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 4624 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 4625 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 4626 | |
| 4627 | return len; |
| 4628 | } |
| 4629 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4630 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | { |
| 4632 | char *cmd; |
| 4633 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4634 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4636 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4637 | return -ENODEV; |
| 4638 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4639 | enable = 0; |
| 4640 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | |
| 4642 | while ((cmd = next_cmd(&buf))) { |
| 4643 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4644 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4646 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4648 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4650 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4651 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4652 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4653 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4654 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4655 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4656 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4658 | res = video_autosw_set(1); |
| 4659 | if (res) |
| 4660 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4662 | res = video_autosw_set(0); |
| 4663 | if (res) |
| 4664 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4666 | res = video_outputsw_cycle(); |
| 4667 | if (res) |
| 4668 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4670 | res = video_expand_toggle(); |
| 4671 | if (res) |
| 4672 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | } else |
| 4674 | return -EINVAL; |
| 4675 | } |
| 4676 | |
| 4677 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4678 | status = video_outputsw_get(); |
| 4679 | if (status < 0) |
| 4680 | return status; |
| 4681 | res = video_outputsw_set((status & ~disable) | enable); |
| 4682 | if (res) |
| 4683 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | return 0; |
| 4687 | } |
| 4688 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4689 | static struct ibm_struct video_driver_data = { |
| 4690 | .name = "video", |
| 4691 | .read = video_read, |
| 4692 | .write = video_write, |
| 4693 | .exit = video_exit, |
| 4694 | }; |
| 4695 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4696 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 4697 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4698 | /************************************************************************* |
| 4699 | * Light (thinklight) subdriver |
| 4700 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4702 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 4703 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4704 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4705 | static int light_get_status(void) |
| 4706 | { |
| 4707 | int status = 0; |
| 4708 | |
| 4709 | if (tp_features.light_status) { |
| 4710 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 4711 | return -EIO; |
| 4712 | return (!!status); |
| 4713 | } |
| 4714 | |
| 4715 | return -ENXIO; |
| 4716 | } |
| 4717 | |
| 4718 | static int light_set_status(int status) |
| 4719 | { |
| 4720 | int rc; |
| 4721 | |
| 4722 | if (tp_features.light) { |
| 4723 | if (cmos_handle) { |
| 4724 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", |
| 4725 | (status)? |
| 4726 | TP_CMOS_THINKLIGHT_ON : |
| 4727 | TP_CMOS_THINKLIGHT_OFF); |
| 4728 | } else { |
| 4729 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", |
| 4730 | (status)? 1 : 0); |
| 4731 | } |
| 4732 | return (rc)? 0 : -EIO; |
| 4733 | } |
| 4734 | |
| 4735 | return -ENXIO; |
| 4736 | } |
| 4737 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4738 | static void light_set_status_worker(struct work_struct *work) |
| 4739 | { |
| 4740 | struct tpacpi_led_classdev *data = |
| 4741 | container_of(work, struct tpacpi_led_classdev, work); |
| 4742 | |
| 4743 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4744 | light_set_status((data->new_state != TPACPI_LED_OFF)); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | static void light_sysfs_set(struct led_classdev *led_cdev, |
| 4748 | enum led_brightness brightness) |
| 4749 | { |
| 4750 | struct tpacpi_led_classdev *data = |
| 4751 | container_of(led_cdev, |
| 4752 | struct tpacpi_led_classdev, |
| 4753 | led_classdev); |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4754 | data->new_state = (brightness != LED_OFF) ? |
| 4755 | TPACPI_LED_ON : TPACPI_LED_OFF; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4756 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4757 | } |
| 4758 | |
| 4759 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) |
| 4760 | { |
| 4761 | return (light_get_status() == 1)? LED_FULL : LED_OFF; |
| 4762 | } |
| 4763 | |
| 4764 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { |
| 4765 | .led_classdev = { |
| 4766 | .name = "tpacpi::thinklight", |
| 4767 | .brightness_set = &light_sysfs_set, |
| 4768 | .brightness_get = &light_sysfs_get, |
| 4769 | } |
| 4770 | }; |
| 4771 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4772 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4774 | int rc; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4775 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4776 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 4777 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4778 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 4779 | TPACPI_ACPIHANDLE_INIT(lght); |
| 4780 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4781 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4782 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4783 | /* 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] | 4784 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4785 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4786 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4787 | /* light status not supported on |
| 4788 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4789 | tp_features.light_status = |
| 4790 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4792 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
| 4793 | str_supported(tp_features.light), |
| 4794 | str_supported(tp_features.light_status)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4795 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4796 | if (!tp_features.light) |
| 4797 | return 1; |
| 4798 | |
| 4799 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 4800 | &tpacpi_led_thinklight.led_classdev); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4801 | |
| 4802 | if (rc < 0) { |
| 4803 | tp_features.light = 0; |
| 4804 | tp_features.light_status = 0; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4805 | } else { |
| 4806 | rc = 0; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4807 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4808 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4809 | return rc; |
| 4810 | } |
| 4811 | |
| 4812 | static void light_exit(void) |
| 4813 | { |
| 4814 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); |
| 4815 | if (work_pending(&tpacpi_led_thinklight.work)) |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4816 | flush_workqueue(tpacpi_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | } |
| 4818 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4819 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | { |
| 4821 | int len = 0; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4822 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4824 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4825 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4826 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4827 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 4828 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 4829 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4830 | status = light_get_status(); |
| 4831 | if (status < 0) |
| 4832 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4833 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4834 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 4835 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | |
| 4837 | return len; |
| 4838 | } |
| 4839 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4840 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4843 | int newstatus = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4844 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4845 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4846 | return -ENODEV; |
| 4847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | while ((cmd = next_cmd(&buf))) { |
| 4849 | if (strlencmp(cmd, "on") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4850 | newstatus = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | } else if (strlencmp(cmd, "off") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4852 | newstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 | } else |
| 4854 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | } |
| 4856 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4857 | return light_set_status(newstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | } |
| 4859 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4860 | static struct ibm_struct light_driver_data = { |
| 4861 | .name = "light", |
| 4862 | .read = light_read, |
| 4863 | .write = light_write, |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4864 | .exit = light_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4865 | }; |
| 4866 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4867 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4868 | * CMOS subdriver |
| 4869 | */ |
| 4870 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4871 | /* sysfs cmos_command -------------------------------------------------- */ |
| 4872 | static ssize_t cmos_command_store(struct device *dev, |
| 4873 | struct device_attribute *attr, |
| 4874 | const char *buf, size_t count) |
| 4875 | { |
| 4876 | unsigned long cmos_cmd; |
| 4877 | int res; |
| 4878 | |
| 4879 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 4880 | return -EINVAL; |
| 4881 | |
| 4882 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4883 | return (res)? res : count; |
| 4884 | } |
| 4885 | |
| 4886 | static struct device_attribute dev_attr_cmos_command = |
| 4887 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 4888 | |
| 4889 | /* --------------------------------------------------------------------- */ |
| 4890 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4891 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4892 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4893 | int res; |
| 4894 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4895 | vdbg_printk(TPACPI_DBG_INIT, |
| 4896 | "initializing cmos commands subdriver\n"); |
| 4897 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4898 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4899 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4900 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 4901 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4902 | |
| 4903 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4904 | if (res) |
| 4905 | return res; |
| 4906 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4907 | return (cmos_handle)? 0 : 1; |
| 4908 | } |
| 4909 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4910 | static void cmos_exit(void) |
| 4911 | { |
| 4912 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4913 | } |
| 4914 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4915 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | { |
| 4917 | int len = 0; |
| 4918 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4919 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4920 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | if (!cmos_handle) |
| 4922 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4923 | else { |
| 4924 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4925 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | return len; |
| 4929 | } |
| 4930 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4931 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | { |
| 4933 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4934 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4935 | |
| 4936 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4937 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 4938 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | /* cmos_cmd set */ |
| 4940 | } else |
| 4941 | return -EINVAL; |
| 4942 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4943 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4944 | if (res) |
| 4945 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4949 | } |
| 4950 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4951 | static struct ibm_struct cmos_driver_data = { |
| 4952 | .name = "cmos", |
| 4953 | .read = cmos_read, |
| 4954 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4955 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4956 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4957 | |
| 4958 | /************************************************************************* |
| 4959 | * LED subdriver |
| 4960 | */ |
| 4961 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4962 | enum led_access_mode { |
| 4963 | TPACPI_LED_NONE = 0, |
| 4964 | TPACPI_LED_570, /* 570 */ |
| 4965 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 4966 | TPACPI_LED_NEW, /* all others */ |
| 4967 | }; |
| 4968 | |
| 4969 | enum { /* For TPACPI_LED_OLD */ |
| 4970 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 4971 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 4972 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 4973 | }; |
| 4974 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4975 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4976 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4977 | TPACPI_HANDLE(led, ec, "SLED", /* 570 */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4978 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */ |
| 4979 | /* T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4980 | "LED", /* all others */ |
| 4981 | ); /* R30, R31 */ |
| 4982 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4983 | #define TPACPI_LED_NUMLEDS 16 |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4984 | static struct tpacpi_led_classdev *tpacpi_leds; |
| 4985 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; |
Harvey Harrison | e3aa51f | 2008-05-29 17:51:57 -0700 | [diff] [blame] | 4986 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4987 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
| 4988 | "tpacpi::power", |
| 4989 | "tpacpi:orange:batt", |
| 4990 | "tpacpi:green:batt", |
| 4991 | "tpacpi::dock_active", |
| 4992 | "tpacpi::bay_active", |
| 4993 | "tpacpi::dock_batt", |
| 4994 | "tpacpi::unknown_led", |
| 4995 | "tpacpi::standby", |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4996 | "tpacpi::dock_status1", |
| 4997 | "tpacpi::dock_status2", |
| 4998 | "tpacpi::unknown_led2", |
| 4999 | "tpacpi::unknown_led3", |
| 5000 | "tpacpi::thinkvantage", |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5001 | }; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5002 | #define TPACPI_SAFE_LEDS 0x1081U |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5003 | |
| 5004 | static inline bool tpacpi_is_led_restricted(const unsigned int led) |
| 5005 | { |
| 5006 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
| 5007 | return false; |
| 5008 | #else |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5009 | return (1U & (TPACPI_SAFE_LEDS >> led)) == 0; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5010 | #endif |
| 5011 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5012 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5013 | static int led_get_status(const unsigned int led) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5014 | { |
| 5015 | int status; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5016 | enum led_status_t led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5017 | |
| 5018 | switch (led_supported) { |
| 5019 | case TPACPI_LED_570: |
| 5020 | if (!acpi_evalf(ec_handle, |
| 5021 | &status, "GLED", "dd", 1 << led)) |
| 5022 | return -EIO; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5023 | led_s = (status == 0)? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5024 | TPACPI_LED_OFF : |
| 5025 | ((status == 1)? |
| 5026 | TPACPI_LED_ON : |
| 5027 | TPACPI_LED_BLINK); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5028 | tpacpi_led_state_cache[led] = led_s; |
| 5029 | return led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5030 | default: |
| 5031 | return -ENXIO; |
| 5032 | } |
| 5033 | |
| 5034 | /* not reached */ |
| 5035 | } |
| 5036 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5037 | static int led_set_status(const unsigned int led, |
| 5038 | const enum led_status_t ledstatus) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5039 | { |
| 5040 | /* off, on, blink. Index is led_status_t */ |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5041 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
| 5042 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5043 | |
| 5044 | int rc = 0; |
| 5045 | |
| 5046 | switch (led_supported) { |
| 5047 | case TPACPI_LED_570: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5048 | /* 570 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5049 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5050 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5051 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5052 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5053 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5054 | (1 << led), led_sled_arg1[ledstatus])) |
| 5055 | rc = -EIO; |
| 5056 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5057 | case TPACPI_LED_OLD: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5058 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5059 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5060 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5061 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5062 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5063 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
| 5064 | if (rc >= 0) |
| 5065 | rc = ec_write(TPACPI_LED_EC_HLBL, |
| 5066 | (ledstatus == TPACPI_LED_BLINK) << led); |
| 5067 | if (rc >= 0) |
| 5068 | rc = ec_write(TPACPI_LED_EC_HLCL, |
| 5069 | (ledstatus != TPACPI_LED_OFF) << led); |
| 5070 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5071 | case TPACPI_LED_NEW: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5072 | /* all others */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5073 | if (unlikely(led >= TPACPI_LED_NUMLEDS)) |
| 5074 | return -EINVAL; |
| 5075 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5076 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5077 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5078 | led, led_led_arg1[ledstatus])) |
| 5079 | rc = -EIO; |
| 5080 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5081 | default: |
| 5082 | rc = -ENXIO; |
| 5083 | } |
| 5084 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5085 | if (!rc) |
| 5086 | tpacpi_led_state_cache[led] = ledstatus; |
| 5087 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5088 | return rc; |
| 5089 | } |
| 5090 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5091 | static void led_set_status_worker(struct work_struct *work) |
| 5092 | { |
| 5093 | struct tpacpi_led_classdev *data = |
| 5094 | container_of(work, struct tpacpi_led_classdev, work); |
| 5095 | |
| 5096 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5097 | led_set_status(data->led, data->new_state); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | static void led_sysfs_set(struct led_classdev *led_cdev, |
| 5101 | enum led_brightness brightness) |
| 5102 | { |
| 5103 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5104 | struct tpacpi_led_classdev, led_classdev); |
| 5105 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5106 | if (brightness == LED_OFF) |
| 5107 | data->new_state = TPACPI_LED_OFF; |
| 5108 | else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) |
| 5109 | data->new_state = TPACPI_LED_ON; |
| 5110 | else |
| 5111 | data->new_state = TPACPI_LED_BLINK; |
| 5112 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5113 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5114 | } |
| 5115 | |
| 5116 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, |
| 5117 | unsigned long *delay_on, unsigned long *delay_off) |
| 5118 | { |
| 5119 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5120 | struct tpacpi_led_classdev, led_classdev); |
| 5121 | |
| 5122 | /* Can we choose the flash rate? */ |
| 5123 | if (*delay_on == 0 && *delay_off == 0) { |
| 5124 | /* yes. set them to the hardware blink rate (1 Hz) */ |
| 5125 | *delay_on = 500; /* ms */ |
| 5126 | *delay_off = 500; /* ms */ |
| 5127 | } else if ((*delay_on != 500) || (*delay_off != 500)) |
| 5128 | return -EINVAL; |
| 5129 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5130 | data->new_state = TPACPI_LED_BLINK; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5131 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5132 | |
| 5133 | return 0; |
| 5134 | } |
| 5135 | |
| 5136 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) |
| 5137 | { |
| 5138 | int rc; |
| 5139 | |
| 5140 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5141 | struct tpacpi_led_classdev, led_classdev); |
| 5142 | |
| 5143 | rc = led_get_status(data->led); |
| 5144 | |
| 5145 | if (rc == TPACPI_LED_OFF || rc < 0) |
| 5146 | rc = LED_OFF; /* no error handling in led class :( */ |
| 5147 | else |
| 5148 | rc = LED_FULL; |
| 5149 | |
| 5150 | return rc; |
| 5151 | } |
| 5152 | |
| 5153 | static void led_exit(void) |
| 5154 | { |
| 5155 | unsigned int i; |
| 5156 | |
| 5157 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 5158 | if (tpacpi_leds[i].led_classdev.name) |
| 5159 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); |
| 5160 | } |
| 5161 | |
| 5162 | kfree(tpacpi_leds); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5163 | } |
| 5164 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5165 | static int __init tpacpi_init_led(unsigned int led) |
| 5166 | { |
| 5167 | int rc; |
| 5168 | |
| 5169 | tpacpi_leds[led].led = led; |
| 5170 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5171 | /* LEDs with no name don't get registered */ |
| 5172 | if (!tpacpi_led_names[led]) |
| 5173 | return 0; |
| 5174 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5175 | tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set; |
| 5176 | tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set; |
| 5177 | if (led_supported == TPACPI_LED_570) |
| 5178 | tpacpi_leds[led].led_classdev.brightness_get = |
| 5179 | &led_sysfs_get; |
| 5180 | |
| 5181 | tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led]; |
| 5182 | |
| 5183 | INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker); |
| 5184 | |
| 5185 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 5186 | &tpacpi_leds[led].led_classdev); |
| 5187 | if (rc < 0) |
| 5188 | tpacpi_leds[led].led_classdev.name = NULL; |
| 5189 | |
| 5190 | return rc; |
| 5191 | } |
| 5192 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5193 | static const struct tpacpi_quirk led_useful_qtable[] __initconst = { |
| 5194 | TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */ |
| 5195 | TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */ |
| 5196 | TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */ |
| 5197 | |
| 5198 | TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */ |
| 5199 | TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */ |
| 5200 | TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */ |
| 5201 | TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */ |
| 5202 | TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */ |
| 5203 | TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */ |
| 5204 | TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */ |
| 5205 | TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */ |
| 5206 | |
| 5207 | TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */ |
| 5208 | TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */ |
| 5209 | TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */ |
| 5210 | TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */ |
| 5211 | TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */ |
| 5212 | |
| 5213 | TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */ |
| 5214 | TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */ |
| 5215 | TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */ |
| 5216 | TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */ |
| 5217 | |
| 5218 | /* (1) - may have excess leds enabled on MSB */ |
| 5219 | |
| 5220 | /* Defaults (order matters, keep last, don't reorder!) */ |
| 5221 | { /* Lenovo */ |
| 5222 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 5223 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5224 | .quirks = 0x1fffU, |
| 5225 | }, |
| 5226 | { /* IBM ThinkPads with no EC version string */ |
| 5227 | .vendor = PCI_VENDOR_ID_IBM, |
| 5228 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_UNKNOWN, |
| 5229 | .quirks = 0x00ffU, |
| 5230 | }, |
| 5231 | { /* IBM ThinkPads with EC version string */ |
| 5232 | .vendor = PCI_VENDOR_ID_IBM, |
| 5233 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5234 | .quirks = 0x00bfU, |
| 5235 | }, |
| 5236 | }; |
| 5237 | |
| 5238 | #undef TPACPI_LEDQ_IBM |
| 5239 | #undef TPACPI_LEDQ_LNV |
| 5240 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5241 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5242 | { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5243 | unsigned int i; |
| 5244 | int rc; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5245 | unsigned long useful_leds; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5246 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5247 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 5248 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5249 | TPACPI_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5250 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5251 | if (!led_handle) |
| 5252 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5253 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5254 | else if (strlencmp(led_path, "SLED") == 0) |
| 5255 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5256 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5257 | else if (strlencmp(led_path, "SYSL") == 0) |
| 5258 | /* 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] | 5259 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5260 | else |
| 5261 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5262 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5263 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5264 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 5265 | str_supported(led_supported), led_supported); |
| 5266 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5267 | if (led_supported == TPACPI_LED_NONE) |
| 5268 | return 1; |
| 5269 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5270 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
| 5271 | GFP_KERNEL); |
| 5272 | if (!tpacpi_leds) { |
| 5273 | printk(TPACPI_ERR "Out of memory for LED data\n"); |
| 5274 | return -ENOMEM; |
| 5275 | } |
| 5276 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5277 | useful_leds = tpacpi_check_quirks(led_useful_qtable, |
| 5278 | ARRAY_SIZE(led_useful_qtable)); |
| 5279 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5280 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5281 | if (!tpacpi_is_led_restricted(i) && |
| 5282 | test_bit(i, &useful_leds)) { |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5283 | rc = tpacpi_init_led(i); |
| 5284 | if (rc < 0) { |
| 5285 | led_exit(); |
| 5286 | return rc; |
| 5287 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5288 | } |
| 5289 | } |
| 5290 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5291 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5292 | printk(TPACPI_NOTICE |
| 5293 | "warning: userspace override of important " |
| 5294 | "firmware LEDs is enabled\n"); |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5295 | #endif |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5296 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5297 | } |
| 5298 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5299 | #define str_led_status(s) \ |
| 5300 | ((s) == TPACPI_LED_OFF ? "off" : \ |
| 5301 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5302 | |
| 5303 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5304 | { |
| 5305 | int len = 0; |
| 5306 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5307 | if (!led_supported) { |
| 5308 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5309 | return len; |
| 5310 | } |
| 5311 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 5312 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5313 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5314 | /* 570 */ |
| 5315 | int i, status; |
| 5316 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5317 | status = led_get_status(i); |
| 5318 | if (status < 0) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5319 | return -EIO; |
| 5320 | len += sprintf(p + len, "%d:\t\t%s\n", |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5321 | i, str_led_status(status)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5322 | } |
| 5323 | } |
| 5324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | len += sprintf(p + len, "commands:\t" |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5326 | "<led> on, <led> off, <led> blink (<led> is 0-15)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 | |
| 5328 | return len; |
| 5329 | } |
| 5330 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5331 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5332 | { |
| 5333 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5334 | int led, rc; |
| 5335 | enum led_status_t s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5336 | |
| 5337 | if (!led_supported) |
| 5338 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5339 | |
| 5340 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5341 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5342 | return -EINVAL; |
| 5343 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5344 | if (strstr(cmd, "off")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5345 | s = TPACPI_LED_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5346 | } else if (strstr(cmd, "on")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5347 | s = TPACPI_LED_ON; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5348 | } else if (strstr(cmd, "blink")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5349 | s = TPACPI_LED_BLINK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5350 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5351 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5352 | } |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5353 | |
| 5354 | rc = led_set_status(led, s); |
| 5355 | if (rc < 0) |
| 5356 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5360 | } |
| 5361 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5362 | static struct ibm_struct led_driver_data = { |
| 5363 | .name = "led", |
| 5364 | .read = led_read, |
| 5365 | .write = led_write, |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5366 | .exit = led_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5367 | }; |
| 5368 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5369 | /************************************************************************* |
| 5370 | * Beep subdriver |
| 5371 | */ |
| 5372 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5373 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5374 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5375 | #define TPACPI_BEEP_Q1 0x0001 |
| 5376 | |
| 5377 | static const struct tpacpi_quirk beep_quirk_table[] __initconst = { |
| 5378 | TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1), /* 570 */ |
| 5379 | TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */ |
| 5380 | }; |
| 5381 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5382 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5383 | { |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5384 | unsigned long quirks; |
| 5385 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5386 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 5387 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5388 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5389 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5390 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 5391 | str_supported(beep_handle != NULL)); |
| 5392 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5393 | quirks = tpacpi_check_quirks(beep_quirk_table, |
| 5394 | ARRAY_SIZE(beep_quirk_table)); |
| 5395 | |
| 5396 | tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); |
| 5397 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5398 | return (beep_handle)? 0 : 1; |
| 5399 | } |
| 5400 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5401 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5402 | { |
| 5403 | int len = 0; |
| 5404 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5405 | if (!beep_handle) |
| 5406 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5407 | else { |
| 5408 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 5409 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 5410 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5411 | |
| 5412 | return len; |
| 5413 | } |
| 5414 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5415 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5416 | { |
| 5417 | char *cmd; |
| 5418 | int beep_cmd; |
| 5419 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5420 | if (!beep_handle) |
| 5421 | return -ENODEV; |
| 5422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5424 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 5425 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5426 | /* beep_cmd set */ |
| 5427 | } else |
| 5428 | return -EINVAL; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5429 | if (tp_features.beep_needs_two_args) { |
| 5430 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", |
| 5431 | beep_cmd, 0)) |
| 5432 | return -EIO; |
| 5433 | } else { |
| 5434 | if (!acpi_evalf(beep_handle, NULL, NULL, "vd", |
| 5435 | beep_cmd)) |
| 5436 | return -EIO; |
| 5437 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5441 | } |
| 5442 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5443 | static struct ibm_struct beep_driver_data = { |
| 5444 | .name = "beep", |
| 5445 | .read = beep_read, |
| 5446 | .write = beep_write, |
| 5447 | }; |
| 5448 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5449 | /************************************************************************* |
| 5450 | * Thermal subdriver |
| 5451 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5452 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5453 | enum thermal_access_mode { |
| 5454 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 5455 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 5456 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 5457 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 5458 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 5459 | }; |
| 5460 | |
| 5461 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 5462 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 5463 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 5464 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
| 5465 | }; |
| 5466 | |
| 5467 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 5468 | struct ibm_thermal_sensors_struct { |
| 5469 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 5470 | }; |
| 5471 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5472 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5473 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5474 | /* idx is zero-based */ |
| 5475 | static int thermal_get_sensor(int idx, s32 *value) |
| 5476 | { |
| 5477 | int t; |
| 5478 | s8 tmp; |
| 5479 | char tmpi[5]; |
| 5480 | |
| 5481 | t = TP_EC_THERMAL_TMP0; |
| 5482 | |
| 5483 | switch (thermal_read_mode) { |
| 5484 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 5485 | case TPACPI_THERMAL_TPEC_16: |
| 5486 | if (idx >= 8 && idx <= 15) { |
| 5487 | t = TP_EC_THERMAL_TMP8; |
| 5488 | idx -= 8; |
| 5489 | } |
| 5490 | /* fallthrough */ |
| 5491 | #endif |
| 5492 | case TPACPI_THERMAL_TPEC_8: |
| 5493 | if (idx <= 7) { |
| 5494 | if (!acpi_ec_read(t + idx, &tmp)) |
| 5495 | return -EIO; |
| 5496 | *value = tmp * 1000; |
| 5497 | return 0; |
| 5498 | } |
| 5499 | break; |
| 5500 | |
| 5501 | case TPACPI_THERMAL_ACPI_UPDT: |
| 5502 | if (idx <= 7) { |
| 5503 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5504 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 5505 | return -EIO; |
| 5506 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5507 | return -EIO; |
| 5508 | *value = (t - 2732) * 100; |
| 5509 | return 0; |
| 5510 | } |
| 5511 | break; |
| 5512 | |
| 5513 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5514 | if (idx <= 7) { |
| 5515 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5516 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5517 | return -EIO; |
| 5518 | if (t > 127 || t < -127) |
| 5519 | t = TP_EC_THERMAL_TMP_NA; |
| 5520 | *value = t * 1000; |
| 5521 | return 0; |
| 5522 | } |
| 5523 | break; |
| 5524 | |
| 5525 | case TPACPI_THERMAL_NONE: |
| 5526 | default: |
| 5527 | return -ENOSYS; |
| 5528 | } |
| 5529 | |
| 5530 | return -EINVAL; |
| 5531 | } |
| 5532 | |
| 5533 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 5534 | { |
| 5535 | int res, i; |
| 5536 | int n; |
| 5537 | |
| 5538 | n = 8; |
| 5539 | i = 0; |
| 5540 | |
| 5541 | if (!s) |
| 5542 | return -EINVAL; |
| 5543 | |
| 5544 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 5545 | n = 16; |
| 5546 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5547 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5548 | res = thermal_get_sensor(i, &s->temp[i]); |
| 5549 | if (res) |
| 5550 | return res; |
| 5551 | } |
| 5552 | |
| 5553 | return n; |
| 5554 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5555 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5556 | /* sysfs temp##_input -------------------------------------------------- */ |
| 5557 | |
| 5558 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 5559 | struct device_attribute *attr, |
| 5560 | char *buf) |
| 5561 | { |
| 5562 | struct sensor_device_attribute *sensor_attr = |
| 5563 | to_sensor_dev_attr(attr); |
| 5564 | int idx = sensor_attr->index; |
| 5565 | s32 value; |
| 5566 | int res; |
| 5567 | |
| 5568 | res = thermal_get_sensor(idx, &value); |
| 5569 | if (res) |
| 5570 | return res; |
| 5571 | if (value == TP_EC_THERMAL_TMP_NA * 1000) |
| 5572 | return -ENXIO; |
| 5573 | |
| 5574 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 5575 | } |
| 5576 | |
| 5577 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5578 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 5579 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5580 | |
| 5581 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 5582 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 5583 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 5584 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 5585 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 5586 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 5587 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 5588 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 5589 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 5590 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 5591 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 5592 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 5593 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 5594 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 5595 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 5596 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 5597 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 5598 | }; |
| 5599 | |
| 5600 | #define THERMAL_ATTRS(X) \ |
| 5601 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 5602 | |
| 5603 | static struct attribute *thermal_temp_input_attr[] = { |
| 5604 | THERMAL_ATTRS(8), |
| 5605 | THERMAL_ATTRS(9), |
| 5606 | THERMAL_ATTRS(10), |
| 5607 | THERMAL_ATTRS(11), |
| 5608 | THERMAL_ATTRS(12), |
| 5609 | THERMAL_ATTRS(13), |
| 5610 | THERMAL_ATTRS(14), |
| 5611 | THERMAL_ATTRS(15), |
| 5612 | THERMAL_ATTRS(0), |
| 5613 | THERMAL_ATTRS(1), |
| 5614 | THERMAL_ATTRS(2), |
| 5615 | THERMAL_ATTRS(3), |
| 5616 | THERMAL_ATTRS(4), |
| 5617 | THERMAL_ATTRS(5), |
| 5618 | THERMAL_ATTRS(6), |
| 5619 | THERMAL_ATTRS(7), |
| 5620 | NULL |
| 5621 | }; |
| 5622 | |
| 5623 | static const struct attribute_group thermal_temp_input16_group = { |
| 5624 | .attrs = thermal_temp_input_attr |
| 5625 | }; |
| 5626 | |
| 5627 | static const struct attribute_group thermal_temp_input8_group = { |
| 5628 | .attrs = &thermal_temp_input_attr[8] |
| 5629 | }; |
| 5630 | |
| 5631 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 5632 | #undef THERMAL_ATTRS |
| 5633 | |
| 5634 | /* --------------------------------------------------------------------- */ |
| 5635 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5636 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5637 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5638 | u8 t, ta1, ta2; |
| 5639 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5640 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5641 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5642 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5643 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 5644 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5645 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5646 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 5647 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5648 | /* |
| 5649 | * Direct EC access mode: sensors at registers |
| 5650 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 5651 | * non-implemented, thermal sensors return 0x80 when |
| 5652 | * not available |
| 5653 | */ |
| 5654 | |
| 5655 | ta1 = ta2 = 0; |
| 5656 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5657 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5658 | ta1 |= t; |
| 5659 | } else { |
| 5660 | ta1 = 0; |
| 5661 | break; |
| 5662 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5663 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5664 | ta2 |= t; |
| 5665 | } else { |
| 5666 | ta1 = 0; |
| 5667 | break; |
| 5668 | } |
| 5669 | } |
| 5670 | if (ta1 == 0) { |
| 5671 | /* This is sheer paranoia, but we handle it anyway */ |
| 5672 | if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5673 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5674 | "ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5675 | "falling back to ACPI TMPx access " |
| 5676 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5677 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5678 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5679 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5680 | "ThinkPad ACPI EC access misbehaving, " |
| 5681 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5682 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5683 | } |
| 5684 | } else { |
| 5685 | thermal_read_mode = |
| 5686 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5687 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5688 | } |
| 5689 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5690 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 5691 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5692 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5693 | } else { |
| 5694 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5695 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5696 | } |
| 5697 | } else { |
| 5698 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5699 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5700 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5701 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5702 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 5703 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 5704 | thermal_read_mode); |
| 5705 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5706 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5707 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5708 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5709 | &thermal_temp_input16_group); |
| 5710 | if (res) |
| 5711 | return res; |
| 5712 | break; |
| 5713 | case TPACPI_THERMAL_TPEC_8: |
| 5714 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5715 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5716 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5717 | &thermal_temp_input8_group); |
| 5718 | if (res) |
| 5719 | return res; |
| 5720 | break; |
| 5721 | case TPACPI_THERMAL_NONE: |
| 5722 | default: |
| 5723 | return 1; |
| 5724 | } |
| 5725 | |
| 5726 | return 0; |
| 5727 | } |
| 5728 | |
| 5729 | static void thermal_exit(void) |
| 5730 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5731 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5732 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5733 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5734 | &thermal_temp_input16_group); |
| 5735 | break; |
| 5736 | case TPACPI_THERMAL_TPEC_8: |
| 5737 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5738 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5739 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5740 | &thermal_temp_input16_group); |
| 5741 | break; |
| 5742 | case TPACPI_THERMAL_NONE: |
| 5743 | default: |
| 5744 | break; |
| 5745 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5746 | } |
| 5747 | |
| 5748 | static int thermal_read(char *p) |
| 5749 | { |
| 5750 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5751 | int n, i; |
| 5752 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5753 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5754 | n = thermal_get_sensors(&t); |
| 5755 | if (unlikely(n < 0)) |
| 5756 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5757 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5758 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5759 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5760 | if (n > 0) { |
| 5761 | for (i = 0; i < (n - 1); i++) |
| 5762 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 5763 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 5764 | } else |
| 5765 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5766 | |
| 5767 | return len; |
| 5768 | } |
| 5769 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5770 | static struct ibm_struct thermal_driver_data = { |
| 5771 | .name = "thermal", |
| 5772 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5773 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5774 | }; |
| 5775 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5776 | /************************************************************************* |
| 5777 | * EC Dump subdriver |
| 5778 | */ |
| 5779 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5780 | static u8 ecdump_regs[256]; |
| 5781 | |
| 5782 | static int ecdump_read(char *p) |
| 5783 | { |
| 5784 | int len = 0; |
| 5785 | int i, j; |
| 5786 | u8 v; |
| 5787 | |
| 5788 | len += sprintf(p + len, "EC " |
| 5789 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 5790 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 5791 | for (i = 0; i < 256; i += 16) { |
| 5792 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 5793 | for (j = 0; j < 16; j++) { |
| 5794 | if (!acpi_ec_read(i + j, &v)) |
| 5795 | break; |
| 5796 | if (v != ecdump_regs[i + j]) |
| 5797 | len += sprintf(p + len, " *%02x", v); |
| 5798 | else |
| 5799 | len += sprintf(p + len, " %02x", v); |
| 5800 | ecdump_regs[i + j] = v; |
| 5801 | } |
| 5802 | len += sprintf(p + len, "\n"); |
| 5803 | if (j != 16) |
| 5804 | break; |
| 5805 | } |
| 5806 | |
| 5807 | /* These are way too dangerous to advertise openly... */ |
| 5808 | #if 0 |
| 5809 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 5810 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 5811 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 5812 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 5813 | #endif |
| 5814 | return len; |
| 5815 | } |
| 5816 | |
| 5817 | static int ecdump_write(char *buf) |
| 5818 | { |
| 5819 | char *cmd; |
| 5820 | int i, v; |
| 5821 | |
| 5822 | while ((cmd = next_cmd(&buf))) { |
| 5823 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 5824 | /* i and v set */ |
| 5825 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 5826 | /* i and v set */ |
| 5827 | } else |
| 5828 | return -EINVAL; |
| 5829 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 5830 | if (!acpi_ec_write(i, v)) |
| 5831 | return -EIO; |
| 5832 | } else |
| 5833 | return -EINVAL; |
| 5834 | } |
| 5835 | |
| 5836 | return 0; |
| 5837 | } |
| 5838 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5839 | static struct ibm_struct ecdump_driver_data = { |
| 5840 | .name = "ecdump", |
| 5841 | .read = ecdump_read, |
| 5842 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5843 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5844 | }; |
| 5845 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5846 | /************************************************************************* |
| 5847 | * Backlight/brightness subdriver |
| 5848 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 5849 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5850 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 5851 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5852 | /* |
| 5853 | * ThinkPads can read brightness from two places: EC HBRV (0x31), or |
| 5854 | * CMOS NVRAM byte 0x5E, bits 0-3. |
| 5855 | * |
| 5856 | * EC HBRV (0x31) has the following layout |
| 5857 | * Bit 7: unknown function |
| 5858 | * Bit 6: unknown function |
| 5859 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 5860 | * Bit 4: must be set to zero to avoid problems |
| 5861 | * Bit 3-0: backlight brightness level |
| 5862 | * |
| 5863 | * brightness_get_raw returns status data in the HBRV layout |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 5864 | * |
| 5865 | * WARNING: The X61 has been verified to use HBRV for something else, so |
| 5866 | * this should be used _only_ on IBM ThinkPads, and maybe with some careful |
| 5867 | * testing on the very early *60 Lenovo models... |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5868 | */ |
| 5869 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5870 | enum { |
| 5871 | TP_EC_BACKLIGHT = 0x31, |
| 5872 | |
| 5873 | /* TP_EC_BACKLIGHT bitmasks */ |
| 5874 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 5875 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 5876 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 5877 | }; |
| 5878 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5879 | enum tpacpi_brightness_access_mode { |
| 5880 | TPACPI_BRGHT_MODE_AUTO = 0, /* Not implemented yet */ |
| 5881 | TPACPI_BRGHT_MODE_EC, /* EC control */ |
| 5882 | TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */ |
| 5883 | TPACPI_BRGHT_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 5884 | TPACPI_BRGHT_MODE_MAX |
| 5885 | }; |
| 5886 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5887 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5888 | |
| 5889 | static enum tpacpi_brightness_access_mode brightness_mode = |
| 5890 | TPACPI_BRGHT_MODE_MAX; |
| 5891 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5892 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 5893 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5894 | static struct mutex brightness_mutex; |
| 5895 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5896 | /* NVRAM brightness access, |
| 5897 | * call with brightness_mutex held! */ |
| 5898 | static unsigned int tpacpi_brightness_nvram_get(void) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5899 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5900 | u8 lnvram; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5901 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5902 | lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 5903 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5904 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 5905 | lnvram &= (tp_features.bright_16levels) ? 0x0f : 0x07; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5906 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5907 | return lnvram; |
| 5908 | } |
| 5909 | |
| 5910 | static void tpacpi_brightness_checkpoint_nvram(void) |
| 5911 | { |
| 5912 | u8 lec = 0; |
| 5913 | u8 b_nvram; |
| 5914 | |
| 5915 | if (brightness_mode != TPACPI_BRGHT_MODE_ECNVRAM) |
| 5916 | return; |
| 5917 | |
| 5918 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5919 | "trying to checkpoint backlight level to NVRAM...\n"); |
| 5920 | |
| 5921 | if (mutex_lock_killable(&brightness_mutex) < 0) |
| 5922 | return; |
| 5923 | |
| 5924 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5925 | goto unlock; |
| 5926 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
| 5927 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 5928 | |
| 5929 | if (lec != ((b_nvram & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5930 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS)) { |
| 5931 | /* NVRAM needs update */ |
| 5932 | b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS << |
| 5933 | TP_NVRAM_POS_LEVEL_BRIGHTNESS); |
| 5934 | b_nvram |= lec; |
| 5935 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_BRIGHTNESS); |
| 5936 | dbg_printk(TPACPI_DBG_BRGHT, |
| 5937 | "updated NVRAM backlight level to %u (0x%02x)\n", |
| 5938 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5939 | } else |
| 5940 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5941 | "NVRAM backlight level already is %u (0x%02x)\n", |
| 5942 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5943 | |
| 5944 | unlock: |
| 5945 | mutex_unlock(&brightness_mutex); |
| 5946 | } |
| 5947 | |
| 5948 | |
| 5949 | /* call with brightness_mutex held! */ |
| 5950 | static int tpacpi_brightness_get_raw(int *status) |
| 5951 | { |
| 5952 | u8 lec = 0; |
| 5953 | |
| 5954 | switch (brightness_mode) { |
| 5955 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 5956 | *status = tpacpi_brightness_nvram_get(); |
| 5957 | return 0; |
| 5958 | case TPACPI_BRGHT_MODE_EC: |
| 5959 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 5960 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 5961 | return -EIO; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5962 | *status = lec; |
| 5963 | return 0; |
| 5964 | default: |
| 5965 | return -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5966 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5967 | } |
| 5968 | |
| 5969 | /* call with brightness_mutex held! */ |
| 5970 | /* do NOT call with illegal backlight level value */ |
| 5971 | static int tpacpi_brightness_set_ec(unsigned int value) |
| 5972 | { |
| 5973 | u8 lec = 0; |
| 5974 | |
| 5975 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5976 | return -EIO; |
| 5977 | |
| 5978 | if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT, |
| 5979 | (lec & TP_EC_BACKLIGHT_CMDMSK) | |
| 5980 | (value & TP_EC_BACKLIGHT_LVLMSK)))) |
| 5981 | return -EIO; |
| 5982 | |
| 5983 | return 0; |
| 5984 | } |
| 5985 | |
| 5986 | /* call with brightness_mutex held! */ |
| 5987 | static int tpacpi_brightness_set_ucmsstep(unsigned int value) |
| 5988 | { |
| 5989 | int cmos_cmd, inc; |
| 5990 | unsigned int current_value, i; |
| 5991 | |
| 5992 | current_value = tpacpi_brightness_nvram_get(); |
| 5993 | |
| 5994 | if (value == current_value) |
| 5995 | return 0; |
| 5996 | |
| 5997 | cmos_cmd = (value > current_value) ? |
| 5998 | TP_CMOS_BRIGHTNESS_UP : |
| 5999 | TP_CMOS_BRIGHTNESS_DOWN; |
| 6000 | inc = (value > current_value) ? 1 : -1; |
| 6001 | |
| 6002 | for (i = current_value; i != value; i += inc) |
| 6003 | if (issue_thinkpad_cmos_command(cmos_cmd)) |
| 6004 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6005 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6006 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6007 | } |
| 6008 | |
| 6009 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6010 | static int brightness_set(unsigned int value) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6011 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6012 | int res; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6013 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6014 | if (value > ((tp_features.bright_16levels)? 15 : 7) || |
| 6015 | value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6016 | return -EINVAL; |
| 6017 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6018 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 6019 | "set backlight level to %d\n", value); |
| 6020 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6021 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6022 | if (res < 0) |
| 6023 | return res; |
| 6024 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6025 | switch (brightness_mode) { |
| 6026 | case TPACPI_BRGHT_MODE_EC: |
| 6027 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 6028 | res = tpacpi_brightness_set_ec(value); |
| 6029 | break; |
| 6030 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 6031 | res = tpacpi_brightness_set_ucmsstep(value); |
| 6032 | break; |
| 6033 | default: |
| 6034 | res = -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6035 | } |
| 6036 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6037 | mutex_unlock(&brightness_mutex); |
| 6038 | return res; |
| 6039 | } |
| 6040 | |
| 6041 | /* sysfs backlight class ----------------------------------------------- */ |
| 6042 | |
| 6043 | static int brightness_update_status(struct backlight_device *bd) |
| 6044 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6045 | unsigned int level = |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6046 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 6047 | bd->props.power == FB_BLANK_UNBLANK) ? |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6048 | bd->props.brightness : 0; |
| 6049 | |
| 6050 | dbg_printk(TPACPI_DBG_BRGHT, |
| 6051 | "backlight: attempt to set level to %d\n", |
| 6052 | level); |
| 6053 | |
| 6054 | /* it is the backlight class's job (caller) to handle |
| 6055 | * EINTR and other errors properly */ |
| 6056 | return brightness_set(level); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6057 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 6058 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6059 | static int brightness_get(struct backlight_device *bd) |
| 6060 | { |
| 6061 | int status, res; |
| 6062 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6063 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6064 | if (res < 0) |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6065 | return 0; |
| 6066 | |
| 6067 | res = tpacpi_brightness_get_raw(&status); |
| 6068 | |
| 6069 | mutex_unlock(&brightness_mutex); |
| 6070 | |
| 6071 | if (res < 0) |
| 6072 | return 0; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6073 | |
| 6074 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 6075 | } |
| 6076 | |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6077 | static void tpacpi_brightness_notify_change(void) |
| 6078 | { |
| 6079 | backlight_force_update(ibm_backlight_device, |
| 6080 | BACKLIGHT_UPDATE_HOTKEY); |
| 6081 | } |
| 6082 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6083 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6084 | .get_brightness = brightness_get, |
| 6085 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6086 | }; |
| 6087 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6088 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6089 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6090 | /* |
| 6091 | * These are only useful for models that have only one possibility |
| 6092 | * of GPU. If the BIOS model handles both ATI and Intel, don't use |
| 6093 | * these quirks. |
| 6094 | */ |
| 6095 | #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */ |
| 6096 | #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */ |
| 6097 | #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */ |
| 6098 | |
| 6099 | static const struct tpacpi_quirk brightness_quirk_table[] __initconst = { |
| 6100 | /* Models with ATI GPUs known to require ECNVRAM mode */ |
| 6101 | TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */ |
| 6102 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6103 | /* Models with ATI GPUs that can use ECNVRAM */ |
| 6104 | TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6105 | TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6106 | TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6107 | TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6108 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6109 | /* Models with Intel Extreme Graphics 2 */ |
| 6110 | TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), |
Henrique de Moraes Holschuh | a9f8eac | 2009-12-09 01:36:21 +0000 | [diff] [blame] | 6111 | TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6112 | TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6113 | |
| 6114 | /* Models with Intel GMA900 */ |
| 6115 | TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC), /* T43, R52 */ |
| 6116 | TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC), /* X41 */ |
| 6117 | TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC), /* X41 Tablet */ |
| 6118 | }; |
| 6119 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6120 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6121 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6122 | int b; |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6123 | unsigned long quirks; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6124 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6125 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 6126 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6127 | mutex_init(&brightness_mutex); |
| 6128 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6129 | quirks = tpacpi_check_quirks(brightness_quirk_table, |
| 6130 | ARRAY_SIZE(brightness_quirk_table)); |
| 6131 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6132 | /* |
| 6133 | * We always attempt to detect acpi support, so as to switch |
| 6134 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 6135 | * going to publish a backlight interface |
| 6136 | */ |
| 6137 | b = tpacpi_check_std_acpi_brightness_support(); |
| 6138 | if (b > 0) { |
Thomas Renninger | 2dba1b5 | 2008-08-01 17:38:03 +0200 | [diff] [blame] | 6139 | |
| 6140 | if (acpi_video_backlight_support()) { |
| 6141 | if (brightness_enable > 1) { |
| 6142 | printk(TPACPI_NOTICE |
| 6143 | "Standard ACPI backlight interface " |
| 6144 | "available, not loading native one.\n"); |
| 6145 | return 1; |
| 6146 | } else if (brightness_enable == 1) { |
| 6147 | printk(TPACPI_NOTICE |
| 6148 | "Backlight control force enabled, even if standard " |
| 6149 | "ACPI backlight interface is available\n"); |
| 6150 | } |
| 6151 | } else { |
| 6152 | if (brightness_enable > 1) { |
| 6153 | printk(TPACPI_NOTICE |
| 6154 | "Standard ACPI backlight interface not " |
| 6155 | "available, thinkpad_acpi native " |
| 6156 | "brightness control enabled\n"); |
| 6157 | } |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 6158 | } |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6159 | } |
| 6160 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6161 | if (!brightness_enable) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6162 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6163 | "brightness support disabled by " |
| 6164 | "module parameter\n"); |
| 6165 | return 1; |
| 6166 | } |
| 6167 | |
| 6168 | if (b > 16) { |
| 6169 | printk(TPACPI_ERR |
| 6170 | "Unsupported brightness interface, " |
| 6171 | "please contact %s\n", TPACPI_MAIL); |
| 6172 | return 1; |
| 6173 | } |
| 6174 | if (b == 16) |
| 6175 | tp_features.bright_16levels = 1; |
| 6176 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6177 | /* |
| 6178 | * Check for module parameter bogosity, note that we |
| 6179 | * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be |
| 6180 | * able to detect "unspecified" |
| 6181 | */ |
| 6182 | if (brightness_mode > TPACPI_BRGHT_MODE_MAX) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6183 | return -EINVAL; |
| 6184 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6185 | /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */ |
| 6186 | if (brightness_mode == TPACPI_BRGHT_MODE_AUTO || |
| 6187 | brightness_mode == TPACPI_BRGHT_MODE_MAX) { |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6188 | if (quirks & TPACPI_BRGHT_Q_EC) |
| 6189 | brightness_mode = TPACPI_BRGHT_MODE_ECNVRAM; |
| 6190 | else |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6191 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
| 6192 | |
| 6193 | dbg_printk(TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6194 | "driver auto-selected brightness_mode=%d\n", |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6195 | brightness_mode); |
| 6196 | } |
| 6197 | |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 6198 | /* Safety */ |
| 6199 | if (thinkpad_id.vendor != PCI_VENDOR_ID_IBM && |
| 6200 | (brightness_mode == TPACPI_BRGHT_MODE_ECNVRAM || |
| 6201 | brightness_mode == TPACPI_BRGHT_MODE_EC)) |
| 6202 | return -EINVAL; |
| 6203 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6204 | if (tpacpi_brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6205 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6206 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6207 | if (tp_features.bright_16levels) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6208 | printk(TPACPI_INFO |
| 6209 | "detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6210 | |
Henrique de Moraes Holschuh | 7d5a015 | 2007-04-24 11:48:20 -0300 | [diff] [blame] | 6211 | ibm_backlight_device = backlight_device_register( |
| 6212 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
| 6213 | &ibm_backlight_data); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6214 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6215 | int rc = PTR_ERR(ibm_backlight_device); |
| 6216 | ibm_backlight_device = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6217 | printk(TPACPI_ERR "Could not register backlight device\n"); |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6218 | return rc; |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6219 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6220 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6221 | "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6222 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6223 | if (quirks & TPACPI_BRGHT_Q_ASK) { |
| 6224 | printk(TPACPI_NOTICE |
| 6225 | "brightness: will use unverified default: " |
| 6226 | "brightness_mode=%d\n", brightness_mode); |
| 6227 | printk(TPACPI_NOTICE |
| 6228 | "brightness: please report to %s whether it works well " |
| 6229 | "or not on your ThinkPad\n", TPACPI_MAIL); |
| 6230 | } |
| 6231 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6232 | ibm_backlight_device->props.max_brightness = |
| 6233 | (tp_features.bright_16levels)? 15 : 7; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6234 | ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6235 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6236 | |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6237 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6238 | "brightness: registering brightness hotkeys " |
| 6239 | "as change notification\n"); |
| 6240 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
| 6241 | | TP_ACPI_HKEY_BRGHTUP_MASK |
| 6242 | | TP_ACPI_HKEY_BRGHTDWN_MASK);; |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6243 | return 0; |
| 6244 | } |
| 6245 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6246 | static void brightness_suspend(pm_message_t state) |
| 6247 | { |
| 6248 | tpacpi_brightness_checkpoint_nvram(); |
| 6249 | } |
| 6250 | |
| 6251 | static void brightness_shutdown(void) |
| 6252 | { |
| 6253 | tpacpi_brightness_checkpoint_nvram(); |
| 6254 | } |
| 6255 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6256 | static void brightness_exit(void) |
| 6257 | { |
| 6258 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6259 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6260 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6261 | backlight_device_unregister(ibm_backlight_device); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6262 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6263 | |
| 6264 | tpacpi_brightness_checkpoint_nvram(); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6265 | } |
| 6266 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6267 | static int brightness_read(char *p) |
| 6268 | { |
| 6269 | int len = 0; |
| 6270 | int level; |
| 6271 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6272 | level = brightness_get(NULL); |
| 6273 | if (level < 0) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6274 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 6275 | } else { |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6276 | len += sprintf(p + len, "level:\t\t%d\n", level); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6277 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 6278 | len += sprintf(p + len, "commands:\tlevel <level>" |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6279 | " (<level> is 0-%d)\n", |
| 6280 | (tp_features.bright_16levels) ? 15 : 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6281 | } |
| 6282 | |
| 6283 | return len; |
| 6284 | } |
| 6285 | |
| 6286 | static int brightness_write(char *buf) |
| 6287 | { |
| 6288 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6289 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6290 | char *cmd; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6291 | int max_level = (tp_features.bright_16levels) ? 15 : 7; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6292 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6293 | level = brightness_get(NULL); |
| 6294 | if (level < 0) |
| 6295 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6296 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6297 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6298 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6299 | if (level < max_level) |
| 6300 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6301 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6302 | if (level > 0) |
| 6303 | level--; |
| 6304 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
| 6305 | level >= 0 && level <= max_level) { |
| 6306 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6307 | } else |
| 6308 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6309 | } |
| 6310 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6311 | tpacpi_disclose_usertask("procfs brightness", |
| 6312 | "set level to %d\n", level); |
| 6313 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6314 | /* |
| 6315 | * Now we know what the final level should be, so we try to set it. |
| 6316 | * Doing it this way makes the syscall restartable in case of EINTR |
| 6317 | */ |
| 6318 | rc = brightness_set(level); |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6319 | if (!rc && ibm_backlight_device) |
| 6320 | backlight_force_update(ibm_backlight_device, |
| 6321 | BACKLIGHT_UPDATE_SYSFS); |
Roel Kluin | 80a8d12 | 2009-11-20 19:48:23 +0100 | [diff] [blame] | 6322 | return (rc == -EINTR)? -ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6323 | } |
| 6324 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6325 | static struct ibm_struct brightness_driver_data = { |
| 6326 | .name = "brightness", |
| 6327 | .read = brightness_read, |
| 6328 | .write = brightness_write, |
| 6329 | .exit = brightness_exit, |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6330 | .suspend = brightness_suspend, |
| 6331 | .shutdown = brightness_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6332 | }; |
| 6333 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6334 | /************************************************************************* |
| 6335 | * Volume subdriver |
| 6336 | */ |
| 6337 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6338 | static int volume_offset = 0x30; |
| 6339 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6340 | static int volume_read(char *p) |
| 6341 | { |
| 6342 | int len = 0; |
| 6343 | u8 level; |
| 6344 | |
| 6345 | if (!acpi_ec_read(volume_offset, &level)) { |
| 6346 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 6347 | } else { |
| 6348 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 6349 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 6350 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 6351 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 6352 | " (<level> is 0-15)\n"); |
| 6353 | } |
| 6354 | |
| 6355 | return len; |
| 6356 | } |
| 6357 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6358 | static int volume_write(char *buf) |
| 6359 | { |
| 6360 | int cmos_cmd, inc, i; |
| 6361 | u8 level, mute; |
| 6362 | int new_level, new_mute; |
| 6363 | char *cmd; |
| 6364 | |
| 6365 | while ((cmd = next_cmd(&buf))) { |
| 6366 | if (!acpi_ec_read(volume_offset, &level)) |
| 6367 | return -EIO; |
| 6368 | new_mute = mute = level & 0x40; |
| 6369 | new_level = level = level & 0xf; |
| 6370 | |
| 6371 | if (strlencmp(cmd, "up") == 0) { |
| 6372 | if (mute) |
| 6373 | new_mute = 0; |
| 6374 | else |
| 6375 | new_level = level == 15 ? 15 : level + 1; |
| 6376 | } else if (strlencmp(cmd, "down") == 0) { |
| 6377 | if (mute) |
| 6378 | new_mute = 0; |
| 6379 | else |
| 6380 | new_level = level == 0 ? 0 : level - 1; |
| 6381 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 6382 | new_level >= 0 && new_level <= 15) { |
| 6383 | /* new_level set */ |
| 6384 | } else if (strlencmp(cmd, "mute") == 0) { |
| 6385 | new_mute = 0x40; |
| 6386 | } else |
| 6387 | return -EINVAL; |
| 6388 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6389 | if (new_level != level) { |
| 6390 | /* mute doesn't change */ |
| 6391 | |
| 6392 | cmos_cmd = (new_level > level) ? |
| 6393 | TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6394 | inc = new_level > level ? 1 : -1; |
| 6395 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6396 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6397 | !acpi_ec_write(volume_offset, level))) |
| 6398 | return -EIO; |
| 6399 | |
| 6400 | for (i = level; i != new_level; i += inc) |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6401 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6402 | !acpi_ec_write(volume_offset, i + inc)) |
| 6403 | return -EIO; |
| 6404 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6405 | if (mute && |
| 6406 | (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
| 6407 | !acpi_ec_write(volume_offset, new_level + mute))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6408 | return -EIO; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6409 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6410 | } |
| 6411 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6412 | if (new_mute != mute) { |
| 6413 | /* level doesn't change */ |
| 6414 | |
| 6415 | cmos_cmd = (new_mute) ? |
| 6416 | TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6417 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6418 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6419 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 6420 | return -EIO; |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | return 0; |
| 6425 | } |
| 6426 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6427 | static struct ibm_struct volume_driver_data = { |
| 6428 | .name = "volume", |
| 6429 | .read = volume_read, |
| 6430 | .write = volume_write, |
| 6431 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6432 | |
| 6433 | /************************************************************************* |
| 6434 | * Fan subdriver |
| 6435 | */ |
| 6436 | |
| 6437 | /* |
| 6438 | * FAN ACCESS MODES |
| 6439 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6440 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6441 | * ACPI GFAN method: returns fan level |
| 6442 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6443 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6444 | * EC 0x2f (HFSP) not available if GFAN exists |
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_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6447 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 6448 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6449 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 6450 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6451 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6452 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6453 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 6454 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6455 | * |
| 6456 | * Fan speed changes of any sort (including those caused by the |
| 6457 | * disengaged mode) are usually done slowly by the firmware as the |
| 6458 | * maximum ammount of fan duty cycle change per second seems to be |
| 6459 | * limited. |
| 6460 | * |
| 6461 | * Reading is not available if GFAN exists. |
| 6462 | * Writing is not available if SFAN exists. |
| 6463 | * |
| 6464 | * Bits |
| 6465 | * 7 automatic mode engaged; |
| 6466 | * (default operation mode of the ThinkPad) |
| 6467 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6468 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6469 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6470 | * the tachometer while the fan controller ramps up |
| 6471 | * the speed (which can take up to a few *minutes*). |
| 6472 | * Speeds up fan to 100% duty-cycle, which is far above |
| 6473 | * the standard RPM levels. It is not impossible that |
| 6474 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6475 | * 5-3 unused in some models. Extra bits for fan level |
| 6476 | * in others, but still useless as all values above |
| 6477 | * 7 map to the same speed as level 7 in these models. |
| 6478 | * 2-0 fan level (0..7 usually) |
| 6479 | * 0x00 = stop |
| 6480 | * 0x07 = max (set when temperatures critical) |
| 6481 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6482 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6483 | * |
| 6484 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 6485 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 6486 | * does so, its initial value is meaningless (0x07). |
| 6487 | * |
| 6488 | * For firmware bugs, refer to: |
| 6489 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 6490 | * |
| 6491 | * ---- |
| 6492 | * |
| 6493 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 6494 | * Main fan tachometer reading (in RPM) |
| 6495 | * |
| 6496 | * This register is present on all ThinkPads with a new-style EC, and |
| 6497 | * it is known not to be present on the A21m/e, and T22, as there is |
| 6498 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 6499 | * ThinkPads from this same time period (and earlier) probably lack the |
| 6500 | * tachometer as well. |
| 6501 | * |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 6502 | * 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] | 6503 | * was never fixed by IBM to report the EC firmware version string |
| 6504 | * probably support the tachometer (like the early X models), so |
| 6505 | * detecting it is quite hard. We need more data to know for sure. |
| 6506 | * |
| 6507 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 6508 | * might result. |
| 6509 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6510 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 6511 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6512 | * |
| 6513 | * For firmware bugs, refer to: |
| 6514 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 6515 | * |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6516 | * ---- |
| 6517 | * |
| 6518 | * ThinkPad EC register 0x31 bit 0 (only on select models) |
| 6519 | * |
| 6520 | * When bit 0 of EC register 0x31 is zero, the tachometer registers |
| 6521 | * show the speed of the main fan. When bit 0 of EC register 0x31 |
| 6522 | * is one, the tachometer registers show the speed of the auxiliary |
| 6523 | * fan. |
| 6524 | * |
| 6525 | * Fan control seems to affect both fans, regardless of the state |
| 6526 | * of this bit. |
| 6527 | * |
| 6528 | * So far, only the firmware for the X60/X61 non-tablet versions |
| 6529 | * seem to support this (firmware TP-7M). |
| 6530 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6531 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6532 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 6533 | * |
| 6534 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 6535 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 6536 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 6537 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 6538 | * |
| 6539 | * The speeds are stored on handles |
| 6540 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 6541 | * |
| 6542 | * There are three default speed sets, acessible as handles: |
| 6543 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 6544 | * |
| 6545 | * ACPI DSDT switches which set is in use depending on various |
| 6546 | * factors. |
| 6547 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6548 | * 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] | 6549 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 6550 | * but the ACPI tables just mention level 7. |
| 6551 | */ |
| 6552 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6553 | enum { /* Fan control constants */ |
| 6554 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 6555 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 6556 | * 0x84 must be read before 0x85 */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6557 | fan_select_offset = 0x31, /* EC register 0x31 (Firmware 7M) |
| 6558 | bit 0 selects which fan is active */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6559 | |
| 6560 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 6561 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 6562 | |
| 6563 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 6564 | }; |
| 6565 | |
| 6566 | enum fan_status_access_mode { |
| 6567 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 6568 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 6569 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 6570 | }; |
| 6571 | |
| 6572 | enum fan_control_access_mode { |
| 6573 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 6574 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 6575 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 6576 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 6577 | }; |
| 6578 | |
| 6579 | enum fan_control_commands { |
| 6580 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 6581 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 6582 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 6583 | * and also watchdog cmd */ |
| 6584 | }; |
| 6585 | |
| 6586 | static int fan_control_allowed; |
| 6587 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6588 | static enum fan_status_access_mode fan_status_access_mode; |
| 6589 | static enum fan_control_access_mode fan_control_access_mode; |
| 6590 | static enum fan_control_commands fan_control_commands; |
| 6591 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6592 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6593 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 6594 | static u8 fan_control_resume_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6595 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6596 | |
| 6597 | static struct mutex fan_mutex; |
| 6598 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6599 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 6600 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6601 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6602 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 6603 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6604 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 6605 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6606 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6607 | "JFNS", /* 770x-JL */ |
| 6608 | ); /* all others */ |
| 6609 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6610 | /* |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6611 | * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the |
| 6612 | * HFSP register at boot, so it contains 0x07 but the Thinkpad could |
| 6613 | * be in auto mode (0x80). |
| 6614 | * |
| 6615 | * This is corrected by any write to HFSP either by the driver, or |
| 6616 | * by the firmware. |
| 6617 | * |
| 6618 | * We assume 0x07 really means auto mode while this quirk is active, |
| 6619 | * as this is far more likely than the ThinkPad being in level 7, |
| 6620 | * which is only used by the firmware during thermal emergencies. |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6621 | * |
| 6622 | * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52), |
| 6623 | * TP-70 (T43, R52), which are known to be buggy. |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6624 | */ |
| 6625 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6626 | static void fan_quirk1_setup(void) |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6627 | { |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6628 | if (fan_control_initial_status == 0x07) { |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6629 | printk(TPACPI_NOTICE |
| 6630 | "fan_init: initial fan status is unknown, " |
| 6631 | "assuming it is in auto mode\n"); |
| 6632 | tp_features.fan_ctrl_status_undef = 1; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6633 | } |
| 6634 | } |
| 6635 | |
| 6636 | static void fan_quirk1_handle(u8 *fan_status) |
| 6637 | { |
| 6638 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 6639 | if (*fan_status != fan_control_initial_status) { |
| 6640 | /* something changed the HFSP regisnter since |
| 6641 | * driver init time, so it is not undefined |
| 6642 | * anymore */ |
| 6643 | tp_features.fan_ctrl_status_undef = 0; |
| 6644 | } else { |
| 6645 | /* Return most likely status. In fact, it |
| 6646 | * might be the only possible status */ |
| 6647 | *fan_status = TP_EC_FAN_AUTO; |
| 6648 | } |
| 6649 | } |
| 6650 | } |
| 6651 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6652 | /* Select main fan on X60/X61, NOOP on others */ |
| 6653 | static bool fan_select_fan1(void) |
| 6654 | { |
| 6655 | if (tp_features.second_fan) { |
| 6656 | u8 val; |
| 6657 | |
| 6658 | if (ec_read(fan_select_offset, &val) < 0) |
| 6659 | return false; |
| 6660 | val &= 0xFEU; |
| 6661 | if (ec_write(fan_select_offset, val) < 0) |
| 6662 | return false; |
| 6663 | } |
| 6664 | return true; |
| 6665 | } |
| 6666 | |
| 6667 | /* Select secondary fan on X60/X61 */ |
| 6668 | static bool fan_select_fan2(void) |
| 6669 | { |
| 6670 | u8 val; |
| 6671 | |
| 6672 | if (!tp_features.second_fan) |
| 6673 | return false; |
| 6674 | |
| 6675 | if (ec_read(fan_select_offset, &val) < 0) |
| 6676 | return false; |
| 6677 | val |= 0x01U; |
| 6678 | if (ec_write(fan_select_offset, val) < 0) |
| 6679 | return false; |
| 6680 | |
| 6681 | return true; |
| 6682 | } |
| 6683 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6684 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6685 | * Call with fan_mutex held |
| 6686 | */ |
| 6687 | static void fan_update_desired_level(u8 status) |
| 6688 | { |
| 6689 | if ((status & |
| 6690 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 6691 | if (status > 7) |
| 6692 | fan_control_desired_level = 7; |
| 6693 | else |
| 6694 | fan_control_desired_level = status; |
| 6695 | } |
| 6696 | } |
| 6697 | |
| 6698 | static int fan_get_status(u8 *status) |
| 6699 | { |
| 6700 | u8 s; |
| 6701 | |
| 6702 | /* TODO: |
| 6703 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 6704 | |
| 6705 | switch (fan_status_access_mode) { |
| 6706 | case TPACPI_FAN_RD_ACPI_GFAN: |
| 6707 | /* 570, 600e/x, 770e, 770x */ |
| 6708 | |
| 6709 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
| 6710 | return -EIO; |
| 6711 | |
| 6712 | if (likely(status)) |
| 6713 | *status = s & 0x07; |
| 6714 | |
| 6715 | break; |
| 6716 | |
| 6717 | case TPACPI_FAN_RD_TPEC: |
| 6718 | /* all except 570, 600e/x, 770e, 770x */ |
| 6719 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 6720 | return -EIO; |
| 6721 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6722 | if (likely(status)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6723 | *status = s; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6724 | fan_quirk1_handle(status); |
| 6725 | } |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6726 | |
| 6727 | break; |
| 6728 | |
| 6729 | default: |
| 6730 | return -ENXIO; |
| 6731 | } |
| 6732 | |
| 6733 | return 0; |
| 6734 | } |
| 6735 | |
| 6736 | static int fan_get_status_safe(u8 *status) |
| 6737 | { |
| 6738 | int rc; |
| 6739 | u8 s; |
| 6740 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6741 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6742 | return -ERESTARTSYS; |
| 6743 | rc = fan_get_status(&s); |
| 6744 | if (!rc) |
| 6745 | fan_update_desired_level(s); |
| 6746 | mutex_unlock(&fan_mutex); |
| 6747 | |
| 6748 | if (status) |
| 6749 | *status = s; |
| 6750 | |
| 6751 | return rc; |
| 6752 | } |
| 6753 | |
| 6754 | static int fan_get_speed(unsigned int *speed) |
| 6755 | { |
| 6756 | u8 hi, lo; |
| 6757 | |
| 6758 | switch (fan_status_access_mode) { |
| 6759 | case TPACPI_FAN_RD_TPEC: |
| 6760 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6761 | if (unlikely(!fan_select_fan1())) |
| 6762 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6763 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 6764 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 6765 | return -EIO; |
| 6766 | |
| 6767 | if (likely(speed)) |
| 6768 | *speed = (hi << 8) | lo; |
| 6769 | |
| 6770 | break; |
| 6771 | |
| 6772 | default: |
| 6773 | return -ENXIO; |
| 6774 | } |
| 6775 | |
| 6776 | return 0; |
| 6777 | } |
| 6778 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6779 | static int fan2_get_speed(unsigned int *speed) |
| 6780 | { |
| 6781 | u8 hi, lo; |
| 6782 | bool rc; |
| 6783 | |
| 6784 | switch (fan_status_access_mode) { |
| 6785 | case TPACPI_FAN_RD_TPEC: |
| 6786 | /* all except 570, 600e/x, 770e, 770x */ |
| 6787 | if (unlikely(!fan_select_fan2())) |
| 6788 | return -EIO; |
| 6789 | rc = !acpi_ec_read(fan_rpm_offset, &lo) || |
| 6790 | !acpi_ec_read(fan_rpm_offset + 1, &hi); |
| 6791 | fan_select_fan1(); /* play it safe */ |
| 6792 | if (rc) |
| 6793 | return -EIO; |
| 6794 | |
| 6795 | if (likely(speed)) |
| 6796 | *speed = (hi << 8) | lo; |
| 6797 | |
| 6798 | break; |
| 6799 | |
| 6800 | default: |
| 6801 | return -ENXIO; |
| 6802 | } |
| 6803 | |
| 6804 | return 0; |
| 6805 | } |
| 6806 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6807 | static int fan_set_level(int level) |
| 6808 | { |
| 6809 | if (!fan_control_allowed) |
| 6810 | return -EPERM; |
| 6811 | |
| 6812 | switch (fan_control_access_mode) { |
| 6813 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6814 | if (level >= 0 && level <= 7) { |
| 6815 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 6816 | return -EIO; |
| 6817 | } else |
| 6818 | return -EINVAL; |
| 6819 | break; |
| 6820 | |
| 6821 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6822 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 6823 | if (!(level & TP_EC_FAN_AUTO) && |
| 6824 | !(level & TP_EC_FAN_FULLSPEED) && |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6825 | ((level < 0) || (level > 7))) |
| 6826 | return -EINVAL; |
| 6827 | |
| 6828 | /* safety net should the EC not support AUTO |
| 6829 | * or FULLSPEED mode bits and just ignore them */ |
| 6830 | if (level & TP_EC_FAN_FULLSPEED) |
| 6831 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 6832 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6833 | level |= 4; /* safety min speed 4 */ |
| 6834 | |
| 6835 | if (!acpi_ec_write(fan_status_offset, level)) |
| 6836 | return -EIO; |
| 6837 | else |
| 6838 | tp_features.fan_ctrl_status_undef = 0; |
| 6839 | break; |
| 6840 | |
| 6841 | default: |
| 6842 | return -ENXIO; |
| 6843 | } |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6844 | |
| 6845 | vdbg_printk(TPACPI_DBG_FAN, |
| 6846 | "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] | 6847 | return 0; |
| 6848 | } |
| 6849 | |
| 6850 | static int fan_set_level_safe(int level) |
| 6851 | { |
| 6852 | int rc; |
| 6853 | |
| 6854 | if (!fan_control_allowed) |
| 6855 | return -EPERM; |
| 6856 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6857 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6858 | return -ERESTARTSYS; |
| 6859 | |
| 6860 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 6861 | level = fan_control_desired_level; |
| 6862 | |
| 6863 | rc = fan_set_level(level); |
| 6864 | if (!rc) |
| 6865 | fan_update_desired_level(level); |
| 6866 | |
| 6867 | mutex_unlock(&fan_mutex); |
| 6868 | return rc; |
| 6869 | } |
| 6870 | |
| 6871 | static int fan_set_enable(void) |
| 6872 | { |
| 6873 | u8 s; |
| 6874 | int rc; |
| 6875 | |
| 6876 | if (!fan_control_allowed) |
| 6877 | return -EPERM; |
| 6878 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6879 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6880 | return -ERESTARTSYS; |
| 6881 | |
| 6882 | switch (fan_control_access_mode) { |
| 6883 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6884 | case TPACPI_FAN_WR_TPEC: |
| 6885 | rc = fan_get_status(&s); |
| 6886 | if (rc < 0) |
| 6887 | break; |
| 6888 | |
| 6889 | /* Don't go out of emergency fan mode */ |
| 6890 | if (s != 7) { |
| 6891 | s &= 0x07; |
| 6892 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 6893 | } |
| 6894 | |
| 6895 | if (!acpi_ec_write(fan_status_offset, s)) |
| 6896 | rc = -EIO; |
| 6897 | else { |
| 6898 | tp_features.fan_ctrl_status_undef = 0; |
| 6899 | rc = 0; |
| 6900 | } |
| 6901 | break; |
| 6902 | |
| 6903 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6904 | rc = fan_get_status(&s); |
| 6905 | if (rc < 0) |
| 6906 | break; |
| 6907 | |
| 6908 | s &= 0x07; |
| 6909 | |
| 6910 | /* Set fan to at least level 4 */ |
| 6911 | s |= 4; |
| 6912 | |
| 6913 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6914 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6915 | else |
| 6916 | rc = 0; |
| 6917 | break; |
| 6918 | |
| 6919 | default: |
| 6920 | rc = -ENXIO; |
| 6921 | } |
| 6922 | |
| 6923 | mutex_unlock(&fan_mutex); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6924 | |
| 6925 | if (!rc) |
| 6926 | vdbg_printk(TPACPI_DBG_FAN, |
| 6927 | "fan control: set fan control register to 0x%02x\n", |
| 6928 | s); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6929 | return rc; |
| 6930 | } |
| 6931 | |
| 6932 | static int fan_set_disable(void) |
| 6933 | { |
| 6934 | int rc; |
| 6935 | |
| 6936 | if (!fan_control_allowed) |
| 6937 | return -EPERM; |
| 6938 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6939 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6940 | return -ERESTARTSYS; |
| 6941 | |
| 6942 | rc = 0; |
| 6943 | switch (fan_control_access_mode) { |
| 6944 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6945 | case TPACPI_FAN_WR_TPEC: |
| 6946 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 6947 | rc = -EIO; |
| 6948 | else { |
| 6949 | fan_control_desired_level = 0; |
| 6950 | tp_features.fan_ctrl_status_undef = 0; |
| 6951 | } |
| 6952 | break; |
| 6953 | |
| 6954 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6955 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 6956 | rc = -EIO; |
| 6957 | else |
| 6958 | fan_control_desired_level = 0; |
| 6959 | break; |
| 6960 | |
| 6961 | default: |
| 6962 | rc = -ENXIO; |
| 6963 | } |
| 6964 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6965 | if (!rc) |
| 6966 | vdbg_printk(TPACPI_DBG_FAN, |
| 6967 | "fan control: set fan control register to 0\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6968 | |
| 6969 | mutex_unlock(&fan_mutex); |
| 6970 | return rc; |
| 6971 | } |
| 6972 | |
| 6973 | static int fan_set_speed(int speed) |
| 6974 | { |
| 6975 | int rc; |
| 6976 | |
| 6977 | if (!fan_control_allowed) |
| 6978 | return -EPERM; |
| 6979 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6980 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6981 | return -ERESTARTSYS; |
| 6982 | |
| 6983 | rc = 0; |
| 6984 | switch (fan_control_access_mode) { |
| 6985 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6986 | if (speed >= 0 && speed <= 65535) { |
| 6987 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 6988 | speed, speed, speed)) |
| 6989 | rc = -EIO; |
| 6990 | } else |
| 6991 | rc = -EINVAL; |
| 6992 | break; |
| 6993 | |
| 6994 | default: |
| 6995 | rc = -ENXIO; |
| 6996 | } |
| 6997 | |
| 6998 | mutex_unlock(&fan_mutex); |
| 6999 | return rc; |
| 7000 | } |
| 7001 | |
| 7002 | static void fan_watchdog_reset(void) |
| 7003 | { |
| 7004 | static int fan_watchdog_active; |
| 7005 | |
| 7006 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 7007 | return; |
| 7008 | |
| 7009 | if (fan_watchdog_active) |
| 7010 | cancel_delayed_work(&fan_watchdog_task); |
| 7011 | |
| 7012 | if (fan_watchdog_maxinterval > 0 && |
| 7013 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
| 7014 | fan_watchdog_active = 1; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7015 | if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task, |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7016 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 7017 | * 1000))) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7018 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7019 | "failed to queue the fan watchdog, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7020 | "watchdog will not trigger\n"); |
| 7021 | } |
| 7022 | } else |
| 7023 | fan_watchdog_active = 0; |
| 7024 | } |
| 7025 | |
| 7026 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 7027 | { |
| 7028 | int rc; |
| 7029 | |
| 7030 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 7031 | return; |
| 7032 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7033 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7034 | rc = fan_set_enable(); |
| 7035 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7036 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7037 | "will try again later...\n", -rc); |
| 7038 | /* reschedule for later */ |
| 7039 | fan_watchdog_reset(); |
| 7040 | } |
| 7041 | } |
| 7042 | |
| 7043 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7044 | * SYSFS fan layout: hwmon compatible (device) |
| 7045 | * |
| 7046 | * pwm*_enable: |
| 7047 | * 0: "disengaged" mode |
| 7048 | * 1: manual mode |
| 7049 | * 2: native EC "auto" mode (recommended, hardware default) |
| 7050 | * |
| 7051 | * pwm*: set speed in manual mode, ignored otherwise. |
| 7052 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 7053 | * interpolation. |
| 7054 | * |
| 7055 | * fan*_input: tachometer reading, RPM |
| 7056 | * |
| 7057 | * |
| 7058 | * SYSFS fan layout: extensions |
| 7059 | * |
| 7060 | * fan_watchdog (driver): |
| 7061 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 7062 | */ |
| 7063 | |
| 7064 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 7065 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 7066 | struct device_attribute *attr, |
| 7067 | char *buf) |
| 7068 | { |
| 7069 | int res, mode; |
| 7070 | u8 status; |
| 7071 | |
| 7072 | res = fan_get_status_safe(&status); |
| 7073 | if (res) |
| 7074 | return res; |
| 7075 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7076 | if (status & TP_EC_FAN_FULLSPEED) { |
| 7077 | mode = 0; |
| 7078 | } else if (status & TP_EC_FAN_AUTO) { |
| 7079 | mode = 2; |
| 7080 | } else |
| 7081 | mode = 1; |
| 7082 | |
| 7083 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 7084 | } |
| 7085 | |
| 7086 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 7087 | struct device_attribute *attr, |
| 7088 | const char *buf, size_t count) |
| 7089 | { |
| 7090 | unsigned long t; |
| 7091 | int res, level; |
| 7092 | |
| 7093 | if (parse_strtoul(buf, 2, &t)) |
| 7094 | return -EINVAL; |
| 7095 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7096 | tpacpi_disclose_usertask("hwmon pwm1_enable", |
| 7097 | "set fan mode to %lu\n", t); |
| 7098 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7099 | switch (t) { |
| 7100 | case 0: |
| 7101 | level = TP_EC_FAN_FULLSPEED; |
| 7102 | break; |
| 7103 | case 1: |
| 7104 | level = TPACPI_FAN_LAST_LEVEL; |
| 7105 | break; |
| 7106 | case 2: |
| 7107 | level = TP_EC_FAN_AUTO; |
| 7108 | break; |
| 7109 | case 3: |
| 7110 | /* reserved for software-controlled auto mode */ |
| 7111 | return -ENOSYS; |
| 7112 | default: |
| 7113 | return -EINVAL; |
| 7114 | } |
| 7115 | |
| 7116 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 7117 | if (res == -ENXIO) |
| 7118 | return -EINVAL; |
| 7119 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7120 | return res; |
| 7121 | |
| 7122 | fan_watchdog_reset(); |
| 7123 | |
| 7124 | return count; |
| 7125 | } |
| 7126 | |
| 7127 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 7128 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 7129 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 7130 | |
| 7131 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 7132 | static ssize_t fan_pwm1_show(struct device *dev, |
| 7133 | struct device_attribute *attr, |
| 7134 | char *buf) |
| 7135 | { |
| 7136 | int res; |
| 7137 | u8 status; |
| 7138 | |
| 7139 | res = fan_get_status_safe(&status); |
| 7140 | if (res) |
| 7141 | return res; |
| 7142 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7143 | if ((status & |
| 7144 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 7145 | status = fan_control_desired_level; |
| 7146 | |
| 7147 | if (status > 7) |
| 7148 | status = 7; |
| 7149 | |
| 7150 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 7151 | } |
| 7152 | |
| 7153 | static ssize_t fan_pwm1_store(struct device *dev, |
| 7154 | struct device_attribute *attr, |
| 7155 | const char *buf, size_t count) |
| 7156 | { |
| 7157 | unsigned long s; |
| 7158 | int rc; |
| 7159 | u8 status, newlevel; |
| 7160 | |
| 7161 | if (parse_strtoul(buf, 255, &s)) |
| 7162 | return -EINVAL; |
| 7163 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7164 | tpacpi_disclose_usertask("hwmon pwm1", |
| 7165 | "set fan speed to %lu\n", s); |
| 7166 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7167 | /* scale down from 0-255 to 0-7 */ |
| 7168 | newlevel = (s >> 5) & 0x07; |
| 7169 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7170 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 7171 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7172 | |
| 7173 | rc = fan_get_status(&status); |
| 7174 | if (!rc && (status & |
| 7175 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 7176 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 7177 | if (rc == -ENXIO) |
| 7178 | rc = -EINVAL; |
| 7179 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7180 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 7181 | fan_watchdog_reset(); |
| 7182 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7183 | } |
| 7184 | |
| 7185 | mutex_unlock(&fan_mutex); |
| 7186 | return (rc)? rc : count; |
| 7187 | } |
| 7188 | |
| 7189 | static struct device_attribute dev_attr_fan_pwm1 = |
| 7190 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 7191 | fan_pwm1_show, fan_pwm1_store); |
| 7192 | |
| 7193 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 7194 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 7195 | struct device_attribute *attr, |
| 7196 | char *buf) |
| 7197 | { |
| 7198 | int res; |
| 7199 | unsigned int speed; |
| 7200 | |
| 7201 | res = fan_get_speed(&speed); |
| 7202 | if (res < 0) |
| 7203 | return res; |
| 7204 | |
| 7205 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7206 | } |
| 7207 | |
| 7208 | static struct device_attribute dev_attr_fan_fan1_input = |
| 7209 | __ATTR(fan1_input, S_IRUGO, |
| 7210 | fan_fan1_input_show, NULL); |
| 7211 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7212 | /* sysfs fan fan2_input ------------------------------------------------ */ |
| 7213 | static ssize_t fan_fan2_input_show(struct device *dev, |
| 7214 | struct device_attribute *attr, |
| 7215 | char *buf) |
| 7216 | { |
| 7217 | int res; |
| 7218 | unsigned int speed; |
| 7219 | |
| 7220 | res = fan2_get_speed(&speed); |
| 7221 | if (res < 0) |
| 7222 | return res; |
| 7223 | |
| 7224 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7225 | } |
| 7226 | |
| 7227 | static struct device_attribute dev_attr_fan_fan2_input = |
| 7228 | __ATTR(fan2_input, S_IRUGO, |
| 7229 | fan_fan2_input_show, NULL); |
| 7230 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7231 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7232 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 7233 | char *buf) |
| 7234 | { |
| 7235 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 7236 | } |
| 7237 | |
| 7238 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 7239 | const char *buf, size_t count) |
| 7240 | { |
| 7241 | unsigned long t; |
| 7242 | |
| 7243 | if (parse_strtoul(buf, 120, &t)) |
| 7244 | return -EINVAL; |
| 7245 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7246 | if (!fan_control_allowed) |
| 7247 | return -EPERM; |
| 7248 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7249 | fan_watchdog_maxinterval = t; |
| 7250 | fan_watchdog_reset(); |
| 7251 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7252 | tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t); |
| 7253 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7254 | return count; |
| 7255 | } |
| 7256 | |
| 7257 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 7258 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 7259 | |
| 7260 | /* --------------------------------------------------------------------- */ |
| 7261 | static struct attribute *fan_attributes[] = { |
| 7262 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 7263 | &dev_attr_fan_fan1_input.attr, |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7264 | NULL, /* for fan2_input */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7265 | NULL |
| 7266 | }; |
| 7267 | |
| 7268 | static const struct attribute_group fan_attr_group = { |
| 7269 | .attrs = fan_attributes, |
| 7270 | }; |
| 7271 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7272 | #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */ |
| 7273 | #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] | 7274 | |
| 7275 | #define TPACPI_FAN_QI(__id1, __id2, __quirks) \ |
| 7276 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 7277 | .bios = TPACPI_MATCH_ANY, \ |
| 7278 | .ec = TPID(__id1, __id2), \ |
| 7279 | .quirks = __quirks } |
| 7280 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7281 | #define TPACPI_FAN_QL(__id1, __id2, __quirks) \ |
| 7282 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 7283 | .bios = TPACPI_MATCH_ANY, \ |
| 7284 | .ec = TPID(__id1, __id2), \ |
| 7285 | .quirks = __quirks } |
| 7286 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7287 | static const struct tpacpi_quirk fan_quirk_table[] __initconst = { |
| 7288 | TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1), |
| 7289 | TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1), |
| 7290 | TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1), |
| 7291 | TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1), |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7292 | TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN), |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7293 | }; |
| 7294 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7295 | #undef TPACPI_FAN_QL |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7296 | #undef TPACPI_FAN_QI |
| 7297 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7298 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7299 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7300 | int rc; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7301 | unsigned long quirks; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7302 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7303 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7304 | "initializing fan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7305 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 7306 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7307 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 7308 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7309 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7310 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 7311 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7312 | tp_features.second_fan = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7313 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7314 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7315 | TPACPI_ACPIHANDLE_INIT(fans); |
| 7316 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 7317 | TPACPI_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7318 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7319 | quirks = tpacpi_check_quirks(fan_quirk_table, |
| 7320 | ARRAY_SIZE(fan_quirk_table)); |
| 7321 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7322 | if (gfan_handle) { |
| 7323 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7324 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7325 | } else { |
| 7326 | /* all other ThinkPads: note that even old-style |
| 7327 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7328 | if (likely(acpi_ec_read(fan_status_offset, |
| 7329 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7330 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7331 | if (quirks & TPACPI_FAN_Q1) |
| 7332 | fan_quirk1_setup(); |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7333 | if (quirks & TPACPI_FAN_2FAN) { |
| 7334 | tp_features.second_fan = 1; |
| 7335 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7336 | "secondary fan support enabled\n"); |
| 7337 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7338 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7339 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7340 | "ThinkPad ACPI EC access misbehaving, " |
| 7341 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7342 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7343 | } |
| 7344 | } |
| 7345 | |
| 7346 | if (sfan_handle) { |
| 7347 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7348 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 7349 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7350 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7351 | } else { |
| 7352 | if (!gfan_handle) { |
| 7353 | /* gfan without sfan means no fan control */ |
| 7354 | /* all other models implement TP EC 0x2f control */ |
| 7355 | |
| 7356 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7357 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7358 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7359 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -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_SPEED | |
| 7362 | TPACPI_FAN_CMD_LEVEL | |
| 7363 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7364 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7365 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7366 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7367 | TPACPI_FAN_CMD_LEVEL | |
| 7368 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7369 | } |
| 7370 | } |
| 7371 | } |
| 7372 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7373 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7374 | "fan is %s, modes %d, %d\n", |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7375 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 7376 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 7377 | fan_status_access_mode, fan_control_access_mode); |
| 7378 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7379 | /* fan control master switch */ |
| 7380 | if (!fan_control_allowed) { |
| 7381 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 7382 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7383 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7384 | "fan control features disabled by parameter\n"); |
| 7385 | } |
| 7386 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7387 | /* update fan_control_desired_level */ |
| 7388 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 7389 | fan_get_status_safe(NULL); |
| 7390 | |
| 7391 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 7392 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7393 | if (tp_features.second_fan) { |
| 7394 | /* attach second fan tachometer */ |
| 7395 | fan_attributes[ARRAY_SIZE(fan_attributes)-2] = |
| 7396 | &dev_attr_fan_fan2_input.attr; |
| 7397 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7398 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7399 | &fan_attr_group); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7400 | if (rc < 0) |
| 7401 | return rc; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 7402 | |
| 7403 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
| 7404 | &driver_attr_fan_watchdog); |
| 7405 | if (rc < 0) { |
| 7406 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
| 7407 | &fan_attr_group); |
| 7408 | return rc; |
| 7409 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7410 | return 0; |
| 7411 | } else |
| 7412 | return 1; |
| 7413 | } |
| 7414 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7415 | static void fan_exit(void) |
| 7416 | { |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7417 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7418 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7419 | |
| 7420 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7421 | 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] | 7422 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 7423 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7424 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7425 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7426 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7427 | } |
| 7428 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7429 | static void fan_suspend(pm_message_t state) |
| 7430 | { |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7431 | int rc; |
| 7432 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7433 | if (!fan_control_allowed) |
| 7434 | return; |
| 7435 | |
| 7436 | /* Store fan status in cache */ |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7437 | fan_control_resume_level = 0; |
| 7438 | rc = fan_get_status_safe(&fan_control_resume_level); |
| 7439 | if (rc < 0) |
| 7440 | printk(TPACPI_NOTICE |
| 7441 | "failed to read fan level for later " |
| 7442 | "restore during resume: %d\n", rc); |
| 7443 | |
| 7444 | /* if it is undefined, don't attempt to restore it. |
| 7445 | * KEEP THIS LAST */ |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7446 | if (tp_features.fan_ctrl_status_undef) |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7447 | fan_control_resume_level = 0; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7448 | } |
| 7449 | |
| 7450 | static void fan_resume(void) |
| 7451 | { |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7452 | u8 current_level = 7; |
| 7453 | bool do_set = false; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7454 | int rc; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7455 | |
| 7456 | /* DSDT *always* updates status on resume */ |
| 7457 | tp_features.fan_ctrl_status_undef = 0; |
| 7458 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7459 | if (!fan_control_allowed || |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7460 | !fan_control_resume_level || |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7461 | (fan_get_status_safe(¤t_level) < 0)) |
| 7462 | return; |
| 7463 | |
| 7464 | switch (fan_control_access_mode) { |
| 7465 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7466 | /* never decrease fan level */ |
| 7467 | do_set = (fan_control_resume_level > current_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7468 | break; |
| 7469 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7470 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7471 | /* never decrease fan level, scale is: |
| 7472 | * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO |
| 7473 | * |
| 7474 | * We expect the firmware to set either 7 or AUTO, but we |
| 7475 | * handle FULLSPEED out of paranoia. |
| 7476 | * |
| 7477 | * So, we can safely only restore FULLSPEED or 7, anything |
| 7478 | * else could slow the fan. Restoring AUTO is useless, at |
| 7479 | * best that's exactly what the DSDT already set (it is the |
| 7480 | * slower it uses). |
| 7481 | * |
| 7482 | * Always keep in mind that the DSDT *will* have set the |
| 7483 | * fans to what the vendor supposes is the best level. We |
| 7484 | * muck with it only to speed the fan up. |
| 7485 | */ |
| 7486 | if (fan_control_resume_level != 7 && |
| 7487 | !(fan_control_resume_level & TP_EC_FAN_FULLSPEED)) |
| 7488 | return; |
| 7489 | else |
| 7490 | do_set = !(current_level & TP_EC_FAN_FULLSPEED) && |
| 7491 | (current_level != fan_control_resume_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7492 | break; |
| 7493 | default: |
| 7494 | return; |
| 7495 | } |
| 7496 | if (do_set) { |
| 7497 | printk(TPACPI_NOTICE |
| 7498 | "restoring fan level to 0x%02x\n", |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7499 | fan_control_resume_level); |
| 7500 | rc = fan_set_level_safe(fan_control_resume_level); |
| 7501 | if (rc < 0) |
| 7502 | printk(TPACPI_NOTICE |
| 7503 | "failed to restore fan level: %d\n", rc); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7504 | } |
| 7505 | } |
| 7506 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7507 | static int fan_read(char *p) |
| 7508 | { |
| 7509 | int len = 0; |
| 7510 | int rc; |
| 7511 | u8 status; |
| 7512 | unsigned int speed = 0; |
| 7513 | |
| 7514 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7515 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7516 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7517 | rc = fan_get_status_safe(&status); |
| 7518 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7519 | return rc; |
| 7520 | |
| 7521 | len += sprintf(p + len, "status:\t\t%s\n" |
| 7522 | "level:\t\t%d\n", |
| 7523 | (status != 0) ? "enabled" : "disabled", status); |
| 7524 | break; |
| 7525 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7526 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7527 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7528 | rc = fan_get_status_safe(&status); |
| 7529 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7530 | return rc; |
| 7531 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7532 | len += sprintf(p + len, "status:\t\t%s\n", |
| 7533 | (status != 0) ? "enabled" : "disabled"); |
| 7534 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7535 | rc = fan_get_speed(&speed); |
| 7536 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7537 | return rc; |
| 7538 | |
| 7539 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 7540 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7541 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7542 | /* Disengaged mode takes precedence */ |
| 7543 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7544 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7545 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 7546 | else |
| 7547 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 7548 | break; |
| 7549 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7550 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7551 | default: |
| 7552 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 7553 | } |
| 7554 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7555 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7556 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 7557 | |
| 7558 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7559 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7560 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 7561 | break; |
| 7562 | |
| 7563 | default: |
| 7564 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7565 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7566 | break; |
| 7567 | } |
| 7568 | } |
| 7569 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7570 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7571 | len += sprintf(p + len, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7572 | "commands:\twatchdog <timeout> (<timeout> " |
| 7573 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7574 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7575 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7576 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 7577 | " (<speed> is 0-65535)\n"); |
| 7578 | |
| 7579 | return len; |
| 7580 | } |
| 7581 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7582 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 7583 | { |
| 7584 | int level; |
| 7585 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7586 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7587 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7588 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7589 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7590 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7591 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7592 | return 0; |
| 7593 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7594 | *rc = fan_set_level_safe(level); |
| 7595 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7596 | printk(TPACPI_ERR "level command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7597 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7598 | else if (!*rc) |
| 7599 | tpacpi_disclose_usertask("procfs fan", |
| 7600 | "set level to %d\n", level); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7601 | |
| 7602 | return 1; |
| 7603 | } |
| 7604 | |
| 7605 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 7606 | { |
| 7607 | if (strlencmp(cmd, "enable") != 0) |
| 7608 | return 0; |
| 7609 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7610 | *rc = fan_set_enable(); |
| 7611 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7612 | printk(TPACPI_ERR "enable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7613 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7614 | else if (!*rc) |
| 7615 | tpacpi_disclose_usertask("procfs fan", "enable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7616 | |
| 7617 | return 1; |
| 7618 | } |
| 7619 | |
| 7620 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 7621 | { |
| 7622 | if (strlencmp(cmd, "disable") != 0) |
| 7623 | return 0; |
| 7624 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7625 | *rc = fan_set_disable(); |
| 7626 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7627 | printk(TPACPI_ERR "disable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7628 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7629 | else if (!*rc) |
| 7630 | tpacpi_disclose_usertask("procfs fan", "disable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7631 | |
| 7632 | return 1; |
| 7633 | } |
| 7634 | |
| 7635 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 7636 | { |
| 7637 | int speed; |
| 7638 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7639 | /* TODO: |
| 7640 | * Support speed <low> <medium> <high> ? */ |
| 7641 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7642 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 7643 | return 0; |
| 7644 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7645 | *rc = fan_set_speed(speed); |
| 7646 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7647 | printk(TPACPI_ERR "speed command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7648 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7649 | else if (!*rc) |
| 7650 | tpacpi_disclose_usertask("procfs fan", |
| 7651 | "set speed to %d\n", speed); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7652 | |
| 7653 | return 1; |
| 7654 | } |
| 7655 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7656 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 7657 | { |
| 7658 | int interval; |
| 7659 | |
| 7660 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 7661 | return 0; |
| 7662 | |
| 7663 | if (interval < 0 || interval > 120) |
| 7664 | *rc = -EINVAL; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7665 | else { |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7666 | fan_watchdog_maxinterval = interval; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7667 | tpacpi_disclose_usertask("procfs fan", |
| 7668 | "set watchdog timer to %d\n", |
| 7669 | interval); |
| 7670 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7671 | |
| 7672 | return 1; |
| 7673 | } |
| 7674 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7675 | static int fan_write(char *buf) |
| 7676 | { |
| 7677 | char *cmd; |
| 7678 | int rc = 0; |
| 7679 | |
| 7680 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7681 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7682 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7683 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7684 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7685 | fan_write_cmd_disable(cmd, &rc) || |
| 7686 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7687 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7688 | fan_write_cmd_speed(cmd, &rc)) |
| 7689 | ) |
| 7690 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7691 | else if (!rc) |
| 7692 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7693 | } |
| 7694 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7695 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7696 | } |
| 7697 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7698 | static struct ibm_struct fan_driver_data = { |
| 7699 | .name = "fan", |
| 7700 | .read = fan_read, |
| 7701 | .write = fan_write, |
| 7702 | .exit = fan_exit, |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7703 | .suspend = fan_suspend, |
| 7704 | .resume = fan_resume, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7705 | }; |
| 7706 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7707 | /**************************************************************************** |
| 7708 | **************************************************************************** |
| 7709 | * |
| 7710 | * Infrastructure |
| 7711 | * |
| 7712 | **************************************************************************** |
| 7713 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7714 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 7715 | /* |
| 7716 | * HKEY event callout for other subdrivers go here |
| 7717 | * (yes, it is ugly, but it is quick, safe, and gets the job done |
| 7718 | */ |
| 7719 | static void tpacpi_driver_event(const unsigned int hkey_event) |
| 7720 | { |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 7721 | if (ibm_backlight_device) { |
| 7722 | switch (hkey_event) { |
| 7723 | case TP_HKEY_EV_BRGHT_UP: |
| 7724 | case TP_HKEY_EV_BRGHT_DOWN: |
| 7725 | tpacpi_brightness_notify_change(); |
| 7726 | } |
| 7727 | } |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 7728 | } |
| 7729 | |
| 7730 | |
| 7731 | |
| 7732 | static void hotkey_driver_event(const unsigned int scancode) |
| 7733 | { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 7734 | tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 7735 | } |
| 7736 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7737 | /* sysfs name ---------------------------------------------------------- */ |
| 7738 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 7739 | struct device_attribute *attr, |
| 7740 | char *buf) |
| 7741 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7742 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7743 | } |
| 7744 | |
| 7745 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 7746 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 7747 | |
| 7748 | /* --------------------------------------------------------------------- */ |
| 7749 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7750 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 7751 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7752 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7753 | /* |
| 7754 | * Module and infrastructure proble, init and exit handling |
| 7755 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7756 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7757 | static int force_load; |
| 7758 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7759 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7760 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7761 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7762 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7763 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7764 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7765 | } |
| 7766 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 7767 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7768 | static void ibm_exit(struct ibm_struct *ibm) |
| 7769 | { |
| 7770 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 7771 | |
| 7772 | list_del_init(&ibm->all_drivers); |
| 7773 | |
| 7774 | if (ibm->flags.acpi_notify_installed) { |
| 7775 | dbg_printk(TPACPI_DBG_EXIT, |
| 7776 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 7777 | BUG_ON(!ibm->acpi); |
| 7778 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 7779 | ibm->acpi->type, |
| 7780 | dispatch_acpi_notify); |
| 7781 | ibm->flags.acpi_notify_installed = 0; |
| 7782 | ibm->flags.acpi_notify_installed = 0; |
| 7783 | } |
| 7784 | |
| 7785 | if (ibm->flags.proc_created) { |
| 7786 | dbg_printk(TPACPI_DBG_EXIT, |
| 7787 | "%s: remove_proc_entry\n", ibm->name); |
| 7788 | remove_proc_entry(ibm->name, proc_dir); |
| 7789 | ibm->flags.proc_created = 0; |
| 7790 | } |
| 7791 | |
| 7792 | if (ibm->flags.acpi_driver_registered) { |
| 7793 | dbg_printk(TPACPI_DBG_EXIT, |
| 7794 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 7795 | BUG_ON(!ibm->acpi); |
| 7796 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 7797 | kfree(ibm->acpi->driver); |
| 7798 | ibm->acpi->driver = NULL; |
| 7799 | ibm->flags.acpi_driver_registered = 0; |
| 7800 | } |
| 7801 | |
| 7802 | if (ibm->flags.init_called && ibm->exit) { |
| 7803 | ibm->exit(); |
| 7804 | ibm->flags.init_called = 0; |
| 7805 | } |
| 7806 | |
| 7807 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 7808 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7809 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7810 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7811 | { |
| 7812 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7813 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7814 | struct proc_dir_entry *entry; |
| 7815 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7816 | BUG_ON(ibm == NULL); |
| 7817 | |
| 7818 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 7819 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7820 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7821 | return 0; |
| 7822 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7823 | dbg_printk(TPACPI_DBG_INIT, |
| 7824 | "probing for %s\n", ibm->name); |
| 7825 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7826 | if (iibm->init) { |
| 7827 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7828 | if (ret > 0) |
| 7829 | return 0; /* probe failed */ |
| 7830 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7831 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7832 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7833 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7834 | } |
| 7835 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7836 | if (ibm->acpi) { |
| 7837 | if (ibm->acpi->hid) { |
| 7838 | ret = register_tpacpi_subdriver(ibm); |
| 7839 | if (ret) |
| 7840 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7841 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7842 | |
| 7843 | if (ibm->acpi->notify) { |
| 7844 | ret = setup_acpi_notify(ibm); |
| 7845 | if (ret == -ENODEV) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7846 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7847 | ibm->name); |
| 7848 | ret = 0; |
| 7849 | goto err_out; |
| 7850 | } |
| 7851 | if (ret < 0) |
| 7852 | goto err_out; |
| 7853 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7854 | } |
| 7855 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7856 | dbg_printk(TPACPI_DBG_INIT, |
| 7857 | "%s installed\n", ibm->name); |
| 7858 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7859 | if (ibm->read) { |
| 7860 | entry = create_proc_entry(ibm->name, |
| 7861 | S_IFREG | S_IRUGO | S_IWUSR, |
| 7862 | proc_dir); |
| 7863 | if (!entry) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7864 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7865 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7866 | ret = -ENODEV; |
| 7867 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7868 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7869 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7870 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7871 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7872 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7873 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7874 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7875 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7876 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 7877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7878 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7879 | |
| 7880 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7881 | dbg_printk(TPACPI_DBG_INIT, |
| 7882 | "%s: at error exit path with result %d\n", |
| 7883 | ibm->name, ret); |
| 7884 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7885 | ibm_exit(ibm); |
| 7886 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7887 | } |
| 7888 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7889 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7890 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7891 | static bool __pure __init tpacpi_is_fw_digit(const char c) |
| 7892 | { |
| 7893 | return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); |
| 7894 | } |
| 7895 | |
| 7896 | /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */ |
| 7897 | static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, |
| 7898 | const char t) |
| 7899 | { |
| 7900 | return s && strlen(s) >= 8 && |
| 7901 | tpacpi_is_fw_digit(s[0]) && |
| 7902 | tpacpi_is_fw_digit(s[1]) && |
| 7903 | s[2] == t && s[3] == 'T' && |
| 7904 | tpacpi_is_fw_digit(s[4]) && |
| 7905 | tpacpi_is_fw_digit(s[5]) && |
| 7906 | s[6] == 'W' && s[7] == 'W'; |
| 7907 | } |
| 7908 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7909 | /* returns 0 - probe ok, or < 0 - probe error. |
| 7910 | * Probe ok doesn't mean thinkpad found. |
| 7911 | * On error, kfree() cleanup on tp->* is not performed, caller must do it */ |
| 7912 | static int __must_check __init get_thinkpad_model_data( |
| 7913 | struct thinkpad_id_data *tp) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7914 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 7915 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7916 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7917 | char const *s; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7918 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7919 | if (!tp) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7920 | return -EINVAL; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7921 | |
| 7922 | memset(tp, 0, sizeof(*tp)); |
| 7923 | |
| 7924 | if (dmi_name_in_vendors("IBM")) |
| 7925 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 7926 | else if (dmi_name_in_vendors("LENOVO")) |
| 7927 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 7928 | else |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7929 | return 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7930 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7931 | s = dmi_get_system_info(DMI_BIOS_VERSION); |
| 7932 | tp->bios_version_str = kstrdup(s, GFP_KERNEL); |
| 7933 | if (s && !tp->bios_version_str) |
| 7934 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7935 | |
| 7936 | /* Really ancient ThinkPad 240X will fail this, which is fine */ |
| 7937 | 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] | 7938 | return 0; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7939 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7940 | tp->bios_model = tp->bios_version_str[0] |
| 7941 | | (tp->bios_version_str[1] << 8); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7942 | tp->bios_release = (tp->bios_version_str[4] << 8) |
| 7943 | | tp->bios_version_str[5]; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7944 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7945 | /* |
| 7946 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 7947 | * X32 or newer, all Z series; Some models must have an |
| 7948 | * up-to-date BIOS or they will not be detected. |
| 7949 | * |
| 7950 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 7951 | */ |
| 7952 | 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] | 7953 | if (sscanf(dev->name, |
| 7954 | "IBM ThinkPad Embedded Controller -[%17c", |
| 7955 | ec_fw_string) == 1) { |
| 7956 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 7957 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7958 | |
| 7959 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7960 | if (!tp->ec_version_str) |
| 7961 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7962 | |
| 7963 | if (tpacpi_is_valid_fw_id(ec_fw_string, 'H')) { |
| 7964 | tp->ec_model = ec_fw_string[0] |
| 7965 | | (ec_fw_string[1] << 8); |
| 7966 | tp->ec_release = (ec_fw_string[4] << 8) |
| 7967 | | ec_fw_string[5]; |
| 7968 | } else { |
| 7969 | printk(TPACPI_NOTICE |
| 7970 | "ThinkPad firmware release %s " |
| 7971 | "doesn't match the known patterns\n", |
| 7972 | ec_fw_string); |
| 7973 | printk(TPACPI_NOTICE |
| 7974 | "please report this to %s\n", |
| 7975 | TPACPI_MAIL); |
| 7976 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7977 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7978 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7979 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7980 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7981 | s = dmi_get_system_info(DMI_PRODUCT_VERSION); |
| 7982 | if (s && !strnicmp(s, "ThinkPad", 8)) { |
| 7983 | tp->model_str = kstrdup(s, GFP_KERNEL); |
| 7984 | if (!tp->model_str) |
| 7985 | return -ENOMEM; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7986 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 7987 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7988 | s = dmi_get_system_info(DMI_PRODUCT_NAME); |
| 7989 | tp->nummodel_str = kstrdup(s, GFP_KERNEL); |
| 7990 | if (s && !tp->nummodel_str) |
| 7991 | return -ENOMEM; |
| 7992 | |
| 7993 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7994 | } |
| 7995 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7996 | static int __init probe_for_thinkpad(void) |
| 7997 | { |
| 7998 | int is_thinkpad; |
| 7999 | |
| 8000 | if (acpi_disabled) |
| 8001 | return -ENODEV; |
| 8002 | |
| 8003 | /* |
| 8004 | * 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] | 8005 | * 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] | 8006 | */ |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 8007 | is_thinkpad = (thinkpad_id.model_str != NULL) || |
| 8008 | (thinkpad_id.ec_model != 0) || |
| 8009 | tpacpi_is_fw_known(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8010 | |
| 8011 | /* 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] | 8012 | TPACPI_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8013 | if (!ec_handle) { |
| 8014 | if (is_thinkpad) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8015 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8016 | "Not yet supported ThinkPad detected!\n"); |
| 8017 | return -ENODEV; |
| 8018 | } |
| 8019 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 8020 | if (!is_thinkpad && !force_load) |
| 8021 | return -ENODEV; |
| 8022 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8023 | return 0; |
| 8024 | } |
| 8025 | |
| 8026 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8027 | /* Module init, exit, parameters */ |
| 8028 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8029 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 8030 | { |
| 8031 | .init = thinkpad_acpi_driver_init, |
| 8032 | .data = &thinkpad_acpi_driver_data, |
| 8033 | }, |
| 8034 | { |
| 8035 | .init = hotkey_init, |
| 8036 | .data = &hotkey_driver_data, |
| 8037 | }, |
| 8038 | { |
| 8039 | .init = bluetooth_init, |
| 8040 | .data = &bluetooth_driver_data, |
| 8041 | }, |
| 8042 | { |
| 8043 | .init = wan_init, |
| 8044 | .data = &wan_driver_data, |
| 8045 | }, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8046 | { |
| 8047 | .init = uwb_init, |
| 8048 | .data = &uwb_driver_data, |
| 8049 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 8050 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8051 | { |
| 8052 | .init = video_init, |
| 8053 | .data = &video_driver_data, |
| 8054 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 8055 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8056 | { |
| 8057 | .init = light_init, |
| 8058 | .data = &light_driver_data, |
| 8059 | }, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8060 | { |
| 8061 | .init = cmos_init, |
| 8062 | .data = &cmos_driver_data, |
| 8063 | }, |
| 8064 | { |
| 8065 | .init = led_init, |
| 8066 | .data = &led_driver_data, |
| 8067 | }, |
| 8068 | { |
| 8069 | .init = beep_init, |
| 8070 | .data = &beep_driver_data, |
| 8071 | }, |
| 8072 | { |
| 8073 | .init = thermal_init, |
| 8074 | .data = &thermal_driver_data, |
| 8075 | }, |
| 8076 | { |
| 8077 | .data = &ecdump_driver_data, |
| 8078 | }, |
| 8079 | { |
| 8080 | .init = brightness_init, |
| 8081 | .data = &brightness_driver_data, |
| 8082 | }, |
| 8083 | { |
| 8084 | .data = &volume_driver_data, |
| 8085 | }, |
| 8086 | { |
| 8087 | .init = fan_init, |
| 8088 | .data = &fan_driver_data, |
| 8089 | }, |
| 8090 | }; |
| 8091 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8092 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 8093 | { |
| 8094 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8095 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8096 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 8097 | if (!kp || !kp->name || !val) |
| 8098 | return -EINVAL; |
| 8099 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8100 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 8101 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 8102 | WARN_ON(ibm == NULL); |
| 8103 | |
| 8104 | if (!ibm || !ibm->name) |
| 8105 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8106 | |
| 8107 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 8108 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8109 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8110 | strcpy(ibms_init[i].param, val); |
| 8111 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8112 | return 0; |
| 8113 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8114 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8115 | |
| 8116 | return -EINVAL; |
| 8117 | } |
| 8118 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame^] | 8119 | module_param(experimental, int, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8120 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8121 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8122 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 8123 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8124 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 8125 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame^] | 8126 | module_param(force_load, bool, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8127 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8128 | "Attempts to load the driver even on a " |
| 8129 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 8130 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame^] | 8131 | module_param_named(fan_control, fan_control_allowed, bool, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8132 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8133 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8134 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame^] | 8135 | module_param_named(brightness_mode, brightness_mode, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8136 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8137 | "Selects brightness control strategy: " |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 8138 | "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 8139 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame^] | 8140 | module_param(brightness_enable, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8141 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8142 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 8143 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame^] | 8144 | module_param(hotkey_report_mode, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8145 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8146 | "used for backwards compatibility with userspace, " |
| 8147 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8148 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8149 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8150 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 8151 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8152 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8153 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8154 | TPACPI_PARAM(hotkey); |
| 8155 | TPACPI_PARAM(bluetooth); |
| 8156 | TPACPI_PARAM(video); |
| 8157 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8158 | TPACPI_PARAM(cmos); |
| 8159 | TPACPI_PARAM(led); |
| 8160 | TPACPI_PARAM(beep); |
| 8161 | TPACPI_PARAM(ecdump); |
| 8162 | TPACPI_PARAM(brightness); |
| 8163 | TPACPI_PARAM(volume); |
| 8164 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8165 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8166 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame^] | 8167 | module_param(dbg_wlswemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8168 | MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation"); |
| 8169 | module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0); |
| 8170 | MODULE_PARM_DESC(wlsw_state, |
| 8171 | "Initial state of the emulated WLSW switch"); |
| 8172 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame^] | 8173 | module_param(dbg_bluetoothemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8174 | MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation"); |
| 8175 | module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0); |
| 8176 | MODULE_PARM_DESC(bluetooth_state, |
| 8177 | "Initial state of the emulated bluetooth switch"); |
| 8178 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame^] | 8179 | module_param(dbg_wwanemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8180 | MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation"); |
| 8181 | module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0); |
| 8182 | MODULE_PARM_DESC(wwan_state, |
| 8183 | "Initial state of the emulated WWAN switch"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8184 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame^] | 8185 | module_param(dbg_uwbemul, uint, 0444); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8186 | MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation"); |
| 8187 | module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0); |
| 8188 | MODULE_PARM_DESC(uwb_state, |
| 8189 | "Initial state of the emulated UWB switch"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8190 | #endif |
| 8191 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8192 | static void thinkpad_acpi_module_exit(void) |
| 8193 | { |
| 8194 | struct ibm_struct *ibm, *itmp; |
| 8195 | |
| 8196 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 8197 | |
| 8198 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 8199 | &tpacpi_all_drivers, |
| 8200 | all_drivers) { |
| 8201 | ibm_exit(ibm); |
| 8202 | } |
| 8203 | |
| 8204 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 8205 | |
| 8206 | if (tpacpi_inputdev) { |
| 8207 | if (tp_features.input_device_registered) |
| 8208 | input_unregister_device(tpacpi_inputdev); |
| 8209 | else |
| 8210 | input_free_device(tpacpi_inputdev); |
| 8211 | } |
| 8212 | |
| 8213 | if (tpacpi_hwmon) |
| 8214 | hwmon_device_unregister(tpacpi_hwmon); |
| 8215 | |
| 8216 | if (tp_features.sensors_pdev_attrs_registered) |
| 8217 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 8218 | &dev_attr_thinkpad_acpi_pdev_name); |
| 8219 | if (tpacpi_sensors_pdev) |
| 8220 | platform_device_unregister(tpacpi_sensors_pdev); |
| 8221 | if (tpacpi_pdev) |
| 8222 | platform_device_unregister(tpacpi_pdev); |
| 8223 | |
| 8224 | if (tp_features.sensors_pdrv_attrs_registered) |
| 8225 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 8226 | if (tp_features.platform_drv_attrs_registered) |
| 8227 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 8228 | |
| 8229 | if (tp_features.sensors_pdrv_registered) |
| 8230 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 8231 | |
| 8232 | if (tp_features.platform_drv_registered) |
| 8233 | platform_driver_unregister(&tpacpi_pdriver); |
| 8234 | |
| 8235 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8236 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8237 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8238 | if (tpacpi_wq) |
| 8239 | destroy_workqueue(tpacpi_wq); |
| 8240 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8241 | kfree(thinkpad_id.bios_version_str); |
| 8242 | kfree(thinkpad_id.ec_version_str); |
| 8243 | kfree(thinkpad_id.model_str); |
| 8244 | } |
| 8245 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 8246 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8247 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8248 | { |
| 8249 | int ret, i; |
| 8250 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 8251 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 8252 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8253 | /* Parameter checking */ |
| 8254 | if (hotkey_report_mode > 2) |
| 8255 | return -EINVAL; |
| 8256 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8257 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8258 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8259 | ret = get_thinkpad_model_data(&thinkpad_id); |
| 8260 | if (ret) { |
| 8261 | printk(TPACPI_ERR |
| 8262 | "unable to get DMI data: %d\n", ret); |
| 8263 | thinkpad_acpi_module_exit(); |
| 8264 | return ret; |
| 8265 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8266 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8267 | if (ret) { |
| 8268 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8269 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8271 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8272 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8273 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8274 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 8275 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8276 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8277 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
| 8278 | if (!tpacpi_wq) { |
| 8279 | thinkpad_acpi_module_exit(); |
| 8280 | return -ENOMEM; |
| 8281 | } |
| 8282 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8283 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8284 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8285 | printk(TPACPI_ERR |
| 8286 | "unable to create proc dir " TPACPI_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8287 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8288 | return -ENODEV; |
| 8289 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8290 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8291 | ret = platform_driver_register(&tpacpi_pdriver); |
| 8292 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8293 | printk(TPACPI_ERR |
| 8294 | "unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8295 | thinkpad_acpi_module_exit(); |
| 8296 | return ret; |
| 8297 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 8298 | tp_features.platform_drv_registered = 1; |
| 8299 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8300 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 8301 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8302 | printk(TPACPI_ERR |
| 8303 | "unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8304 | thinkpad_acpi_module_exit(); |
| 8305 | return ret; |
| 8306 | } |
| 8307 | tp_features.sensors_pdrv_registered = 1; |
| 8308 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8309 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8310 | if (!ret) { |
| 8311 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8312 | ret = tpacpi_create_driver_attributes( |
| 8313 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8314 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8315 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8316 | printk(TPACPI_ERR |
| 8317 | "unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8318 | thinkpad_acpi_module_exit(); |
| 8319 | return ret; |
| 8320 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8321 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8322 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8323 | |
| 8324 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8325 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8326 | NULL, 0); |
| 8327 | if (IS_ERR(tpacpi_pdev)) { |
| 8328 | ret = PTR_ERR(tpacpi_pdev); |
| 8329 | tpacpi_pdev = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8330 | printk(TPACPI_ERR "unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8331 | thinkpad_acpi_module_exit(); |
| 8332 | return ret; |
| 8333 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8334 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8335 | TPACPI_HWMON_DRVR_NAME, |
| 8336 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8337 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 8338 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 8339 | tpacpi_sensors_pdev = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8340 | printk(TPACPI_ERR |
| 8341 | "unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8342 | thinkpad_acpi_module_exit(); |
| 8343 | return ret; |
| 8344 | } |
| 8345 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 8346 | &dev_attr_thinkpad_acpi_pdev_name); |
| 8347 | if (ret) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8348 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8349 | "unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8350 | thinkpad_acpi_module_exit(); |
| 8351 | return ret; |
| 8352 | } |
| 8353 | tp_features.sensors_pdev_attrs_registered = 1; |
| 8354 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8355 | if (IS_ERR(tpacpi_hwmon)) { |
| 8356 | ret = PTR_ERR(tpacpi_hwmon); |
| 8357 | tpacpi_hwmon = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8358 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8359 | thinkpad_acpi_module_exit(); |
| 8360 | return ret; |
| 8361 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 8362 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8363 | tpacpi_inputdev = input_allocate_device(); |
| 8364 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8365 | printk(TPACPI_ERR "unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8366 | thinkpad_acpi_module_exit(); |
| 8367 | return -ENOMEM; |
| 8368 | } else { |
| 8369 | /* Prepare input device, but don't register */ |
| 8370 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8371 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8372 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 8373 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
| 8374 | thinkpad_id.vendor : |
| 8375 | PCI_VENDOR_ID_IBM; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8376 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 8377 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
Henrique de Moraes Holschuh | d112ef9 | 2009-12-09 01:36:26 +0000 | [diff] [blame] | 8378 | tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8379 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8380 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 8381 | ret = ibm_init(&ibms_init[i]); |
| 8382 | if (ret >= 0 && *ibms_init[i].param) |
| 8383 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8384 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8385 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8386 | return ret; |
| 8387 | } |
| 8388 | } |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8389 | ret = input_register_device(tpacpi_inputdev); |
| 8390 | if (ret < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8391 | printk(TPACPI_ERR "unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8392 | thinkpad_acpi_module_exit(); |
| 8393 | return ret; |
| 8394 | } else { |
| 8395 | tp_features.input_device_registered = 1; |
| 8396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8397 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 8398 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8399 | return 0; |
| 8400 | } |
| 8401 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 8402 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 8403 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8404 | /* |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 8405 | * This will autoload the driver in almost every ThinkPad |
| 8406 | * in widespread use. |
| 8407 | * |
| 8408 | * Only _VERY_ old models, like the 240, 240x and 570 lack |
| 8409 | * the HKEY event interface. |
| 8410 | */ |
| 8411 | MODULE_DEVICE_TABLE(acpi, ibm_htk_device_ids); |
| 8412 | |
| 8413 | /* |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8414 | * DMI matching for module autoloading |
| 8415 | * |
| 8416 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 8417 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 8418 | * |
| 8419 | * Only models listed in thinkwiki will be supported, so add yours |
| 8420 | * if it is not there yet. |
| 8421 | */ |
| 8422 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
Mathieu Chouquet-Stringer | b36a50f | 2009-03-14 16:35:26 +0100 | [diff] [blame] | 8423 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*") |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8424 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8425 | /* Ancient thinkpad BIOSes have to be identified by |
| 8426 | * BIOS type or model number, and there are far less |
| 8427 | * BIOS types than model numbers... */ |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 8428 | IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8429 | |
Henrique de Moraes Holschuh | f68f53a | 2009-04-14 02:44:12 +0000 | [diff] [blame] | 8430 | MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>"); |
| 8431 | MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8432 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 8433 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8434 | MODULE_LICENSE("GPL"); |
| 8435 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8436 | module_init(thinkpad_acpi_module_init); |
| 8437 | module_exit(thinkpad_acpi_module_exit); |