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 | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 25 | #define TPACPI_SYSFS_VERSION 0x020700 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 26 | |
| 27 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * Changelog: |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 29 | * 2007-10-20 changelog trimmed down |
| 30 | * |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 31 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
| 32 | * drivers/misc. |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 33 | * |
| 34 | * 2006-11-22 0.13 new maintainer |
| 35 | * changelog now lives in git commit history, and will |
| 36 | * not be updated further in-file. |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 37 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 38 | * 2005-03-17 0.11 support for 600e, 770x |
| 39 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 40 | * |
| 41 | * 2005-01-16 0.9 use MODULE_VERSION |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 42 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
| 43 | * fix parameter passing on module loading |
| 44 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
| 45 | * thanks to Jim Radford <radford@blackbean.org> |
| 46 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
| 47 | * thanks to Chris Wright <chrisw@osdl.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | */ |
| 49 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 50 | #include <linux/kernel.h> |
| 51 | #include <linux/module.h> |
| 52 | #include <linux/init.h> |
| 53 | #include <linux/types.h> |
| 54 | #include <linux/string.h> |
| 55 | #include <linux/list.h> |
| 56 | #include <linux/mutex.h> |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 57 | #include <linux/sched.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 58 | #include <linux/kthread.h> |
| 59 | #include <linux/freezer.h> |
| 60 | #include <linux/delay.h> |
| 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 | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 234 | #define TPACPI_DBG_MIXER 0x0040 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 235 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 236 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 237 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 238 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 239 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 240 | |
| 241 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 242 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 243 | */ |
| 244 | |
| 245 | struct ibm_struct; |
| 246 | |
| 247 | struct tp_acpi_drv_struct { |
| 248 | const struct acpi_device_id *hid; |
| 249 | struct acpi_driver *driver; |
| 250 | |
| 251 | void (*notify) (struct ibm_struct *, u32); |
| 252 | acpi_handle *handle; |
| 253 | u32 type; |
| 254 | struct acpi_device *device; |
| 255 | }; |
| 256 | |
| 257 | struct ibm_struct { |
| 258 | char *name; |
| 259 | |
| 260 | int (*read) (char *); |
| 261 | int (*write) (char *); |
| 262 | void (*exit) (void); |
| 263 | void (*resume) (void); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 264 | void (*suspend) (pm_message_t state); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 265 | void (*shutdown) (void); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 266 | |
| 267 | struct list_head all_drivers; |
| 268 | |
| 269 | struct tp_acpi_drv_struct *acpi; |
| 270 | |
| 271 | struct { |
| 272 | u8 acpi_driver_registered:1; |
| 273 | u8 acpi_notify_installed:1; |
| 274 | u8 proc_created:1; |
| 275 | u8 init_called:1; |
| 276 | u8 experimental:1; |
| 277 | } flags; |
| 278 | }; |
| 279 | |
| 280 | struct ibm_init_struct { |
| 281 | char param[32]; |
| 282 | |
| 283 | int (*init) (struct ibm_init_struct *); |
| 284 | struct ibm_struct *data; |
| 285 | }; |
| 286 | |
| 287 | static struct { |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 288 | u32 bluetooth:1; |
| 289 | u32 hotkey:1; |
| 290 | u32 hotkey_mask:1; |
| 291 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 292 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 293 | u32 light:1; |
| 294 | u32 light_status:1; |
| 295 | u32 bright_16levels:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 296 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 297 | u32 wan:1; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 298 | u32 uwb:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 299 | u32 fan_ctrl_status_undef:1; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 300 | u32 second_fan:1; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 301 | u32 beep_needs_two_args:1; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 302 | u32 mixer_no_level_control:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 303 | u32 input_device_registered:1; |
| 304 | u32 platform_drv_registered:1; |
| 305 | u32 platform_drv_attrs_registered:1; |
| 306 | u32 sensors_pdrv_registered:1; |
| 307 | u32 sensors_pdrv_attrs_registered:1; |
| 308 | u32 sensors_pdev_attrs_registered:1; |
| 309 | u32 hotkey_poll_active:1; |
| 310 | } tp_features; |
| 311 | |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 312 | static struct { |
| 313 | u16 hotkey_mask_ff:1; |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame^] | 314 | u16 volume_ctrl_forbidden:1; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 315 | } tp_warned; |
| 316 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 317 | struct thinkpad_id_data { |
| 318 | unsigned int vendor; /* ThinkPad vendor: |
| 319 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 320 | |
| 321 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 322 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 323 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 324 | u16 bios_model; /* 1Y = 0x5931, 0 = unknown */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 325 | u16 ec_model; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 326 | u16 bios_release; /* 1ZETK1WW = 0x314b, 0 = unknown */ |
| 327 | u16 ec_release; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 328 | |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 329 | char *model_str; /* ThinkPad T43 */ |
| 330 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 331 | }; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 332 | static struct thinkpad_id_data thinkpad_id; |
| 333 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 334 | static enum { |
| 335 | TPACPI_LIFE_INIT = 0, |
| 336 | TPACPI_LIFE_RUNNING, |
| 337 | TPACPI_LIFE_EXITING, |
| 338 | } tpacpi_lifecycle; |
| 339 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 340 | static int experimental; |
| 341 | static u32 dbg_level; |
| 342 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 343 | static struct workqueue_struct *tpacpi_wq; |
| 344 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 345 | enum led_status_t { |
| 346 | TPACPI_LED_OFF = 0, |
| 347 | TPACPI_LED_ON, |
| 348 | TPACPI_LED_BLINK, |
| 349 | }; |
| 350 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 351 | /* Special LED class that can defer work */ |
| 352 | struct tpacpi_led_classdev { |
| 353 | struct led_classdev led_classdev; |
| 354 | struct work_struct work; |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 355 | enum led_status_t new_state; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 356 | unsigned int led; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 357 | }; |
| 358 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 359 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 360 | static int dbg_wlswemul; |
| 361 | static int tpacpi_wlsw_emulstate; |
| 362 | static int dbg_bluetoothemul; |
| 363 | static int tpacpi_bluetooth_emulstate; |
| 364 | static int dbg_wwanemul; |
| 365 | static int tpacpi_wwan_emulstate; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 366 | static int dbg_uwbemul; |
| 367 | static int tpacpi_uwb_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 368 | #endif |
| 369 | |
| 370 | |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 371 | /************************************************************************* |
| 372 | * Debugging helpers |
| 373 | */ |
| 374 | |
| 375 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 376 | do { if (dbg_level & (a_dbg_level)) \ |
| 377 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ |
| 378 | } while (0) |
| 379 | |
| 380 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 381 | #define vdbg_printk dbg_printk |
| 382 | static const char *str_supported(int is_supported); |
| 383 | #else |
| 384 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 385 | do { } while (0) |
| 386 | #endif |
| 387 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 388 | static void tpacpi_log_usertask(const char * const what) |
| 389 | { |
| 390 | printk(TPACPI_DEBUG "%s: access by process with PID %d\n", |
| 391 | what, task_tgid_vnr(current)); |
| 392 | } |
| 393 | |
| 394 | #define tpacpi_disclose_usertask(what, format, arg...) \ |
| 395 | do { \ |
| 396 | if (unlikely( \ |
| 397 | (dbg_level & TPACPI_DBG_DISCLOSETASK) && \ |
| 398 | (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \ |
| 399 | printk(TPACPI_DEBUG "%s: PID %d: " format, \ |
| 400 | what, task_tgid_vnr(current), ## arg); \ |
| 401 | } \ |
| 402 | } while (0) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 403 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 404 | /* |
| 405 | * Quirk handling helpers |
| 406 | * |
| 407 | * ThinkPad IDs and versions seen in the field so far |
| 408 | * are two-characters from the set [0-9A-Z], i.e. base 36. |
| 409 | * |
| 410 | * We use values well outside that range as specials. |
| 411 | */ |
| 412 | |
| 413 | #define TPACPI_MATCH_ANY 0xffffU |
| 414 | #define TPACPI_MATCH_UNKNOWN 0U |
| 415 | |
| 416 | /* TPID('1', 'Y') == 0x5931 */ |
| 417 | #define TPID(__c1, __c2) (((__c2) << 8) | (__c1)) |
| 418 | |
| 419 | #define TPACPI_Q_IBM(__id1, __id2, __quirk) \ |
| 420 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 421 | .bios = TPID(__id1, __id2), \ |
| 422 | .ec = TPACPI_MATCH_ANY, \ |
| 423 | .quirks = (__quirk) } |
| 424 | |
| 425 | #define TPACPI_Q_LNV(__id1, __id2, __quirk) \ |
| 426 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 427 | .bios = TPID(__id1, __id2), \ |
| 428 | .ec = TPACPI_MATCH_ANY, \ |
| 429 | .quirks = (__quirk) } |
| 430 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 431 | #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \ |
| 432 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 433 | .bios = TPACPI_MATCH_ANY, \ |
| 434 | .ec = TPID(__id1, __id2), \ |
| 435 | .quirks = (__quirk) } |
| 436 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 437 | struct tpacpi_quirk { |
| 438 | unsigned int vendor; |
| 439 | u16 bios; |
| 440 | u16 ec; |
| 441 | unsigned long quirks; |
| 442 | }; |
| 443 | |
| 444 | /** |
| 445 | * tpacpi_check_quirks() - search BIOS/EC version on a list |
| 446 | * @qlist: array of &struct tpacpi_quirk |
| 447 | * @qlist_size: number of elements in @qlist |
| 448 | * |
| 449 | * Iterates over a quirks list until one is found that matches the |
| 450 | * ThinkPad's vendor, BIOS and EC model. |
| 451 | * |
| 452 | * Returns 0 if nothing matches, otherwise returns the quirks field of |
| 453 | * the matching &struct tpacpi_quirk entry. |
| 454 | * |
| 455 | * The match criteria is: vendor, ec and bios much match. |
| 456 | */ |
| 457 | static unsigned long __init tpacpi_check_quirks( |
| 458 | const struct tpacpi_quirk *qlist, |
| 459 | unsigned int qlist_size) |
| 460 | { |
| 461 | while (qlist_size) { |
| 462 | if ((qlist->vendor == thinkpad_id.vendor || |
| 463 | qlist->vendor == TPACPI_MATCH_ANY) && |
| 464 | (qlist->bios == thinkpad_id.bios_model || |
| 465 | qlist->bios == TPACPI_MATCH_ANY) && |
| 466 | (qlist->ec == thinkpad_id.ec_model || |
| 467 | qlist->ec == TPACPI_MATCH_ANY)) |
| 468 | return qlist->quirks; |
| 469 | |
| 470 | qlist_size--; |
| 471 | qlist++; |
| 472 | } |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 477 | /**************************************************************************** |
| 478 | **************************************************************************** |
| 479 | * |
| 480 | * ACPI Helpers and device model |
| 481 | * |
| 482 | **************************************************************************** |
| 483 | ****************************************************************************/ |
| 484 | |
| 485 | /************************************************************************* |
| 486 | * ACPI basic handles |
| 487 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 489 | static acpi_handle root_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 491 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | static acpi_handle object##_handle; \ |
| 493 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 494 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | static char *object##_paths[] = { paths } |
| 496 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 497 | TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 498 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 499 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 500 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 501 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 502 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 503 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 504 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 506 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 507 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 509 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 510 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 511 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 512 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 513 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 514 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 515 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 516 | "^HKEY", /* R30, R31 */ |
| 517 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 518 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 519 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 520 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 521 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 522 | "\\_SB.PCI0.VID0", /* 770e */ |
| 523 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 524 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 525 | ); /* R30, R31 */ |
| 526 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 527 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 528 | /************************************************************************* |
| 529 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 530 | */ |
| 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | static int acpi_evalf(acpi_handle handle, |
| 533 | void *res, char *method, char *fmt, ...) |
| 534 | { |
| 535 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 536 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 537 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 538 | struct acpi_buffer result, *resultp; |
| 539 | union acpi_object out_obj; |
| 540 | acpi_status status; |
| 541 | va_list ap; |
| 542 | char res_type; |
| 543 | int success; |
| 544 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
| 546 | if (!*fmt) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 547 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | if (*fmt == 'q') { |
| 552 | quiet = 1; |
| 553 | fmt++; |
| 554 | } else |
| 555 | quiet = 0; |
| 556 | |
| 557 | res_type = *(fmt++); |
| 558 | |
| 559 | params.count = 0; |
| 560 | params.pointer = &in_objs[0]; |
| 561 | |
| 562 | va_start(ap, fmt); |
| 563 | while (*fmt) { |
| 564 | char c = *(fmt++); |
| 565 | switch (c) { |
| 566 | case 'd': /* int */ |
| 567 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 568 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 569 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 570 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 572 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | "with invalid format character '%c'\n", c); |
| 574 | return 0; |
| 575 | } |
| 576 | } |
| 577 | va_end(ap); |
| 578 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 579 | if (res_type != 'v') { |
| 580 | result.length = sizeof(out_obj); |
| 581 | result.pointer = &out_obj; |
| 582 | resultp = &result; |
| 583 | } else |
| 584 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 586 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
| 588 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 589 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | if (res) |
| 591 | *(int *)res = out_obj.integer.value; |
| 592 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 593 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 594 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | success = status == AE_OK; |
| 596 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 597 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 599 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | "with invalid format character '%c'\n", res_type); |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | if (!success && !quiet) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 605 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | method, fmt0, status); |
| 607 | |
| 608 | return success; |
| 609 | } |
| 610 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 611 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 612 | { |
| 613 | int v; |
| 614 | |
| 615 | if (ecrd_handle) { |
| 616 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 617 | return 0; |
| 618 | *p = v; |
| 619 | } else { |
| 620 | if (ec_read(i, p) < 0) |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | return 1; |
| 625 | } |
| 626 | |
| 627 | static int acpi_ec_write(int i, u8 v) |
| 628 | { |
| 629 | if (ecwr_handle) { |
| 630 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 631 | return 0; |
| 632 | } else { |
| 633 | if (ec_write(i, v) < 0) |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | return 1; |
| 638 | } |
| 639 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 640 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 641 | { |
| 642 | if (!cmos_handle) |
| 643 | return -ENXIO; |
| 644 | |
| 645 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 646 | return -EIO; |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 651 | /************************************************************************* |
| 652 | * ACPI device model |
| 653 | */ |
| 654 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 655 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 656 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 657 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
| 658 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 659 | static void drv_acpi_handle_init(char *name, |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 660 | acpi_handle *handle, acpi_handle parent, |
| 661 | char **paths, int num_paths, char **path) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 662 | { |
| 663 | int i; |
| 664 | acpi_status status; |
| 665 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 666 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 667 | name); |
| 668 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 669 | for (i = 0; i < num_paths; i++) { |
| 670 | status = acpi_get_handle(parent, paths[i], handle); |
| 671 | if (ACPI_SUCCESS(status)) { |
| 672 | *path = paths[i]; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 673 | dbg_printk(TPACPI_DBG_INIT, |
| 674 | "Found ACPI handle %s for %s\n", |
| 675 | *path, name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 676 | return; |
| 677 | } |
| 678 | } |
| 679 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 680 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 681 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 682 | *handle = NULL; |
| 683 | } |
| 684 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 685 | 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] | 686 | { |
| 687 | struct ibm_struct *ibm = data; |
| 688 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 689 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 690 | return; |
| 691 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 692 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 693 | return; |
| 694 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 695 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 696 | } |
| 697 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 698 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 699 | { |
| 700 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 701 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 702 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 703 | BUG_ON(!ibm->acpi); |
| 704 | |
| 705 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 706 | return 0; |
| 707 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 708 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 709 | "setting up ACPI notify for %s\n", ibm->name); |
| 710 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 711 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 712 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 713 | 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] | 714 | ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 715 | return -ENODEV; |
| 716 | } |
| 717 | |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 718 | ibm->acpi->device->driver_data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 719 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 720 | TPACPI_ACPI_EVENT_PREFIX, |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 721 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 722 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 723 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 724 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 725 | if (ACPI_FAILURE(status)) { |
| 726 | if (status == AE_ALREADY_EXISTS) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 727 | printk(TPACPI_NOTICE |
| 728 | "another device driver is already " |
| 729 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 730 | } else { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 731 | printk(TPACPI_ERR |
| 732 | "acpi_install_notify_handler(%s) failed: %d\n", |
| 733 | ibm->name, status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 734 | } |
| 735 | return -ENODEV; |
| 736 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 737 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 738 | return 0; |
| 739 | } |
| 740 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 741 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 742 | { |
| 743 | return 0; |
| 744 | } |
| 745 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 746 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 747 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 748 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 749 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 750 | dbg_printk(TPACPI_DBG_INIT, |
| 751 | "registering %s as an ACPI driver\n", ibm->name); |
| 752 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 753 | BUG_ON(!ibm->acpi); |
| 754 | |
| 755 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 756 | if (!ibm->acpi->driver) { |
Mariusz Kozlowski | 4f778b9 | 2008-10-18 14:23:53 -0300 | [diff] [blame] | 757 | printk(TPACPI_ERR |
| 758 | "failed to allocate memory for ibm->acpi->driver\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 759 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 760 | } |
| 761 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 762 | 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] | 763 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 764 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 765 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
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 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 768 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 769 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 770 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 771 | kfree(ibm->acpi->driver); |
| 772 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 773 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 774 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 775 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 776 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | |
| 780 | /**************************************************************************** |
| 781 | **************************************************************************** |
| 782 | * |
| 783 | * Procfs Helpers |
| 784 | * |
| 785 | **************************************************************************** |
| 786 | ****************************************************************************/ |
| 787 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 788 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 789 | int count, int *eof, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 790 | { |
| 791 | struct ibm_struct *ibm = data; |
| 792 | int len; |
| 793 | |
| 794 | if (!ibm || !ibm->read) |
| 795 | return -EINVAL; |
| 796 | |
| 797 | len = ibm->read(page); |
| 798 | if (len < 0) |
| 799 | return len; |
| 800 | |
| 801 | if (len <= off + count) |
| 802 | *eof = 1; |
| 803 | *start = page + off; |
| 804 | len -= off; |
| 805 | if (len > count) |
| 806 | len = count; |
| 807 | if (len < 0) |
| 808 | len = 0; |
| 809 | |
| 810 | return len; |
| 811 | } |
| 812 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 813 | static int dispatch_procfs_write(struct file *file, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 814 | const char __user *userbuf, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 815 | unsigned long count, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 816 | { |
| 817 | struct ibm_struct *ibm = data; |
| 818 | char *kernbuf; |
| 819 | int ret; |
| 820 | |
| 821 | if (!ibm || !ibm->write) |
| 822 | return -EINVAL; |
Michael Buesch | 5b05d46 | 2009-08-01 12:04:19 -0300 | [diff] [blame] | 823 | if (count > PAGE_SIZE - 2) |
| 824 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 825 | |
| 826 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 827 | if (!kernbuf) |
| 828 | return -ENOMEM; |
| 829 | |
| 830 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 831 | kfree(kernbuf); |
| 832 | return -EFAULT; |
| 833 | } |
| 834 | |
| 835 | kernbuf[count] = 0; |
| 836 | strcat(kernbuf, ","); |
| 837 | ret = ibm->write(kernbuf); |
| 838 | if (ret == 0) |
| 839 | ret = count; |
| 840 | |
| 841 | kfree(kernbuf); |
| 842 | |
| 843 | return ret; |
| 844 | } |
| 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | static char *next_cmd(char **cmds) |
| 847 | { |
| 848 | char *start = *cmds; |
| 849 | char *end; |
| 850 | |
| 851 | while ((end = strchr(start, ',')) && end == start) |
| 852 | start = end + 1; |
| 853 | |
| 854 | if (!end) |
| 855 | return NULL; |
| 856 | |
| 857 | *end = 0; |
| 858 | *cmds = end + 1; |
| 859 | return start; |
| 860 | } |
| 861 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 862 | |
| 863 | /**************************************************************************** |
| 864 | **************************************************************************** |
| 865 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 866 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 867 | * |
| 868 | **************************************************************************** |
| 869 | ****************************************************************************/ |
| 870 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 871 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 872 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 873 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 874 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 875 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 876 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 877 | |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 878 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
| 879 | pm_message_t state) |
| 880 | { |
| 881 | struct ibm_struct *ibm, *itmp; |
| 882 | |
| 883 | list_for_each_entry_safe(ibm, itmp, |
| 884 | &tpacpi_all_drivers, |
| 885 | all_drivers) { |
| 886 | if (ibm->suspend) |
| 887 | (ibm->suspend)(state); |
| 888 | } |
| 889 | |
| 890 | return 0; |
| 891 | } |
| 892 | |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 893 | static int tpacpi_resume_handler(struct platform_device *pdev) |
| 894 | { |
| 895 | struct ibm_struct *ibm, *itmp; |
| 896 | |
| 897 | list_for_each_entry_safe(ibm, itmp, |
| 898 | &tpacpi_all_drivers, |
| 899 | all_drivers) { |
| 900 | if (ibm->resume) |
| 901 | (ibm->resume)(); |
| 902 | } |
| 903 | |
| 904 | return 0; |
| 905 | } |
| 906 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 907 | static void tpacpi_shutdown_handler(struct platform_device *pdev) |
| 908 | { |
| 909 | struct ibm_struct *ibm, *itmp; |
| 910 | |
| 911 | list_for_each_entry_safe(ibm, itmp, |
| 912 | &tpacpi_all_drivers, |
| 913 | all_drivers) { |
| 914 | if (ibm->shutdown) |
| 915 | (ibm->shutdown)(); |
| 916 | } |
| 917 | } |
| 918 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 919 | static struct platform_driver tpacpi_pdriver = { |
| 920 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 921 | .name = TPACPI_DRVR_NAME, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 922 | .owner = THIS_MODULE, |
| 923 | }, |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 924 | .suspend = tpacpi_suspend_handler, |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 925 | .resume = tpacpi_resume_handler, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 926 | .shutdown = tpacpi_shutdown_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 927 | }; |
| 928 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 929 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 930 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 931 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 932 | .owner = THIS_MODULE, |
| 933 | }, |
| 934 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 935 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 936 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 937 | * sysfs support helpers |
| 938 | */ |
| 939 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 940 | struct attribute_set { |
| 941 | unsigned int members, max_members; |
| 942 | struct attribute_group group; |
| 943 | }; |
| 944 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 945 | struct attribute_set_obj { |
| 946 | struct attribute_set s; |
| 947 | struct attribute *a; |
| 948 | } __attribute__((packed)); |
| 949 | |
| 950 | 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] | 951 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 952 | { |
| 953 | struct attribute_set_obj *sobj; |
| 954 | |
| 955 | if (max_members == 0) |
| 956 | return NULL; |
| 957 | |
| 958 | /* Allocates space for implicit NULL at the end too */ |
| 959 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 960 | max_members * sizeof(struct attribute *), |
| 961 | GFP_KERNEL); |
| 962 | if (!sobj) |
| 963 | return NULL; |
| 964 | sobj->s.max_members = max_members; |
| 965 | sobj->s.group.attrs = &sobj->a; |
| 966 | sobj->s.group.name = name; |
| 967 | |
| 968 | return &sobj->s; |
| 969 | } |
| 970 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 971 | #define destroy_attr_set(_set) \ |
| 972 | kfree(_set); |
| 973 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 974 | /* 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] | 975 | 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] | 976 | { |
| 977 | if (!s || !attr) |
| 978 | return -EINVAL; |
| 979 | |
| 980 | if (s->members >= s->max_members) |
| 981 | return -ENOMEM; |
| 982 | |
| 983 | s->group.attrs[s->members] = attr; |
| 984 | s->members++; |
| 985 | |
| 986 | return 0; |
| 987 | } |
| 988 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 989 | 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] | 990 | struct attribute **attr, |
| 991 | unsigned int count) |
| 992 | { |
| 993 | int i, res; |
| 994 | |
| 995 | for (i = 0; i < count; i++) { |
| 996 | res = add_to_attr_set(s, attr[i]); |
| 997 | if (res) |
| 998 | return res; |
| 999 | } |
| 1000 | |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1004 | 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] | 1005 | { |
| 1006 | sysfs_remove_group(kobj, &s->group); |
| 1007 | destroy_attr_set(s); |
| 1008 | } |
| 1009 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1010 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 1011 | sysfs_create_group(_kobj, &_attr_set->group) |
| 1012 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1013 | static int parse_strtoul(const char *buf, |
| 1014 | unsigned long max, unsigned long *value) |
| 1015 | { |
| 1016 | char *endp; |
| 1017 | |
Henrique de Moraes Holschuh | 32afbf0 | 2007-10-08 10:12:56 -0300 | [diff] [blame] | 1018 | while (*buf && isspace(*buf)) |
| 1019 | buf++; |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1020 | *value = simple_strtoul(buf, &endp, 0); |
| 1021 | while (*endp && isspace(*endp)) |
| 1022 | endp++; |
| 1023 | if (*endp || *value > max) |
| 1024 | return -EINVAL; |
| 1025 | |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 1029 | static void tpacpi_disable_brightness_delay(void) |
| 1030 | { |
| 1031 | if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0)) |
| 1032 | printk(TPACPI_NOTICE |
| 1033 | "ACPI backlight control delay disabled\n"); |
| 1034 | } |
| 1035 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 1036 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 1037 | { |
| 1038 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 1039 | union acpi_object *obj; |
| 1040 | int rc; |
| 1041 | |
| 1042 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { |
| 1043 | obj = (union acpi_object *)buffer.pointer; |
| 1044 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
| 1045 | printk(TPACPI_ERR "Unknown _BCL data, " |
| 1046 | "please report this to %s\n", TPACPI_MAIL); |
| 1047 | rc = 0; |
| 1048 | } else { |
| 1049 | rc = obj->package.count; |
| 1050 | } |
| 1051 | } else { |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | kfree(buffer.pointer); |
| 1056 | return rc; |
| 1057 | } |
| 1058 | |
| 1059 | static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle, |
| 1060 | u32 lvl, void *context, void **rv) |
| 1061 | { |
| 1062 | char name[ACPI_PATH_SEGMENT_LENGTH]; |
| 1063 | struct acpi_buffer buffer = { sizeof(name), &name }; |
| 1064 | |
| 1065 | if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && |
| 1066 | !strncmp("_BCL", name, sizeof(name) - 1)) { |
| 1067 | BUG_ON(!rv || !*rv); |
| 1068 | **(int **)rv = tpacpi_query_bcl_levels(handle); |
| 1069 | return AE_CTRL_TERMINATE; |
| 1070 | } else { |
| 1071 | return AE_OK; |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | /* |
| 1076 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 1077 | */ |
| 1078 | static int __init tpacpi_check_std_acpi_brightness_support(void) |
| 1079 | { |
| 1080 | int status; |
| 1081 | int bcl_levels = 0; |
| 1082 | void *bcl_ptr = &bcl_levels; |
| 1083 | |
| 1084 | if (!vid_handle) { |
| 1085 | TPACPI_ACPIHANDLE_INIT(vid); |
| 1086 | } |
| 1087 | if (!vid_handle) |
| 1088 | return 0; |
| 1089 | |
| 1090 | /* |
| 1091 | * Search for a _BCL method, and execute it. This is safe on all |
| 1092 | * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista |
| 1093 | * BIOS in ACPI backlight control mode. We do NOT have to care |
| 1094 | * about calling the _BCL method in an enabled video device, any |
| 1095 | * will do for our purposes. |
| 1096 | */ |
| 1097 | |
| 1098 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, |
| 1099 | tpacpi_acpi_walk_find_bcl, NULL, |
| 1100 | &bcl_ptr); |
| 1101 | |
| 1102 | if (ACPI_SUCCESS(status) && bcl_levels > 2) { |
| 1103 | tp_features.bright_acpimode = 1; |
| 1104 | return (bcl_levels - 2); |
| 1105 | } |
| 1106 | |
| 1107 | return 0; |
| 1108 | } |
| 1109 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1110 | static void printk_deprecated_attribute(const char * const what, |
| 1111 | const char * const details) |
| 1112 | { |
| 1113 | tpacpi_log_usertask("deprecated sysfs attribute"); |
| 1114 | printk(TPACPI_WARN "WARNING: sysfs attribute %s is deprecated and " |
| 1115 | "will be removed. %s\n", |
| 1116 | what, details); |
| 1117 | } |
| 1118 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1119 | /************************************************************************* |
| 1120 | * rfkill and radio control support helpers |
| 1121 | */ |
| 1122 | |
| 1123 | /* |
| 1124 | * ThinkPad-ACPI firmware handling model: |
| 1125 | * |
| 1126 | * WLSW (master wireless switch) is event-driven, and is common to all |
| 1127 | * firmware-controlled radios. It cannot be controlled, just monitored, |
| 1128 | * as expected. It overrides all radio state in firmware |
| 1129 | * |
| 1130 | * The kernel, a masked-off hotkey, and WLSW can change the radio state |
| 1131 | * (TODO: verify how WLSW interacts with the returned radio state). |
| 1132 | * |
| 1133 | * The only time there are shadow radio state changes, is when |
| 1134 | * masked-off hotkeys are used. |
| 1135 | */ |
| 1136 | |
| 1137 | /* |
| 1138 | * Internal driver API for radio state: |
| 1139 | * |
| 1140 | * int: < 0 = error, otherwise enum tpacpi_rfkill_state |
| 1141 | * bool: true means radio blocked (off) |
| 1142 | */ |
| 1143 | enum tpacpi_rfkill_state { |
| 1144 | TPACPI_RFK_RADIO_OFF = 0, |
| 1145 | TPACPI_RFK_RADIO_ON |
| 1146 | }; |
| 1147 | |
| 1148 | /* rfkill switches */ |
| 1149 | enum tpacpi_rfk_id { |
| 1150 | TPACPI_RFK_BLUETOOTH_SW_ID = 0, |
| 1151 | TPACPI_RFK_WWAN_SW_ID, |
| 1152 | TPACPI_RFK_UWB_SW_ID, |
| 1153 | TPACPI_RFK_SW_MAX |
| 1154 | }; |
| 1155 | |
| 1156 | static const char *tpacpi_rfkill_names[] = { |
| 1157 | [TPACPI_RFK_BLUETOOTH_SW_ID] = "bluetooth", |
| 1158 | [TPACPI_RFK_WWAN_SW_ID] = "wwan", |
| 1159 | [TPACPI_RFK_UWB_SW_ID] = "uwb", |
| 1160 | [TPACPI_RFK_SW_MAX] = NULL |
| 1161 | }; |
| 1162 | |
| 1163 | /* ThinkPad-ACPI rfkill subdriver */ |
| 1164 | struct tpacpi_rfk { |
| 1165 | struct rfkill *rfkill; |
| 1166 | enum tpacpi_rfk_id id; |
| 1167 | const struct tpacpi_rfk_ops *ops; |
| 1168 | }; |
| 1169 | |
| 1170 | struct tpacpi_rfk_ops { |
| 1171 | /* firmware interface */ |
| 1172 | int (*get_status)(void); |
| 1173 | int (*set_status)(const enum tpacpi_rfkill_state); |
| 1174 | }; |
| 1175 | |
| 1176 | static struct tpacpi_rfk *tpacpi_rfkill_switches[TPACPI_RFK_SW_MAX]; |
| 1177 | |
| 1178 | /* Query FW and update rfkill sw state for a given rfkill switch */ |
| 1179 | static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk *tp_rfk) |
| 1180 | { |
| 1181 | int status; |
| 1182 | |
| 1183 | if (!tp_rfk) |
| 1184 | return -ENODEV; |
| 1185 | |
| 1186 | status = (tp_rfk->ops->get_status)(); |
| 1187 | if (status < 0) |
| 1188 | return status; |
| 1189 | |
| 1190 | rfkill_set_sw_state(tp_rfk->rfkill, |
| 1191 | (status == TPACPI_RFK_RADIO_OFF)); |
| 1192 | |
| 1193 | return status; |
| 1194 | } |
| 1195 | |
| 1196 | /* Query FW and update rfkill sw state for all rfkill switches */ |
| 1197 | static void tpacpi_rfk_update_swstate_all(void) |
| 1198 | { |
| 1199 | unsigned int i; |
| 1200 | |
| 1201 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) |
| 1202 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[i]); |
| 1203 | } |
| 1204 | |
| 1205 | /* |
| 1206 | * Sync the HW-blocking state of all rfkill switches, |
| 1207 | * do notice it causes the rfkill core to schedule uevents |
| 1208 | */ |
| 1209 | static void tpacpi_rfk_update_hwblock_state(bool blocked) |
| 1210 | { |
| 1211 | unsigned int i; |
| 1212 | struct tpacpi_rfk *tp_rfk; |
| 1213 | |
| 1214 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) { |
| 1215 | tp_rfk = tpacpi_rfkill_switches[i]; |
| 1216 | if (tp_rfk) { |
| 1217 | if (rfkill_set_hw_state(tp_rfk->rfkill, |
| 1218 | blocked)) { |
| 1219 | /* ignore -- we track sw block */ |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | /* Call to get the WLSW state from the firmware */ |
| 1226 | static int hotkey_get_wlsw(void); |
| 1227 | |
| 1228 | /* Call to query WLSW state and update all rfkill switches */ |
| 1229 | static bool tpacpi_rfk_check_hwblock_state(void) |
| 1230 | { |
| 1231 | int res = hotkey_get_wlsw(); |
| 1232 | int hw_blocked; |
| 1233 | |
| 1234 | /* When unknown or unsupported, we have to assume it is unblocked */ |
| 1235 | if (res < 0) |
| 1236 | return false; |
| 1237 | |
| 1238 | hw_blocked = (res == TPACPI_RFK_RADIO_OFF); |
| 1239 | tpacpi_rfk_update_hwblock_state(hw_blocked); |
| 1240 | |
| 1241 | return hw_blocked; |
| 1242 | } |
| 1243 | |
| 1244 | static int tpacpi_rfk_hook_set_block(void *data, bool blocked) |
| 1245 | { |
| 1246 | struct tpacpi_rfk *tp_rfk = data; |
| 1247 | int res; |
| 1248 | |
| 1249 | dbg_printk(TPACPI_DBG_RFKILL, |
| 1250 | "request to change radio state to %s\n", |
| 1251 | blocked ? "blocked" : "unblocked"); |
| 1252 | |
| 1253 | /* try to set radio state */ |
| 1254 | res = (tp_rfk->ops->set_status)(blocked ? |
| 1255 | TPACPI_RFK_RADIO_OFF : TPACPI_RFK_RADIO_ON); |
| 1256 | |
| 1257 | /* and update the rfkill core with whatever the FW really did */ |
| 1258 | tpacpi_rfk_update_swstate(tp_rfk); |
| 1259 | |
| 1260 | return (res < 0) ? res : 0; |
| 1261 | } |
| 1262 | |
| 1263 | static const struct rfkill_ops tpacpi_rfk_rfkill_ops = { |
| 1264 | .set_block = tpacpi_rfk_hook_set_block, |
| 1265 | }; |
| 1266 | |
| 1267 | static int __init tpacpi_new_rfkill(const enum tpacpi_rfk_id id, |
| 1268 | const struct tpacpi_rfk_ops *tp_rfkops, |
| 1269 | const enum rfkill_type rfktype, |
| 1270 | const char *name, |
| 1271 | const bool set_default) |
| 1272 | { |
| 1273 | struct tpacpi_rfk *atp_rfk; |
| 1274 | int res; |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1275 | bool sw_state = false; |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1276 | bool hw_state; |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1277 | int sw_status; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1278 | |
| 1279 | BUG_ON(id >= TPACPI_RFK_SW_MAX || tpacpi_rfkill_switches[id]); |
| 1280 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1281 | atp_rfk = kzalloc(sizeof(struct tpacpi_rfk), GFP_KERNEL); |
| 1282 | if (atp_rfk) |
| 1283 | atp_rfk->rfkill = rfkill_alloc(name, |
| 1284 | &tpacpi_pdev->dev, |
| 1285 | rfktype, |
| 1286 | &tpacpi_rfk_rfkill_ops, |
| 1287 | atp_rfk); |
| 1288 | if (!atp_rfk || !atp_rfk->rfkill) { |
| 1289 | printk(TPACPI_ERR |
| 1290 | "failed to allocate memory for rfkill class\n"); |
| 1291 | kfree(atp_rfk); |
| 1292 | return -ENOMEM; |
| 1293 | } |
| 1294 | |
| 1295 | atp_rfk->id = id; |
| 1296 | atp_rfk->ops = tp_rfkops; |
| 1297 | |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1298 | sw_status = (tp_rfkops->get_status)(); |
| 1299 | if (sw_status < 0) { |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1300 | printk(TPACPI_ERR |
| 1301 | "failed to read initial state for %s, error %d\n", |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1302 | name, sw_status); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1303 | } else { |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1304 | sw_state = (sw_status == TPACPI_RFK_RADIO_OFF); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1305 | if (set_default) { |
| 1306 | /* try to keep the initial state, since we ask the |
| 1307 | * firmware to preserve it across S5 in NVRAM */ |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1308 | rfkill_init_sw_state(atp_rfk->rfkill, sw_state); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1309 | } |
| 1310 | } |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1311 | hw_state = tpacpi_rfk_check_hwblock_state(); |
| 1312 | rfkill_set_hw_state(atp_rfk->rfkill, hw_state); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1313 | |
| 1314 | res = rfkill_register(atp_rfk->rfkill); |
| 1315 | if (res < 0) { |
| 1316 | printk(TPACPI_ERR |
| 1317 | "failed to register %s rfkill switch: %d\n", |
| 1318 | name, res); |
| 1319 | rfkill_destroy(atp_rfk->rfkill); |
| 1320 | kfree(atp_rfk); |
| 1321 | return res; |
| 1322 | } |
| 1323 | |
| 1324 | tpacpi_rfkill_switches[id] = atp_rfk; |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1325 | |
| 1326 | printk(TPACPI_INFO "rfkill switch %s: radio is %sblocked\n", |
| 1327 | name, (sw_state || hw_state) ? "" : "un"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1328 | return 0; |
| 1329 | } |
| 1330 | |
| 1331 | static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id) |
| 1332 | { |
| 1333 | struct tpacpi_rfk *tp_rfk; |
| 1334 | |
| 1335 | BUG_ON(id >= TPACPI_RFK_SW_MAX); |
| 1336 | |
| 1337 | tp_rfk = tpacpi_rfkill_switches[id]; |
| 1338 | if (tp_rfk) { |
| 1339 | rfkill_unregister(tp_rfk->rfkill); |
Corentin Chary | 5f0dadb | 2009-09-14 12:43:52 +0200 | [diff] [blame] | 1340 | rfkill_destroy(tp_rfk->rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1341 | tpacpi_rfkill_switches[id] = NULL; |
| 1342 | kfree(tp_rfk); |
| 1343 | } |
| 1344 | } |
| 1345 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1346 | static void printk_deprecated_rfkill_attribute(const char * const what) |
| 1347 | { |
| 1348 | printk_deprecated_attribute(what, |
| 1349 | "Please switch to generic rfkill before year 2010"); |
| 1350 | } |
| 1351 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1352 | /* sysfs <radio> enable ------------------------------------------------ */ |
| 1353 | static ssize_t tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id, |
| 1354 | struct device_attribute *attr, |
| 1355 | char *buf) |
| 1356 | { |
| 1357 | int status; |
| 1358 | |
| 1359 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1360 | |
| 1361 | /* This is in the ABI... */ |
| 1362 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1363 | status = TPACPI_RFK_RADIO_OFF; |
| 1364 | } else { |
| 1365 | status = tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1366 | if (status < 0) |
| 1367 | return status; |
| 1368 | } |
| 1369 | |
| 1370 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1371 | (status == TPACPI_RFK_RADIO_ON) ? 1 : 0); |
| 1372 | } |
| 1373 | |
| 1374 | static ssize_t tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id, |
| 1375 | struct device_attribute *attr, |
| 1376 | const char *buf, size_t count) |
| 1377 | { |
| 1378 | unsigned long t; |
| 1379 | int res; |
| 1380 | |
| 1381 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1382 | |
| 1383 | if (parse_strtoul(buf, 1, &t)) |
| 1384 | return -EINVAL; |
| 1385 | |
| 1386 | tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); |
| 1387 | |
| 1388 | /* This is in the ABI... */ |
| 1389 | if (tpacpi_rfk_check_hwblock_state() && !!t) |
| 1390 | return -EPERM; |
| 1391 | |
| 1392 | res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? |
| 1393 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF); |
| 1394 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1395 | |
| 1396 | return (res < 0) ? res : count; |
| 1397 | } |
| 1398 | |
| 1399 | /* procfs -------------------------------------------------------------- */ |
| 1400 | static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id, char *p) |
| 1401 | { |
| 1402 | int len = 0; |
| 1403 | |
| 1404 | if (id >= TPACPI_RFK_SW_MAX) |
| 1405 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1406 | else { |
| 1407 | int status; |
| 1408 | |
| 1409 | /* This is in the ABI... */ |
| 1410 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1411 | status = TPACPI_RFK_RADIO_OFF; |
| 1412 | } else { |
| 1413 | status = tpacpi_rfk_update_swstate( |
| 1414 | tpacpi_rfkill_switches[id]); |
| 1415 | if (status < 0) |
| 1416 | return status; |
| 1417 | } |
| 1418 | |
| 1419 | len += sprintf(p + len, "status:\t\t%s\n", |
| 1420 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1421 | "enabled" : "disabled"); |
| 1422 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 1423 | } |
| 1424 | |
| 1425 | return len; |
| 1426 | } |
| 1427 | |
| 1428 | static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf) |
| 1429 | { |
| 1430 | char *cmd; |
| 1431 | int status = -1; |
| 1432 | int res = 0; |
| 1433 | |
| 1434 | if (id >= TPACPI_RFK_SW_MAX) |
| 1435 | return -ENODEV; |
| 1436 | |
| 1437 | while ((cmd = next_cmd(&buf))) { |
| 1438 | if (strlencmp(cmd, "enable") == 0) |
| 1439 | status = TPACPI_RFK_RADIO_ON; |
| 1440 | else if (strlencmp(cmd, "disable") == 0) |
| 1441 | status = TPACPI_RFK_RADIO_OFF; |
| 1442 | else |
| 1443 | return -EINVAL; |
| 1444 | } |
| 1445 | |
| 1446 | if (status != -1) { |
| 1447 | tpacpi_disclose_usertask("procfs", "attempt to %s %s\n", |
| 1448 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1449 | "enable" : "disable", |
| 1450 | tpacpi_rfkill_names[id]); |
| 1451 | res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); |
| 1452 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1453 | } |
| 1454 | |
| 1455 | return res; |
| 1456 | } |
| 1457 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1458 | /************************************************************************* |
| 1459 | * thinkpad-acpi driver attributes |
| 1460 | */ |
| 1461 | |
| 1462 | /* interface_version --------------------------------------------------- */ |
| 1463 | static ssize_t tpacpi_driver_interface_version_show( |
| 1464 | struct device_driver *drv, |
| 1465 | char *buf) |
| 1466 | { |
| 1467 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 1468 | } |
| 1469 | |
| 1470 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 1471 | tpacpi_driver_interface_version_show, NULL); |
| 1472 | |
| 1473 | /* debug_level --------------------------------------------------------- */ |
| 1474 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 1475 | char *buf) |
| 1476 | { |
| 1477 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 1478 | } |
| 1479 | |
| 1480 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 1481 | const char *buf, size_t count) |
| 1482 | { |
| 1483 | unsigned long t; |
| 1484 | |
| 1485 | if (parse_strtoul(buf, 0xffff, &t)) |
| 1486 | return -EINVAL; |
| 1487 | |
| 1488 | dbg_level = t; |
| 1489 | |
| 1490 | return count; |
| 1491 | } |
| 1492 | |
| 1493 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1494 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 1495 | |
| 1496 | /* version ------------------------------------------------------------- */ |
| 1497 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 1498 | char *buf) |
| 1499 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1500 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 1501 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | static DRIVER_ATTR(version, S_IRUGO, |
| 1505 | tpacpi_driver_version_show, NULL); |
| 1506 | |
| 1507 | /* --------------------------------------------------------------------- */ |
| 1508 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1509 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1510 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1511 | /* wlsw_emulstate ------------------------------------------------------ */ |
| 1512 | static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv, |
| 1513 | char *buf) |
| 1514 | { |
| 1515 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate); |
| 1516 | } |
| 1517 | |
| 1518 | static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv, |
| 1519 | const char *buf, size_t count) |
| 1520 | { |
| 1521 | unsigned long t; |
| 1522 | |
| 1523 | if (parse_strtoul(buf, 1, &t)) |
| 1524 | return -EINVAL; |
| 1525 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1526 | if (tpacpi_wlsw_emulstate != !!t) { |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1527 | tpacpi_wlsw_emulstate = !!t; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1528 | tpacpi_rfk_update_hwblock_state(!t); /* negative logic */ |
| 1529 | } |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1530 | |
| 1531 | return count; |
| 1532 | } |
| 1533 | |
| 1534 | static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO, |
| 1535 | tpacpi_driver_wlsw_emulstate_show, |
| 1536 | tpacpi_driver_wlsw_emulstate_store); |
| 1537 | |
| 1538 | /* bluetooth_emulstate ------------------------------------------------- */ |
| 1539 | static ssize_t tpacpi_driver_bluetooth_emulstate_show( |
| 1540 | struct device_driver *drv, |
| 1541 | char *buf) |
| 1542 | { |
| 1543 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate); |
| 1544 | } |
| 1545 | |
| 1546 | static ssize_t tpacpi_driver_bluetooth_emulstate_store( |
| 1547 | struct device_driver *drv, |
| 1548 | const char *buf, size_t count) |
| 1549 | { |
| 1550 | unsigned long t; |
| 1551 | |
| 1552 | if (parse_strtoul(buf, 1, &t)) |
| 1553 | return -EINVAL; |
| 1554 | |
| 1555 | tpacpi_bluetooth_emulstate = !!t; |
| 1556 | |
| 1557 | return count; |
| 1558 | } |
| 1559 | |
| 1560 | static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO, |
| 1561 | tpacpi_driver_bluetooth_emulstate_show, |
| 1562 | tpacpi_driver_bluetooth_emulstate_store); |
| 1563 | |
| 1564 | /* wwan_emulstate ------------------------------------------------- */ |
| 1565 | static ssize_t tpacpi_driver_wwan_emulstate_show( |
| 1566 | struct device_driver *drv, |
| 1567 | char *buf) |
| 1568 | { |
| 1569 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate); |
| 1570 | } |
| 1571 | |
| 1572 | static ssize_t tpacpi_driver_wwan_emulstate_store( |
| 1573 | struct device_driver *drv, |
| 1574 | const char *buf, size_t count) |
| 1575 | { |
| 1576 | unsigned long t; |
| 1577 | |
| 1578 | if (parse_strtoul(buf, 1, &t)) |
| 1579 | return -EINVAL; |
| 1580 | |
| 1581 | tpacpi_wwan_emulstate = !!t; |
| 1582 | |
| 1583 | return count; |
| 1584 | } |
| 1585 | |
| 1586 | static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO, |
| 1587 | tpacpi_driver_wwan_emulstate_show, |
| 1588 | tpacpi_driver_wwan_emulstate_store); |
| 1589 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1590 | /* uwb_emulstate ------------------------------------------------- */ |
| 1591 | static ssize_t tpacpi_driver_uwb_emulstate_show( |
| 1592 | struct device_driver *drv, |
| 1593 | char *buf) |
| 1594 | { |
| 1595 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate); |
| 1596 | } |
| 1597 | |
| 1598 | static ssize_t tpacpi_driver_uwb_emulstate_store( |
| 1599 | struct device_driver *drv, |
| 1600 | const char *buf, size_t count) |
| 1601 | { |
| 1602 | unsigned long t; |
| 1603 | |
| 1604 | if (parse_strtoul(buf, 1, &t)) |
| 1605 | return -EINVAL; |
| 1606 | |
| 1607 | tpacpi_uwb_emulstate = !!t; |
| 1608 | |
| 1609 | return count; |
| 1610 | } |
| 1611 | |
| 1612 | static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO, |
| 1613 | tpacpi_driver_uwb_emulstate_show, |
| 1614 | tpacpi_driver_uwb_emulstate_store); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1615 | #endif |
| 1616 | |
| 1617 | /* --------------------------------------------------------------------- */ |
| 1618 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1619 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1620 | &driver_attr_debug_level, &driver_attr_version, |
| 1621 | &driver_attr_interface_version, |
| 1622 | }; |
| 1623 | |
| 1624 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 1625 | { |
| 1626 | int i, res; |
| 1627 | |
| 1628 | i = 0; |
| 1629 | res = 0; |
| 1630 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 1631 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 1632 | i++; |
| 1633 | } |
| 1634 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1635 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1636 | if (!res && dbg_wlswemul) |
| 1637 | res = driver_create_file(drv, &driver_attr_wlsw_emulstate); |
| 1638 | if (!res && dbg_bluetoothemul) |
| 1639 | res = driver_create_file(drv, &driver_attr_bluetooth_emulstate); |
| 1640 | if (!res && dbg_wwanemul) |
| 1641 | res = driver_create_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1642 | if (!res && dbg_uwbemul) |
| 1643 | res = driver_create_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1644 | #endif |
| 1645 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1646 | return res; |
| 1647 | } |
| 1648 | |
| 1649 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 1650 | { |
| 1651 | int i; |
| 1652 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1653 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1654 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1655 | |
| 1656 | #ifdef THINKPAD_ACPI_DEBUGFACILITIES |
| 1657 | driver_remove_file(drv, &driver_attr_wlsw_emulstate); |
| 1658 | driver_remove_file(drv, &driver_attr_bluetooth_emulstate); |
| 1659 | driver_remove_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1660 | driver_remove_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1661 | #endif |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1662 | } |
| 1663 | |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1664 | /************************************************************************* |
| 1665 | * Firmware Data |
| 1666 | */ |
| 1667 | |
| 1668 | /* |
| 1669 | * Table of recommended minimum BIOS versions |
| 1670 | * |
| 1671 | * Reasons for listing: |
| 1672 | * 1. Stable BIOS, listed because the unknown ammount of |
| 1673 | * bugs and bad ACPI behaviour on older versions |
| 1674 | * |
| 1675 | * 2. BIOS or EC fw with known bugs that trigger on Linux |
| 1676 | * |
| 1677 | * 3. BIOS with known reduced functionality in older versions |
| 1678 | * |
| 1679 | * We recommend the latest BIOS and EC version. |
| 1680 | * We only support the latest BIOS and EC fw version as a rule. |
| 1681 | * |
| 1682 | * Sources: IBM ThinkPad Public Web Documents (update changelogs), |
| 1683 | * Information from users in ThinkWiki |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1684 | * |
| 1685 | * WARNING: we use this table also to detect that the machine is |
| 1686 | * 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] | 1687 | */ |
| 1688 | |
| 1689 | #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \ |
| 1690 | { .vendor = (__v), \ |
| 1691 | .bios = TPID(__id1, __id2), \ |
| 1692 | .ec = TPACPI_MATCH_ANY, \ |
| 1693 | .quirks = TPACPI_MATCH_ANY << 16 \ |
| 1694 | | (__bv1) << 8 | (__bv2) } |
| 1695 | |
| 1696 | #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1697 | __eid, __ev1, __ev2) \ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1698 | { .vendor = (__v), \ |
| 1699 | .bios = TPID(__bid1, __bid2), \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1700 | .ec = __eid, \ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1701 | .quirks = (__ev1) << 24 | (__ev2) << 16 \ |
| 1702 | | (__bv1) << 8 | (__bv2) } |
| 1703 | |
| 1704 | #define TPV_QI0(__id1, __id2, __bv1, __bv2) \ |
| 1705 | TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2) |
| 1706 | |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1707 | /* Outdated IBM BIOSes often lack the EC id string */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1708 | #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1709 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1710 | __bv1, __bv2, TPID(__id1, __id2), \ |
| 1711 | __ev1, __ev2), \ |
| 1712 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
| 1713 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ |
| 1714 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1715 | |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1716 | /* Outdated IBM BIOSes often lack the EC id string */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1717 | #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \ |
| 1718 | __eid1, __eid2, __ev1, __ev2) \ |
| 1719 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1720 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
| 1721 | __ev1, __ev2), \ |
| 1722 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
| 1723 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ |
| 1724 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1725 | |
| 1726 | #define TPV_QL0(__id1, __id2, __bv1, __bv2) \ |
| 1727 | TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2) |
| 1728 | |
| 1729 | #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1730 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1731 | __bv1, __bv2, TPID(__id1, __id2), \ |
| 1732 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1733 | |
| 1734 | #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \ |
| 1735 | __eid1, __eid2, __ev1, __ev2) \ |
| 1736 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1737 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
| 1738 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1739 | |
| 1740 | static const struct tpacpi_quirk tpacpi_bios_version_qtable[] __initconst = { |
| 1741 | /* Numeric models ------------------ */ |
| 1742 | /* FW MODEL BIOS VERS */ |
| 1743 | TPV_QI0('I', 'M', '6', '5'), /* 570 */ |
| 1744 | TPV_QI0('I', 'U', '2', '6'), /* 570E */ |
| 1745 | TPV_QI0('I', 'B', '5', '4'), /* 600 */ |
| 1746 | TPV_QI0('I', 'H', '4', '7'), /* 600E */ |
| 1747 | TPV_QI0('I', 'N', '3', '6'), /* 600E */ |
| 1748 | TPV_QI0('I', 'T', '5', '5'), /* 600X */ |
| 1749 | TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */ |
| 1750 | TPV_QI0('I', 'I', '4', '2'), /* 770X */ |
| 1751 | TPV_QI0('I', 'O', '2', '3'), /* 770Z */ |
| 1752 | |
| 1753 | /* A-series ------------------------- */ |
| 1754 | /* FW MODEL BIOS VERS EC VERS */ |
| 1755 | TPV_QI0('I', 'W', '5', '9'), /* A20m */ |
| 1756 | TPV_QI0('I', 'V', '6', '9'), /* A20p */ |
| 1757 | TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */ |
| 1758 | TPV_QI0('K', 'U', '3', '6'), /* A21e */ |
| 1759 | TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */ |
| 1760 | TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */ |
| 1761 | TPV_QI0('1', 'B', '1', '7'), /* A22e */ |
| 1762 | TPV_QI0('1', '3', '2', '0'), /* A22m */ |
| 1763 | TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */ |
| 1764 | TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */ |
| 1765 | TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */ |
| 1766 | |
| 1767 | /* G-series ------------------------- */ |
| 1768 | /* FW MODEL BIOS VERS */ |
| 1769 | TPV_QI0('1', 'T', 'A', '6'), /* G40 */ |
| 1770 | TPV_QI0('1', 'X', '5', '7'), /* G41 */ |
| 1771 | |
| 1772 | /* R-series, T-series --------------- */ |
| 1773 | /* FW MODEL BIOS VERS EC VERS */ |
| 1774 | TPV_QI0('1', 'C', 'F', '0'), /* R30 */ |
| 1775 | TPV_QI0('1', 'F', 'F', '1'), /* R31 */ |
| 1776 | TPV_QI0('1', 'M', '9', '7'), /* R32 */ |
| 1777 | TPV_QI0('1', 'O', '6', '1'), /* R40 */ |
| 1778 | TPV_QI0('1', 'P', '6', '5'), /* R40 */ |
| 1779 | TPV_QI0('1', 'S', '7', '0'), /* R40e */ |
| 1780 | TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51, |
| 1781 | T40/p, T41/p, T42/p (1) */ |
| 1782 | TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */ |
| 1783 | TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */ |
| 1784 | TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */ |
| 1785 | TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */ |
| 1786 | |
| 1787 | TPV_QI0('I', 'Y', '6', '1'), /* T20 */ |
| 1788 | TPV_QI0('K', 'Z', '3', '4'), /* T21 */ |
| 1789 | TPV_QI0('1', '6', '3', '2'), /* T22 */ |
| 1790 | TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */ |
| 1791 | TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */ |
| 1792 | TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */ |
| 1793 | |
| 1794 | TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */ |
| 1795 | TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */ |
Henrique de Moraes Holschuh | 90765c6 | 2009-12-09 01:36:23 +0000 | [diff] [blame] | 1796 | TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1797 | |
| 1798 | /* BIOS FW BIOS VERS EC FW EC VERS */ |
| 1799 | TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */ |
| 1800 | TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */ |
| 1801 | |
| 1802 | /* X-series ------------------------- */ |
| 1803 | /* FW MODEL BIOS VERS EC VERS */ |
| 1804 | TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */ |
| 1805 | TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */ |
| 1806 | TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */ |
| 1807 | TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */ |
| 1808 | TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */ |
| 1809 | TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */ |
| 1810 | TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */ |
| 1811 | |
Henrique de Moraes Holschuh | 90765c6 | 2009-12-09 01:36:23 +0000 | [diff] [blame] | 1812 | TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */ |
| 1813 | TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1814 | |
| 1815 | /* (0) - older versions lack DMI EC fw string and functionality */ |
| 1816 | /* (1) - older versions known to lack functionality */ |
| 1817 | }; |
| 1818 | |
| 1819 | #undef TPV_QL1 |
| 1820 | #undef TPV_QL0 |
| 1821 | #undef TPV_QI2 |
| 1822 | #undef TPV_QI1 |
| 1823 | #undef TPV_QI0 |
| 1824 | #undef TPV_Q_X |
| 1825 | #undef TPV_Q |
| 1826 | |
| 1827 | static void __init tpacpi_check_outdated_fw(void) |
| 1828 | { |
| 1829 | unsigned long fwvers; |
| 1830 | u16 ec_version, bios_version; |
| 1831 | |
| 1832 | fwvers = tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1833 | ARRAY_SIZE(tpacpi_bios_version_qtable)); |
| 1834 | |
| 1835 | if (!fwvers) |
| 1836 | return; |
| 1837 | |
| 1838 | bios_version = fwvers & 0xffffU; |
| 1839 | ec_version = (fwvers >> 16) & 0xffffU; |
| 1840 | |
| 1841 | /* note that unknown versions are set to 0x0000 and we use that */ |
| 1842 | if ((bios_version > thinkpad_id.bios_release) || |
| 1843 | (ec_version > thinkpad_id.ec_release && |
| 1844 | ec_version != TPACPI_MATCH_ANY)) { |
| 1845 | /* |
| 1846 | * The changelogs would let us track down the exact |
| 1847 | * reason, but it is just too much of a pain to track |
| 1848 | * it. We only list BIOSes that are either really |
| 1849 | * broken, or really stable to begin with, so it is |
| 1850 | * best if the user upgrades the firmware anyway. |
| 1851 | */ |
| 1852 | printk(TPACPI_WARN |
| 1853 | "WARNING: Outdated ThinkPad BIOS/EC firmware\n"); |
| 1854 | printk(TPACPI_WARN |
| 1855 | "WARNING: This firmware may be missing critical bug " |
| 1856 | "fixes and/or important features\n"); |
| 1857 | } |
| 1858 | } |
| 1859 | |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1860 | static bool __init tpacpi_is_fw_known(void) |
| 1861 | { |
| 1862 | return tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1863 | ARRAY_SIZE(tpacpi_bios_version_qtable)) != 0; |
| 1864 | } |
| 1865 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1866 | /**************************************************************************** |
| 1867 | **************************************************************************** |
| 1868 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1869 | * Subdrivers |
| 1870 | * |
| 1871 | **************************************************************************** |
| 1872 | ****************************************************************************/ |
| 1873 | |
| 1874 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 1875 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1876 | */ |
| 1877 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1878 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1880 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 1881 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1883 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1884 | (thinkpad_id.bios_version_str) ? |
| 1885 | thinkpad_id.bios_version_str : "unknown", |
| 1886 | (thinkpad_id.ec_version_str) ? |
| 1887 | thinkpad_id.ec_version_str : "unknown"); |
| 1888 | |
| 1889 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1890 | printk(TPACPI_INFO "%s %s, model %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1891 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 1892 | "IBM" : ((thinkpad_id.vendor == |
| 1893 | PCI_VENDOR_ID_LENOVO) ? |
| 1894 | "Lenovo" : "Unknown vendor"), |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1895 | thinkpad_id.model_str, |
| 1896 | (thinkpad_id.nummodel_str) ? |
| 1897 | thinkpad_id.nummodel_str : "unknown"); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 1898 | |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1899 | tpacpi_check_outdated_fw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | return 0; |
| 1901 | } |
| 1902 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1903 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | { |
| 1905 | int len = 0; |
| 1906 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1907 | len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); |
| 1908 | len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | |
| 1910 | return len; |
| 1911 | } |
| 1912 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1913 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1914 | .name = "driver", |
| 1915 | .read = thinkpad_acpi_driver_read, |
| 1916 | }; |
| 1917 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1918 | /************************************************************************* |
| 1919 | * Hotkey subdriver |
| 1920 | */ |
| 1921 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1922 | /* |
| 1923 | * ThinkPad firmware event model |
| 1924 | * |
| 1925 | * The ThinkPad firmware has two main event interfaces: normal ACPI |
| 1926 | * notifications (which follow the ACPI standard), and a private event |
| 1927 | * interface. |
| 1928 | * |
| 1929 | * The private event interface also issues events for the hotkeys. As |
| 1930 | * the driver gained features, the event handling code ended up being |
| 1931 | * built around the hotkey subdriver. This will need to be refactored |
| 1932 | * to a more formal event API eventually. |
| 1933 | * |
| 1934 | * Some "hotkeys" are actually supposed to be used as event reports, |
| 1935 | * such as "brightness has changed", "volume has changed", depending on |
| 1936 | * the ThinkPad model and how the firmware is operating. |
| 1937 | * |
| 1938 | * Unlike other classes, hotkey-class events have mask/unmask control on |
| 1939 | * non-ancient firmware. However, how it behaves changes a lot with the |
| 1940 | * firmware model and version. |
| 1941 | */ |
| 1942 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1943 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1944 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1945 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1946 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1947 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1948 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1949 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1950 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1951 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1952 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1953 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1954 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1955 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1956 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1957 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1958 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1959 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1960 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1961 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1962 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1963 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1964 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1965 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1966 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1967 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1968 | }; |
| 1969 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1970 | enum { /* Keys/events available through NVRAM polling */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1971 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1972 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1973 | }; |
| 1974 | |
| 1975 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1976 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1977 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1978 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1979 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1980 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1981 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1982 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1983 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1984 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1985 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1986 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1987 | }; |
| 1988 | |
| 1989 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1990 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1991 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1992 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1993 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1994 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1995 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1996 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1997 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1998 | TP_ACPI_HKEY_MUTE_MASK, |
| 1999 | }; |
| 2000 | |
| 2001 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2002 | struct tp_nvram_state { |
| 2003 | u16 thinkpad_toggle:1; |
| 2004 | u16 zoom_toggle:1; |
| 2005 | u16 display_toggle:1; |
| 2006 | u16 thinklight_toggle:1; |
| 2007 | u16 hibernate_toggle:1; |
| 2008 | u16 displayexp_toggle:1; |
| 2009 | u16 display_state:1; |
| 2010 | u16 brightness_toggle:1; |
| 2011 | u16 volume_toggle:1; |
| 2012 | u16 mute:1; |
| 2013 | |
| 2014 | u8 brightness_level; |
| 2015 | u8 volume_level; |
| 2016 | }; |
| 2017 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2018 | /* kthread for the hotkey poller */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2019 | static struct task_struct *tpacpi_hotkey_task; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2020 | |
| 2021 | /* 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] | 2022 | static struct mutex hotkey_thread_mutex; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2023 | |
| 2024 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2025 | * Acquire mutex to write poller control variables as an |
| 2026 | * atomic block. |
| 2027 | * |
| 2028 | * Increment hotkey_config_change when changing them if you |
| 2029 | * want the kthread to forget old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2030 | * |
| 2031 | * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 2032 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2033 | static struct mutex hotkey_thread_data_mutex; |
| 2034 | static unsigned int hotkey_config_change; |
| 2035 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2036 | /* |
| 2037 | * hotkey poller control variables |
| 2038 | * |
| 2039 | * 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] | 2040 | * |
| 2041 | * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 2042 | * should be used only when the changes need to be taken as |
| 2043 | * a block, OR when one needs to force the kthread to forget |
| 2044 | * old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2045 | */ |
| 2046 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 2047 | static unsigned int hotkey_poll_freq = 10; /* Hz */ |
| 2048 | |
| 2049 | #define HOTKEY_CONFIG_CRITICAL_START \ |
| 2050 | do { \ |
| 2051 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 2052 | hotkey_config_change++; \ |
| 2053 | } while (0); |
| 2054 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 2055 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2056 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2057 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2058 | |
| 2059 | #define hotkey_source_mask 0U |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2060 | #define HOTKEY_CONFIG_CRITICAL_START |
| 2061 | #define HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2062 | |
| 2063 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2064 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2065 | static struct mutex hotkey_mutex; |
| 2066 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2067 | static enum { /* Reasons for waking up */ |
| 2068 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 2069 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 2070 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 2071 | } hotkey_wakeup_reason; |
| 2072 | |
| 2073 | static int hotkey_autosleep_ack; |
| 2074 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2075 | static u32 hotkey_orig_mask; /* events the BIOS had enabled */ |
| 2076 | static u32 hotkey_all_mask; /* all events supported in fw */ |
| 2077 | static u32 hotkey_reserved_mask; /* events better left disabled */ |
| 2078 | static u32 hotkey_driver_mask; /* events needed by the driver */ |
| 2079 | static u32 hotkey_user_mask; /* events visible to userspace */ |
| 2080 | static u32 hotkey_acpi_mask; /* events enabled in firmware */ |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2081 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 2082 | static unsigned int hotkey_report_mode; |
| 2083 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2084 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2085 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 2086 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2087 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2088 | static void tpacpi_driver_event(const unsigned int hkey_event); |
| 2089 | static void hotkey_driver_event(const unsigned int scancode); |
| 2090 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2091 | /* HKEY.MHKG() return bits */ |
| 2092 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 2093 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2094 | static int hotkey_get_wlsw(void) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2095 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2096 | int status; |
| 2097 | |
| 2098 | if (!tp_features.hotkey_wlsw) |
| 2099 | return -ENODEV; |
| 2100 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2101 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2102 | if (dbg_wlswemul) |
| 2103 | return (tpacpi_wlsw_emulstate) ? |
| 2104 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2105 | #endif |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2106 | |
| 2107 | if (!acpi_evalf(hkey_handle, &status, "WLSW", "d")) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2108 | return -EIO; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2109 | |
| 2110 | return (status) ? TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2111 | } |
| 2112 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2113 | static int hotkey_get_tablet_mode(int *status) |
| 2114 | { |
| 2115 | int s; |
| 2116 | |
| 2117 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 2118 | return -EIO; |
| 2119 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 2120 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 2121 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2122 | } |
| 2123 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2124 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2125 | * Reads current event mask from firmware, and updates |
| 2126 | * hotkey_acpi_mask accordingly. Also resets any bits |
| 2127 | * from hotkey_user_mask that are unavailable to be |
| 2128 | * delivered (shadow requirement of the userspace ABI). |
| 2129 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2130 | * Call with hotkey_mutex held |
| 2131 | */ |
| 2132 | static int hotkey_mask_get(void) |
| 2133 | { |
| 2134 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2135 | u32 m = 0; |
| 2136 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2137 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2138 | return -EIO; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2139 | |
| 2140 | hotkey_acpi_mask = m; |
| 2141 | } else { |
| 2142 | /* no mask support doesn't mean no event support... */ |
| 2143 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2144 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2145 | |
| 2146 | /* sync userspace-visible mask */ |
| 2147 | hotkey_user_mask &= (hotkey_acpi_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2148 | |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2152 | void static hotkey_mask_warn_incomplete_mask(void) |
| 2153 | { |
| 2154 | /* log only what the user can fix... */ |
| 2155 | const u32 wantedmask = hotkey_driver_mask & |
| 2156 | ~(hotkey_acpi_mask | hotkey_source_mask) & |
| 2157 | (hotkey_all_mask | TPACPI_HKEY_NVRAM_KNOWN_MASK); |
| 2158 | |
| 2159 | if (wantedmask) |
| 2160 | printk(TPACPI_NOTICE |
| 2161 | "required events 0x%08x not enabled!\n", |
| 2162 | wantedmask); |
| 2163 | } |
| 2164 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2165 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2166 | * Set the firmware mask when supported |
| 2167 | * |
| 2168 | * Also calls hotkey_mask_get to update hotkey_acpi_mask. |
| 2169 | * |
| 2170 | * NOTE: does not set bits in hotkey_user_mask, but may reset them. |
| 2171 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2172 | * Call with hotkey_mutex held |
| 2173 | */ |
| 2174 | static int hotkey_mask_set(u32 mask) |
| 2175 | { |
| 2176 | int i; |
| 2177 | int rc = 0; |
| 2178 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2179 | const u32 fwmask = mask & ~hotkey_source_mask; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 2180 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2181 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2182 | for (i = 0; i < 32; i++) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2183 | if (!acpi_evalf(hkey_handle, |
| 2184 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2185 | !!(mask & (1 << i)))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2186 | rc = -EIO; |
| 2187 | break; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2188 | } |
| 2189 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2190 | } |
| 2191 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2192 | /* |
| 2193 | * We *must* make an inconditional call to hotkey_mask_get to |
| 2194 | * refresh hotkey_acpi_mask and update hotkey_user_mask |
| 2195 | * |
| 2196 | * Take the opportunity to also log when we cannot _enable_ |
| 2197 | * a given event. |
| 2198 | */ |
| 2199 | if (!hotkey_mask_get() && !rc && (fwmask & ~hotkey_acpi_mask)) { |
| 2200 | printk(TPACPI_NOTICE |
| 2201 | "asked for hotkey mask 0x%08x, but " |
| 2202 | "firmware forced it to 0x%08x\n", |
| 2203 | fwmask, hotkey_acpi_mask); |
| 2204 | } |
| 2205 | |
Henrique de Moraes Holschuh | 6b30eb7 | 2009-12-09 01:36:25 +0000 | [diff] [blame] | 2206 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING) |
| 2207 | hotkey_mask_warn_incomplete_mask(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2208 | |
| 2209 | return rc; |
| 2210 | } |
| 2211 | |
| 2212 | /* |
| 2213 | * Sets hotkey_user_mask and tries to set the firmware mask |
| 2214 | * |
| 2215 | * Call with hotkey_mutex held |
| 2216 | */ |
| 2217 | static int hotkey_user_mask_set(const u32 mask) |
| 2218 | { |
| 2219 | int rc; |
| 2220 | |
| 2221 | /* Give people a chance to notice they are doing something that |
| 2222 | * is bound to go boom on their users sooner or later */ |
| 2223 | if (!tp_warned.hotkey_mask_ff && |
| 2224 | (mask == 0xffff || mask == 0xffffff || |
| 2225 | mask == 0xffffffff)) { |
| 2226 | tp_warned.hotkey_mask_ff = 1; |
| 2227 | printk(TPACPI_NOTICE |
| 2228 | "setting the hotkey mask to 0x%08x is likely " |
| 2229 | "not the best way to go about it\n", mask); |
| 2230 | printk(TPACPI_NOTICE |
| 2231 | "please consider using the driver defaults, " |
| 2232 | "and refer to up-to-date thinkpad-acpi " |
| 2233 | "documentation\n"); |
| 2234 | } |
| 2235 | |
| 2236 | /* Try to enable what the user asked for, plus whatever we need. |
| 2237 | * this syncs everything but won't enable bits in hotkey_user_mask */ |
| 2238 | rc = hotkey_mask_set((mask | hotkey_driver_mask) & ~hotkey_source_mask); |
| 2239 | |
| 2240 | /* Enable the available bits in hotkey_user_mask */ |
| 2241 | hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask); |
| 2242 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2243 | return rc; |
| 2244 | } |
| 2245 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2246 | /* |
| 2247 | * Sets the driver hotkey mask. |
| 2248 | * |
| 2249 | * Can be called even if the hotkey subdriver is inactive |
| 2250 | */ |
| 2251 | static int tpacpi_hotkey_driver_mask_set(const u32 mask) |
| 2252 | { |
| 2253 | int rc; |
| 2254 | |
| 2255 | /* Do the right thing if hotkey_init has not been called yet */ |
| 2256 | if (!tp_features.hotkey) { |
| 2257 | hotkey_driver_mask = mask; |
| 2258 | return 0; |
| 2259 | } |
| 2260 | |
| 2261 | mutex_lock(&hotkey_mutex); |
| 2262 | |
| 2263 | HOTKEY_CONFIG_CRITICAL_START |
| 2264 | hotkey_driver_mask = mask; |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2265 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2266 | hotkey_source_mask |= (mask & ~hotkey_all_mask); |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2267 | #endif |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2268 | HOTKEY_CONFIG_CRITICAL_END |
| 2269 | |
| 2270 | rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) & |
| 2271 | ~hotkey_source_mask); |
| 2272 | mutex_unlock(&hotkey_mutex); |
| 2273 | |
| 2274 | return rc; |
| 2275 | } |
| 2276 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2277 | static int hotkey_status_get(int *status) |
| 2278 | { |
| 2279 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 2280 | return -EIO; |
| 2281 | |
| 2282 | return 0; |
| 2283 | } |
| 2284 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2285 | static int hotkey_status_set(bool enable) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2286 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2287 | 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] | 2288 | return -EIO; |
| 2289 | |
| 2290 | return 0; |
| 2291 | } |
| 2292 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2293 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2294 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2295 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2296 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2297 | if (tp_features.hotkey_tablet && |
| 2298 | !hotkey_get_tablet_mode(&state)) { |
| 2299 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2300 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2301 | input_report_switch(tpacpi_inputdev, |
| 2302 | SW_TABLET_MODE, !!state); |
| 2303 | input_sync(tpacpi_inputdev); |
| 2304 | |
| 2305 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2306 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2307 | } |
| 2308 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2309 | /* Do NOT call without validating scancode first */ |
| 2310 | static void tpacpi_input_send_key(const unsigned int scancode) |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2311 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2312 | const unsigned int keycode = hotkey_keycode_map[scancode]; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2313 | |
| 2314 | if (keycode != KEY_RESERVED) { |
| 2315 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2316 | |
| 2317 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 2318 | if (keycode == KEY_UNKNOWN) |
| 2319 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 2320 | scancode); |
| 2321 | input_sync(tpacpi_inputdev); |
| 2322 | |
| 2323 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 2324 | if (keycode == KEY_UNKNOWN) |
| 2325 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 2326 | scancode); |
| 2327 | input_sync(tpacpi_inputdev); |
| 2328 | |
| 2329 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2330 | } |
| 2331 | } |
| 2332 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2333 | /* Do NOT call without validating scancode first */ |
| 2334 | static void tpacpi_input_send_key_masked(const unsigned int scancode) |
| 2335 | { |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2336 | hotkey_driver_event(scancode); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2337 | if (hotkey_user_mask & (1 << scancode)) |
| 2338 | tpacpi_input_send_key(scancode); |
| 2339 | } |
| 2340 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2341 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2342 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 2343 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2344 | /* Do NOT call without validating scancode first */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2345 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 2346 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2347 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2348 | if (hotkey_report_mode < 2) { |
| 2349 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 2350 | 0x80, TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2354 | 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] | 2355 | { |
| 2356 | u8 d; |
| 2357 | |
| 2358 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 2359 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 2360 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 2361 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 2362 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 2363 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 2364 | } |
| 2365 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 2366 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 2367 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 2368 | } |
| 2369 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 2370 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 2371 | n->displayexp_toggle = |
| 2372 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 2373 | } |
| 2374 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 2375 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 2376 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 2377 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 2378 | n->brightness_toggle = |
| 2379 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 2380 | } |
| 2381 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 2382 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 2383 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 2384 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 2385 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 2386 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 2387 | } |
| 2388 | } |
| 2389 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2390 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
| 2391 | struct tp_nvram_state *newn, |
| 2392 | const u32 event_mask) |
| 2393 | { |
| 2394 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2395 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2396 | do { \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2397 | if ((event_mask & (1 << __scancode)) && \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2398 | oldn->__member != newn->__member) \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2399 | tpacpi_hotkey_send_key(__scancode); \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2400 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2401 | |
| 2402 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2403 | do { \ |
| 2404 | if (event_mask & (1 << __scancode)) \ |
| 2405 | tpacpi_hotkey_send_key(__scancode); \ |
| 2406 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2407 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2408 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 2409 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 2410 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 2411 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 2412 | |
| 2413 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 2414 | |
| 2415 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 2416 | |
| 2417 | /* handle volume */ |
| 2418 | if (oldn->volume_toggle != newn->volume_toggle) { |
| 2419 | if (oldn->mute != newn->mute) { |
| 2420 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2421 | } |
| 2422 | if (oldn->volume_level > newn->volume_level) { |
| 2423 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2424 | } else if (oldn->volume_level < newn->volume_level) { |
| 2425 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2426 | } else if (oldn->mute == newn->mute) { |
| 2427 | /* repeated key presses that didn't change state */ |
| 2428 | if (newn->mute) { |
| 2429 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2430 | } else if (newn->volume_level != 0) { |
| 2431 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2432 | } else { |
| 2433 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2434 | } |
| 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | /* handle brightness */ |
| 2439 | if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 2440 | if (oldn->brightness_level < newn->brightness_level) { |
| 2441 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2442 | } else if (oldn->brightness_level > newn->brightness_level) { |
| 2443 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2444 | } else { |
| 2445 | /* repeated key presses that didn't change state */ |
| 2446 | if (newn->brightness_level != 0) { |
| 2447 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2448 | } else { |
| 2449 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2450 | } |
| 2451 | } |
| 2452 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2453 | |
| 2454 | #undef TPACPI_COMPARE_KEY |
| 2455 | #undef TPACPI_MAY_SEND_KEY |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2456 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2457 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2458 | /* |
| 2459 | * Polling driver |
| 2460 | * |
| 2461 | * We track all events in hotkey_source_mask all the time, since |
| 2462 | * most of them are edge-based. We only issue those requested by |
| 2463 | * hotkey_user_mask or hotkey_driver_mask, though. |
| 2464 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2465 | static int hotkey_kthread(void *data) |
| 2466 | { |
| 2467 | struct tp_nvram_state s[2]; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2468 | u32 poll_mask, event_mask; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2469 | unsigned int si, so; |
| 2470 | unsigned long t; |
| 2471 | unsigned int change_detector, must_reset; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2472 | unsigned int poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2473 | |
| 2474 | mutex_lock(&hotkey_thread_mutex); |
| 2475 | |
| 2476 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 2477 | goto exit; |
| 2478 | |
| 2479 | set_freezable(); |
| 2480 | |
| 2481 | so = 0; |
| 2482 | si = 1; |
| 2483 | t = 0; |
| 2484 | |
| 2485 | /* Initial state for compares */ |
| 2486 | mutex_lock(&hotkey_thread_data_mutex); |
| 2487 | change_detector = hotkey_config_change; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2488 | poll_mask = hotkey_source_mask; |
| 2489 | event_mask = hotkey_source_mask & |
| 2490 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2491 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2492 | mutex_unlock(&hotkey_thread_data_mutex); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2493 | hotkey_read_nvram(&s[so], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2494 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2495 | while (!kthread_should_stop()) { |
| 2496 | if (t == 0) { |
| 2497 | if (likely(poll_freq)) |
| 2498 | t = 1000/poll_freq; |
| 2499 | else |
| 2500 | t = 100; /* should never happen... */ |
| 2501 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2502 | t = msleep_interruptible(t); |
| 2503 | if (unlikely(kthread_should_stop())) |
| 2504 | break; |
| 2505 | must_reset = try_to_freeze(); |
| 2506 | if (t > 0 && !must_reset) |
| 2507 | continue; |
| 2508 | |
| 2509 | mutex_lock(&hotkey_thread_data_mutex); |
| 2510 | if (must_reset || hotkey_config_change != change_detector) { |
| 2511 | /* forget old state on thaw or config change */ |
| 2512 | si = so; |
| 2513 | t = 0; |
| 2514 | change_detector = hotkey_config_change; |
| 2515 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2516 | poll_mask = hotkey_source_mask; |
| 2517 | event_mask = hotkey_source_mask & |
| 2518 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2519 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2520 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2521 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2522 | if (likely(poll_mask)) { |
| 2523 | hotkey_read_nvram(&s[si], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2524 | if (likely(si != so)) { |
| 2525 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2526 | event_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2527 | } |
| 2528 | } |
| 2529 | |
| 2530 | so = si; |
| 2531 | si ^= 1; |
| 2532 | } |
| 2533 | |
| 2534 | exit: |
| 2535 | mutex_unlock(&hotkey_thread_mutex); |
| 2536 | return 0; |
| 2537 | } |
| 2538 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2539 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2540 | static void hotkey_poll_stop_sync(void) |
| 2541 | { |
| 2542 | if (tpacpi_hotkey_task) { |
| 2543 | if (frozen(tpacpi_hotkey_task) || |
| 2544 | freezing(tpacpi_hotkey_task)) |
| 2545 | thaw_process(tpacpi_hotkey_task); |
| 2546 | |
| 2547 | kthread_stop(tpacpi_hotkey_task); |
| 2548 | tpacpi_hotkey_task = NULL; |
| 2549 | mutex_lock(&hotkey_thread_mutex); |
| 2550 | /* at this point, the thread did exit */ |
| 2551 | mutex_unlock(&hotkey_thread_mutex); |
| 2552 | } |
| 2553 | } |
| 2554 | |
| 2555 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2556 | static void hotkey_poll_setup(bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2557 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2558 | const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask; |
| 2559 | const u32 poll_user_mask = hotkey_user_mask & hotkey_source_mask; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2560 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2561 | if (hotkey_poll_freq > 0 && |
| 2562 | (poll_driver_mask || |
| 2563 | (poll_user_mask && tpacpi_inputdev->users > 0))) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2564 | if (!tpacpi_hotkey_task) { |
| 2565 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 2566 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2567 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 2568 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2569 | printk(TPACPI_ERR |
| 2570 | "could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2571 | "for hotkey polling\n"); |
| 2572 | } |
| 2573 | } |
| 2574 | } else { |
| 2575 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2576 | if (may_warn && (poll_driver_mask || poll_user_mask) && |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2577 | hotkey_poll_freq == 0) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2578 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2579 | "hot keys 0x%08x and/or events 0x%08x " |
| 2580 | "require polling, which is currently " |
| 2581 | "disabled\n", |
| 2582 | poll_user_mask, poll_driver_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2587 | static void hotkey_poll_setup_safe(bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2588 | { |
| 2589 | mutex_lock(&hotkey_mutex); |
| 2590 | hotkey_poll_setup(may_warn); |
| 2591 | mutex_unlock(&hotkey_mutex); |
| 2592 | } |
| 2593 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2594 | /* call with hotkey_mutex held */ |
| 2595 | static void hotkey_poll_set_freq(unsigned int freq) |
| 2596 | { |
| 2597 | if (!freq) |
| 2598 | hotkey_poll_stop_sync(); |
| 2599 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2600 | hotkey_poll_freq = freq; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2601 | } |
| 2602 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2603 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2604 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2605 | static void hotkey_poll_setup_safe(bool __unused) |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2606 | { |
| 2607 | } |
| 2608 | |
| 2609 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2610 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2611 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 2612 | { |
| 2613 | switch (tpacpi_lifecycle) { |
| 2614 | case TPACPI_LIFE_INIT: |
| 2615 | /* |
| 2616 | * hotkey_init will call hotkey_poll_setup_safe |
| 2617 | * at the appropriate moment |
| 2618 | */ |
| 2619 | return 0; |
| 2620 | case TPACPI_LIFE_EXITING: |
| 2621 | return -EBUSY; |
| 2622 | case TPACPI_LIFE_RUNNING: |
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 | return 0; |
| 2625 | } |
| 2626 | |
| 2627 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 2628 | BUG(); |
| 2629 | return -EBUSY; |
| 2630 | } |
| 2631 | |
| 2632 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 2633 | { |
| 2634 | /* disable hotkey polling when possible */ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2635 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING && |
| 2636 | !(hotkey_source_mask & hotkey_driver_mask)) |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2637 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2638 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2639 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2640 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 2641 | static ssize_t hotkey_enable_show(struct device *dev, |
| 2642 | struct device_attribute *attr, |
| 2643 | char *buf) |
| 2644 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2645 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2646 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2647 | printk_deprecated_attribute("hotkey_enable", |
| 2648 | "Hotkey reporting is always enabled"); |
| 2649 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2650 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2651 | if (res) |
| 2652 | return res; |
| 2653 | |
| 2654 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 2655 | } |
| 2656 | |
| 2657 | static ssize_t hotkey_enable_store(struct device *dev, |
| 2658 | struct device_attribute *attr, |
| 2659 | const char *buf, size_t count) |
| 2660 | { |
| 2661 | unsigned long t; |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2662 | |
| 2663 | printk_deprecated_attribute("hotkey_enable", |
| 2664 | "Hotkeys can be disabled through hotkey_mask"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2665 | |
| 2666 | if (parse_strtoul(buf, 1, &t)) |
| 2667 | return -EINVAL; |
| 2668 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2669 | if (t == 0) |
| 2670 | return -EPERM; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2671 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2672 | return count; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2676 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2677 | hotkey_enable_show, hotkey_enable_store); |
| 2678 | |
| 2679 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 2680 | static ssize_t hotkey_mask_show(struct device *dev, |
| 2681 | struct device_attribute *attr, |
| 2682 | char *buf) |
| 2683 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2684 | 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] | 2685 | } |
| 2686 | |
| 2687 | static ssize_t hotkey_mask_store(struct device *dev, |
| 2688 | struct device_attribute *attr, |
| 2689 | const char *buf, size_t count) |
| 2690 | { |
| 2691 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2692 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2693 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2694 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2695 | return -EINVAL; |
| 2696 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2697 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2698 | return -ERESTARTSYS; |
| 2699 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2700 | res = hotkey_user_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2701 | |
| 2702 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2703 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2704 | #endif |
| 2705 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2706 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2707 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2708 | tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t); |
| 2709 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2710 | return (res) ? res : count; |
| 2711 | } |
| 2712 | |
| 2713 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2714 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2715 | hotkey_mask_show, hotkey_mask_store); |
| 2716 | |
| 2717 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 2718 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 2719 | struct device_attribute *attr, |
| 2720 | char *buf) |
| 2721 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2722 | return sprintf(buf, "0\n"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2726 | __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] | 2727 | |
| 2728 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 2729 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 2730 | struct device_attribute *attr, |
| 2731 | char *buf) |
| 2732 | { |
Henrique de Moraes Holschuh | 06777be | 2009-09-12 15:22:15 -0300 | [diff] [blame] | 2733 | printk_deprecated_attribute("hotkey_bios_mask", |
| 2734 | "This attribute is useless."); |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2735 | 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] | 2736 | } |
| 2737 | |
| 2738 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2739 | __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] | 2740 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2741 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 2742 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 2743 | struct device_attribute *attr, |
| 2744 | char *buf) |
| 2745 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2746 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 2747 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 2751 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 2752 | |
| 2753 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 2754 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 2755 | struct device_attribute *attr, |
| 2756 | char *buf) |
| 2757 | { |
| 2758 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2759 | (hotkey_all_mask | hotkey_source_mask) |
| 2760 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 2764 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 2765 | hotkey_recommended_mask_show, NULL); |
| 2766 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2767 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2768 | |
| 2769 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 2770 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 2771 | struct device_attribute *attr, |
| 2772 | char *buf) |
| 2773 | { |
| 2774 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 2775 | } |
| 2776 | |
| 2777 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 2778 | struct device_attribute *attr, |
| 2779 | const char *buf, size_t count) |
| 2780 | { |
| 2781 | unsigned long t; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2782 | u32 r_ev; |
| 2783 | int rc; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2784 | |
| 2785 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 2786 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 2787 | return -EINVAL; |
| 2788 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2789 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2790 | return -ERESTARTSYS; |
| 2791 | |
| 2792 | HOTKEY_CONFIG_CRITICAL_START |
| 2793 | hotkey_source_mask = t; |
| 2794 | HOTKEY_CONFIG_CRITICAL_END |
| 2795 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2796 | rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) & |
| 2797 | ~hotkey_source_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2798 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2799 | |
| 2800 | /* check if events needed by the driver got disabled */ |
| 2801 | r_ev = hotkey_driver_mask & ~(hotkey_acpi_mask & hotkey_all_mask) |
| 2802 | & ~hotkey_source_mask & TPACPI_HKEY_NVRAM_KNOWN_MASK; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2803 | |
| 2804 | mutex_unlock(&hotkey_mutex); |
| 2805 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2806 | if (rc < 0) |
| 2807 | printk(TPACPI_ERR "hotkey_source_mask: failed to update the" |
| 2808 | "firmware event mask!\n"); |
| 2809 | |
| 2810 | if (r_ev) |
| 2811 | printk(TPACPI_NOTICE "hotkey_source_mask: " |
| 2812 | "some important events were disabled: " |
| 2813 | "0x%04x\n", r_ev); |
| 2814 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2815 | tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); |
| 2816 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2817 | return (rc < 0) ? rc : count; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 2821 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 2822 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 2823 | |
| 2824 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 2825 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 2826 | struct device_attribute *attr, |
| 2827 | char *buf) |
| 2828 | { |
| 2829 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 2830 | } |
| 2831 | |
| 2832 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 2833 | struct device_attribute *attr, |
| 2834 | const char *buf, size_t count) |
| 2835 | { |
| 2836 | unsigned long t; |
| 2837 | |
| 2838 | if (parse_strtoul(buf, 25, &t)) |
| 2839 | return -EINVAL; |
| 2840 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2841 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2842 | return -ERESTARTSYS; |
| 2843 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2844 | hotkey_poll_set_freq(t); |
| 2845 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2846 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2847 | mutex_unlock(&hotkey_mutex); |
| 2848 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2849 | tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t); |
| 2850 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2851 | return count; |
| 2852 | } |
| 2853 | |
| 2854 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 2855 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 2856 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 2857 | |
| 2858 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2859 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2860 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2861 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 2862 | struct device_attribute *attr, |
| 2863 | char *buf) |
| 2864 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2865 | int res; |
| 2866 | res = hotkey_get_wlsw(); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2867 | if (res < 0) |
| 2868 | return res; |
| 2869 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2870 | /* Opportunistic update */ |
| 2871 | tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF)); |
| 2872 | |
| 2873 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2874 | (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 2878 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 2879 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2880 | static void hotkey_radio_sw_notify_change(void) |
| 2881 | { |
| 2882 | if (tp_features.hotkey_wlsw) |
| 2883 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2884 | "hotkey_radio_sw"); |
| 2885 | } |
| 2886 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2887 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 2888 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 2889 | struct device_attribute *attr, |
| 2890 | char *buf) |
| 2891 | { |
| 2892 | int res, s; |
| 2893 | res = hotkey_get_tablet_mode(&s); |
| 2894 | if (res < 0) |
| 2895 | return res; |
| 2896 | |
| 2897 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 2898 | } |
| 2899 | |
| 2900 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 2901 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 2902 | |
| 2903 | static void hotkey_tablet_mode_notify_change(void) |
| 2904 | { |
| 2905 | if (tp_features.hotkey_tablet) |
| 2906 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2907 | "hotkey_tablet_mode"); |
| 2908 | } |
| 2909 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2910 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 2911 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 2912 | struct device_attribute *attr, |
| 2913 | char *buf) |
| 2914 | { |
| 2915 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2916 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 2917 | } |
| 2918 | |
| 2919 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 2920 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 2921 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2922 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2923 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 2924 | struct device_attribute *attr, |
| 2925 | char *buf) |
| 2926 | { |
| 2927 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 2928 | } |
| 2929 | |
| 2930 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 2931 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 2932 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2933 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2934 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2935 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2936 | "wakeup_reason"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2940 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 2941 | struct device_attribute *attr, |
| 2942 | char *buf) |
| 2943 | { |
| 2944 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 2945 | } |
| 2946 | |
| 2947 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 2948 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 2949 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 2950 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2951 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2952 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2953 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2954 | "wakeup_hotunplug_complete"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2955 | } |
| 2956 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2957 | /* --------------------------------------------------------------------- */ |
| 2958 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2959 | static struct attribute *hotkey_attributes[] __initdata = { |
| 2960 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2961 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2962 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2963 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2964 | &dev_attr_hotkey_wakeup_reason.attr, |
| 2965 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2966 | &dev_attr_hotkey_mask.attr, |
| 2967 | &dev_attr_hotkey_all_mask.attr, |
| 2968 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2969 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2970 | &dev_attr_hotkey_source_mask.attr, |
| 2971 | &dev_attr_hotkey_poll_freq.attr, |
| 2972 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2973 | }; |
| 2974 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2975 | /* |
| 2976 | * Sync both the hw and sw blocking state of all switches |
| 2977 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2978 | static void tpacpi_send_radiosw_update(void) |
| 2979 | { |
| 2980 | int wlsw; |
| 2981 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2982 | /* |
| 2983 | * We must sync all rfkill controllers *before* issuing any |
| 2984 | * rfkill input events, or we will race the rfkill core input |
| 2985 | * handler. |
| 2986 | * |
| 2987 | * tpacpi_inputdev_send_mutex works as a syncronization point |
| 2988 | * for the above. |
| 2989 | * |
| 2990 | * We optimize to avoid numerous calls to hotkey_get_wlsw. |
| 2991 | */ |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 2992 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2993 | wlsw = hotkey_get_wlsw(); |
| 2994 | |
| 2995 | /* Sync hw blocking state first if it is hw-blocked */ |
| 2996 | if (wlsw == TPACPI_RFK_RADIO_OFF) |
| 2997 | tpacpi_rfk_update_hwblock_state(true); |
| 2998 | |
| 2999 | /* Sync sw blocking state */ |
| 3000 | tpacpi_rfk_update_swstate_all(); |
| 3001 | |
| 3002 | /* Sync hw blocking state last if it is hw-unblocked */ |
| 3003 | if (wlsw == TPACPI_RFK_RADIO_ON) |
| 3004 | tpacpi_rfk_update_hwblock_state(false); |
| 3005 | |
| 3006 | /* Issue rfkill input event for WLSW switch */ |
| 3007 | if (!(wlsw < 0)) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3008 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 3009 | |
| 3010 | input_report_switch(tpacpi_inputdev, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3011 | SW_RFKILL_ALL, (wlsw > 0)); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3012 | input_sync(tpacpi_inputdev); |
| 3013 | |
| 3014 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 3015 | } |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3016 | |
| 3017 | /* |
| 3018 | * this can be unconditional, as we will poll state again |
| 3019 | * if userspace uses the notify to read data |
| 3020 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3021 | hotkey_radio_sw_notify_change(); |
| 3022 | } |
| 3023 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3024 | static void hotkey_exit(void) |
| 3025 | { |
| 3026 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3027 | mutex_lock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3028 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3029 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3030 | #endif |
| 3031 | |
| 3032 | if (hotkey_dev_attributes) |
| 3033 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3034 | |
| 3035 | kfree(hotkey_keycode_map); |
| 3036 | |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3037 | dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3038 | "restoring original HKEY status and mask\n"); |
| 3039 | /* yes, there is a bitwise or below, we want the |
| 3040 | * functions to be called even if one of them fail */ |
| 3041 | if (((tp_features.hotkey_mask && |
| 3042 | hotkey_mask_set(hotkey_orig_mask)) | |
| 3043 | hotkey_status_set(false)) != 0) |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3044 | printk(TPACPI_ERR |
| 3045 | "failed to restore hot key mask " |
| 3046 | "to BIOS defaults\n"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3047 | } |
| 3048 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3049 | static void __init hotkey_unmap(const unsigned int scancode) |
| 3050 | { |
| 3051 | if (hotkey_keycode_map[scancode] != KEY_RESERVED) { |
| 3052 | clear_bit(hotkey_keycode_map[scancode], |
| 3053 | tpacpi_inputdev->keybit); |
| 3054 | hotkey_keycode_map[scancode] = KEY_RESERVED; |
| 3055 | } |
| 3056 | } |
| 3057 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3058 | /* |
| 3059 | * HKEY quirks: |
| 3060 | * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12 |
| 3061 | */ |
| 3062 | |
| 3063 | #define TPACPI_HK_Q_INIMASK 0x0001 |
| 3064 | |
| 3065 | static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = { |
| 3066 | TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3067 | TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3068 | TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK), /* 770, 770E, 770ED */ |
| 3069 | TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK), /* A20m */ |
| 3070 | TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK), /* A20p */ |
| 3071 | TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK), /* A21e, A22e */ |
| 3072 | TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK), /* A21e */ |
| 3073 | TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK), /* A21m, A22m */ |
| 3074 | TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK), /* A21p, A22p */ |
| 3075 | TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK), /* A22e */ |
| 3076 | TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK), /* A22m */ |
| 3077 | TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK), /* A30/p (0) */ |
| 3078 | TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK), /* R30 */ |
| 3079 | TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK), /* R31 */ |
| 3080 | TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK), /* T20 */ |
| 3081 | TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK), /* T21 */ |
| 3082 | TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK), /* T22 */ |
| 3083 | TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK), /* X20, X21 */ |
| 3084 | TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */ |
| 3085 | }; |
| 3086 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3087 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3088 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3089 | /* Requirements for changing the default keymaps: |
| 3090 | * |
| 3091 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 3092 | * good reasons. Do not change them unless you have deep |
| 3093 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 3094 | * the various ThinkPad models. The driver behaves |
| 3095 | * differently for KEY_RESERVED: such keys have their |
| 3096 | * hot key mask *unset* in mask_recommended, and also |
| 3097 | * in the initial hot key mask programmed into the |
| 3098 | * firmware at driver load time, which means the firm- |
| 3099 | * ware may react very differently if you change them to |
| 3100 | * something else; |
| 3101 | * |
| 3102 | * 2. You must be subscribed to the linux-thinkpad and |
| 3103 | * ibm-acpi-devel mailing lists, and you should read the |
| 3104 | * list archives since 2007 if you want to change the |
| 3105 | * keymaps. This requirement exists so that you will |
| 3106 | * know the past history of problems with the thinkpad- |
| 3107 | * acpi driver keymaps, and also that you will be |
| 3108 | * listening to any bug reports; |
| 3109 | * |
| 3110 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 3111 | * for merging, *ever*. Send them to the linux-acpi |
| 3112 | * mailinglist for comments. Merging is to be done only |
| 3113 | * through acpi-test and the ACPI maintainer. |
| 3114 | * |
| 3115 | * If the above is too much to ask, don't change the keymap. |
| 3116 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 3117 | */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3118 | static u16 ibm_keycode_map[] __initdata = { |
| 3119 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 3120 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
| 3121 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 3122 | 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] | 3123 | |
| 3124 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3125 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3126 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3127 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3128 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3129 | /* brightness: firmware always reacts to them */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3130 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3131 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3132 | |
| 3133 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3134 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3135 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3136 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3137 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3138 | |
| 3139 | /* Volume: firmware always react to it and reprograms |
| 3140 | * the built-in *extra* mixer. Never map it to control |
| 3141 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3142 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3143 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3144 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3145 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3146 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3147 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3148 | /* (assignments unknown, please report if found) */ |
| 3149 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3150 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3151 | }; |
| 3152 | static u16 lenovo_keycode_map[] __initdata = { |
| 3153 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 3154 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
| 3155 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 3156 | 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] | 3157 | |
| 3158 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3159 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3160 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3161 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3162 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3163 | /* These should be enabled --only-- when ACPI video |
| 3164 | * is disabled (i.e. in "vendor" mode), and are handled |
| 3165 | * in a special way by the init code */ |
| 3166 | KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ |
| 3167 | KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3168 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3169 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3170 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3171 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3172 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3173 | |
| 3174 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 3175 | * react to it and reprograms the built-in *extra* mixer. |
| 3176 | * Never map it to control another mixer by default. |
| 3177 | * |
| 3178 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 3179 | * these over the regular keyboard, so these are no-ops, |
| 3180 | * but there are still weird bugs re. MUTE, so do not |
| 3181 | * change unless you get test reports from all Lenovo |
| 3182 | * models. May cause the BIOS to interfere with the |
| 3183 | * HDA mixer. |
| 3184 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3185 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3186 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3187 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3188 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3189 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3190 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3191 | /* (assignments unknown, please report if found) */ |
| 3192 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3193 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3194 | }; |
| 3195 | |
| 3196 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) |
| 3197 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) |
| 3198 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) |
| 3199 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3200 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3201 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 3202 | int hkeyv; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3203 | bool radiosw_state = false; |
| 3204 | bool tabletsw_state = false; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3205 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3206 | unsigned long quirks; |
| 3207 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3208 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3209 | "initializing hotkey subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3210 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3211 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3212 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 3213 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3214 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3215 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3216 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3217 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3218 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 3219 | mutex_init(&hotkey_thread_mutex); |
| 3220 | mutex_init(&hotkey_thread_data_mutex); |
| 3221 | #endif |
| 3222 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3223 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3224 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3225 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3226 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3227 | "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3228 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3229 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3230 | if (!tp_features.hotkey) |
| 3231 | return 1; |
| 3232 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3233 | quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, |
| 3234 | ARRAY_SIZE(tpacpi_hotkey_qtable)); |
| 3235 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3236 | tpacpi_disable_brightness_delay(); |
| 3237 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3238 | /* MUST have enough space for all attributes to be added to |
| 3239 | * hotkey_dev_attributes */ |
| 3240 | hotkey_dev_attributes = create_attr_set( |
| 3241 | ARRAY_SIZE(hotkey_attributes) + 2, |
| 3242 | NULL); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3243 | if (!hotkey_dev_attributes) |
| 3244 | return -ENOMEM; |
| 3245 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 3246 | hotkey_attributes, |
| 3247 | ARRAY_SIZE(hotkey_attributes)); |
| 3248 | if (res) |
| 3249 | goto err_exit; |
| 3250 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3251 | /* 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] | 3252 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 3253 | for HKEY interface version 0x100 */ |
| 3254 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 3255 | if ((hkeyv >> 8) != 1) { |
| 3256 | printk(TPACPI_ERR "unknown version of the " |
| 3257 | "HKEY interface: 0x%x\n", hkeyv); |
| 3258 | printk(TPACPI_ERR "please report this to %s\n", |
| 3259 | TPACPI_MAIL); |
| 3260 | } else { |
| 3261 | /* |
| 3262 | * MHKV 0x100 in A31, R40, R40e, |
| 3263 | * T4x, X31, and later |
| 3264 | */ |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3265 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3266 | "firmware HKEY interface version: 0x%x\n", |
| 3267 | hkeyv); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3268 | |
| 3269 | /* Paranoia check AND init hotkey_all_mask */ |
| 3270 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
| 3271 | "MHKA", "qd")) { |
| 3272 | printk(TPACPI_ERR |
| 3273 | "missing MHKA handler, " |
| 3274 | "please report this to %s\n", |
| 3275 | TPACPI_MAIL); |
| 3276 | /* Fallback: pre-init for FN+F3,F4,F12 */ |
| 3277 | hotkey_all_mask = 0x080cU; |
| 3278 | } else { |
| 3279 | tp_features.hotkey_mask = 1; |
| 3280 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3281 | } |
| 3282 | } |
| 3283 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3284 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3285 | "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3286 | str_supported(tp_features.hotkey_mask)); |
| 3287 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3288 | /* Init hotkey_all_mask if not initialized yet */ |
| 3289 | if (!tp_features.hotkey_mask && !hotkey_all_mask && |
| 3290 | (quirks & TPACPI_HK_Q_INIMASK)) |
| 3291 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3292 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3293 | /* Init hotkey_acpi_mask and hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3294 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3295 | /* hotkey_source_mask *must* be zero for |
| 3296 | * the first hotkey_mask_get to return hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3297 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3298 | if (res) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3299 | goto err_exit; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3300 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3301 | hotkey_orig_mask = hotkey_acpi_mask; |
| 3302 | } else { |
| 3303 | hotkey_orig_mask = hotkey_all_mask; |
| 3304 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3305 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3306 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3307 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3308 | if (dbg_wlswemul) { |
| 3309 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3310 | radiosw_state = !!tpacpi_wlsw_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3311 | printk(TPACPI_INFO |
| 3312 | "radio switch emulation enabled\n"); |
| 3313 | } else |
| 3314 | #endif |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3315 | /* Not all thinkpads have a hardware radio switch */ |
| 3316 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 3317 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3318 | radiosw_state = !!status; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3319 | printk(TPACPI_INFO |
| 3320 | "radio switch found; radios are %s\n", |
| 3321 | enabled(status, 0)); |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3322 | } |
| 3323 | if (tp_features.hotkey_wlsw) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3324 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3325 | &dev_attr_hotkey_radio_sw.attr); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3326 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3327 | /* For X41t, X60t, X61t Tablets... */ |
| 3328 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 3329 | tp_features.hotkey_tablet = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3330 | tabletsw_state = !!(status & TP_HOTKEY_TABLET_MASK); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3331 | printk(TPACPI_INFO |
| 3332 | "possible tablet mode switch found; " |
| 3333 | "ThinkPad in %s mode\n", |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3334 | (tabletsw_state) ? "tablet" : "laptop"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3335 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3336 | &dev_attr_hotkey_tablet_mode.attr); |
| 3337 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3338 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3339 | if (!res) |
| 3340 | res = register_attr_set_with_sysfs( |
| 3341 | hotkey_dev_attributes, |
| 3342 | &tpacpi_pdev->dev.kobj); |
| 3343 | if (res) |
| 3344 | goto err_exit; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3345 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3346 | /* Set up key map */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3347 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3348 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 3349 | GFP_KERNEL); |
| 3350 | if (!hotkey_keycode_map) { |
| 3351 | printk(TPACPI_ERR |
| 3352 | "failed to allocate memory for key map\n"); |
| 3353 | res = -ENOMEM; |
| 3354 | goto err_exit; |
| 3355 | } |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3356 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3357 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3358 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3359 | "using Lenovo default hot key map\n"); |
| 3360 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, |
| 3361 | TPACPI_HOTKEY_MAP_SIZE); |
| 3362 | } else { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3363 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3364 | "using IBM default hot key map\n"); |
| 3365 | memcpy(hotkey_keycode_map, &ibm_keycode_map, |
| 3366 | TPACPI_HOTKEY_MAP_SIZE); |
| 3367 | } |
| 3368 | |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3369 | input_set_capability(tpacpi_inputdev, EV_MSC, MSC_SCAN); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3370 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 3371 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 3372 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 3373 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
| 3374 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3375 | input_set_capability(tpacpi_inputdev, EV_KEY, |
| 3376 | hotkey_keycode_map[i]); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3377 | } else { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3378 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 3379 | hotkey_reserved_mask |= 1 << i; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3380 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3381 | } |
| 3382 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3383 | if (tp_features.hotkey_wlsw) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3384 | input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL); |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3385 | input_report_switch(tpacpi_inputdev, |
| 3386 | SW_RFKILL_ALL, radiosw_state); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3387 | } |
| 3388 | if (tp_features.hotkey_tablet) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3389 | input_set_capability(tpacpi_inputdev, EV_SW, SW_TABLET_MODE); |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3390 | input_report_switch(tpacpi_inputdev, |
| 3391 | SW_TABLET_MODE, tabletsw_state); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3392 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3393 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3394 | /* Do not issue duplicate brightness change events to |
| 3395 | * userspace */ |
| 3396 | if (!tp_features.bright_acpimode) |
| 3397 | /* update bright_acpimode... */ |
| 3398 | tpacpi_check_std_acpi_brightness_support(); |
| 3399 | |
Henrique de Moraes Holschuh | 8bf3d4c | 2009-05-30 13:25:09 -0300 | [diff] [blame] | 3400 | if (tp_features.bright_acpimode && acpi_video_backlight_support()) { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3401 | printk(TPACPI_INFO |
| 3402 | "This ThinkPad has standard ACPI backlight " |
| 3403 | "brightness control, supported by the ACPI " |
| 3404 | "video driver\n"); |
| 3405 | printk(TPACPI_NOTICE |
| 3406 | "Disabling thinkpad-acpi brightness events " |
| 3407 | "by default...\n"); |
| 3408 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3409 | /* Disable brightness up/down on Lenovo thinkpads when |
| 3410 | * ACPI is handling them, otherwise it is plain impossible |
| 3411 | * for userspace to do something even remotely sane */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3412 | hotkey_reserved_mask |= |
| 3413 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 3414 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3415 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 3416 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3417 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3418 | |
Henrique de Moraes Holschuh | 230d8cf | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3419 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3420 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 3421 | & ~hotkey_all_mask |
| 3422 | & ~hotkey_reserved_mask; |
Henrique de Moraes Holschuh | 230d8cf | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3423 | |
| 3424 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3425 | "hotkey source mask 0x%08x, polling freq %u\n", |
| 3426 | hotkey_source_mask, hotkey_poll_freq); |
| 3427 | #endif |
| 3428 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3429 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3430 | "enabling firmware HKEY event interface...\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3431 | res = hotkey_status_set(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3432 | if (res) { |
| 3433 | hotkey_exit(); |
| 3434 | return res; |
| 3435 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3436 | res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask) |
| 3437 | | hotkey_driver_mask) |
| 3438 | & ~hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3439 | if (res < 0 && res != -ENXIO) { |
| 3440 | hotkey_exit(); |
| 3441 | return res; |
| 3442 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3443 | hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask) |
| 3444 | & ~hotkey_reserved_mask; |
| 3445 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3446 | "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n", |
| 3447 | hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3448 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3449 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3450 | "legacy ibm/hotkey event reporting over procfs %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3451 | (hotkey_report_mode < 2) ? |
| 3452 | "enabled" : "disabled"); |
| 3453 | |
| 3454 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 3455 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 3456 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3457 | hotkey_poll_setup_safe(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3458 | |
| 3459 | return 0; |
| 3460 | |
| 3461 | err_exit: |
| 3462 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3463 | hotkey_dev_attributes = NULL; |
| 3464 | |
| 3465 | return (res < 0)? res : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3466 | } |
| 3467 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3468 | static bool hotkey_notify_hotkey(const u32 hkey, |
| 3469 | bool *send_acpi_ev, |
| 3470 | bool *ignore_acpi_ev) |
| 3471 | { |
| 3472 | /* 0x1000-0x1FFF: key presses */ |
| 3473 | unsigned int scancode = hkey & 0xfff; |
| 3474 | *send_acpi_ev = true; |
| 3475 | *ignore_acpi_ev = false; |
| 3476 | |
| 3477 | if (scancode > 0 && scancode < 0x21) { |
| 3478 | scancode--; |
| 3479 | if (!(hotkey_source_mask & (1 << scancode))) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3480 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3481 | *send_acpi_ev = false; |
| 3482 | } else { |
| 3483 | *ignore_acpi_ev = true; |
| 3484 | } |
| 3485 | return true; |
| 3486 | } |
| 3487 | return false; |
| 3488 | } |
| 3489 | |
| 3490 | static bool hotkey_notify_wakeup(const u32 hkey, |
| 3491 | bool *send_acpi_ev, |
| 3492 | bool *ignore_acpi_ev) |
| 3493 | { |
| 3494 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3495 | *send_acpi_ev = true; |
| 3496 | *ignore_acpi_ev = false; |
| 3497 | |
| 3498 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3499 | case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */ |
| 3500 | case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3501 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 3502 | *ignore_acpi_ev = true; |
| 3503 | break; |
| 3504 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3505 | case TP_HKEY_EV_WKUP_S3_BAYEJ: /* suspend, bay eject */ |
| 3506 | case TP_HKEY_EV_WKUP_S4_BAYEJ: /* hibernation, bay eject */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3507 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 3508 | *ignore_acpi_ev = true; |
| 3509 | break; |
| 3510 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3511 | case TP_HKEY_EV_WKUP_S3_BATLOW: /* Battery on critical low level/S3 */ |
| 3512 | 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] | 3513 | printk(TPACPI_ALERT |
| 3514 | "EMERGENCY WAKEUP: battery almost empty\n"); |
| 3515 | /* how to auto-heal: */ |
| 3516 | /* 2313: woke up from S3, go to S4/S5 */ |
| 3517 | /* 2413: woke up from S4, go to S5 */ |
| 3518 | break; |
| 3519 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3520 | default: |
| 3521 | return false; |
| 3522 | } |
| 3523 | |
| 3524 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
| 3525 | printk(TPACPI_INFO |
| 3526 | "woke up due to a hot-unplug " |
| 3527 | "request...\n"); |
| 3528 | hotkey_wakeup_reason_notify_change(); |
| 3529 | } |
| 3530 | return true; |
| 3531 | } |
| 3532 | |
| 3533 | static bool hotkey_notify_usrevent(const u32 hkey, |
| 3534 | bool *send_acpi_ev, |
| 3535 | bool *ignore_acpi_ev) |
| 3536 | { |
| 3537 | /* 0x5000-0x5FFF: human interface helpers */ |
| 3538 | *send_acpi_ev = true; |
| 3539 | *ignore_acpi_ev = false; |
| 3540 | |
| 3541 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3542 | case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */ |
| 3543 | 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] | 3544 | return true; |
| 3545 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3546 | case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */ |
| 3547 | case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3548 | tpacpi_input_send_tabletsw(); |
| 3549 | hotkey_tablet_mode_notify_change(); |
| 3550 | *send_acpi_ev = false; |
| 3551 | return true; |
| 3552 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3553 | case TP_HKEY_EV_LID_CLOSE: /* Lid closed */ |
| 3554 | case TP_HKEY_EV_LID_OPEN: /* Lid opened */ |
| 3555 | case TP_HKEY_EV_BRGHT_CHANGED: /* brightness changed */ |
Henrique de Moraes Holschuh | 176dd98 | 2009-09-20 14:09:24 -0300 | [diff] [blame] | 3556 | /* do not propagate these events */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3557 | *ignore_acpi_ev = true; |
| 3558 | return true; |
| 3559 | |
| 3560 | default: |
| 3561 | return false; |
| 3562 | } |
| 3563 | } |
| 3564 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3565 | static void thermal_dump_all_sensors(void); |
| 3566 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3567 | static bool hotkey_notify_thermal(const u32 hkey, |
| 3568 | bool *send_acpi_ev, |
| 3569 | bool *ignore_acpi_ev) |
| 3570 | { |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3571 | bool known = true; |
| 3572 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3573 | /* 0x6000-0x6FFF: thermal alarms */ |
| 3574 | *send_acpi_ev = true; |
| 3575 | *ignore_acpi_ev = false; |
| 3576 | |
| 3577 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3578 | case TP_HKEY_EV_THM_TABLE_CHANGED: |
Henrique de Moraes Holschuh | 54926ce | 2009-01-11 03:01:09 -0200 | [diff] [blame] | 3579 | printk(TPACPI_INFO |
| 3580 | "EC reports that Thermal Table has changed\n"); |
| 3581 | /* recommended action: do nothing, we don't have |
| 3582 | * Lenovo ATM information */ |
| 3583 | return true; |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3584 | case TP_HKEY_EV_ALARM_BAT_HOT: |
| 3585 | printk(TPACPI_CRIT |
| 3586 | "THERMAL ALARM: battery is too hot!\n"); |
| 3587 | /* recommended action: warn user through gui */ |
| 3588 | break; |
| 3589 | case TP_HKEY_EV_ALARM_BAT_XHOT: |
| 3590 | printk(TPACPI_ALERT |
| 3591 | "THERMAL EMERGENCY: battery is extremely hot!\n"); |
| 3592 | /* recommended action: immediate sleep/hibernate */ |
| 3593 | break; |
| 3594 | case TP_HKEY_EV_ALARM_SENSOR_HOT: |
| 3595 | printk(TPACPI_CRIT |
| 3596 | "THERMAL ALARM: " |
| 3597 | "a sensor reports something is too hot!\n"); |
| 3598 | /* recommended action: warn user through gui, that */ |
| 3599 | /* some internal component is too hot */ |
| 3600 | break; |
| 3601 | case TP_HKEY_EV_ALARM_SENSOR_XHOT: |
| 3602 | printk(TPACPI_ALERT |
| 3603 | "THERMAL EMERGENCY: " |
| 3604 | "a sensor reports something is extremely hot!\n"); |
| 3605 | /* recommended action: immediate sleep/hibernate */ |
| 3606 | break; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3607 | default: |
| 3608 | printk(TPACPI_ALERT |
| 3609 | "THERMAL ALERT: unknown thermal alarm received\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3610 | known = false; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3611 | } |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3612 | |
| 3613 | thermal_dump_all_sensors(); |
| 3614 | |
| 3615 | return known; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3616 | } |
| 3617 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3618 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 3619 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3620 | u32 hkey; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3621 | bool send_acpi_ev; |
| 3622 | bool ignore_acpi_ev; |
| 3623 | bool known_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3624 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3625 | if (event != 0x80) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3626 | printk(TPACPI_ERR |
| 3627 | "unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3628 | /* 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] | 3629 | acpi_bus_generate_netlink_event( |
| 3630 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3631 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3632 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3633 | return; |
| 3634 | } |
| 3635 | |
| 3636 | while (1) { |
| 3637 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3638 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3639 | return; |
| 3640 | } |
| 3641 | |
| 3642 | if (hkey == 0) { |
| 3643 | /* queue empty */ |
| 3644 | return; |
| 3645 | } |
| 3646 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3647 | send_acpi_ev = true; |
| 3648 | ignore_acpi_ev = false; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3649 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3650 | switch (hkey >> 12) { |
| 3651 | case 1: |
| 3652 | /* 0x1000-0x1FFF: key presses */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3653 | known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev, |
| 3654 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3655 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3656 | case 2: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3657 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3658 | known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev, |
| 3659 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3660 | break; |
| 3661 | case 3: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3662 | /* 0x3000-0x3FFF: bay-related wakeups */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3663 | if (hkey == TP_HKEY_EV_BAYEJ_ACK) { |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3664 | hotkey_autosleep_ack = 1; |
| 3665 | printk(TPACPI_INFO |
| 3666 | "bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3667 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3668 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3669 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3670 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3671 | } |
| 3672 | break; |
| 3673 | case 4: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3674 | /* 0x4000-0x4FFF: dock-related wakeups */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3675 | if (hkey == TP_HKEY_EV_UNDOCK_ACK) { |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3676 | hotkey_autosleep_ack = 1; |
| 3677 | printk(TPACPI_INFO |
| 3678 | "undocked\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3679 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3680 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3681 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3682 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3683 | } |
| 3684 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3685 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 3686 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3687 | known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev, |
| 3688 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3689 | break; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3690 | case 6: |
| 3691 | /* 0x6000-0x6FFF: thermal alarms */ |
| 3692 | known_ev = hotkey_notify_thermal(hkey, &send_acpi_ev, |
| 3693 | &ignore_acpi_ev); |
| 3694 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3695 | case 7: |
| 3696 | /* 0x7000-0x7FFF: misc */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3697 | if (tp_features.hotkey_wlsw && |
| 3698 | hkey == TP_HKEY_EV_RFKILL_CHANGED) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3699 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3700 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3701 | known_ev = true; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3702 | break; |
| 3703 | } |
| 3704 | /* fallthrough to default */ |
| 3705 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3706 | known_ev = false; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3707 | } |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3708 | if (!known_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3709 | printk(TPACPI_NOTICE |
| 3710 | "unhandled HKEY event 0x%04x\n", hkey); |
Henrique de Moraes Holschuh | cb42935 | 2009-01-11 03:01:07 -0200 | [diff] [blame] | 3711 | printk(TPACPI_NOTICE |
| 3712 | "please report the conditions when this " |
| 3713 | "event happened to %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3714 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3715 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3716 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3717 | if (!ignore_acpi_ev && |
| 3718 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 3719 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 3720 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3721 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3722 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3723 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3724 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3725 | acpi_bus_generate_netlink_event( |
| 3726 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3727 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3728 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3729 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3730 | } |
| 3731 | } |
| 3732 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3733 | static void hotkey_suspend(pm_message_t state) |
| 3734 | { |
| 3735 | /* Do these on suspend, we get the events on early resume! */ |
| 3736 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 3737 | hotkey_autosleep_ack = 0; |
| 3738 | } |
| 3739 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3740 | static void hotkey_resume(void) |
| 3741 | { |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3742 | tpacpi_disable_brightness_delay(); |
| 3743 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3744 | if (hotkey_status_set(true) < 0 || |
| 3745 | hotkey_mask_set(hotkey_acpi_mask) < 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3746 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3747 | "error while attempting to reset the event " |
| 3748 | "firmware interface\n"); |
| 3749 | |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3750 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3751 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3752 | hotkey_wakeup_reason_notify_change(); |
| 3753 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3754 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3755 | } |
| 3756 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3757 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3758 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3760 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | int len = 0; |
| 3762 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3763 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3764 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3765 | return len; |
| 3766 | } |
| 3767 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3768 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3769 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3770 | res = hotkey_status_get(&status); |
| 3771 | if (!res) |
| 3772 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3773 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3774 | if (res) |
| 3775 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | |
| 3777 | 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] | 3778 | if (hotkey_all_mask) { |
| 3779 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_user_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | len += sprintf(p + len, |
| 3781 | "commands:\tenable, disable, reset, <mask>\n"); |
| 3782 | } else { |
| 3783 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 3784 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 3785 | } |
| 3786 | |
| 3787 | return len; |
| 3788 | } |
| 3789 | |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3790 | static void hotkey_enabledisable_warn(bool enable) |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3791 | { |
| 3792 | tpacpi_log_usertask("procfs hotkey enable/disable"); |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3793 | if (!WARN((tpacpi_lifecycle == TPACPI_LIFE_RUNNING || !enable), |
| 3794 | TPACPI_WARN |
| 3795 | "hotkey enable/disable functionality has been " |
| 3796 | "removed from the driver. Hotkeys are always " |
| 3797 | "enabled\n")) |
| 3798 | printk(TPACPI_ERR |
| 3799 | "Please remove the hotkey=enable module " |
| 3800 | "parameter, it is deprecated. Hotkeys are always " |
| 3801 | "enabled\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3802 | } |
| 3803 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3804 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3806 | int res; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3807 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3810 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | return -ENODEV; |
| 3812 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3813 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3814 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3815 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3816 | mask = hotkey_user_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3817 | |
| 3818 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | while ((cmd = next_cmd(&buf))) { |
| 3820 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3821 | hotkey_enabledisable_warn(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3823 | hotkey_enabledisable_warn(0); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3824 | res = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | } else if (strlencmp(cmd, "reset") == 0) { |
Henrique de Moraes Holschuh | 20c9aa4 | 2009-09-12 15:22:16 -0300 | [diff] [blame] | 3826 | mask = (hotkey_all_mask | hotkey_source_mask) |
| 3827 | & ~hotkey_reserved_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 3829 | /* mask set */ |
| 3830 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 3831 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3832 | } else { |
| 3833 | res = -EINVAL; |
| 3834 | goto errexit; |
| 3835 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | } |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3837 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3838 | if (!res) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3839 | tpacpi_disclose_usertask("procfs hotkey", |
| 3840 | "set mask to 0x%08x\n", mask); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3841 | res = hotkey_user_mask_set(mask); |
| 3842 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3844 | errexit: |
| 3845 | mutex_unlock(&hotkey_mutex); |
| 3846 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3847 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3849 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3850 | {TPACPI_ACPI_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3851 | {"", 0}, |
| 3852 | }; |
| 3853 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3854 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3855 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3856 | .notify = hotkey_notify, |
| 3857 | .handle = &hkey_handle, |
| 3858 | .type = ACPI_DEVICE_NOTIFY, |
| 3859 | }; |
| 3860 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3861 | static struct ibm_struct hotkey_driver_data = { |
| 3862 | .name = "hotkey", |
| 3863 | .read = hotkey_read, |
| 3864 | .write = hotkey_write, |
| 3865 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3866 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3867 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3868 | .acpi = &ibm_hotkey_acpidriver, |
| 3869 | }; |
| 3870 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3871 | /************************************************************************* |
| 3872 | * Bluetooth subdriver |
| 3873 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3875 | enum { |
| 3876 | /* ACPI GBDC/SBDC bits */ |
| 3877 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 3878 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3879 | TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: |
| 3880 | off / last state */ |
| 3881 | }; |
| 3882 | |
| 3883 | enum { |
| 3884 | /* ACPI \BLTH commands */ |
| 3885 | TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */ |
| 3886 | TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */ |
| 3887 | TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */ |
| 3888 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */ |
| 3889 | 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] | 3890 | }; |
| 3891 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3892 | #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" |
| 3893 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3894 | static int bluetooth_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3895 | { |
| 3896 | int status; |
| 3897 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3898 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3899 | if (dbg_bluetoothemul) |
| 3900 | return (tpacpi_bluetooth_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3901 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3902 | #endif |
| 3903 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3904 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 3905 | return -EIO; |
| 3906 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3907 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3908 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3909 | } |
| 3910 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3911 | static int bluetooth_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3912 | { |
| 3913 | int status; |
| 3914 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3915 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3916 | "will attempt to %s bluetooth\n", |
| 3917 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3918 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3919 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3920 | if (dbg_bluetoothemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3921 | tpacpi_bluetooth_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3922 | return 0; |
| 3923 | } |
| 3924 | #endif |
| 3925 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3926 | /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */ |
Henrique de Moraes Holschuh | 208b996 | 2009-12-09 01:36:22 +0000 | [diff] [blame] | 3927 | status = TP_ACPI_BLUETOOTH_RESUMECTRL; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3928 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 208b996 | 2009-12-09 01:36:22 +0000 | [diff] [blame] | 3929 | status |= TP_ACPI_BLUETOOTH_RADIOSSW; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3930 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3931 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 3932 | return -EIO; |
| 3933 | |
| 3934 | return 0; |
| 3935 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3936 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3937 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 3938 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 3939 | struct device_attribute *attr, |
| 3940 | char *buf) |
| 3941 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3942 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3943 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 3947 | struct device_attribute *attr, |
| 3948 | const char *buf, size_t count) |
| 3949 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3950 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3951 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3952 | } |
| 3953 | |
| 3954 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 3955 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3956 | bluetooth_enable_show, bluetooth_enable_store); |
| 3957 | |
| 3958 | /* --------------------------------------------------------------------- */ |
| 3959 | |
| 3960 | static struct attribute *bluetooth_attributes[] = { |
| 3961 | &dev_attr_bluetooth_enable.attr, |
| 3962 | NULL |
| 3963 | }; |
| 3964 | |
| 3965 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3966 | .attrs = bluetooth_attributes, |
| 3967 | }; |
| 3968 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3969 | static const struct tpacpi_rfk_ops bluetooth_tprfk_ops = { |
| 3970 | .get_status = bluetooth_get_status, |
| 3971 | .set_status = bluetooth_set_status, |
| 3972 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3973 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3974 | static void bluetooth_shutdown(void) |
| 3975 | { |
| 3976 | /* Order firmware to save current state to NVRAM */ |
| 3977 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 3978 | TP_ACPI_BLTH_SAVE_STATE)) |
| 3979 | printk(TPACPI_NOTICE |
| 3980 | "failed to save bluetooth state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3981 | else |
| 3982 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3983 | "bluestooth state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3984 | } |
| 3985 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3986 | static void bluetooth_exit(void) |
| 3987 | { |
| 3988 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 3989 | &bluetooth_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3990 | |
| 3991 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
| 3992 | |
| 3993 | bluetooth_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3994 | } |
| 3995 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3996 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3998 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3999 | int status = 0; |
| 4000 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4001 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4002 | "initializing bluetooth subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4003 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4004 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4005 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4006 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4007 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4008 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4009 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4011 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4012 | "bluetooth is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4013 | str_supported(tp_features.bluetooth), |
| 4014 | status); |
| 4015 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4016 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4017 | if (dbg_bluetoothemul) { |
| 4018 | tp_features.bluetooth = 1; |
| 4019 | printk(TPACPI_INFO |
| 4020 | "bluetooth switch emulation enabled\n"); |
| 4021 | } else |
| 4022 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4023 | if (tp_features.bluetooth && |
| 4024 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 4025 | /* no bluetooth hardware present in system */ |
| 4026 | tp_features.bluetooth = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4027 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4028 | "bluetooth hardware not installed\n"); |
| 4029 | } |
| 4030 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4031 | if (!tp_features.bluetooth) |
| 4032 | return 1; |
| 4033 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4034 | res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 4035 | &bluetooth_tprfk_ops, |
| 4036 | RFKILL_TYPE_BLUETOOTH, |
| 4037 | TPACPI_RFK_BLUETOOTH_SW_NAME, |
| 4038 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4039 | if (res) |
| 4040 | return res; |
| 4041 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4042 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4043 | &bluetooth_attr_group); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4044 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4045 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4046 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4047 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4048 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4049 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | } |
| 4051 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4052 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4053 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4055 | return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4056 | } |
| 4057 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4058 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4060 | return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | } |
| 4062 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4063 | static struct ibm_struct bluetooth_driver_data = { |
| 4064 | .name = "bluetooth", |
| 4065 | .read = bluetooth_read, |
| 4066 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4067 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4068 | .shutdown = bluetooth_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4069 | }; |
| 4070 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4071 | /************************************************************************* |
| 4072 | * Wan subdriver |
| 4073 | */ |
| 4074 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4075 | enum { |
| 4076 | /* ACPI GWAN/SWAN bits */ |
| 4077 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 4078 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4079 | TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: |
| 4080 | off / last state */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4081 | }; |
| 4082 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4083 | #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" |
| 4084 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4085 | static int wan_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4086 | { |
| 4087 | int status; |
| 4088 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4089 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4090 | if (dbg_wwanemul) |
| 4091 | return (tpacpi_wwan_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4092 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4093 | #endif |
| 4094 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4095 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 4096 | return -EIO; |
| 4097 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4098 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4099 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4100 | } |
| 4101 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4102 | static int wan_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4103 | { |
| 4104 | int status; |
| 4105 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4106 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4107 | "will attempt to %s wwan\n", |
| 4108 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4109 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4110 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4111 | if (dbg_wwanemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4112 | tpacpi_wwan_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4113 | return 0; |
| 4114 | } |
| 4115 | #endif |
| 4116 | |
Henrique de Moraes Holschuh | 208b996 | 2009-12-09 01:36:22 +0000 | [diff] [blame] | 4117 | /* We make sure to set TP_ACPI_WANCARD_RESUMECTRL */ |
| 4118 | status = TP_ACPI_WANCARD_RESUMECTRL; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4119 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 208b996 | 2009-12-09 01:36:22 +0000 | [diff] [blame] | 4120 | status |= TP_ACPI_WANCARD_RADIOSSW; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4121 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4122 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 4123 | return -EIO; |
| 4124 | |
| 4125 | return 0; |
| 4126 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4127 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4128 | /* sysfs wan enable ---------------------------------------------------- */ |
| 4129 | static ssize_t wan_enable_show(struct device *dev, |
| 4130 | struct device_attribute *attr, |
| 4131 | char *buf) |
| 4132 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4133 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID, |
| 4134 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | static ssize_t wan_enable_store(struct device *dev, |
| 4138 | struct device_attribute *attr, |
| 4139 | const char *buf, size_t count) |
| 4140 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4141 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID, |
| 4142 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4143 | } |
| 4144 | |
| 4145 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 4146 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4147 | wan_enable_show, wan_enable_store); |
| 4148 | |
| 4149 | /* --------------------------------------------------------------------- */ |
| 4150 | |
| 4151 | static struct attribute *wan_attributes[] = { |
| 4152 | &dev_attr_wan_enable.attr, |
| 4153 | NULL |
| 4154 | }; |
| 4155 | |
| 4156 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4157 | .attrs = wan_attributes, |
| 4158 | }; |
| 4159 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4160 | static const struct tpacpi_rfk_ops wan_tprfk_ops = { |
| 4161 | .get_status = wan_get_status, |
| 4162 | .set_status = wan_set_status, |
| 4163 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4164 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4165 | static void wan_shutdown(void) |
| 4166 | { |
| 4167 | /* Order firmware to save current state to NVRAM */ |
| 4168 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd", |
| 4169 | TP_ACPI_WGSV_SAVE_STATE)) |
| 4170 | printk(TPACPI_NOTICE |
| 4171 | "failed to save WWAN state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4172 | else |
| 4173 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 4174 | "WWAN state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4175 | } |
| 4176 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4177 | static void wan_exit(void) |
| 4178 | { |
| 4179 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 4180 | &wan_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4181 | |
| 4182 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
| 4183 | |
| 4184 | wan_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4185 | } |
| 4186 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4187 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4188 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4189 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4190 | int status = 0; |
| 4191 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4192 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4193 | "initializing wan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4194 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4195 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4196 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4197 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4198 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4199 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4200 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4201 | "wan is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4202 | str_supported(tp_features.wan), |
| 4203 | status); |
| 4204 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4205 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4206 | if (dbg_wwanemul) { |
| 4207 | tp_features.wan = 1; |
| 4208 | printk(TPACPI_INFO |
| 4209 | "wwan switch emulation enabled\n"); |
| 4210 | } else |
| 4211 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4212 | if (tp_features.wan && |
| 4213 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 4214 | /* no wan hardware present in system */ |
| 4215 | tp_features.wan = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4216 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4217 | "wan hardware not installed\n"); |
| 4218 | } |
| 4219 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4220 | if (!tp_features.wan) |
| 4221 | return 1; |
| 4222 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4223 | res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, |
| 4224 | &wan_tprfk_ops, |
| 4225 | RFKILL_TYPE_WWAN, |
| 4226 | TPACPI_RFK_WWAN_SW_NAME, |
| 4227 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4228 | if (res) |
| 4229 | return res; |
| 4230 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4231 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4232 | &wan_attr_group); |
| 4233 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4234 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4235 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4236 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4237 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4238 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4239 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4240 | } |
| 4241 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4242 | /* procfs -------------------------------------------------------------- */ |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4243 | static int wan_read(char *p) |
| 4244 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4245 | return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID, p); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | static int wan_write(char *buf) |
| 4249 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4250 | return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID, buf); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4251 | } |
| 4252 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4253 | static struct ibm_struct wan_driver_data = { |
| 4254 | .name = "wan", |
| 4255 | .read = wan_read, |
| 4256 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4257 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4258 | .shutdown = wan_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4259 | }; |
| 4260 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4261 | /************************************************************************* |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4262 | * UWB subdriver |
| 4263 | */ |
| 4264 | |
| 4265 | enum { |
| 4266 | /* ACPI GUWB/SUWB bits */ |
| 4267 | TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */ |
| 4268 | TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */ |
| 4269 | }; |
| 4270 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4271 | #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" |
| 4272 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4273 | static int uwb_get_status(void) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4274 | { |
| 4275 | int status; |
| 4276 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4277 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4278 | if (dbg_uwbemul) |
| 4279 | return (tpacpi_uwb_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4280 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4281 | #endif |
| 4282 | |
| 4283 | if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) |
| 4284 | return -EIO; |
| 4285 | |
| 4286 | return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4287 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4288 | } |
| 4289 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4290 | static int uwb_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4291 | { |
| 4292 | int status; |
| 4293 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4294 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4295 | "will attempt to %s UWB\n", |
| 4296 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4297 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4298 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4299 | if (dbg_uwbemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4300 | tpacpi_uwb_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4301 | return 0; |
| 4302 | } |
| 4303 | #endif |
| 4304 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4305 | if (state == TPACPI_RFK_RADIO_ON) |
| 4306 | status = TP_ACPI_UWB_RADIOSSW; |
| 4307 | else |
| 4308 | status = 0; |
| 4309 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4310 | if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) |
| 4311 | return -EIO; |
| 4312 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4313 | return 0; |
| 4314 | } |
| 4315 | |
| 4316 | /* --------------------------------------------------------------------- */ |
| 4317 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4318 | static const struct tpacpi_rfk_ops uwb_tprfk_ops = { |
| 4319 | .get_status = uwb_get_status, |
| 4320 | .set_status = uwb_set_status, |
| 4321 | }; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4322 | |
| 4323 | static void uwb_exit(void) |
| 4324 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4325 | tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | static int __init uwb_init(struct ibm_init_struct *iibm) |
| 4329 | { |
| 4330 | int res; |
| 4331 | int status = 0; |
| 4332 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4333 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4334 | "initializing uwb subdriver\n"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4335 | |
| 4336 | TPACPI_ACPIHANDLE_INIT(hkey); |
| 4337 | |
| 4338 | tp_features.uwb = hkey_handle && |
| 4339 | acpi_evalf(hkey_handle, &status, "GUWB", "qd"); |
| 4340 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4341 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4342 | "uwb is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4343 | str_supported(tp_features.uwb), |
| 4344 | status); |
| 4345 | |
| 4346 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4347 | if (dbg_uwbemul) { |
| 4348 | tp_features.uwb = 1; |
| 4349 | printk(TPACPI_INFO |
| 4350 | "uwb switch emulation enabled\n"); |
| 4351 | } else |
| 4352 | #endif |
| 4353 | if (tp_features.uwb && |
| 4354 | !(status & TP_ACPI_UWB_HWPRESENT)) { |
| 4355 | /* no uwb hardware present in system */ |
| 4356 | tp_features.uwb = 0; |
| 4357 | dbg_printk(TPACPI_DBG_INIT, |
| 4358 | "uwb hardware not installed\n"); |
| 4359 | } |
| 4360 | |
| 4361 | if (!tp_features.uwb) |
| 4362 | return 1; |
| 4363 | |
| 4364 | res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4365 | &uwb_tprfk_ops, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4366 | RFKILL_TYPE_UWB, |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4367 | TPACPI_RFK_UWB_SW_NAME, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4368 | false); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4369 | return res; |
| 4370 | } |
| 4371 | |
| 4372 | static struct ibm_struct uwb_driver_data = { |
| 4373 | .name = "uwb", |
| 4374 | .exit = uwb_exit, |
| 4375 | .flags.experimental = 1, |
| 4376 | }; |
| 4377 | |
| 4378 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4379 | * Video subdriver |
| 4380 | */ |
| 4381 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4382 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 4383 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4384 | enum video_access_mode { |
| 4385 | TPACPI_VIDEO_NONE = 0, |
| 4386 | TPACPI_VIDEO_570, /* 570 */ |
| 4387 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 4388 | TPACPI_VIDEO_NEW, /* all others */ |
| 4389 | }; |
| 4390 | |
| 4391 | enum { /* video status flags, based on VIDEO_570 */ |
| 4392 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 4393 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 4394 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 4395 | }; |
| 4396 | |
| 4397 | enum { /* TPACPI_VIDEO_570 constants */ |
| 4398 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 4399 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 4400 | * video_status_flags */ |
| 4401 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 4402 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 4403 | }; |
| 4404 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4405 | static enum video_access_mode video_supported; |
| 4406 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4407 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4408 | static int video_autosw_get(void); |
| 4409 | static int video_autosw_set(int enable); |
| 4410 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4411 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4412 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4413 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4415 | int ivga; |
| 4416 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4417 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 4418 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4419 | TPACPI_ACPIHANDLE_INIT(vid); |
| 4420 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4421 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4422 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 4423 | /* G41, assume IVGA doesn't change */ |
| 4424 | vid_handle = vid2_handle; |
| 4425 | |
| 4426 | if (!vid_handle) |
| 4427 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4428 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4429 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 4430 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4431 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4432 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 4433 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4434 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4435 | else |
| 4436 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4437 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4439 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 4440 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 4441 | video_supported); |
| 4442 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4443 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | } |
| 4445 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4446 | static void video_exit(void) |
| 4447 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4448 | dbg_printk(TPACPI_DBG_EXIT, |
| 4449 | "restoring original video autoswitch mode\n"); |
| 4450 | if (video_autosw_set(video_orig_autosw)) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4451 | printk(TPACPI_ERR "error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4452 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4453 | } |
| 4454 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4455 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | { |
| 4457 | int status = 0; |
| 4458 | int i; |
| 4459 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4460 | switch (video_supported) { |
| 4461 | case TPACPI_VIDEO_570: |
| 4462 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 4463 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 4464 | return -EIO; |
| 4465 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 4466 | break; |
| 4467 | case TPACPI_VIDEO_770: |
| 4468 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4469 | return -EIO; |
| 4470 | if (i) |
| 4471 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4472 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4473 | return -EIO; |
| 4474 | if (i) |
| 4475 | status |= TP_ACPI_VIDEO_S_CRT; |
| 4476 | break; |
| 4477 | case TPACPI_VIDEO_NEW: |
| 4478 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 4479 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4480 | return -EIO; |
| 4481 | if (i) |
| 4482 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4484 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 4485 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4486 | return -EIO; |
| 4487 | if (i) |
| 4488 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4489 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 4490 | return -EIO; |
| 4491 | if (i) |
| 4492 | status |= TP_ACPI_VIDEO_S_DVI; |
| 4493 | break; |
| 4494 | default: |
| 4495 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | |
| 4498 | return status; |
| 4499 | } |
| 4500 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4501 | static int video_outputsw_set(int status) |
| 4502 | { |
| 4503 | int autosw; |
| 4504 | int res = 0; |
| 4505 | |
| 4506 | switch (video_supported) { |
| 4507 | case TPACPI_VIDEO_570: |
| 4508 | res = acpi_evalf(NULL, NULL, |
| 4509 | "\\_SB.PHS2", "vdd", |
| 4510 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 4511 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 4512 | break; |
| 4513 | case TPACPI_VIDEO_770: |
| 4514 | autosw = video_autosw_get(); |
| 4515 | if (autosw < 0) |
| 4516 | return autosw; |
| 4517 | |
| 4518 | res = video_autosw_set(1); |
| 4519 | if (res) |
| 4520 | return res; |
| 4521 | res = acpi_evalf(vid_handle, NULL, |
| 4522 | "ASWT", "vdd", status * 0x100, 0); |
| 4523 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4524 | printk(TPACPI_ERR |
| 4525 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4526 | return -EIO; |
| 4527 | } |
| 4528 | break; |
| 4529 | case TPACPI_VIDEO_NEW: |
| 4530 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4531 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4532 | break; |
| 4533 | default: |
| 4534 | return -ENOSYS; |
| 4535 | } |
| 4536 | |
| 4537 | return (res)? 0 : -EIO; |
| 4538 | } |
| 4539 | |
| 4540 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4542 | int autosw = 0; |
| 4543 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4544 | switch (video_supported) { |
| 4545 | case TPACPI_VIDEO_570: |
| 4546 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 4547 | return -EIO; |
| 4548 | break; |
| 4549 | case TPACPI_VIDEO_770: |
| 4550 | case TPACPI_VIDEO_NEW: |
| 4551 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 4552 | return -EIO; |
| 4553 | break; |
| 4554 | default: |
| 4555 | return -ENOSYS; |
| 4556 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4557 | |
| 4558 | return autosw & 1; |
| 4559 | } |
| 4560 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4561 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4562 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4563 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4564 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4565 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4566 | } |
| 4567 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4568 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4569 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4570 | int autosw = video_autosw_get(); |
| 4571 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4572 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4573 | if (autosw < 0) |
| 4574 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4575 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4576 | switch (video_supported) { |
| 4577 | case TPACPI_VIDEO_570: |
| 4578 | res = video_autosw_set(1); |
| 4579 | if (res) |
| 4580 | return res; |
| 4581 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 4582 | break; |
| 4583 | case TPACPI_VIDEO_770: |
| 4584 | case TPACPI_VIDEO_NEW: |
| 4585 | res = video_autosw_set(1); |
| 4586 | if (res) |
| 4587 | return res; |
| 4588 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 4589 | break; |
| 4590 | default: |
| 4591 | return -ENOSYS; |
| 4592 | } |
| 4593 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4594 | printk(TPACPI_ERR |
| 4595 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4596 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4597 | } |
| 4598 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4599 | return (res)? 0 : -EIO; |
| 4600 | } |
| 4601 | |
| 4602 | static int video_expand_toggle(void) |
| 4603 | { |
| 4604 | switch (video_supported) { |
| 4605 | case TPACPI_VIDEO_570: |
| 4606 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 4607 | 0 : -EIO; |
| 4608 | case TPACPI_VIDEO_770: |
| 4609 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 4610 | 0 : -EIO; |
| 4611 | case TPACPI_VIDEO_NEW: |
| 4612 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 4613 | 0 : -EIO; |
| 4614 | default: |
| 4615 | return -ENOSYS; |
| 4616 | } |
| 4617 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4618 | } |
| 4619 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4620 | static int video_read(char *p) |
| 4621 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4622 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4623 | int len = 0; |
| 4624 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4625 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4626 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4627 | return len; |
| 4628 | } |
| 4629 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4630 | status = video_outputsw_get(); |
| 4631 | if (status < 0) |
| 4632 | return status; |
| 4633 | |
| 4634 | autosw = video_autosw_get(); |
| 4635 | if (autosw < 0) |
| 4636 | return autosw; |
| 4637 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4638 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 4639 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 4640 | 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] | 4641 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4642 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 4643 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 4644 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 4645 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4646 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4647 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 4648 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 4649 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 4650 | |
| 4651 | return len; |
| 4652 | } |
| 4653 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4654 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | { |
| 4656 | char *cmd; |
| 4657 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4658 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4660 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4661 | return -ENODEV; |
| 4662 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4663 | enable = 0; |
| 4664 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | |
| 4666 | while ((cmd = next_cmd(&buf))) { |
| 4667 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4668 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4670 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4672 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4674 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4675 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4676 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4677 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4678 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4679 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4680 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4681 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4682 | res = video_autosw_set(1); |
| 4683 | if (res) |
| 4684 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4686 | res = video_autosw_set(0); |
| 4687 | if (res) |
| 4688 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4690 | res = video_outputsw_cycle(); |
| 4691 | if (res) |
| 4692 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4693 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4694 | res = video_expand_toggle(); |
| 4695 | if (res) |
| 4696 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | } else |
| 4698 | return -EINVAL; |
| 4699 | } |
| 4700 | |
| 4701 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4702 | status = video_outputsw_get(); |
| 4703 | if (status < 0) |
| 4704 | return status; |
| 4705 | res = video_outputsw_set((status & ~disable) | enable); |
| 4706 | if (res) |
| 4707 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | return 0; |
| 4711 | } |
| 4712 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4713 | static struct ibm_struct video_driver_data = { |
| 4714 | .name = "video", |
| 4715 | .read = video_read, |
| 4716 | .write = video_write, |
| 4717 | .exit = video_exit, |
| 4718 | }; |
| 4719 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4720 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 4721 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4722 | /************************************************************************* |
| 4723 | * Light (thinklight) subdriver |
| 4724 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4726 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 4727 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4728 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4729 | static int light_get_status(void) |
| 4730 | { |
| 4731 | int status = 0; |
| 4732 | |
| 4733 | if (tp_features.light_status) { |
| 4734 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 4735 | return -EIO; |
| 4736 | return (!!status); |
| 4737 | } |
| 4738 | |
| 4739 | return -ENXIO; |
| 4740 | } |
| 4741 | |
| 4742 | static int light_set_status(int status) |
| 4743 | { |
| 4744 | int rc; |
| 4745 | |
| 4746 | if (tp_features.light) { |
| 4747 | if (cmos_handle) { |
| 4748 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", |
| 4749 | (status)? |
| 4750 | TP_CMOS_THINKLIGHT_ON : |
| 4751 | TP_CMOS_THINKLIGHT_OFF); |
| 4752 | } else { |
| 4753 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", |
| 4754 | (status)? 1 : 0); |
| 4755 | } |
| 4756 | return (rc)? 0 : -EIO; |
| 4757 | } |
| 4758 | |
| 4759 | return -ENXIO; |
| 4760 | } |
| 4761 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4762 | static void light_set_status_worker(struct work_struct *work) |
| 4763 | { |
| 4764 | struct tpacpi_led_classdev *data = |
| 4765 | container_of(work, struct tpacpi_led_classdev, work); |
| 4766 | |
| 4767 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4768 | light_set_status((data->new_state != TPACPI_LED_OFF)); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | static void light_sysfs_set(struct led_classdev *led_cdev, |
| 4772 | enum led_brightness brightness) |
| 4773 | { |
| 4774 | struct tpacpi_led_classdev *data = |
| 4775 | container_of(led_cdev, |
| 4776 | struct tpacpi_led_classdev, |
| 4777 | led_classdev); |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4778 | data->new_state = (brightness != LED_OFF) ? |
| 4779 | TPACPI_LED_ON : TPACPI_LED_OFF; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4780 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) |
| 4784 | { |
| 4785 | return (light_get_status() == 1)? LED_FULL : LED_OFF; |
| 4786 | } |
| 4787 | |
| 4788 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { |
| 4789 | .led_classdev = { |
| 4790 | .name = "tpacpi::thinklight", |
| 4791 | .brightness_set = &light_sysfs_set, |
| 4792 | .brightness_get = &light_sysfs_get, |
| 4793 | } |
| 4794 | }; |
| 4795 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4796 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4798 | int rc; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4799 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4800 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 4801 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4802 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 4803 | TPACPI_ACPIHANDLE_INIT(lght); |
| 4804 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4805 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4806 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4807 | /* 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] | 4808 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4809 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4810 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4811 | /* light status not supported on |
| 4812 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4813 | tp_features.light_status = |
| 4814 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4815 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4816 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
| 4817 | str_supported(tp_features.light), |
| 4818 | str_supported(tp_features.light_status)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4819 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4820 | if (!tp_features.light) |
| 4821 | return 1; |
| 4822 | |
| 4823 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 4824 | &tpacpi_led_thinklight.led_classdev); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4825 | |
| 4826 | if (rc < 0) { |
| 4827 | tp_features.light = 0; |
| 4828 | tp_features.light_status = 0; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4829 | } else { |
| 4830 | rc = 0; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4831 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4832 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4833 | return rc; |
| 4834 | } |
| 4835 | |
| 4836 | static void light_exit(void) |
| 4837 | { |
| 4838 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); |
| 4839 | if (work_pending(&tpacpi_led_thinklight.work)) |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4840 | flush_workqueue(tpacpi_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4843 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | { |
| 4845 | int len = 0; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4846 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4848 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4849 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4850 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4851 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 4852 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 4853 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4854 | status = light_get_status(); |
| 4855 | if (status < 0) |
| 4856 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4858 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 4859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | |
| 4861 | return len; |
| 4862 | } |
| 4863 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4864 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4867 | int newstatus = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4868 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4869 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4870 | return -ENODEV; |
| 4871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | while ((cmd = next_cmd(&buf))) { |
| 4873 | if (strlencmp(cmd, "on") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4874 | newstatus = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | } else if (strlencmp(cmd, "off") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4876 | newstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4877 | } else |
| 4878 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | } |
| 4880 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4881 | return light_set_status(newstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | } |
| 4883 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4884 | static struct ibm_struct light_driver_data = { |
| 4885 | .name = "light", |
| 4886 | .read = light_read, |
| 4887 | .write = light_write, |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4888 | .exit = light_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4889 | }; |
| 4890 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4891 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4892 | * CMOS subdriver |
| 4893 | */ |
| 4894 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4895 | /* sysfs cmos_command -------------------------------------------------- */ |
| 4896 | static ssize_t cmos_command_store(struct device *dev, |
| 4897 | struct device_attribute *attr, |
| 4898 | const char *buf, size_t count) |
| 4899 | { |
| 4900 | unsigned long cmos_cmd; |
| 4901 | int res; |
| 4902 | |
| 4903 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 4904 | return -EINVAL; |
| 4905 | |
| 4906 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4907 | return (res)? res : count; |
| 4908 | } |
| 4909 | |
| 4910 | static struct device_attribute dev_attr_cmos_command = |
| 4911 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 4912 | |
| 4913 | /* --------------------------------------------------------------------- */ |
| 4914 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4915 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4916 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4917 | int res; |
| 4918 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4919 | vdbg_printk(TPACPI_DBG_INIT, |
| 4920 | "initializing cmos commands subdriver\n"); |
| 4921 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4922 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4923 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4924 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 4925 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4926 | |
| 4927 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4928 | if (res) |
| 4929 | return res; |
| 4930 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4931 | return (cmos_handle)? 0 : 1; |
| 4932 | } |
| 4933 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4934 | static void cmos_exit(void) |
| 4935 | { |
| 4936 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4937 | } |
| 4938 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4939 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4940 | { |
| 4941 | int len = 0; |
| 4942 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4943 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4944 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4945 | if (!cmos_handle) |
| 4946 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4947 | else { |
| 4948 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4949 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | } |
| 4951 | |
| 4952 | return len; |
| 4953 | } |
| 4954 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4955 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4956 | { |
| 4957 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4958 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | |
| 4960 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4961 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 4962 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | /* cmos_cmd set */ |
| 4964 | } else |
| 4965 | return -EINVAL; |
| 4966 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4967 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4968 | if (res) |
| 4969 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
| 4972 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4973 | } |
| 4974 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4975 | static struct ibm_struct cmos_driver_data = { |
| 4976 | .name = "cmos", |
| 4977 | .read = cmos_read, |
| 4978 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4979 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4980 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4981 | |
| 4982 | /************************************************************************* |
| 4983 | * LED subdriver |
| 4984 | */ |
| 4985 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4986 | enum led_access_mode { |
| 4987 | TPACPI_LED_NONE = 0, |
| 4988 | TPACPI_LED_570, /* 570 */ |
| 4989 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 4990 | TPACPI_LED_NEW, /* all others */ |
| 4991 | }; |
| 4992 | |
| 4993 | enum { /* For TPACPI_LED_OLD */ |
| 4994 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 4995 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 4996 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 4997 | }; |
| 4998 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4999 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5000 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5001 | TPACPI_HANDLE(led, ec, "SLED", /* 570 */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5002 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */ |
| 5003 | /* T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5004 | "LED", /* all others */ |
| 5005 | ); /* R30, R31 */ |
| 5006 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5007 | #define TPACPI_LED_NUMLEDS 16 |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5008 | static struct tpacpi_led_classdev *tpacpi_leds; |
| 5009 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; |
Harvey Harrison | e3aa51f | 2008-05-29 17:51:57 -0700 | [diff] [blame] | 5010 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5011 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
| 5012 | "tpacpi::power", |
| 5013 | "tpacpi:orange:batt", |
| 5014 | "tpacpi:green:batt", |
| 5015 | "tpacpi::dock_active", |
| 5016 | "tpacpi::bay_active", |
| 5017 | "tpacpi::dock_batt", |
| 5018 | "tpacpi::unknown_led", |
| 5019 | "tpacpi::standby", |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5020 | "tpacpi::dock_status1", |
| 5021 | "tpacpi::dock_status2", |
| 5022 | "tpacpi::unknown_led2", |
| 5023 | "tpacpi::unknown_led3", |
| 5024 | "tpacpi::thinkvantage", |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5025 | }; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5026 | #define TPACPI_SAFE_LEDS 0x1081U |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5027 | |
| 5028 | static inline bool tpacpi_is_led_restricted(const unsigned int led) |
| 5029 | { |
| 5030 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
| 5031 | return false; |
| 5032 | #else |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5033 | return (1U & (TPACPI_SAFE_LEDS >> led)) == 0; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5034 | #endif |
| 5035 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5036 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5037 | static int led_get_status(const unsigned int led) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5038 | { |
| 5039 | int status; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5040 | enum led_status_t led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5041 | |
| 5042 | switch (led_supported) { |
| 5043 | case TPACPI_LED_570: |
| 5044 | if (!acpi_evalf(ec_handle, |
| 5045 | &status, "GLED", "dd", 1 << led)) |
| 5046 | return -EIO; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5047 | led_s = (status == 0)? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5048 | TPACPI_LED_OFF : |
| 5049 | ((status == 1)? |
| 5050 | TPACPI_LED_ON : |
| 5051 | TPACPI_LED_BLINK); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5052 | tpacpi_led_state_cache[led] = led_s; |
| 5053 | return led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5054 | default: |
| 5055 | return -ENXIO; |
| 5056 | } |
| 5057 | |
| 5058 | /* not reached */ |
| 5059 | } |
| 5060 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5061 | static int led_set_status(const unsigned int led, |
| 5062 | const enum led_status_t ledstatus) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5063 | { |
| 5064 | /* off, on, blink. Index is led_status_t */ |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5065 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
| 5066 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5067 | |
| 5068 | int rc = 0; |
| 5069 | |
| 5070 | switch (led_supported) { |
| 5071 | case TPACPI_LED_570: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5072 | /* 570 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5073 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5074 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 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 | (1 << led), led_sled_arg1[ledstatus])) |
| 5079 | rc = -EIO; |
| 5080 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5081 | case TPACPI_LED_OLD: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5082 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5083 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5084 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5085 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5086 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5087 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
| 5088 | if (rc >= 0) |
| 5089 | rc = ec_write(TPACPI_LED_EC_HLBL, |
| 5090 | (ledstatus == TPACPI_LED_BLINK) << led); |
| 5091 | if (rc >= 0) |
| 5092 | rc = ec_write(TPACPI_LED_EC_HLCL, |
| 5093 | (ledstatus != TPACPI_LED_OFF) << led); |
| 5094 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5095 | case TPACPI_LED_NEW: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5096 | /* all others */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5097 | if (unlikely(led >= TPACPI_LED_NUMLEDS)) |
| 5098 | return -EINVAL; |
| 5099 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5100 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5101 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5102 | led, led_led_arg1[ledstatus])) |
| 5103 | rc = -EIO; |
| 5104 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5105 | default: |
| 5106 | rc = -ENXIO; |
| 5107 | } |
| 5108 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5109 | if (!rc) |
| 5110 | tpacpi_led_state_cache[led] = ledstatus; |
| 5111 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5112 | return rc; |
| 5113 | } |
| 5114 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5115 | static void led_set_status_worker(struct work_struct *work) |
| 5116 | { |
| 5117 | struct tpacpi_led_classdev *data = |
| 5118 | container_of(work, struct tpacpi_led_classdev, work); |
| 5119 | |
| 5120 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5121 | led_set_status(data->led, data->new_state); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | static void led_sysfs_set(struct led_classdev *led_cdev, |
| 5125 | enum led_brightness brightness) |
| 5126 | { |
| 5127 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5128 | struct tpacpi_led_classdev, led_classdev); |
| 5129 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5130 | if (brightness == LED_OFF) |
| 5131 | data->new_state = TPACPI_LED_OFF; |
| 5132 | else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) |
| 5133 | data->new_state = TPACPI_LED_ON; |
| 5134 | else |
| 5135 | data->new_state = TPACPI_LED_BLINK; |
| 5136 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5137 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, |
| 5141 | unsigned long *delay_on, unsigned long *delay_off) |
| 5142 | { |
| 5143 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5144 | struct tpacpi_led_classdev, led_classdev); |
| 5145 | |
| 5146 | /* Can we choose the flash rate? */ |
| 5147 | if (*delay_on == 0 && *delay_off == 0) { |
| 5148 | /* yes. set them to the hardware blink rate (1 Hz) */ |
| 5149 | *delay_on = 500; /* ms */ |
| 5150 | *delay_off = 500; /* ms */ |
| 5151 | } else if ((*delay_on != 500) || (*delay_off != 500)) |
| 5152 | return -EINVAL; |
| 5153 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5154 | data->new_state = TPACPI_LED_BLINK; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5155 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5156 | |
| 5157 | return 0; |
| 5158 | } |
| 5159 | |
| 5160 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) |
| 5161 | { |
| 5162 | int rc; |
| 5163 | |
| 5164 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5165 | struct tpacpi_led_classdev, led_classdev); |
| 5166 | |
| 5167 | rc = led_get_status(data->led); |
| 5168 | |
| 5169 | if (rc == TPACPI_LED_OFF || rc < 0) |
| 5170 | rc = LED_OFF; /* no error handling in led class :( */ |
| 5171 | else |
| 5172 | rc = LED_FULL; |
| 5173 | |
| 5174 | return rc; |
| 5175 | } |
| 5176 | |
| 5177 | static void led_exit(void) |
| 5178 | { |
| 5179 | unsigned int i; |
| 5180 | |
| 5181 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 5182 | if (tpacpi_leds[i].led_classdev.name) |
| 5183 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); |
| 5184 | } |
| 5185 | |
| 5186 | kfree(tpacpi_leds); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5187 | } |
| 5188 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5189 | static int __init tpacpi_init_led(unsigned int led) |
| 5190 | { |
| 5191 | int rc; |
| 5192 | |
| 5193 | tpacpi_leds[led].led = led; |
| 5194 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5195 | /* LEDs with no name don't get registered */ |
| 5196 | if (!tpacpi_led_names[led]) |
| 5197 | return 0; |
| 5198 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5199 | tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set; |
| 5200 | tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set; |
| 5201 | if (led_supported == TPACPI_LED_570) |
| 5202 | tpacpi_leds[led].led_classdev.brightness_get = |
| 5203 | &led_sysfs_get; |
| 5204 | |
| 5205 | tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led]; |
| 5206 | |
| 5207 | INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker); |
| 5208 | |
| 5209 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 5210 | &tpacpi_leds[led].led_classdev); |
| 5211 | if (rc < 0) |
| 5212 | tpacpi_leds[led].led_classdev.name = NULL; |
| 5213 | |
| 5214 | return rc; |
| 5215 | } |
| 5216 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5217 | static const struct tpacpi_quirk led_useful_qtable[] __initconst = { |
| 5218 | TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */ |
| 5219 | TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */ |
| 5220 | TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */ |
| 5221 | |
| 5222 | TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */ |
| 5223 | TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */ |
| 5224 | TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */ |
| 5225 | TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */ |
| 5226 | TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */ |
| 5227 | TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */ |
| 5228 | TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */ |
| 5229 | TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */ |
| 5230 | |
| 5231 | TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */ |
| 5232 | TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */ |
| 5233 | TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */ |
| 5234 | TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */ |
| 5235 | TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */ |
| 5236 | |
| 5237 | TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */ |
| 5238 | TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */ |
| 5239 | TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */ |
| 5240 | TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */ |
| 5241 | |
| 5242 | /* (1) - may have excess leds enabled on MSB */ |
| 5243 | |
| 5244 | /* Defaults (order matters, keep last, don't reorder!) */ |
| 5245 | { /* Lenovo */ |
| 5246 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 5247 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5248 | .quirks = 0x1fffU, |
| 5249 | }, |
| 5250 | { /* IBM ThinkPads with no EC version string */ |
| 5251 | .vendor = PCI_VENDOR_ID_IBM, |
| 5252 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_UNKNOWN, |
| 5253 | .quirks = 0x00ffU, |
| 5254 | }, |
| 5255 | { /* IBM ThinkPads with EC version string */ |
| 5256 | .vendor = PCI_VENDOR_ID_IBM, |
| 5257 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5258 | .quirks = 0x00bfU, |
| 5259 | }, |
| 5260 | }; |
| 5261 | |
| 5262 | #undef TPACPI_LEDQ_IBM |
| 5263 | #undef TPACPI_LEDQ_LNV |
| 5264 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5265 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5266 | { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5267 | unsigned int i; |
| 5268 | int rc; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5269 | unsigned long useful_leds; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5270 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5271 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 5272 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5273 | TPACPI_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5274 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5275 | if (!led_handle) |
| 5276 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5277 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5278 | else if (strlencmp(led_path, "SLED") == 0) |
| 5279 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5280 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5281 | else if (strlencmp(led_path, "SYSL") == 0) |
| 5282 | /* 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] | 5283 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5284 | else |
| 5285 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5286 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5287 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5288 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 5289 | str_supported(led_supported), led_supported); |
| 5290 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5291 | if (led_supported == TPACPI_LED_NONE) |
| 5292 | return 1; |
| 5293 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5294 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
| 5295 | GFP_KERNEL); |
| 5296 | if (!tpacpi_leds) { |
| 5297 | printk(TPACPI_ERR "Out of memory for LED data\n"); |
| 5298 | return -ENOMEM; |
| 5299 | } |
| 5300 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5301 | useful_leds = tpacpi_check_quirks(led_useful_qtable, |
| 5302 | ARRAY_SIZE(led_useful_qtable)); |
| 5303 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5304 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5305 | if (!tpacpi_is_led_restricted(i) && |
| 5306 | test_bit(i, &useful_leds)) { |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5307 | rc = tpacpi_init_led(i); |
| 5308 | if (rc < 0) { |
| 5309 | led_exit(); |
| 5310 | return rc; |
| 5311 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5312 | } |
| 5313 | } |
| 5314 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5315 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5316 | printk(TPACPI_NOTICE |
| 5317 | "warning: userspace override of important " |
| 5318 | "firmware LEDs is enabled\n"); |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5319 | #endif |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5320 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5321 | } |
| 5322 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5323 | #define str_led_status(s) \ |
| 5324 | ((s) == TPACPI_LED_OFF ? "off" : \ |
| 5325 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5326 | |
| 5327 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5328 | { |
| 5329 | int len = 0; |
| 5330 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5331 | if (!led_supported) { |
| 5332 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5333 | return len; |
| 5334 | } |
| 5335 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 5336 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5337 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5338 | /* 570 */ |
| 5339 | int i, status; |
| 5340 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5341 | status = led_get_status(i); |
| 5342 | if (status < 0) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5343 | return -EIO; |
| 5344 | len += sprintf(p + len, "%d:\t\t%s\n", |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5345 | i, str_led_status(status)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5346 | } |
| 5347 | } |
| 5348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | len += sprintf(p + len, "commands:\t" |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5350 | "<led> on, <led> off, <led> blink (<led> is 0-15)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5351 | |
| 5352 | return len; |
| 5353 | } |
| 5354 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5355 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | { |
| 5357 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5358 | int led, rc; |
| 5359 | enum led_status_t s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5360 | |
| 5361 | if (!led_supported) |
| 5362 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5363 | |
| 5364 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5365 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5366 | return -EINVAL; |
| 5367 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5368 | if (strstr(cmd, "off")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5369 | s = TPACPI_LED_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5370 | } else if (strstr(cmd, "on")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5371 | s = TPACPI_LED_ON; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5372 | } else if (strstr(cmd, "blink")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5373 | s = TPACPI_LED_BLINK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5374 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5375 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5376 | } |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5377 | |
| 5378 | rc = led_set_status(led, s); |
| 5379 | if (rc < 0) |
| 5380 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5384 | } |
| 5385 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5386 | static struct ibm_struct led_driver_data = { |
| 5387 | .name = "led", |
| 5388 | .read = led_read, |
| 5389 | .write = led_write, |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5390 | .exit = led_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5391 | }; |
| 5392 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5393 | /************************************************************************* |
| 5394 | * Beep subdriver |
| 5395 | */ |
| 5396 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5397 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5398 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5399 | #define TPACPI_BEEP_Q1 0x0001 |
| 5400 | |
| 5401 | static const struct tpacpi_quirk beep_quirk_table[] __initconst = { |
| 5402 | TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1), /* 570 */ |
| 5403 | TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */ |
| 5404 | }; |
| 5405 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5406 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5407 | { |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5408 | unsigned long quirks; |
| 5409 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5410 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 5411 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5412 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5413 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5414 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 5415 | str_supported(beep_handle != NULL)); |
| 5416 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5417 | quirks = tpacpi_check_quirks(beep_quirk_table, |
| 5418 | ARRAY_SIZE(beep_quirk_table)); |
| 5419 | |
| 5420 | tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); |
| 5421 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5422 | return (beep_handle)? 0 : 1; |
| 5423 | } |
| 5424 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5425 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5426 | { |
| 5427 | int len = 0; |
| 5428 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5429 | if (!beep_handle) |
| 5430 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5431 | else { |
| 5432 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 5433 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 5434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5435 | |
| 5436 | return len; |
| 5437 | } |
| 5438 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5439 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5440 | { |
| 5441 | char *cmd; |
| 5442 | int beep_cmd; |
| 5443 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5444 | if (!beep_handle) |
| 5445 | return -ENODEV; |
| 5446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5447 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5448 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 5449 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5450 | /* beep_cmd set */ |
| 5451 | } else |
| 5452 | return -EINVAL; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5453 | if (tp_features.beep_needs_two_args) { |
| 5454 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", |
| 5455 | beep_cmd, 0)) |
| 5456 | return -EIO; |
| 5457 | } else { |
| 5458 | if (!acpi_evalf(beep_handle, NULL, NULL, "vd", |
| 5459 | beep_cmd)) |
| 5460 | return -EIO; |
| 5461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5465 | } |
| 5466 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5467 | static struct ibm_struct beep_driver_data = { |
| 5468 | .name = "beep", |
| 5469 | .read = beep_read, |
| 5470 | .write = beep_write, |
| 5471 | }; |
| 5472 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5473 | /************************************************************************* |
| 5474 | * Thermal subdriver |
| 5475 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5476 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5477 | enum thermal_access_mode { |
| 5478 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 5479 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 5480 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 5481 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 5482 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 5483 | }; |
| 5484 | |
| 5485 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 5486 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 5487 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 5488 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5489 | |
| 5490 | TPACPI_THERMAL_SENSOR_NA = -128000, /* Sensor not available */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5491 | }; |
| 5492 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5493 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5494 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 5495 | struct ibm_thermal_sensors_struct { |
| 5496 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 5497 | }; |
| 5498 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5499 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5500 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5501 | /* idx is zero-based */ |
| 5502 | static int thermal_get_sensor(int idx, s32 *value) |
| 5503 | { |
| 5504 | int t; |
| 5505 | s8 tmp; |
| 5506 | char tmpi[5]; |
| 5507 | |
| 5508 | t = TP_EC_THERMAL_TMP0; |
| 5509 | |
| 5510 | switch (thermal_read_mode) { |
| 5511 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 5512 | case TPACPI_THERMAL_TPEC_16: |
| 5513 | if (idx >= 8 && idx <= 15) { |
| 5514 | t = TP_EC_THERMAL_TMP8; |
| 5515 | idx -= 8; |
| 5516 | } |
| 5517 | /* fallthrough */ |
| 5518 | #endif |
| 5519 | case TPACPI_THERMAL_TPEC_8: |
| 5520 | if (idx <= 7) { |
| 5521 | if (!acpi_ec_read(t + idx, &tmp)) |
| 5522 | return -EIO; |
| 5523 | *value = tmp * 1000; |
| 5524 | return 0; |
| 5525 | } |
| 5526 | break; |
| 5527 | |
| 5528 | case TPACPI_THERMAL_ACPI_UPDT: |
| 5529 | if (idx <= 7) { |
| 5530 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5531 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 5532 | return -EIO; |
| 5533 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5534 | return -EIO; |
| 5535 | *value = (t - 2732) * 100; |
| 5536 | return 0; |
| 5537 | } |
| 5538 | break; |
| 5539 | |
| 5540 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5541 | if (idx <= 7) { |
| 5542 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5543 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5544 | return -EIO; |
| 5545 | if (t > 127 || t < -127) |
| 5546 | t = TP_EC_THERMAL_TMP_NA; |
| 5547 | *value = t * 1000; |
| 5548 | return 0; |
| 5549 | } |
| 5550 | break; |
| 5551 | |
| 5552 | case TPACPI_THERMAL_NONE: |
| 5553 | default: |
| 5554 | return -ENOSYS; |
| 5555 | } |
| 5556 | |
| 5557 | return -EINVAL; |
| 5558 | } |
| 5559 | |
| 5560 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 5561 | { |
| 5562 | int res, i; |
| 5563 | int n; |
| 5564 | |
| 5565 | n = 8; |
| 5566 | i = 0; |
| 5567 | |
| 5568 | if (!s) |
| 5569 | return -EINVAL; |
| 5570 | |
| 5571 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 5572 | n = 16; |
| 5573 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5574 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5575 | res = thermal_get_sensor(i, &s->temp[i]); |
| 5576 | if (res) |
| 5577 | return res; |
| 5578 | } |
| 5579 | |
| 5580 | return n; |
| 5581 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5582 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5583 | static void thermal_dump_all_sensors(void) |
| 5584 | { |
| 5585 | int n, i; |
| 5586 | struct ibm_thermal_sensors_struct t; |
| 5587 | |
| 5588 | n = thermal_get_sensors(&t); |
| 5589 | if (n <= 0) |
| 5590 | return; |
| 5591 | |
| 5592 | printk(TPACPI_NOTICE |
| 5593 | "temperatures (Celsius):"); |
| 5594 | |
| 5595 | for (i = 0; i < n; i++) { |
| 5596 | if (t.temp[i] != TPACPI_THERMAL_SENSOR_NA) |
| 5597 | printk(KERN_CONT " %d", (int)(t.temp[i] / 1000)); |
| 5598 | else |
| 5599 | printk(KERN_CONT " N/A"); |
| 5600 | } |
| 5601 | |
| 5602 | printk(KERN_CONT "\n"); |
| 5603 | } |
| 5604 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5605 | /* sysfs temp##_input -------------------------------------------------- */ |
| 5606 | |
| 5607 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 5608 | struct device_attribute *attr, |
| 5609 | char *buf) |
| 5610 | { |
| 5611 | struct sensor_device_attribute *sensor_attr = |
| 5612 | to_sensor_dev_attr(attr); |
| 5613 | int idx = sensor_attr->index; |
| 5614 | s32 value; |
| 5615 | int res; |
| 5616 | |
| 5617 | res = thermal_get_sensor(idx, &value); |
| 5618 | if (res) |
| 5619 | return res; |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5620 | if (value == TPACPI_THERMAL_SENSOR_NA) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5621 | return -ENXIO; |
| 5622 | |
| 5623 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 5624 | } |
| 5625 | |
| 5626 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5627 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 5628 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5629 | |
| 5630 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 5631 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 5632 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 5633 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 5634 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 5635 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 5636 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 5637 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 5638 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 5639 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 5640 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 5641 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 5642 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 5643 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 5644 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 5645 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 5646 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 5647 | }; |
| 5648 | |
| 5649 | #define THERMAL_ATTRS(X) \ |
| 5650 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 5651 | |
| 5652 | static struct attribute *thermal_temp_input_attr[] = { |
| 5653 | THERMAL_ATTRS(8), |
| 5654 | THERMAL_ATTRS(9), |
| 5655 | THERMAL_ATTRS(10), |
| 5656 | THERMAL_ATTRS(11), |
| 5657 | THERMAL_ATTRS(12), |
| 5658 | THERMAL_ATTRS(13), |
| 5659 | THERMAL_ATTRS(14), |
| 5660 | THERMAL_ATTRS(15), |
| 5661 | THERMAL_ATTRS(0), |
| 5662 | THERMAL_ATTRS(1), |
| 5663 | THERMAL_ATTRS(2), |
| 5664 | THERMAL_ATTRS(3), |
| 5665 | THERMAL_ATTRS(4), |
| 5666 | THERMAL_ATTRS(5), |
| 5667 | THERMAL_ATTRS(6), |
| 5668 | THERMAL_ATTRS(7), |
| 5669 | NULL |
| 5670 | }; |
| 5671 | |
| 5672 | static const struct attribute_group thermal_temp_input16_group = { |
| 5673 | .attrs = thermal_temp_input_attr |
| 5674 | }; |
| 5675 | |
| 5676 | static const struct attribute_group thermal_temp_input8_group = { |
| 5677 | .attrs = &thermal_temp_input_attr[8] |
| 5678 | }; |
| 5679 | |
| 5680 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 5681 | #undef THERMAL_ATTRS |
| 5682 | |
| 5683 | /* --------------------------------------------------------------------- */ |
| 5684 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5685 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5686 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5687 | u8 t, ta1, ta2; |
| 5688 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5689 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5690 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5691 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5692 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 5693 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5694 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5695 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 5696 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5697 | /* |
| 5698 | * Direct EC access mode: sensors at registers |
| 5699 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 5700 | * non-implemented, thermal sensors return 0x80 when |
| 5701 | * not available |
| 5702 | */ |
| 5703 | |
| 5704 | ta1 = ta2 = 0; |
| 5705 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5706 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5707 | ta1 |= t; |
| 5708 | } else { |
| 5709 | ta1 = 0; |
| 5710 | break; |
| 5711 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5712 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5713 | ta2 |= t; |
| 5714 | } else { |
| 5715 | ta1 = 0; |
| 5716 | break; |
| 5717 | } |
| 5718 | } |
| 5719 | if (ta1 == 0) { |
| 5720 | /* This is sheer paranoia, but we handle it anyway */ |
| 5721 | if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5722 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5723 | "ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5724 | "falling back to ACPI TMPx access " |
| 5725 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5726 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5727 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5728 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5729 | "ThinkPad ACPI EC access misbehaving, " |
| 5730 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5731 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5732 | } |
| 5733 | } else { |
| 5734 | thermal_read_mode = |
| 5735 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5736 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5737 | } |
| 5738 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5739 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 5740 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5741 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5742 | } else { |
| 5743 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5744 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5745 | } |
| 5746 | } else { |
| 5747 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5748 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5749 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5750 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5751 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 5752 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 5753 | thermal_read_mode); |
| 5754 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5755 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5756 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5757 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5758 | &thermal_temp_input16_group); |
| 5759 | if (res) |
| 5760 | return res; |
| 5761 | break; |
| 5762 | case TPACPI_THERMAL_TPEC_8: |
| 5763 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5764 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5765 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5766 | &thermal_temp_input8_group); |
| 5767 | if (res) |
| 5768 | return res; |
| 5769 | break; |
| 5770 | case TPACPI_THERMAL_NONE: |
| 5771 | default: |
| 5772 | return 1; |
| 5773 | } |
| 5774 | |
| 5775 | return 0; |
| 5776 | } |
| 5777 | |
| 5778 | static void thermal_exit(void) |
| 5779 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5780 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5781 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5782 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5783 | &thermal_temp_input16_group); |
| 5784 | break; |
| 5785 | case TPACPI_THERMAL_TPEC_8: |
| 5786 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5787 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5788 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5789 | &thermal_temp_input16_group); |
| 5790 | break; |
| 5791 | case TPACPI_THERMAL_NONE: |
| 5792 | default: |
| 5793 | break; |
| 5794 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | static int thermal_read(char *p) |
| 5798 | { |
| 5799 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5800 | int n, i; |
| 5801 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5802 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5803 | n = thermal_get_sensors(&t); |
| 5804 | if (unlikely(n < 0)) |
| 5805 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5806 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5807 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5808 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5809 | if (n > 0) { |
| 5810 | for (i = 0; i < (n - 1); i++) |
| 5811 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 5812 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 5813 | } else |
| 5814 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5815 | |
| 5816 | return len; |
| 5817 | } |
| 5818 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5819 | static struct ibm_struct thermal_driver_data = { |
| 5820 | .name = "thermal", |
| 5821 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5822 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5823 | }; |
| 5824 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5825 | /************************************************************************* |
| 5826 | * EC Dump subdriver |
| 5827 | */ |
| 5828 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5829 | static u8 ecdump_regs[256]; |
| 5830 | |
| 5831 | static int ecdump_read(char *p) |
| 5832 | { |
| 5833 | int len = 0; |
| 5834 | int i, j; |
| 5835 | u8 v; |
| 5836 | |
| 5837 | len += sprintf(p + len, "EC " |
| 5838 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 5839 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 5840 | for (i = 0; i < 256; i += 16) { |
| 5841 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 5842 | for (j = 0; j < 16; j++) { |
| 5843 | if (!acpi_ec_read(i + j, &v)) |
| 5844 | break; |
| 5845 | if (v != ecdump_regs[i + j]) |
| 5846 | len += sprintf(p + len, " *%02x", v); |
| 5847 | else |
| 5848 | len += sprintf(p + len, " %02x", v); |
| 5849 | ecdump_regs[i + j] = v; |
| 5850 | } |
| 5851 | len += sprintf(p + len, "\n"); |
| 5852 | if (j != 16) |
| 5853 | break; |
| 5854 | } |
| 5855 | |
| 5856 | /* These are way too dangerous to advertise openly... */ |
| 5857 | #if 0 |
| 5858 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 5859 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 5860 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 5861 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 5862 | #endif |
| 5863 | return len; |
| 5864 | } |
| 5865 | |
| 5866 | static int ecdump_write(char *buf) |
| 5867 | { |
| 5868 | char *cmd; |
| 5869 | int i, v; |
| 5870 | |
| 5871 | while ((cmd = next_cmd(&buf))) { |
| 5872 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 5873 | /* i and v set */ |
| 5874 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 5875 | /* i and v set */ |
| 5876 | } else |
| 5877 | return -EINVAL; |
| 5878 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 5879 | if (!acpi_ec_write(i, v)) |
| 5880 | return -EIO; |
| 5881 | } else |
| 5882 | return -EINVAL; |
| 5883 | } |
| 5884 | |
| 5885 | return 0; |
| 5886 | } |
| 5887 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5888 | static struct ibm_struct ecdump_driver_data = { |
| 5889 | .name = "ecdump", |
| 5890 | .read = ecdump_read, |
| 5891 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5892 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5893 | }; |
| 5894 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5895 | /************************************************************************* |
| 5896 | * Backlight/brightness subdriver |
| 5897 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 5898 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5899 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 5900 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5901 | /* |
| 5902 | * ThinkPads can read brightness from two places: EC HBRV (0x31), or |
| 5903 | * CMOS NVRAM byte 0x5E, bits 0-3. |
| 5904 | * |
| 5905 | * EC HBRV (0x31) has the following layout |
| 5906 | * Bit 7: unknown function |
| 5907 | * Bit 6: unknown function |
| 5908 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 5909 | * Bit 4: must be set to zero to avoid problems |
| 5910 | * Bit 3-0: backlight brightness level |
| 5911 | * |
| 5912 | * brightness_get_raw returns status data in the HBRV layout |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 5913 | * |
| 5914 | * WARNING: The X61 has been verified to use HBRV for something else, so |
| 5915 | * this should be used _only_ on IBM ThinkPads, and maybe with some careful |
| 5916 | * testing on the very early *60 Lenovo models... |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5917 | */ |
| 5918 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5919 | enum { |
| 5920 | TP_EC_BACKLIGHT = 0x31, |
| 5921 | |
| 5922 | /* TP_EC_BACKLIGHT bitmasks */ |
| 5923 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 5924 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 5925 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 5926 | }; |
| 5927 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5928 | enum tpacpi_brightness_access_mode { |
| 5929 | TPACPI_BRGHT_MODE_AUTO = 0, /* Not implemented yet */ |
| 5930 | TPACPI_BRGHT_MODE_EC, /* EC control */ |
| 5931 | TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */ |
| 5932 | TPACPI_BRGHT_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 5933 | TPACPI_BRGHT_MODE_MAX |
| 5934 | }; |
| 5935 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5936 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5937 | |
| 5938 | static enum tpacpi_brightness_access_mode brightness_mode = |
| 5939 | TPACPI_BRGHT_MODE_MAX; |
| 5940 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5941 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 5942 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5943 | static struct mutex brightness_mutex; |
| 5944 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5945 | /* NVRAM brightness access, |
| 5946 | * call with brightness_mutex held! */ |
| 5947 | static unsigned int tpacpi_brightness_nvram_get(void) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5948 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5949 | u8 lnvram; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5950 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5951 | lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 5952 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5953 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 5954 | lnvram &= (tp_features.bright_16levels) ? 0x0f : 0x07; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5955 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5956 | return lnvram; |
| 5957 | } |
| 5958 | |
| 5959 | static void tpacpi_brightness_checkpoint_nvram(void) |
| 5960 | { |
| 5961 | u8 lec = 0; |
| 5962 | u8 b_nvram; |
| 5963 | |
| 5964 | if (brightness_mode != TPACPI_BRGHT_MODE_ECNVRAM) |
| 5965 | return; |
| 5966 | |
| 5967 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5968 | "trying to checkpoint backlight level to NVRAM...\n"); |
| 5969 | |
| 5970 | if (mutex_lock_killable(&brightness_mutex) < 0) |
| 5971 | return; |
| 5972 | |
| 5973 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5974 | goto unlock; |
| 5975 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
| 5976 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 5977 | |
| 5978 | if (lec != ((b_nvram & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5979 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS)) { |
| 5980 | /* NVRAM needs update */ |
| 5981 | b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS << |
| 5982 | TP_NVRAM_POS_LEVEL_BRIGHTNESS); |
| 5983 | b_nvram |= lec; |
| 5984 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_BRIGHTNESS); |
| 5985 | dbg_printk(TPACPI_DBG_BRGHT, |
| 5986 | "updated NVRAM backlight level to %u (0x%02x)\n", |
| 5987 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5988 | } else |
| 5989 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5990 | "NVRAM backlight level already is %u (0x%02x)\n", |
| 5991 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5992 | |
| 5993 | unlock: |
| 5994 | mutex_unlock(&brightness_mutex); |
| 5995 | } |
| 5996 | |
| 5997 | |
| 5998 | /* call with brightness_mutex held! */ |
| 5999 | static int tpacpi_brightness_get_raw(int *status) |
| 6000 | { |
| 6001 | u8 lec = 0; |
| 6002 | |
| 6003 | switch (brightness_mode) { |
| 6004 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 6005 | *status = tpacpi_brightness_nvram_get(); |
| 6006 | return 0; |
| 6007 | case TPACPI_BRGHT_MODE_EC: |
| 6008 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 6009 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 6010 | return -EIO; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6011 | *status = lec; |
| 6012 | return 0; |
| 6013 | default: |
| 6014 | return -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6015 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6016 | } |
| 6017 | |
| 6018 | /* call with brightness_mutex held! */ |
| 6019 | /* do NOT call with illegal backlight level value */ |
| 6020 | static int tpacpi_brightness_set_ec(unsigned int value) |
| 6021 | { |
| 6022 | u8 lec = 0; |
| 6023 | |
| 6024 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 6025 | return -EIO; |
| 6026 | |
| 6027 | if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT, |
| 6028 | (lec & TP_EC_BACKLIGHT_CMDMSK) | |
| 6029 | (value & TP_EC_BACKLIGHT_LVLMSK)))) |
| 6030 | return -EIO; |
| 6031 | |
| 6032 | return 0; |
| 6033 | } |
| 6034 | |
| 6035 | /* call with brightness_mutex held! */ |
| 6036 | static int tpacpi_brightness_set_ucmsstep(unsigned int value) |
| 6037 | { |
| 6038 | int cmos_cmd, inc; |
| 6039 | unsigned int current_value, i; |
| 6040 | |
| 6041 | current_value = tpacpi_brightness_nvram_get(); |
| 6042 | |
| 6043 | if (value == current_value) |
| 6044 | return 0; |
| 6045 | |
| 6046 | cmos_cmd = (value > current_value) ? |
| 6047 | TP_CMOS_BRIGHTNESS_UP : |
| 6048 | TP_CMOS_BRIGHTNESS_DOWN; |
| 6049 | inc = (value > current_value) ? 1 : -1; |
| 6050 | |
| 6051 | for (i = current_value; i != value; i += inc) |
| 6052 | if (issue_thinkpad_cmos_command(cmos_cmd)) |
| 6053 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6054 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6055 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6056 | } |
| 6057 | |
| 6058 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6059 | static int brightness_set(unsigned int value) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6060 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6061 | int res; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6062 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6063 | if (value > ((tp_features.bright_16levels)? 15 : 7) || |
| 6064 | value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6065 | return -EINVAL; |
| 6066 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6067 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 6068 | "set backlight level to %d\n", value); |
| 6069 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6070 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6071 | if (res < 0) |
| 6072 | return res; |
| 6073 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6074 | switch (brightness_mode) { |
| 6075 | case TPACPI_BRGHT_MODE_EC: |
| 6076 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 6077 | res = tpacpi_brightness_set_ec(value); |
| 6078 | break; |
| 6079 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 6080 | res = tpacpi_brightness_set_ucmsstep(value); |
| 6081 | break; |
| 6082 | default: |
| 6083 | res = -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6084 | } |
| 6085 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6086 | mutex_unlock(&brightness_mutex); |
| 6087 | return res; |
| 6088 | } |
| 6089 | |
| 6090 | /* sysfs backlight class ----------------------------------------------- */ |
| 6091 | |
| 6092 | static int brightness_update_status(struct backlight_device *bd) |
| 6093 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6094 | unsigned int level = |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6095 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 6096 | bd->props.power == FB_BLANK_UNBLANK) ? |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6097 | bd->props.brightness : 0; |
| 6098 | |
| 6099 | dbg_printk(TPACPI_DBG_BRGHT, |
| 6100 | "backlight: attempt to set level to %d\n", |
| 6101 | level); |
| 6102 | |
| 6103 | /* it is the backlight class's job (caller) to handle |
| 6104 | * EINTR and other errors properly */ |
| 6105 | return brightness_set(level); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6106 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 6107 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6108 | static int brightness_get(struct backlight_device *bd) |
| 6109 | { |
| 6110 | int status, res; |
| 6111 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6112 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6113 | if (res < 0) |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6114 | return 0; |
| 6115 | |
| 6116 | res = tpacpi_brightness_get_raw(&status); |
| 6117 | |
| 6118 | mutex_unlock(&brightness_mutex); |
| 6119 | |
| 6120 | if (res < 0) |
| 6121 | return 0; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6122 | |
| 6123 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 6124 | } |
| 6125 | |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6126 | static void tpacpi_brightness_notify_change(void) |
| 6127 | { |
| 6128 | backlight_force_update(ibm_backlight_device, |
| 6129 | BACKLIGHT_UPDATE_HOTKEY); |
| 6130 | } |
| 6131 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6132 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6133 | .get_brightness = brightness_get, |
| 6134 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6135 | }; |
| 6136 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6137 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6138 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6139 | /* |
| 6140 | * These are only useful for models that have only one possibility |
| 6141 | * of GPU. If the BIOS model handles both ATI and Intel, don't use |
| 6142 | * these quirks. |
| 6143 | */ |
| 6144 | #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */ |
| 6145 | #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */ |
| 6146 | #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */ |
| 6147 | |
| 6148 | static const struct tpacpi_quirk brightness_quirk_table[] __initconst = { |
| 6149 | /* Models with ATI GPUs known to require ECNVRAM mode */ |
| 6150 | TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */ |
| 6151 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6152 | /* Models with ATI GPUs that can use ECNVRAM */ |
| 6153 | TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6154 | TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6155 | TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6156 | TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6157 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6158 | /* Models with Intel Extreme Graphics 2 */ |
| 6159 | TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), |
Henrique de Moraes Holschuh | a9f8eac | 2009-12-09 01:36:21 +0000 | [diff] [blame] | 6160 | TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6161 | 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] | 6162 | |
| 6163 | /* Models with Intel GMA900 */ |
| 6164 | TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC), /* T43, R52 */ |
| 6165 | TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC), /* X41 */ |
| 6166 | TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC), /* X41 Tablet */ |
| 6167 | }; |
| 6168 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6169 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6170 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6171 | int b; |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6172 | unsigned long quirks; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6173 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6174 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 6175 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6176 | mutex_init(&brightness_mutex); |
| 6177 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6178 | quirks = tpacpi_check_quirks(brightness_quirk_table, |
| 6179 | ARRAY_SIZE(brightness_quirk_table)); |
| 6180 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6181 | /* |
| 6182 | * We always attempt to detect acpi support, so as to switch |
| 6183 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 6184 | * going to publish a backlight interface |
| 6185 | */ |
| 6186 | b = tpacpi_check_std_acpi_brightness_support(); |
| 6187 | if (b > 0) { |
Thomas Renninger | 2dba1b5 | 2008-08-01 17:38:03 +0200 | [diff] [blame] | 6188 | |
| 6189 | if (acpi_video_backlight_support()) { |
| 6190 | if (brightness_enable > 1) { |
| 6191 | printk(TPACPI_NOTICE |
| 6192 | "Standard ACPI backlight interface " |
| 6193 | "available, not loading native one.\n"); |
| 6194 | return 1; |
| 6195 | } else if (brightness_enable == 1) { |
| 6196 | printk(TPACPI_NOTICE |
| 6197 | "Backlight control force enabled, even if standard " |
| 6198 | "ACPI backlight interface is available\n"); |
| 6199 | } |
| 6200 | } else { |
| 6201 | if (brightness_enable > 1) { |
| 6202 | printk(TPACPI_NOTICE |
| 6203 | "Standard ACPI backlight interface not " |
| 6204 | "available, thinkpad_acpi native " |
| 6205 | "brightness control enabled\n"); |
| 6206 | } |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 6207 | } |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6208 | } |
| 6209 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6210 | if (!brightness_enable) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6211 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6212 | "brightness support disabled by " |
| 6213 | "module parameter\n"); |
| 6214 | return 1; |
| 6215 | } |
| 6216 | |
| 6217 | if (b > 16) { |
| 6218 | printk(TPACPI_ERR |
| 6219 | "Unsupported brightness interface, " |
| 6220 | "please contact %s\n", TPACPI_MAIL); |
| 6221 | return 1; |
| 6222 | } |
| 6223 | if (b == 16) |
| 6224 | tp_features.bright_16levels = 1; |
| 6225 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6226 | /* |
| 6227 | * Check for module parameter bogosity, note that we |
| 6228 | * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be |
| 6229 | * able to detect "unspecified" |
| 6230 | */ |
| 6231 | if (brightness_mode > TPACPI_BRGHT_MODE_MAX) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6232 | return -EINVAL; |
| 6233 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6234 | /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */ |
| 6235 | if (brightness_mode == TPACPI_BRGHT_MODE_AUTO || |
| 6236 | brightness_mode == TPACPI_BRGHT_MODE_MAX) { |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6237 | if (quirks & TPACPI_BRGHT_Q_EC) |
| 6238 | brightness_mode = TPACPI_BRGHT_MODE_ECNVRAM; |
| 6239 | else |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6240 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
| 6241 | |
| 6242 | dbg_printk(TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6243 | "driver auto-selected brightness_mode=%d\n", |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6244 | brightness_mode); |
| 6245 | } |
| 6246 | |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 6247 | /* Safety */ |
| 6248 | if (thinkpad_id.vendor != PCI_VENDOR_ID_IBM && |
| 6249 | (brightness_mode == TPACPI_BRGHT_MODE_ECNVRAM || |
| 6250 | brightness_mode == TPACPI_BRGHT_MODE_EC)) |
| 6251 | return -EINVAL; |
| 6252 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6253 | if (tpacpi_brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6254 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6255 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6256 | if (tp_features.bright_16levels) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6257 | printk(TPACPI_INFO |
| 6258 | "detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6259 | |
Henrique de Moraes Holschuh | 7d5a015 | 2007-04-24 11:48:20 -0300 | [diff] [blame] | 6260 | ibm_backlight_device = backlight_device_register( |
| 6261 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
| 6262 | &ibm_backlight_data); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6263 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6264 | int rc = PTR_ERR(ibm_backlight_device); |
| 6265 | ibm_backlight_device = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6266 | printk(TPACPI_ERR "Could not register backlight device\n"); |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6267 | return rc; |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6268 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6269 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6270 | "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6271 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6272 | if (quirks & TPACPI_BRGHT_Q_ASK) { |
| 6273 | printk(TPACPI_NOTICE |
| 6274 | "brightness: will use unverified default: " |
| 6275 | "brightness_mode=%d\n", brightness_mode); |
| 6276 | printk(TPACPI_NOTICE |
| 6277 | "brightness: please report to %s whether it works well " |
| 6278 | "or not on your ThinkPad\n", TPACPI_MAIL); |
| 6279 | } |
| 6280 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6281 | ibm_backlight_device->props.max_brightness = |
| 6282 | (tp_features.bright_16levels)? 15 : 7; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6283 | ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6284 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6285 | |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6286 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6287 | "brightness: registering brightness hotkeys " |
| 6288 | "as change notification\n"); |
| 6289 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
| 6290 | | TP_ACPI_HKEY_BRGHTUP_MASK |
| 6291 | | TP_ACPI_HKEY_BRGHTDWN_MASK);; |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6292 | return 0; |
| 6293 | } |
| 6294 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6295 | static void brightness_suspend(pm_message_t state) |
| 6296 | { |
| 6297 | tpacpi_brightness_checkpoint_nvram(); |
| 6298 | } |
| 6299 | |
| 6300 | static void brightness_shutdown(void) |
| 6301 | { |
| 6302 | tpacpi_brightness_checkpoint_nvram(); |
| 6303 | } |
| 6304 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6305 | static void brightness_exit(void) |
| 6306 | { |
| 6307 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6308 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6309 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6310 | backlight_device_unregister(ibm_backlight_device); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6311 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6312 | |
| 6313 | tpacpi_brightness_checkpoint_nvram(); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6314 | } |
| 6315 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6316 | static int brightness_read(char *p) |
| 6317 | { |
| 6318 | int len = 0; |
| 6319 | int level; |
| 6320 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6321 | level = brightness_get(NULL); |
| 6322 | if (level < 0) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6323 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 6324 | } else { |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6325 | len += sprintf(p + len, "level:\t\t%d\n", level); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6326 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 6327 | len += sprintf(p + len, "commands:\tlevel <level>" |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6328 | " (<level> is 0-%d)\n", |
| 6329 | (tp_features.bright_16levels) ? 15 : 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | return len; |
| 6333 | } |
| 6334 | |
| 6335 | static int brightness_write(char *buf) |
| 6336 | { |
| 6337 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6338 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6339 | char *cmd; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6340 | int max_level = (tp_features.bright_16levels) ? 15 : 7; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6341 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6342 | level = brightness_get(NULL); |
| 6343 | if (level < 0) |
| 6344 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6345 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6346 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6347 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6348 | if (level < max_level) |
| 6349 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6350 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6351 | if (level > 0) |
| 6352 | level--; |
| 6353 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
| 6354 | level >= 0 && level <= max_level) { |
| 6355 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6356 | } else |
| 6357 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6358 | } |
| 6359 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6360 | tpacpi_disclose_usertask("procfs brightness", |
| 6361 | "set level to %d\n", level); |
| 6362 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6363 | /* |
| 6364 | * Now we know what the final level should be, so we try to set it. |
| 6365 | * Doing it this way makes the syscall restartable in case of EINTR |
| 6366 | */ |
| 6367 | rc = brightness_set(level); |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6368 | if (!rc && ibm_backlight_device) |
| 6369 | backlight_force_update(ibm_backlight_device, |
| 6370 | BACKLIGHT_UPDATE_SYSFS); |
Roel Kluin | 80a8d12 | 2009-11-20 19:48:23 +0100 | [diff] [blame] | 6371 | return (rc == -EINTR)? -ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6372 | } |
| 6373 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6374 | static struct ibm_struct brightness_driver_data = { |
| 6375 | .name = "brightness", |
| 6376 | .read = brightness_read, |
| 6377 | .write = brightness_write, |
| 6378 | .exit = brightness_exit, |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6379 | .suspend = brightness_suspend, |
| 6380 | .shutdown = brightness_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6381 | }; |
| 6382 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6383 | /************************************************************************* |
| 6384 | * Volume subdriver |
| 6385 | */ |
| 6386 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6387 | /* |
| 6388 | * IBM ThinkPads have a simple volume controller with MUTE gating. |
| 6389 | * Very early Lenovo ThinkPads follow the IBM ThinkPad spec. |
| 6390 | * |
| 6391 | * Since the *61 series (and probably also the later *60 series), Lenovo |
| 6392 | * ThinkPads only implement the MUTE gate. |
| 6393 | * |
| 6394 | * EC register 0x30 |
| 6395 | * Bit 6: MUTE (1 mutes sound) |
| 6396 | * Bit 3-0: Volume |
| 6397 | * Other bits should be zero as far as we know. |
| 6398 | * |
| 6399 | * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and |
| 6400 | * bits 3-0 (volume). Other bits in NVRAM may have other functions, |
| 6401 | * such as bit 7 which is used to detect repeated presses of MUTE, |
| 6402 | * and we leave them unchanged. |
| 6403 | */ |
| 6404 | |
| 6405 | enum { |
| 6406 | TP_EC_AUDIO = 0x30, |
| 6407 | |
| 6408 | /* TP_EC_AUDIO bits */ |
| 6409 | TP_EC_AUDIO_MUTESW = 6, |
| 6410 | |
| 6411 | /* TP_EC_AUDIO bitmasks */ |
| 6412 | TP_EC_AUDIO_LVL_MSK = 0x0F, |
| 6413 | TP_EC_AUDIO_MUTESW_MSK = (1 << TP_EC_AUDIO_MUTESW), |
| 6414 | |
| 6415 | /* Maximum volume */ |
| 6416 | TP_EC_VOLUME_MAX = 14, |
| 6417 | }; |
| 6418 | |
| 6419 | enum tpacpi_volume_access_mode { |
| 6420 | TPACPI_VOL_MODE_AUTO = 0, /* Not implemented yet */ |
| 6421 | TPACPI_VOL_MODE_EC, /* Pure EC control */ |
| 6422 | TPACPI_VOL_MODE_UCMS_STEP, /* UCMS step-based control: N/A */ |
| 6423 | TPACPI_VOL_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 6424 | TPACPI_VOL_MODE_MAX |
| 6425 | }; |
| 6426 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6427 | enum tpacpi_volume_capabilities { |
| 6428 | TPACPI_VOL_CAP_AUTO = 0, /* Use white/blacklist */ |
| 6429 | TPACPI_VOL_CAP_VOLMUTE, /* Output vol and mute */ |
| 6430 | TPACPI_VOL_CAP_MUTEONLY, /* Output mute only */ |
| 6431 | TPACPI_VOL_CAP_MAX |
| 6432 | }; |
| 6433 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6434 | static enum tpacpi_volume_access_mode volume_mode = |
| 6435 | TPACPI_VOL_MODE_MAX; |
| 6436 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6437 | static enum tpacpi_volume_capabilities volume_capabilities; |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame^] | 6438 | static int volume_control_allowed; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6439 | |
| 6440 | /* |
| 6441 | * Used to syncronize writers to TP_EC_AUDIO and |
| 6442 | * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write |
| 6443 | */ |
| 6444 | static struct mutex volume_mutex; |
| 6445 | |
| 6446 | static void tpacpi_volume_checkpoint_nvram(void) |
| 6447 | { |
| 6448 | u8 lec = 0; |
| 6449 | u8 b_nvram; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6450 | u8 ec_mask; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6451 | |
| 6452 | if (volume_mode != TPACPI_VOL_MODE_ECNVRAM) |
| 6453 | return; |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame^] | 6454 | if (!volume_control_allowed) |
| 6455 | return; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6456 | |
| 6457 | vdbg_printk(TPACPI_DBG_MIXER, |
| 6458 | "trying to checkpoint mixer state to NVRAM...\n"); |
| 6459 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6460 | if (tp_features.mixer_no_level_control) |
| 6461 | ec_mask = TP_EC_AUDIO_MUTESW_MSK; |
| 6462 | else |
| 6463 | ec_mask = TP_EC_AUDIO_MUTESW_MSK | TP_EC_AUDIO_LVL_MSK; |
| 6464 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6465 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6466 | return; |
| 6467 | |
| 6468 | if (unlikely(!acpi_ec_read(TP_EC_AUDIO, &lec))) |
| 6469 | goto unlock; |
| 6470 | lec &= ec_mask; |
| 6471 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 6472 | |
| 6473 | if (lec != (b_nvram & ec_mask)) { |
| 6474 | /* NVRAM needs update */ |
| 6475 | b_nvram &= ~ec_mask; |
| 6476 | b_nvram |= lec; |
| 6477 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_MIXER); |
| 6478 | dbg_printk(TPACPI_DBG_MIXER, |
| 6479 | "updated NVRAM mixer status to 0x%02x (0x%02x)\n", |
| 6480 | (unsigned int) lec, (unsigned int) b_nvram); |
| 6481 | } else { |
| 6482 | vdbg_printk(TPACPI_DBG_MIXER, |
| 6483 | "NVRAM mixer status already is 0x%02x (0x%02x)\n", |
| 6484 | (unsigned int) lec, (unsigned int) b_nvram); |
| 6485 | } |
| 6486 | |
| 6487 | unlock: |
| 6488 | mutex_unlock(&volume_mutex); |
| 6489 | } |
| 6490 | |
| 6491 | static int volume_get_status_ec(u8 *status) |
| 6492 | { |
| 6493 | u8 s; |
| 6494 | |
| 6495 | if (!acpi_ec_read(TP_EC_AUDIO, &s)) |
| 6496 | return -EIO; |
| 6497 | |
| 6498 | *status = s; |
| 6499 | |
| 6500 | dbg_printk(TPACPI_DBG_MIXER, "status 0x%02x\n", s); |
| 6501 | |
| 6502 | return 0; |
| 6503 | } |
| 6504 | |
| 6505 | static int volume_get_status(u8 *status) |
| 6506 | { |
| 6507 | return volume_get_status_ec(status); |
| 6508 | } |
| 6509 | |
| 6510 | static int volume_set_status_ec(const u8 status) |
| 6511 | { |
| 6512 | if (!acpi_ec_write(TP_EC_AUDIO, status)) |
| 6513 | return -EIO; |
| 6514 | |
| 6515 | dbg_printk(TPACPI_DBG_MIXER, "set EC mixer to 0x%02x\n", status); |
| 6516 | |
| 6517 | return 0; |
| 6518 | } |
| 6519 | |
| 6520 | static int volume_set_status(const u8 status) |
| 6521 | { |
| 6522 | return volume_set_status_ec(status); |
| 6523 | } |
| 6524 | |
| 6525 | static int volume_set_mute_ec(const bool mute) |
| 6526 | { |
| 6527 | int rc; |
| 6528 | u8 s, n; |
| 6529 | |
| 6530 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6531 | return -EINTR; |
| 6532 | |
| 6533 | rc = volume_get_status_ec(&s); |
| 6534 | if (rc) |
| 6535 | goto unlock; |
| 6536 | |
| 6537 | n = (mute) ? s | TP_EC_AUDIO_MUTESW_MSK : |
| 6538 | s & ~TP_EC_AUDIO_MUTESW_MSK; |
| 6539 | |
| 6540 | if (n != s) |
| 6541 | rc = volume_set_status_ec(n); |
| 6542 | |
| 6543 | unlock: |
| 6544 | mutex_unlock(&volume_mutex); |
| 6545 | return rc; |
| 6546 | } |
| 6547 | |
| 6548 | static int volume_set_mute(const bool mute) |
| 6549 | { |
| 6550 | dbg_printk(TPACPI_DBG_MIXER, "trying to %smute\n", |
| 6551 | (mute) ? "" : "un"); |
| 6552 | return volume_set_mute_ec(mute); |
| 6553 | } |
| 6554 | |
| 6555 | static int volume_set_volume_ec(const u8 vol) |
| 6556 | { |
| 6557 | int rc; |
| 6558 | u8 s, n; |
| 6559 | |
| 6560 | if (vol > TP_EC_VOLUME_MAX) |
| 6561 | return -EINVAL; |
| 6562 | |
| 6563 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6564 | return -EINTR; |
| 6565 | |
| 6566 | rc = volume_get_status_ec(&s); |
| 6567 | if (rc) |
| 6568 | goto unlock; |
| 6569 | |
| 6570 | n = (s & ~TP_EC_AUDIO_LVL_MSK) | vol; |
| 6571 | |
| 6572 | if (n != s) |
| 6573 | rc = volume_set_status_ec(n); |
| 6574 | |
| 6575 | unlock: |
| 6576 | mutex_unlock(&volume_mutex); |
| 6577 | return rc; |
| 6578 | } |
| 6579 | |
| 6580 | static int volume_set_volume(const u8 vol) |
| 6581 | { |
| 6582 | dbg_printk(TPACPI_DBG_MIXER, |
| 6583 | "trying to set volume level to %hu\n", vol); |
| 6584 | return volume_set_volume_ec(vol); |
| 6585 | } |
| 6586 | |
| 6587 | static void volume_suspend(pm_message_t state) |
| 6588 | { |
| 6589 | tpacpi_volume_checkpoint_nvram(); |
| 6590 | } |
| 6591 | |
| 6592 | static void volume_shutdown(void) |
| 6593 | { |
| 6594 | tpacpi_volume_checkpoint_nvram(); |
| 6595 | } |
| 6596 | |
| 6597 | static void volume_exit(void) |
| 6598 | { |
| 6599 | tpacpi_volume_checkpoint_nvram(); |
| 6600 | } |
| 6601 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6602 | #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */ |
| 6603 | #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */ |
| 6604 | |
| 6605 | static const struct tpacpi_quirk volume_quirk_table[] __initconst = { |
| 6606 | /* Whitelist volume level on all IBM by default */ |
| 6607 | { .vendor = PCI_VENDOR_ID_IBM, |
| 6608 | .bios = TPACPI_MATCH_ANY, |
| 6609 | .ec = TPACPI_MATCH_ANY, |
| 6610 | .quirks = TPACPI_VOL_Q_LEVEL }, |
| 6611 | |
| 6612 | /* Lenovo models with volume control (needs confirmation) */ |
| 6613 | TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL), /* R60/i */ |
| 6614 | TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL), /* R60e/i */ |
| 6615 | TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL), /* T60/p */ |
| 6616 | TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL), /* X60/s */ |
| 6617 | TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL), /* X60t */ |
| 6618 | TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL), /* Z60 */ |
| 6619 | TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL), /* Z61 */ |
| 6620 | |
| 6621 | /* Whitelist mute-only on all Lenovo by default */ |
| 6622 | { .vendor = PCI_VENDOR_ID_LENOVO, |
| 6623 | .bios = TPACPI_MATCH_ANY, |
| 6624 | .ec = TPACPI_MATCH_ANY, |
| 6625 | .quirks = TPACPI_VOL_Q_MUTEONLY } |
| 6626 | }; |
| 6627 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6628 | static int __init volume_init(struct ibm_init_struct *iibm) |
| 6629 | { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6630 | unsigned long quirks; |
| 6631 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6632 | vdbg_printk(TPACPI_DBG_INIT, "initializing volume subdriver\n"); |
| 6633 | |
| 6634 | mutex_init(&volume_mutex); |
| 6635 | |
| 6636 | /* |
| 6637 | * Check for module parameter bogosity, note that we |
| 6638 | * init volume_mode to TPACPI_VOL_MODE_MAX in order to be |
| 6639 | * able to detect "unspecified" |
| 6640 | */ |
| 6641 | if (volume_mode > TPACPI_VOL_MODE_MAX) |
| 6642 | return -EINVAL; |
| 6643 | |
| 6644 | if (volume_mode == TPACPI_VOL_MODE_UCMS_STEP) { |
| 6645 | printk(TPACPI_ERR |
| 6646 | "UCMS step volume mode not implemented, " |
| 6647 | "please contact %s\n", TPACPI_MAIL); |
| 6648 | return 1; |
| 6649 | } |
| 6650 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6651 | if (volume_capabilities >= TPACPI_VOL_CAP_MAX) |
| 6652 | return -EINVAL; |
| 6653 | |
| 6654 | quirks = tpacpi_check_quirks(volume_quirk_table, |
| 6655 | ARRAY_SIZE(volume_quirk_table)); |
| 6656 | |
| 6657 | switch (volume_capabilities) { |
| 6658 | case TPACPI_VOL_CAP_AUTO: |
| 6659 | if (quirks & TPACPI_VOL_Q_MUTEONLY) |
| 6660 | tp_features.mixer_no_level_control = 1; |
| 6661 | else if (quirks & TPACPI_VOL_Q_LEVEL) |
| 6662 | tp_features.mixer_no_level_control = 0; |
| 6663 | else |
| 6664 | return 1; /* no mixer */ |
| 6665 | break; |
| 6666 | case TPACPI_VOL_CAP_VOLMUTE: |
| 6667 | tp_features.mixer_no_level_control = 0; |
| 6668 | break; |
| 6669 | case TPACPI_VOL_CAP_MUTEONLY: |
| 6670 | tp_features.mixer_no_level_control = 1; |
| 6671 | break; |
| 6672 | default: |
| 6673 | return 1; |
| 6674 | } |
| 6675 | |
| 6676 | if (volume_capabilities != TPACPI_VOL_CAP_AUTO) |
| 6677 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6678 | "using user-supplied volume_capabilities=%d\n", |
| 6679 | volume_capabilities); |
| 6680 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6681 | if (volume_mode == TPACPI_VOL_MODE_AUTO || |
| 6682 | volume_mode == TPACPI_VOL_MODE_MAX) { |
| 6683 | volume_mode = TPACPI_VOL_MODE_ECNVRAM; |
| 6684 | |
| 6685 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6686 | "driver auto-selected volume_mode=%d\n", |
| 6687 | volume_mode); |
| 6688 | } else { |
| 6689 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6690 | "using user-supplied volume_mode=%d\n", |
| 6691 | volume_mode); |
| 6692 | } |
| 6693 | |
| 6694 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6695 | "mute is supported, volume control is %s\n", |
| 6696 | str_supported(!tp_features.mixer_no_level_control)); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6697 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame^] | 6698 | printk(TPACPI_INFO |
| 6699 | "Console audio control enabled, mode: %s\n", |
| 6700 | (volume_control_allowed) ? |
| 6701 | "override (read/write)" : |
| 6702 | "monitor (read only)"); |
| 6703 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6704 | return 0; |
| 6705 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6706 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6707 | static int volume_read(char *p) |
| 6708 | { |
| 6709 | int len = 0; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6710 | u8 status; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6711 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6712 | if (volume_get_status(&status) < 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6713 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 6714 | } else { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6715 | if (tp_features.mixer_no_level_control) |
| 6716 | len += sprintf(p + len, "level:\t\tunsupported\n"); |
| 6717 | else |
| 6718 | len += sprintf(p + len, "level:\t\t%d\n", |
| 6719 | status & TP_EC_AUDIO_LVL_MSK); |
| 6720 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6721 | len += sprintf(p + len, "mute:\t\t%s\n", |
| 6722 | onoff(status, TP_EC_AUDIO_MUTESW)); |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6723 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame^] | 6724 | if (volume_control_allowed) { |
| 6725 | len += sprintf(p + len, "commands:\tunmute, mute\n"); |
| 6726 | if (!tp_features.mixer_no_level_control) { |
| 6727 | len += sprintf(p + len, |
| 6728 | "commands:\tup, down\n"); |
| 6729 | len += sprintf(p + len, |
| 6730 | "commands:\tlevel <level>" |
| 6731 | " (<level> is 0-%d)\n", |
| 6732 | TP_EC_VOLUME_MAX); |
| 6733 | } |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6734 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6735 | } |
| 6736 | |
| 6737 | return len; |
| 6738 | } |
| 6739 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6740 | static int volume_write(char *buf) |
| 6741 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6742 | u8 s; |
| 6743 | u8 new_level, new_mute; |
| 6744 | int l; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6745 | char *cmd; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6746 | int rc; |
| 6747 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame^] | 6748 | /* |
| 6749 | * We do allow volume control at driver startup, so that the |
| 6750 | * user can set initial state through the volume=... parameter hack. |
| 6751 | */ |
| 6752 | if (!volume_control_allowed && tpacpi_lifecycle != TPACPI_LIFE_INIT) { |
| 6753 | if (unlikely(!tp_warned.volume_ctrl_forbidden)) { |
| 6754 | tp_warned.volume_ctrl_forbidden = 1; |
| 6755 | printk(TPACPI_NOTICE |
| 6756 | "Console audio control in monitor mode, " |
| 6757 | "changes are not allowed.\n"); |
| 6758 | printk(TPACPI_NOTICE |
| 6759 | "Use the volume_control=1 module parameter " |
| 6760 | "to enable volume control\n"); |
| 6761 | } |
| 6762 | return -EPERM; |
| 6763 | } |
| 6764 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6765 | rc = volume_get_status(&s); |
| 6766 | if (rc < 0) |
| 6767 | return rc; |
| 6768 | |
| 6769 | new_level = s & TP_EC_AUDIO_LVL_MSK; |
| 6770 | new_mute = s & TP_EC_AUDIO_MUTESW_MSK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6771 | |
| 6772 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6773 | if (!tp_features.mixer_no_level_control) { |
| 6774 | if (strlencmp(cmd, "up") == 0) { |
| 6775 | if (new_mute) |
| 6776 | new_mute = 0; |
| 6777 | else if (new_level < TP_EC_VOLUME_MAX) |
| 6778 | new_level++; |
| 6779 | continue; |
| 6780 | } else if (strlencmp(cmd, "down") == 0) { |
| 6781 | if (new_mute) |
| 6782 | new_mute = 0; |
| 6783 | else if (new_level > 0) |
| 6784 | new_level--; |
| 6785 | continue; |
| 6786 | } else if (sscanf(cmd, "level %u", &l) == 1 && |
| 6787 | l >= 0 && l <= TP_EC_VOLUME_MAX) { |
| 6788 | new_level = l; |
| 6789 | continue; |
| 6790 | } |
| 6791 | } |
| 6792 | if (strlencmp(cmd, "mute") == 0) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6793 | new_mute = TP_EC_AUDIO_MUTESW_MSK; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6794 | else if (strlencmp(cmd, "unmute") == 0) |
| 6795 | new_mute = 0; |
| 6796 | else |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6797 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6798 | } |
| 6799 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6800 | if (tp_features.mixer_no_level_control) { |
| 6801 | tpacpi_disclose_usertask("procfs volume", "%smute\n", |
| 6802 | new_mute ? "" : "un"); |
| 6803 | rc = volume_set_mute(!!new_mute); |
| 6804 | } else { |
| 6805 | tpacpi_disclose_usertask("procfs volume", |
| 6806 | "%smute and set level to %d\n", |
| 6807 | new_mute ? "" : "un", new_level); |
| 6808 | rc = volume_set_status(new_mute | new_level); |
| 6809 | } |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6810 | |
| 6811 | return (rc == -EINTR) ? -ERESTARTSYS : rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6812 | } |
| 6813 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6814 | static struct ibm_struct volume_driver_data = { |
| 6815 | .name = "volume", |
| 6816 | .read = volume_read, |
| 6817 | .write = volume_write, |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6818 | .exit = volume_exit, |
| 6819 | .suspend = volume_suspend, |
| 6820 | .shutdown = volume_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6821 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6822 | |
| 6823 | /************************************************************************* |
| 6824 | * Fan subdriver |
| 6825 | */ |
| 6826 | |
| 6827 | /* |
| 6828 | * FAN ACCESS MODES |
| 6829 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6830 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6831 | * ACPI GFAN method: returns fan level |
| 6832 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6833 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6834 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6835 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6836 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6837 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 6838 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6839 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 6840 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6841 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6842 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6843 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 6844 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6845 | * |
| 6846 | * Fan speed changes of any sort (including those caused by the |
| 6847 | * disengaged mode) are usually done slowly by the firmware as the |
| 6848 | * maximum ammount of fan duty cycle change per second seems to be |
| 6849 | * limited. |
| 6850 | * |
| 6851 | * Reading is not available if GFAN exists. |
| 6852 | * Writing is not available if SFAN exists. |
| 6853 | * |
| 6854 | * Bits |
| 6855 | * 7 automatic mode engaged; |
| 6856 | * (default operation mode of the ThinkPad) |
| 6857 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6858 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6859 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6860 | * the tachometer while the fan controller ramps up |
| 6861 | * the speed (which can take up to a few *minutes*). |
| 6862 | * Speeds up fan to 100% duty-cycle, which is far above |
| 6863 | * the standard RPM levels. It is not impossible that |
| 6864 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6865 | * 5-3 unused in some models. Extra bits for fan level |
| 6866 | * in others, but still useless as all values above |
| 6867 | * 7 map to the same speed as level 7 in these models. |
| 6868 | * 2-0 fan level (0..7 usually) |
| 6869 | * 0x00 = stop |
| 6870 | * 0x07 = max (set when temperatures critical) |
| 6871 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6872 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6873 | * |
| 6874 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 6875 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 6876 | * does so, its initial value is meaningless (0x07). |
| 6877 | * |
| 6878 | * For firmware bugs, refer to: |
| 6879 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 6880 | * |
| 6881 | * ---- |
| 6882 | * |
| 6883 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 6884 | * Main fan tachometer reading (in RPM) |
| 6885 | * |
| 6886 | * This register is present on all ThinkPads with a new-style EC, and |
| 6887 | * it is known not to be present on the A21m/e, and T22, as there is |
| 6888 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 6889 | * ThinkPads from this same time period (and earlier) probably lack the |
| 6890 | * tachometer as well. |
| 6891 | * |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 6892 | * 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] | 6893 | * was never fixed by IBM to report the EC firmware version string |
| 6894 | * probably support the tachometer (like the early X models), so |
| 6895 | * detecting it is quite hard. We need more data to know for sure. |
| 6896 | * |
| 6897 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 6898 | * might result. |
| 6899 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6900 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 6901 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6902 | * |
| 6903 | * For firmware bugs, refer to: |
| 6904 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 6905 | * |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6906 | * ---- |
| 6907 | * |
| 6908 | * ThinkPad EC register 0x31 bit 0 (only on select models) |
| 6909 | * |
| 6910 | * When bit 0 of EC register 0x31 is zero, the tachometer registers |
| 6911 | * show the speed of the main fan. When bit 0 of EC register 0x31 |
| 6912 | * is one, the tachometer registers show the speed of the auxiliary |
| 6913 | * fan. |
| 6914 | * |
| 6915 | * Fan control seems to affect both fans, regardless of the state |
| 6916 | * of this bit. |
| 6917 | * |
| 6918 | * So far, only the firmware for the X60/X61 non-tablet versions |
| 6919 | * seem to support this (firmware TP-7M). |
| 6920 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6921 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6922 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 6923 | * |
| 6924 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 6925 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 6926 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 6927 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 6928 | * |
| 6929 | * The speeds are stored on handles |
| 6930 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 6931 | * |
| 6932 | * There are three default speed sets, acessible as handles: |
| 6933 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 6934 | * |
| 6935 | * ACPI DSDT switches which set is in use depending on various |
| 6936 | * factors. |
| 6937 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6938 | * 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] | 6939 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 6940 | * but the ACPI tables just mention level 7. |
| 6941 | */ |
| 6942 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6943 | enum { /* Fan control constants */ |
| 6944 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 6945 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 6946 | * 0x84 must be read before 0x85 */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6947 | fan_select_offset = 0x31, /* EC register 0x31 (Firmware 7M) |
| 6948 | bit 0 selects which fan is active */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6949 | |
| 6950 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 6951 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 6952 | |
| 6953 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 6954 | }; |
| 6955 | |
| 6956 | enum fan_status_access_mode { |
| 6957 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 6958 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 6959 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 6960 | }; |
| 6961 | |
| 6962 | enum fan_control_access_mode { |
| 6963 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 6964 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 6965 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 6966 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 6967 | }; |
| 6968 | |
| 6969 | enum fan_control_commands { |
| 6970 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 6971 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 6972 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 6973 | * and also watchdog cmd */ |
| 6974 | }; |
| 6975 | |
| 6976 | static int fan_control_allowed; |
| 6977 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6978 | static enum fan_status_access_mode fan_status_access_mode; |
| 6979 | static enum fan_control_access_mode fan_control_access_mode; |
| 6980 | static enum fan_control_commands fan_control_commands; |
| 6981 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6982 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6983 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 6984 | static u8 fan_control_resume_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6985 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6986 | |
| 6987 | static struct mutex fan_mutex; |
| 6988 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6989 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 6990 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6991 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6992 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 6993 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6994 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 6995 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6996 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6997 | "JFNS", /* 770x-JL */ |
| 6998 | ); /* all others */ |
| 6999 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7000 | /* |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7001 | * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the |
| 7002 | * HFSP register at boot, so it contains 0x07 but the Thinkpad could |
| 7003 | * be in auto mode (0x80). |
| 7004 | * |
| 7005 | * This is corrected by any write to HFSP either by the driver, or |
| 7006 | * by the firmware. |
| 7007 | * |
| 7008 | * We assume 0x07 really means auto mode while this quirk is active, |
| 7009 | * as this is far more likely than the ThinkPad being in level 7, |
| 7010 | * which is only used by the firmware during thermal emergencies. |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7011 | * |
| 7012 | * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52), |
| 7013 | * TP-70 (T43, R52), which are known to be buggy. |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7014 | */ |
| 7015 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7016 | static void fan_quirk1_setup(void) |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7017 | { |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7018 | if (fan_control_initial_status == 0x07) { |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7019 | printk(TPACPI_NOTICE |
| 7020 | "fan_init: initial fan status is unknown, " |
| 7021 | "assuming it is in auto mode\n"); |
| 7022 | tp_features.fan_ctrl_status_undef = 1; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7023 | } |
| 7024 | } |
| 7025 | |
| 7026 | static void fan_quirk1_handle(u8 *fan_status) |
| 7027 | { |
| 7028 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 7029 | if (*fan_status != fan_control_initial_status) { |
| 7030 | /* something changed the HFSP regisnter since |
| 7031 | * driver init time, so it is not undefined |
| 7032 | * anymore */ |
| 7033 | tp_features.fan_ctrl_status_undef = 0; |
| 7034 | } else { |
| 7035 | /* Return most likely status. In fact, it |
| 7036 | * might be the only possible status */ |
| 7037 | *fan_status = TP_EC_FAN_AUTO; |
| 7038 | } |
| 7039 | } |
| 7040 | } |
| 7041 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7042 | /* Select main fan on X60/X61, NOOP on others */ |
| 7043 | static bool fan_select_fan1(void) |
| 7044 | { |
| 7045 | if (tp_features.second_fan) { |
| 7046 | u8 val; |
| 7047 | |
| 7048 | if (ec_read(fan_select_offset, &val) < 0) |
| 7049 | return false; |
| 7050 | val &= 0xFEU; |
| 7051 | if (ec_write(fan_select_offset, val) < 0) |
| 7052 | return false; |
| 7053 | } |
| 7054 | return true; |
| 7055 | } |
| 7056 | |
| 7057 | /* Select secondary fan on X60/X61 */ |
| 7058 | static bool fan_select_fan2(void) |
| 7059 | { |
| 7060 | u8 val; |
| 7061 | |
| 7062 | if (!tp_features.second_fan) |
| 7063 | return false; |
| 7064 | |
| 7065 | if (ec_read(fan_select_offset, &val) < 0) |
| 7066 | return false; |
| 7067 | val |= 0x01U; |
| 7068 | if (ec_write(fan_select_offset, val) < 0) |
| 7069 | return false; |
| 7070 | |
| 7071 | return true; |
| 7072 | } |
| 7073 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7074 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7075 | * Call with fan_mutex held |
| 7076 | */ |
| 7077 | static void fan_update_desired_level(u8 status) |
| 7078 | { |
| 7079 | if ((status & |
| 7080 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 7081 | if (status > 7) |
| 7082 | fan_control_desired_level = 7; |
| 7083 | else |
| 7084 | fan_control_desired_level = status; |
| 7085 | } |
| 7086 | } |
| 7087 | |
| 7088 | static int fan_get_status(u8 *status) |
| 7089 | { |
| 7090 | u8 s; |
| 7091 | |
| 7092 | /* TODO: |
| 7093 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 7094 | |
| 7095 | switch (fan_status_access_mode) { |
| 7096 | case TPACPI_FAN_RD_ACPI_GFAN: |
| 7097 | /* 570, 600e/x, 770e, 770x */ |
| 7098 | |
| 7099 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
| 7100 | return -EIO; |
| 7101 | |
| 7102 | if (likely(status)) |
| 7103 | *status = s & 0x07; |
| 7104 | |
| 7105 | break; |
| 7106 | |
| 7107 | case TPACPI_FAN_RD_TPEC: |
| 7108 | /* all except 570, 600e/x, 770e, 770x */ |
| 7109 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 7110 | return -EIO; |
| 7111 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7112 | if (likely(status)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7113 | *status = s; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7114 | fan_quirk1_handle(status); |
| 7115 | } |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7116 | |
| 7117 | break; |
| 7118 | |
| 7119 | default: |
| 7120 | return -ENXIO; |
| 7121 | } |
| 7122 | |
| 7123 | return 0; |
| 7124 | } |
| 7125 | |
| 7126 | static int fan_get_status_safe(u8 *status) |
| 7127 | { |
| 7128 | int rc; |
| 7129 | u8 s; |
| 7130 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7131 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7132 | return -ERESTARTSYS; |
| 7133 | rc = fan_get_status(&s); |
| 7134 | if (!rc) |
| 7135 | fan_update_desired_level(s); |
| 7136 | mutex_unlock(&fan_mutex); |
| 7137 | |
| 7138 | if (status) |
| 7139 | *status = s; |
| 7140 | |
| 7141 | return rc; |
| 7142 | } |
| 7143 | |
| 7144 | static int fan_get_speed(unsigned int *speed) |
| 7145 | { |
| 7146 | u8 hi, lo; |
| 7147 | |
| 7148 | switch (fan_status_access_mode) { |
| 7149 | case TPACPI_FAN_RD_TPEC: |
| 7150 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7151 | if (unlikely(!fan_select_fan1())) |
| 7152 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7153 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 7154 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 7155 | return -EIO; |
| 7156 | |
| 7157 | if (likely(speed)) |
| 7158 | *speed = (hi << 8) | lo; |
| 7159 | |
| 7160 | break; |
| 7161 | |
| 7162 | default: |
| 7163 | return -ENXIO; |
| 7164 | } |
| 7165 | |
| 7166 | return 0; |
| 7167 | } |
| 7168 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7169 | static int fan2_get_speed(unsigned int *speed) |
| 7170 | { |
| 7171 | u8 hi, lo; |
| 7172 | bool rc; |
| 7173 | |
| 7174 | switch (fan_status_access_mode) { |
| 7175 | case TPACPI_FAN_RD_TPEC: |
| 7176 | /* all except 570, 600e/x, 770e, 770x */ |
| 7177 | if (unlikely(!fan_select_fan2())) |
| 7178 | return -EIO; |
| 7179 | rc = !acpi_ec_read(fan_rpm_offset, &lo) || |
| 7180 | !acpi_ec_read(fan_rpm_offset + 1, &hi); |
| 7181 | fan_select_fan1(); /* play it safe */ |
| 7182 | if (rc) |
| 7183 | return -EIO; |
| 7184 | |
| 7185 | if (likely(speed)) |
| 7186 | *speed = (hi << 8) | lo; |
| 7187 | |
| 7188 | break; |
| 7189 | |
| 7190 | default: |
| 7191 | return -ENXIO; |
| 7192 | } |
| 7193 | |
| 7194 | return 0; |
| 7195 | } |
| 7196 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7197 | static int fan_set_level(int level) |
| 7198 | { |
| 7199 | if (!fan_control_allowed) |
| 7200 | return -EPERM; |
| 7201 | |
| 7202 | switch (fan_control_access_mode) { |
| 7203 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7204 | if (level >= 0 && level <= 7) { |
| 7205 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 7206 | return -EIO; |
| 7207 | } else |
| 7208 | return -EINVAL; |
| 7209 | break; |
| 7210 | |
| 7211 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7212 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7213 | if (!(level & TP_EC_FAN_AUTO) && |
| 7214 | !(level & TP_EC_FAN_FULLSPEED) && |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7215 | ((level < 0) || (level > 7))) |
| 7216 | return -EINVAL; |
| 7217 | |
| 7218 | /* safety net should the EC not support AUTO |
| 7219 | * or FULLSPEED mode bits and just ignore them */ |
| 7220 | if (level & TP_EC_FAN_FULLSPEED) |
| 7221 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 7222 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7223 | level |= 4; /* safety min speed 4 */ |
| 7224 | |
| 7225 | if (!acpi_ec_write(fan_status_offset, level)) |
| 7226 | return -EIO; |
| 7227 | else |
| 7228 | tp_features.fan_ctrl_status_undef = 0; |
| 7229 | break; |
| 7230 | |
| 7231 | default: |
| 7232 | return -ENXIO; |
| 7233 | } |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7234 | |
| 7235 | vdbg_printk(TPACPI_DBG_FAN, |
| 7236 | "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] | 7237 | return 0; |
| 7238 | } |
| 7239 | |
| 7240 | static int fan_set_level_safe(int level) |
| 7241 | { |
| 7242 | int rc; |
| 7243 | |
| 7244 | if (!fan_control_allowed) |
| 7245 | return -EPERM; |
| 7246 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7247 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7248 | return -ERESTARTSYS; |
| 7249 | |
| 7250 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 7251 | level = fan_control_desired_level; |
| 7252 | |
| 7253 | rc = fan_set_level(level); |
| 7254 | if (!rc) |
| 7255 | fan_update_desired_level(level); |
| 7256 | |
| 7257 | mutex_unlock(&fan_mutex); |
| 7258 | return rc; |
| 7259 | } |
| 7260 | |
| 7261 | static int fan_set_enable(void) |
| 7262 | { |
| 7263 | u8 s; |
| 7264 | int rc; |
| 7265 | |
| 7266 | if (!fan_control_allowed) |
| 7267 | return -EPERM; |
| 7268 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7269 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7270 | return -ERESTARTSYS; |
| 7271 | |
| 7272 | switch (fan_control_access_mode) { |
| 7273 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7274 | case TPACPI_FAN_WR_TPEC: |
| 7275 | rc = fan_get_status(&s); |
| 7276 | if (rc < 0) |
| 7277 | break; |
| 7278 | |
| 7279 | /* Don't go out of emergency fan mode */ |
| 7280 | if (s != 7) { |
| 7281 | s &= 0x07; |
| 7282 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 7283 | } |
| 7284 | |
| 7285 | if (!acpi_ec_write(fan_status_offset, s)) |
| 7286 | rc = -EIO; |
| 7287 | else { |
| 7288 | tp_features.fan_ctrl_status_undef = 0; |
| 7289 | rc = 0; |
| 7290 | } |
| 7291 | break; |
| 7292 | |
| 7293 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7294 | rc = fan_get_status(&s); |
| 7295 | if (rc < 0) |
| 7296 | break; |
| 7297 | |
| 7298 | s &= 0x07; |
| 7299 | |
| 7300 | /* Set fan to at least level 4 */ |
| 7301 | s |= 4; |
| 7302 | |
| 7303 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7304 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7305 | else |
| 7306 | rc = 0; |
| 7307 | break; |
| 7308 | |
| 7309 | default: |
| 7310 | rc = -ENXIO; |
| 7311 | } |
| 7312 | |
| 7313 | mutex_unlock(&fan_mutex); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7314 | |
| 7315 | if (!rc) |
| 7316 | vdbg_printk(TPACPI_DBG_FAN, |
| 7317 | "fan control: set fan control register to 0x%02x\n", |
| 7318 | s); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7319 | return rc; |
| 7320 | } |
| 7321 | |
| 7322 | static int fan_set_disable(void) |
| 7323 | { |
| 7324 | int rc; |
| 7325 | |
| 7326 | if (!fan_control_allowed) |
| 7327 | return -EPERM; |
| 7328 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7329 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7330 | return -ERESTARTSYS; |
| 7331 | |
| 7332 | rc = 0; |
| 7333 | switch (fan_control_access_mode) { |
| 7334 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7335 | case TPACPI_FAN_WR_TPEC: |
| 7336 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 7337 | rc = -EIO; |
| 7338 | else { |
| 7339 | fan_control_desired_level = 0; |
| 7340 | tp_features.fan_ctrl_status_undef = 0; |
| 7341 | } |
| 7342 | break; |
| 7343 | |
| 7344 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7345 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 7346 | rc = -EIO; |
| 7347 | else |
| 7348 | fan_control_desired_level = 0; |
| 7349 | break; |
| 7350 | |
| 7351 | default: |
| 7352 | rc = -ENXIO; |
| 7353 | } |
| 7354 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7355 | if (!rc) |
| 7356 | vdbg_printk(TPACPI_DBG_FAN, |
| 7357 | "fan control: set fan control register to 0\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7358 | |
| 7359 | mutex_unlock(&fan_mutex); |
| 7360 | return rc; |
| 7361 | } |
| 7362 | |
| 7363 | static int fan_set_speed(int speed) |
| 7364 | { |
| 7365 | int rc; |
| 7366 | |
| 7367 | if (!fan_control_allowed) |
| 7368 | return -EPERM; |
| 7369 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7370 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7371 | return -ERESTARTSYS; |
| 7372 | |
| 7373 | rc = 0; |
| 7374 | switch (fan_control_access_mode) { |
| 7375 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7376 | if (speed >= 0 && speed <= 65535) { |
| 7377 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 7378 | speed, speed, speed)) |
| 7379 | rc = -EIO; |
| 7380 | } else |
| 7381 | rc = -EINVAL; |
| 7382 | break; |
| 7383 | |
| 7384 | default: |
| 7385 | rc = -ENXIO; |
| 7386 | } |
| 7387 | |
| 7388 | mutex_unlock(&fan_mutex); |
| 7389 | return rc; |
| 7390 | } |
| 7391 | |
| 7392 | static void fan_watchdog_reset(void) |
| 7393 | { |
| 7394 | static int fan_watchdog_active; |
| 7395 | |
| 7396 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 7397 | return; |
| 7398 | |
| 7399 | if (fan_watchdog_active) |
| 7400 | cancel_delayed_work(&fan_watchdog_task); |
| 7401 | |
| 7402 | if (fan_watchdog_maxinterval > 0 && |
| 7403 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
| 7404 | fan_watchdog_active = 1; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7405 | if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task, |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7406 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 7407 | * 1000))) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7408 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7409 | "failed to queue the fan watchdog, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7410 | "watchdog will not trigger\n"); |
| 7411 | } |
| 7412 | } else |
| 7413 | fan_watchdog_active = 0; |
| 7414 | } |
| 7415 | |
| 7416 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 7417 | { |
| 7418 | int rc; |
| 7419 | |
| 7420 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 7421 | return; |
| 7422 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7423 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7424 | rc = fan_set_enable(); |
| 7425 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7426 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7427 | "will try again later...\n", -rc); |
| 7428 | /* reschedule for later */ |
| 7429 | fan_watchdog_reset(); |
| 7430 | } |
| 7431 | } |
| 7432 | |
| 7433 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7434 | * SYSFS fan layout: hwmon compatible (device) |
| 7435 | * |
| 7436 | * pwm*_enable: |
| 7437 | * 0: "disengaged" mode |
| 7438 | * 1: manual mode |
| 7439 | * 2: native EC "auto" mode (recommended, hardware default) |
| 7440 | * |
| 7441 | * pwm*: set speed in manual mode, ignored otherwise. |
| 7442 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 7443 | * interpolation. |
| 7444 | * |
| 7445 | * fan*_input: tachometer reading, RPM |
| 7446 | * |
| 7447 | * |
| 7448 | * SYSFS fan layout: extensions |
| 7449 | * |
| 7450 | * fan_watchdog (driver): |
| 7451 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 7452 | */ |
| 7453 | |
| 7454 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 7455 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 7456 | struct device_attribute *attr, |
| 7457 | char *buf) |
| 7458 | { |
| 7459 | int res, mode; |
| 7460 | u8 status; |
| 7461 | |
| 7462 | res = fan_get_status_safe(&status); |
| 7463 | if (res) |
| 7464 | return res; |
| 7465 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7466 | if (status & TP_EC_FAN_FULLSPEED) { |
| 7467 | mode = 0; |
| 7468 | } else if (status & TP_EC_FAN_AUTO) { |
| 7469 | mode = 2; |
| 7470 | } else |
| 7471 | mode = 1; |
| 7472 | |
| 7473 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 7474 | } |
| 7475 | |
| 7476 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 7477 | struct device_attribute *attr, |
| 7478 | const char *buf, size_t count) |
| 7479 | { |
| 7480 | unsigned long t; |
| 7481 | int res, level; |
| 7482 | |
| 7483 | if (parse_strtoul(buf, 2, &t)) |
| 7484 | return -EINVAL; |
| 7485 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7486 | tpacpi_disclose_usertask("hwmon pwm1_enable", |
| 7487 | "set fan mode to %lu\n", t); |
| 7488 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7489 | switch (t) { |
| 7490 | case 0: |
| 7491 | level = TP_EC_FAN_FULLSPEED; |
| 7492 | break; |
| 7493 | case 1: |
| 7494 | level = TPACPI_FAN_LAST_LEVEL; |
| 7495 | break; |
| 7496 | case 2: |
| 7497 | level = TP_EC_FAN_AUTO; |
| 7498 | break; |
| 7499 | case 3: |
| 7500 | /* reserved for software-controlled auto mode */ |
| 7501 | return -ENOSYS; |
| 7502 | default: |
| 7503 | return -EINVAL; |
| 7504 | } |
| 7505 | |
| 7506 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 7507 | if (res == -ENXIO) |
| 7508 | return -EINVAL; |
| 7509 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7510 | return res; |
| 7511 | |
| 7512 | fan_watchdog_reset(); |
| 7513 | |
| 7514 | return count; |
| 7515 | } |
| 7516 | |
| 7517 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 7518 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 7519 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 7520 | |
| 7521 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 7522 | static ssize_t fan_pwm1_show(struct device *dev, |
| 7523 | struct device_attribute *attr, |
| 7524 | char *buf) |
| 7525 | { |
| 7526 | int res; |
| 7527 | u8 status; |
| 7528 | |
| 7529 | res = fan_get_status_safe(&status); |
| 7530 | if (res) |
| 7531 | return res; |
| 7532 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7533 | if ((status & |
| 7534 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 7535 | status = fan_control_desired_level; |
| 7536 | |
| 7537 | if (status > 7) |
| 7538 | status = 7; |
| 7539 | |
| 7540 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 7541 | } |
| 7542 | |
| 7543 | static ssize_t fan_pwm1_store(struct device *dev, |
| 7544 | struct device_attribute *attr, |
| 7545 | const char *buf, size_t count) |
| 7546 | { |
| 7547 | unsigned long s; |
| 7548 | int rc; |
| 7549 | u8 status, newlevel; |
| 7550 | |
| 7551 | if (parse_strtoul(buf, 255, &s)) |
| 7552 | return -EINVAL; |
| 7553 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7554 | tpacpi_disclose_usertask("hwmon pwm1", |
| 7555 | "set fan speed to %lu\n", s); |
| 7556 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7557 | /* scale down from 0-255 to 0-7 */ |
| 7558 | newlevel = (s >> 5) & 0x07; |
| 7559 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7560 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 7561 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7562 | |
| 7563 | rc = fan_get_status(&status); |
| 7564 | if (!rc && (status & |
| 7565 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 7566 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 7567 | if (rc == -ENXIO) |
| 7568 | rc = -EINVAL; |
| 7569 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7570 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 7571 | fan_watchdog_reset(); |
| 7572 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7573 | } |
| 7574 | |
| 7575 | mutex_unlock(&fan_mutex); |
| 7576 | return (rc)? rc : count; |
| 7577 | } |
| 7578 | |
| 7579 | static struct device_attribute dev_attr_fan_pwm1 = |
| 7580 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 7581 | fan_pwm1_show, fan_pwm1_store); |
| 7582 | |
| 7583 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 7584 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 7585 | struct device_attribute *attr, |
| 7586 | char *buf) |
| 7587 | { |
| 7588 | int res; |
| 7589 | unsigned int speed; |
| 7590 | |
| 7591 | res = fan_get_speed(&speed); |
| 7592 | if (res < 0) |
| 7593 | return res; |
| 7594 | |
| 7595 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7596 | } |
| 7597 | |
| 7598 | static struct device_attribute dev_attr_fan_fan1_input = |
| 7599 | __ATTR(fan1_input, S_IRUGO, |
| 7600 | fan_fan1_input_show, NULL); |
| 7601 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7602 | /* sysfs fan fan2_input ------------------------------------------------ */ |
| 7603 | static ssize_t fan_fan2_input_show(struct device *dev, |
| 7604 | struct device_attribute *attr, |
| 7605 | char *buf) |
| 7606 | { |
| 7607 | int res; |
| 7608 | unsigned int speed; |
| 7609 | |
| 7610 | res = fan2_get_speed(&speed); |
| 7611 | if (res < 0) |
| 7612 | return res; |
| 7613 | |
| 7614 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7615 | } |
| 7616 | |
| 7617 | static struct device_attribute dev_attr_fan_fan2_input = |
| 7618 | __ATTR(fan2_input, S_IRUGO, |
| 7619 | fan_fan2_input_show, NULL); |
| 7620 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7621 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7622 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 7623 | char *buf) |
| 7624 | { |
| 7625 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 7626 | } |
| 7627 | |
| 7628 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 7629 | const char *buf, size_t count) |
| 7630 | { |
| 7631 | unsigned long t; |
| 7632 | |
| 7633 | if (parse_strtoul(buf, 120, &t)) |
| 7634 | return -EINVAL; |
| 7635 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7636 | if (!fan_control_allowed) |
| 7637 | return -EPERM; |
| 7638 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7639 | fan_watchdog_maxinterval = t; |
| 7640 | fan_watchdog_reset(); |
| 7641 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7642 | tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t); |
| 7643 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7644 | return count; |
| 7645 | } |
| 7646 | |
| 7647 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 7648 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 7649 | |
| 7650 | /* --------------------------------------------------------------------- */ |
| 7651 | static struct attribute *fan_attributes[] = { |
| 7652 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 7653 | &dev_attr_fan_fan1_input.attr, |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7654 | NULL, /* for fan2_input */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7655 | NULL |
| 7656 | }; |
| 7657 | |
| 7658 | static const struct attribute_group fan_attr_group = { |
| 7659 | .attrs = fan_attributes, |
| 7660 | }; |
| 7661 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7662 | #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */ |
| 7663 | #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] | 7664 | |
| 7665 | #define TPACPI_FAN_QI(__id1, __id2, __quirks) \ |
| 7666 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 7667 | .bios = TPACPI_MATCH_ANY, \ |
| 7668 | .ec = TPID(__id1, __id2), \ |
| 7669 | .quirks = __quirks } |
| 7670 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7671 | #define TPACPI_FAN_QL(__id1, __id2, __quirks) \ |
| 7672 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 7673 | .bios = TPACPI_MATCH_ANY, \ |
| 7674 | .ec = TPID(__id1, __id2), \ |
| 7675 | .quirks = __quirks } |
| 7676 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7677 | static const struct tpacpi_quirk fan_quirk_table[] __initconst = { |
| 7678 | TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1), |
| 7679 | TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1), |
| 7680 | TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1), |
| 7681 | TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1), |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7682 | TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN), |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7683 | }; |
| 7684 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7685 | #undef TPACPI_FAN_QL |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7686 | #undef TPACPI_FAN_QI |
| 7687 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7688 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7689 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7690 | int rc; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7691 | unsigned long quirks; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7692 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7693 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7694 | "initializing fan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7695 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 7696 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7697 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 7698 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7699 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7700 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 7701 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7702 | tp_features.second_fan = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7703 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7704 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7705 | TPACPI_ACPIHANDLE_INIT(fans); |
| 7706 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 7707 | TPACPI_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7708 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7709 | quirks = tpacpi_check_quirks(fan_quirk_table, |
| 7710 | ARRAY_SIZE(fan_quirk_table)); |
| 7711 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7712 | if (gfan_handle) { |
| 7713 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7714 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7715 | } else { |
| 7716 | /* all other ThinkPads: note that even old-style |
| 7717 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7718 | if (likely(acpi_ec_read(fan_status_offset, |
| 7719 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7720 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7721 | if (quirks & TPACPI_FAN_Q1) |
| 7722 | fan_quirk1_setup(); |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7723 | if (quirks & TPACPI_FAN_2FAN) { |
| 7724 | tp_features.second_fan = 1; |
| 7725 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7726 | "secondary fan support enabled\n"); |
| 7727 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7728 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7729 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7730 | "ThinkPad ACPI EC access misbehaving, " |
| 7731 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7732 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7733 | } |
| 7734 | } |
| 7735 | |
| 7736 | if (sfan_handle) { |
| 7737 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7738 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 7739 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7740 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7741 | } else { |
| 7742 | if (!gfan_handle) { |
| 7743 | /* gfan without sfan means no fan control */ |
| 7744 | /* all other models implement TP EC 0x2f control */ |
| 7745 | |
| 7746 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7747 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7748 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7749 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7750 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7751 | TPACPI_FAN_CMD_SPEED | |
| 7752 | TPACPI_FAN_CMD_LEVEL | |
| 7753 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7754 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7755 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7756 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7757 | TPACPI_FAN_CMD_LEVEL | |
| 7758 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7759 | } |
| 7760 | } |
| 7761 | } |
| 7762 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7763 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7764 | "fan is %s, modes %d, %d\n", |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7765 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 7766 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 7767 | fan_status_access_mode, fan_control_access_mode); |
| 7768 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7769 | /* fan control master switch */ |
| 7770 | if (!fan_control_allowed) { |
| 7771 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 7772 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7773 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7774 | "fan control features disabled by parameter\n"); |
| 7775 | } |
| 7776 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7777 | /* update fan_control_desired_level */ |
| 7778 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 7779 | fan_get_status_safe(NULL); |
| 7780 | |
| 7781 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 7782 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7783 | if (tp_features.second_fan) { |
| 7784 | /* attach second fan tachometer */ |
| 7785 | fan_attributes[ARRAY_SIZE(fan_attributes)-2] = |
| 7786 | &dev_attr_fan_fan2_input.attr; |
| 7787 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7788 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7789 | &fan_attr_group); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7790 | if (rc < 0) |
| 7791 | return rc; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 7792 | |
| 7793 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
| 7794 | &driver_attr_fan_watchdog); |
| 7795 | if (rc < 0) { |
| 7796 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
| 7797 | &fan_attr_group); |
| 7798 | return rc; |
| 7799 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7800 | return 0; |
| 7801 | } else |
| 7802 | return 1; |
| 7803 | } |
| 7804 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7805 | static void fan_exit(void) |
| 7806 | { |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7807 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7808 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7809 | |
| 7810 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7811 | 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] | 7812 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 7813 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7814 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7815 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7816 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7817 | } |
| 7818 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7819 | static void fan_suspend(pm_message_t state) |
| 7820 | { |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7821 | int rc; |
| 7822 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7823 | if (!fan_control_allowed) |
| 7824 | return; |
| 7825 | |
| 7826 | /* Store fan status in cache */ |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7827 | fan_control_resume_level = 0; |
| 7828 | rc = fan_get_status_safe(&fan_control_resume_level); |
| 7829 | if (rc < 0) |
| 7830 | printk(TPACPI_NOTICE |
| 7831 | "failed to read fan level for later " |
| 7832 | "restore during resume: %d\n", rc); |
| 7833 | |
| 7834 | /* if it is undefined, don't attempt to restore it. |
| 7835 | * KEEP THIS LAST */ |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7836 | if (tp_features.fan_ctrl_status_undef) |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7837 | fan_control_resume_level = 0; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7838 | } |
| 7839 | |
| 7840 | static void fan_resume(void) |
| 7841 | { |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7842 | u8 current_level = 7; |
| 7843 | bool do_set = false; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7844 | int rc; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7845 | |
| 7846 | /* DSDT *always* updates status on resume */ |
| 7847 | tp_features.fan_ctrl_status_undef = 0; |
| 7848 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7849 | if (!fan_control_allowed || |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7850 | !fan_control_resume_level || |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7851 | (fan_get_status_safe(¤t_level) < 0)) |
| 7852 | return; |
| 7853 | |
| 7854 | switch (fan_control_access_mode) { |
| 7855 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7856 | /* never decrease fan level */ |
| 7857 | do_set = (fan_control_resume_level > current_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7858 | break; |
| 7859 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7860 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7861 | /* never decrease fan level, scale is: |
| 7862 | * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO |
| 7863 | * |
| 7864 | * We expect the firmware to set either 7 or AUTO, but we |
| 7865 | * handle FULLSPEED out of paranoia. |
| 7866 | * |
| 7867 | * So, we can safely only restore FULLSPEED or 7, anything |
| 7868 | * else could slow the fan. Restoring AUTO is useless, at |
| 7869 | * best that's exactly what the DSDT already set (it is the |
| 7870 | * slower it uses). |
| 7871 | * |
| 7872 | * Always keep in mind that the DSDT *will* have set the |
| 7873 | * fans to what the vendor supposes is the best level. We |
| 7874 | * muck with it only to speed the fan up. |
| 7875 | */ |
| 7876 | if (fan_control_resume_level != 7 && |
| 7877 | !(fan_control_resume_level & TP_EC_FAN_FULLSPEED)) |
| 7878 | return; |
| 7879 | else |
| 7880 | do_set = !(current_level & TP_EC_FAN_FULLSPEED) && |
| 7881 | (current_level != fan_control_resume_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7882 | break; |
| 7883 | default: |
| 7884 | return; |
| 7885 | } |
| 7886 | if (do_set) { |
| 7887 | printk(TPACPI_NOTICE |
| 7888 | "restoring fan level to 0x%02x\n", |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7889 | fan_control_resume_level); |
| 7890 | rc = fan_set_level_safe(fan_control_resume_level); |
| 7891 | if (rc < 0) |
| 7892 | printk(TPACPI_NOTICE |
| 7893 | "failed to restore fan level: %d\n", rc); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7894 | } |
| 7895 | } |
| 7896 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7897 | static int fan_read(char *p) |
| 7898 | { |
| 7899 | int len = 0; |
| 7900 | int rc; |
| 7901 | u8 status; |
| 7902 | unsigned int speed = 0; |
| 7903 | |
| 7904 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7905 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7906 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7907 | rc = fan_get_status_safe(&status); |
| 7908 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7909 | return rc; |
| 7910 | |
| 7911 | len += sprintf(p + len, "status:\t\t%s\n" |
| 7912 | "level:\t\t%d\n", |
| 7913 | (status != 0) ? "enabled" : "disabled", status); |
| 7914 | break; |
| 7915 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7916 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7917 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7918 | rc = fan_get_status_safe(&status); |
| 7919 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7920 | return rc; |
| 7921 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7922 | len += sprintf(p + len, "status:\t\t%s\n", |
| 7923 | (status != 0) ? "enabled" : "disabled"); |
| 7924 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7925 | rc = fan_get_speed(&speed); |
| 7926 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7927 | return rc; |
| 7928 | |
| 7929 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 7930 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7931 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7932 | /* Disengaged mode takes precedence */ |
| 7933 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7934 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7935 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 7936 | else |
| 7937 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 7938 | break; |
| 7939 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7940 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7941 | default: |
| 7942 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 7943 | } |
| 7944 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7945 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7946 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 7947 | |
| 7948 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7949 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7950 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 7951 | break; |
| 7952 | |
| 7953 | default: |
| 7954 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7955 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7956 | break; |
| 7957 | } |
| 7958 | } |
| 7959 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7960 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7961 | len += sprintf(p + len, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7962 | "commands:\twatchdog <timeout> (<timeout> " |
| 7963 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7964 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7965 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7966 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 7967 | " (<speed> is 0-65535)\n"); |
| 7968 | |
| 7969 | return len; |
| 7970 | } |
| 7971 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7972 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 7973 | { |
| 7974 | int level; |
| 7975 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7976 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7977 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7978 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7979 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7980 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7981 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7982 | return 0; |
| 7983 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7984 | *rc = fan_set_level_safe(level); |
| 7985 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7986 | printk(TPACPI_ERR "level command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7987 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7988 | else if (!*rc) |
| 7989 | tpacpi_disclose_usertask("procfs fan", |
| 7990 | "set level to %d\n", level); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7991 | |
| 7992 | return 1; |
| 7993 | } |
| 7994 | |
| 7995 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 7996 | { |
| 7997 | if (strlencmp(cmd, "enable") != 0) |
| 7998 | return 0; |
| 7999 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8000 | *rc = fan_set_enable(); |
| 8001 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8002 | printk(TPACPI_ERR "enable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8003 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8004 | else if (!*rc) |
| 8005 | tpacpi_disclose_usertask("procfs fan", "enable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8006 | |
| 8007 | return 1; |
| 8008 | } |
| 8009 | |
| 8010 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 8011 | { |
| 8012 | if (strlencmp(cmd, "disable") != 0) |
| 8013 | return 0; |
| 8014 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8015 | *rc = fan_set_disable(); |
| 8016 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8017 | printk(TPACPI_ERR "disable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8018 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8019 | else if (!*rc) |
| 8020 | tpacpi_disclose_usertask("procfs fan", "disable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8021 | |
| 8022 | return 1; |
| 8023 | } |
| 8024 | |
| 8025 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 8026 | { |
| 8027 | int speed; |
| 8028 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8029 | /* TODO: |
| 8030 | * Support speed <low> <medium> <high> ? */ |
| 8031 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8032 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 8033 | return 0; |
| 8034 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8035 | *rc = fan_set_speed(speed); |
| 8036 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8037 | printk(TPACPI_ERR "speed command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8038 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8039 | else if (!*rc) |
| 8040 | tpacpi_disclose_usertask("procfs fan", |
| 8041 | "set speed to %d\n", speed); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8042 | |
| 8043 | return 1; |
| 8044 | } |
| 8045 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8046 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 8047 | { |
| 8048 | int interval; |
| 8049 | |
| 8050 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 8051 | return 0; |
| 8052 | |
| 8053 | if (interval < 0 || interval > 120) |
| 8054 | *rc = -EINVAL; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8055 | else { |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8056 | fan_watchdog_maxinterval = interval; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8057 | tpacpi_disclose_usertask("procfs fan", |
| 8058 | "set watchdog timer to %d\n", |
| 8059 | interval); |
| 8060 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8061 | |
| 8062 | return 1; |
| 8063 | } |
| 8064 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8065 | static int fan_write(char *buf) |
| 8066 | { |
| 8067 | char *cmd; |
| 8068 | int rc = 0; |
| 8069 | |
| 8070 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8071 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8072 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8073 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8074 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8075 | fan_write_cmd_disable(cmd, &rc) || |
| 8076 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8077 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8078 | fan_write_cmd_speed(cmd, &rc)) |
| 8079 | ) |
| 8080 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8081 | else if (!rc) |
| 8082 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8083 | } |
| 8084 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8085 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8086 | } |
| 8087 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8088 | static struct ibm_struct fan_driver_data = { |
| 8089 | .name = "fan", |
| 8090 | .read = fan_read, |
| 8091 | .write = fan_write, |
| 8092 | .exit = fan_exit, |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8093 | .suspend = fan_suspend, |
| 8094 | .resume = fan_resume, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8095 | }; |
| 8096 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8097 | /**************************************************************************** |
| 8098 | **************************************************************************** |
| 8099 | * |
| 8100 | * Infrastructure |
| 8101 | * |
| 8102 | **************************************************************************** |
| 8103 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8104 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8105 | /* |
| 8106 | * HKEY event callout for other subdrivers go here |
| 8107 | * (yes, it is ugly, but it is quick, safe, and gets the job done |
| 8108 | */ |
| 8109 | static void tpacpi_driver_event(const unsigned int hkey_event) |
| 8110 | { |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 8111 | if (ibm_backlight_device) { |
| 8112 | switch (hkey_event) { |
| 8113 | case TP_HKEY_EV_BRGHT_UP: |
| 8114 | case TP_HKEY_EV_BRGHT_DOWN: |
| 8115 | tpacpi_brightness_notify_change(); |
| 8116 | } |
| 8117 | } |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8118 | } |
| 8119 | |
| 8120 | |
| 8121 | |
| 8122 | static void hotkey_driver_event(const unsigned int scancode) |
| 8123 | { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 8124 | tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8125 | } |
| 8126 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8127 | /* sysfs name ---------------------------------------------------------- */ |
| 8128 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 8129 | struct device_attribute *attr, |
| 8130 | char *buf) |
| 8131 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8132 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8133 | } |
| 8134 | |
| 8135 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 8136 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 8137 | |
| 8138 | /* --------------------------------------------------------------------- */ |
| 8139 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8140 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 8141 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8142 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8143 | /* |
| 8144 | * Module and infrastructure proble, init and exit handling |
| 8145 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8146 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8147 | static int force_load; |
| 8148 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8149 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8150 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8151 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8152 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8153 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8154 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8155 | } |
| 8156 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 8157 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8158 | static void ibm_exit(struct ibm_struct *ibm) |
| 8159 | { |
| 8160 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 8161 | |
| 8162 | list_del_init(&ibm->all_drivers); |
| 8163 | |
| 8164 | if (ibm->flags.acpi_notify_installed) { |
| 8165 | dbg_printk(TPACPI_DBG_EXIT, |
| 8166 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 8167 | BUG_ON(!ibm->acpi); |
| 8168 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 8169 | ibm->acpi->type, |
| 8170 | dispatch_acpi_notify); |
| 8171 | ibm->flags.acpi_notify_installed = 0; |
| 8172 | ibm->flags.acpi_notify_installed = 0; |
| 8173 | } |
| 8174 | |
| 8175 | if (ibm->flags.proc_created) { |
| 8176 | dbg_printk(TPACPI_DBG_EXIT, |
| 8177 | "%s: remove_proc_entry\n", ibm->name); |
| 8178 | remove_proc_entry(ibm->name, proc_dir); |
| 8179 | ibm->flags.proc_created = 0; |
| 8180 | } |
| 8181 | |
| 8182 | if (ibm->flags.acpi_driver_registered) { |
| 8183 | dbg_printk(TPACPI_DBG_EXIT, |
| 8184 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 8185 | BUG_ON(!ibm->acpi); |
| 8186 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 8187 | kfree(ibm->acpi->driver); |
| 8188 | ibm->acpi->driver = NULL; |
| 8189 | ibm->flags.acpi_driver_registered = 0; |
| 8190 | } |
| 8191 | |
| 8192 | if (ibm->flags.init_called && ibm->exit) { |
| 8193 | ibm->exit(); |
| 8194 | ibm->flags.init_called = 0; |
| 8195 | } |
| 8196 | |
| 8197 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 8198 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 8199 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8200 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8201 | { |
| 8202 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8203 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8204 | struct proc_dir_entry *entry; |
| 8205 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8206 | BUG_ON(ibm == NULL); |
| 8207 | |
| 8208 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 8209 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8210 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8211 | return 0; |
| 8212 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8213 | dbg_printk(TPACPI_DBG_INIT, |
| 8214 | "probing for %s\n", ibm->name); |
| 8215 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8216 | if (iibm->init) { |
| 8217 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8218 | if (ret > 0) |
| 8219 | return 0; /* probe failed */ |
| 8220 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8221 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8222 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8223 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8224 | } |
| 8225 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8226 | if (ibm->acpi) { |
| 8227 | if (ibm->acpi->hid) { |
| 8228 | ret = register_tpacpi_subdriver(ibm); |
| 8229 | if (ret) |
| 8230 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8231 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8232 | |
| 8233 | if (ibm->acpi->notify) { |
| 8234 | ret = setup_acpi_notify(ibm); |
| 8235 | if (ret == -ENODEV) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8236 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8237 | ibm->name); |
| 8238 | ret = 0; |
| 8239 | goto err_out; |
| 8240 | } |
| 8241 | if (ret < 0) |
| 8242 | goto err_out; |
| 8243 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8244 | } |
| 8245 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8246 | dbg_printk(TPACPI_DBG_INIT, |
| 8247 | "%s installed\n", ibm->name); |
| 8248 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8249 | if (ibm->read) { |
| 8250 | entry = create_proc_entry(ibm->name, |
| 8251 | S_IFREG | S_IRUGO | S_IWUSR, |
| 8252 | proc_dir); |
| 8253 | if (!entry) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8254 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8255 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8256 | ret = -ENODEV; |
| 8257 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8258 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8259 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8260 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8261 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8262 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8263 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8264 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8265 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8266 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 8267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8268 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8269 | |
| 8270 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8271 | dbg_printk(TPACPI_DBG_INIT, |
| 8272 | "%s: at error exit path with result %d\n", |
| 8273 | ibm->name, ret); |
| 8274 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8275 | ibm_exit(ibm); |
| 8276 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8277 | } |
| 8278 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8279 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8280 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8281 | static bool __pure __init tpacpi_is_fw_digit(const char c) |
| 8282 | { |
| 8283 | return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); |
| 8284 | } |
| 8285 | |
| 8286 | /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */ |
| 8287 | static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, |
| 8288 | const char t) |
| 8289 | { |
| 8290 | return s && strlen(s) >= 8 && |
| 8291 | tpacpi_is_fw_digit(s[0]) && |
| 8292 | tpacpi_is_fw_digit(s[1]) && |
| 8293 | s[2] == t && s[3] == 'T' && |
| 8294 | tpacpi_is_fw_digit(s[4]) && |
| 8295 | tpacpi_is_fw_digit(s[5]) && |
| 8296 | s[6] == 'W' && s[7] == 'W'; |
| 8297 | } |
| 8298 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8299 | /* returns 0 - probe ok, or < 0 - probe error. |
| 8300 | * Probe ok doesn't mean thinkpad found. |
| 8301 | * On error, kfree() cleanup on tp->* is not performed, caller must do it */ |
| 8302 | static int __must_check __init get_thinkpad_model_data( |
| 8303 | struct thinkpad_id_data *tp) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8304 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 8305 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8306 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8307 | char const *s; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8308 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8309 | if (!tp) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8310 | return -EINVAL; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8311 | |
| 8312 | memset(tp, 0, sizeof(*tp)); |
| 8313 | |
| 8314 | if (dmi_name_in_vendors("IBM")) |
| 8315 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 8316 | else if (dmi_name_in_vendors("LENOVO")) |
| 8317 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 8318 | else |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8319 | return 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8320 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8321 | s = dmi_get_system_info(DMI_BIOS_VERSION); |
| 8322 | tp->bios_version_str = kstrdup(s, GFP_KERNEL); |
| 8323 | if (s && !tp->bios_version_str) |
| 8324 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8325 | |
| 8326 | /* Really ancient ThinkPad 240X will fail this, which is fine */ |
| 8327 | 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] | 8328 | return 0; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8329 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8330 | tp->bios_model = tp->bios_version_str[0] |
| 8331 | | (tp->bios_version_str[1] << 8); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8332 | tp->bios_release = (tp->bios_version_str[4] << 8) |
| 8333 | | tp->bios_version_str[5]; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8334 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8335 | /* |
| 8336 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 8337 | * X32 or newer, all Z series; Some models must have an |
| 8338 | * up-to-date BIOS or they will not be detected. |
| 8339 | * |
| 8340 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 8341 | */ |
| 8342 | 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] | 8343 | if (sscanf(dev->name, |
| 8344 | "IBM ThinkPad Embedded Controller -[%17c", |
| 8345 | ec_fw_string) == 1) { |
| 8346 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 8347 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8348 | |
| 8349 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8350 | if (!tp->ec_version_str) |
| 8351 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8352 | |
| 8353 | if (tpacpi_is_valid_fw_id(ec_fw_string, 'H')) { |
| 8354 | tp->ec_model = ec_fw_string[0] |
| 8355 | | (ec_fw_string[1] << 8); |
| 8356 | tp->ec_release = (ec_fw_string[4] << 8) |
| 8357 | | ec_fw_string[5]; |
| 8358 | } else { |
| 8359 | printk(TPACPI_NOTICE |
| 8360 | "ThinkPad firmware release %s " |
| 8361 | "doesn't match the known patterns\n", |
| 8362 | ec_fw_string); |
| 8363 | printk(TPACPI_NOTICE |
| 8364 | "please report this to %s\n", |
| 8365 | TPACPI_MAIL); |
| 8366 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8367 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8368 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8369 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8370 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8371 | s = dmi_get_system_info(DMI_PRODUCT_VERSION); |
| 8372 | if (s && !strnicmp(s, "ThinkPad", 8)) { |
| 8373 | tp->model_str = kstrdup(s, GFP_KERNEL); |
| 8374 | if (!tp->model_str) |
| 8375 | return -ENOMEM; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8376 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 8377 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8378 | s = dmi_get_system_info(DMI_PRODUCT_NAME); |
| 8379 | tp->nummodel_str = kstrdup(s, GFP_KERNEL); |
| 8380 | if (s && !tp->nummodel_str) |
| 8381 | return -ENOMEM; |
| 8382 | |
| 8383 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8384 | } |
| 8385 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8386 | static int __init probe_for_thinkpad(void) |
| 8387 | { |
| 8388 | int is_thinkpad; |
| 8389 | |
| 8390 | if (acpi_disabled) |
| 8391 | return -ENODEV; |
| 8392 | |
| 8393 | /* |
| 8394 | * 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] | 8395 | * 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] | 8396 | */ |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 8397 | is_thinkpad = (thinkpad_id.model_str != NULL) || |
| 8398 | (thinkpad_id.ec_model != 0) || |
| 8399 | tpacpi_is_fw_known(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8400 | |
| 8401 | /* 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] | 8402 | TPACPI_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8403 | if (!ec_handle) { |
| 8404 | if (is_thinkpad) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8405 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8406 | "Not yet supported ThinkPad detected!\n"); |
| 8407 | return -ENODEV; |
| 8408 | } |
| 8409 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 8410 | if (!is_thinkpad && !force_load) |
| 8411 | return -ENODEV; |
| 8412 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8413 | return 0; |
| 8414 | } |
| 8415 | |
| 8416 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8417 | /* Module init, exit, parameters */ |
| 8418 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8419 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 8420 | { |
| 8421 | .init = thinkpad_acpi_driver_init, |
| 8422 | .data = &thinkpad_acpi_driver_data, |
| 8423 | }, |
| 8424 | { |
| 8425 | .init = hotkey_init, |
| 8426 | .data = &hotkey_driver_data, |
| 8427 | }, |
| 8428 | { |
| 8429 | .init = bluetooth_init, |
| 8430 | .data = &bluetooth_driver_data, |
| 8431 | }, |
| 8432 | { |
| 8433 | .init = wan_init, |
| 8434 | .data = &wan_driver_data, |
| 8435 | }, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8436 | { |
| 8437 | .init = uwb_init, |
| 8438 | .data = &uwb_driver_data, |
| 8439 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 8440 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8441 | { |
| 8442 | .init = video_init, |
| 8443 | .data = &video_driver_data, |
| 8444 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 8445 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8446 | { |
| 8447 | .init = light_init, |
| 8448 | .data = &light_driver_data, |
| 8449 | }, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8450 | { |
| 8451 | .init = cmos_init, |
| 8452 | .data = &cmos_driver_data, |
| 8453 | }, |
| 8454 | { |
| 8455 | .init = led_init, |
| 8456 | .data = &led_driver_data, |
| 8457 | }, |
| 8458 | { |
| 8459 | .init = beep_init, |
| 8460 | .data = &beep_driver_data, |
| 8461 | }, |
| 8462 | { |
| 8463 | .init = thermal_init, |
| 8464 | .data = &thermal_driver_data, |
| 8465 | }, |
| 8466 | { |
| 8467 | .data = &ecdump_driver_data, |
| 8468 | }, |
| 8469 | { |
| 8470 | .init = brightness_init, |
| 8471 | .data = &brightness_driver_data, |
| 8472 | }, |
| 8473 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 8474 | .init = volume_init, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8475 | .data = &volume_driver_data, |
| 8476 | }, |
| 8477 | { |
| 8478 | .init = fan_init, |
| 8479 | .data = &fan_driver_data, |
| 8480 | }, |
| 8481 | }; |
| 8482 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8483 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 8484 | { |
| 8485 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8486 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8487 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 8488 | if (!kp || !kp->name || !val) |
| 8489 | return -EINVAL; |
| 8490 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8491 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 8492 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 8493 | WARN_ON(ibm == NULL); |
| 8494 | |
| 8495 | if (!ibm || !ibm->name) |
| 8496 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8497 | |
| 8498 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 8499 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8500 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8501 | strcpy(ibms_init[i].param, val); |
| 8502 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8503 | return 0; |
| 8504 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8505 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8506 | |
| 8507 | return -EINVAL; |
| 8508 | } |
| 8509 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8510 | module_param(experimental, int, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8511 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8512 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8513 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 8514 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8515 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 8516 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8517 | module_param(force_load, bool, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8518 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8519 | "Attempts to load the driver even on a " |
| 8520 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 8521 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8522 | module_param_named(fan_control, fan_control_allowed, bool, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8523 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8524 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8525 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8526 | module_param_named(brightness_mode, brightness_mode, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8527 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8528 | "Selects brightness control strategy: " |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 8529 | "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 8530 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8531 | module_param(brightness_enable, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8532 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8533 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 8534 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8535 | module_param(hotkey_report_mode, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8536 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8537 | "used for backwards compatibility with userspace, " |
| 8538 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8539 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 8540 | module_param_named(volume_mode, volume_mode, uint, 0444); |
| 8541 | MODULE_PARM_DESC(volume_mode, |
| 8542 | "Selects volume control strategy: " |
| 8543 | "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM"); |
| 8544 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 8545 | module_param_named(volume_capabilities, volume_capabilities, uint, 0444); |
| 8546 | MODULE_PARM_DESC(volume_capabilities, |
| 8547 | "Selects the mixer capabilites: " |
| 8548 | "0=auto, 1=volume and mute, 2=mute only"); |
| 8549 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame^] | 8550 | module_param_named(volume_control, volume_control_allowed, bool, 0444); |
| 8551 | MODULE_PARM_DESC(volume_control, |
| 8552 | "Enables software override for the console audio " |
| 8553 | "control when true"); |
| 8554 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8555 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8556 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 8557 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8558 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8559 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8560 | TPACPI_PARAM(hotkey); |
| 8561 | TPACPI_PARAM(bluetooth); |
| 8562 | TPACPI_PARAM(video); |
| 8563 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8564 | TPACPI_PARAM(cmos); |
| 8565 | TPACPI_PARAM(led); |
| 8566 | TPACPI_PARAM(beep); |
| 8567 | TPACPI_PARAM(ecdump); |
| 8568 | TPACPI_PARAM(brightness); |
| 8569 | TPACPI_PARAM(volume); |
| 8570 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8571 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8572 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8573 | module_param(dbg_wlswemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8574 | MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation"); |
| 8575 | module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0); |
| 8576 | MODULE_PARM_DESC(wlsw_state, |
| 8577 | "Initial state of the emulated WLSW switch"); |
| 8578 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8579 | module_param(dbg_bluetoothemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8580 | MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation"); |
| 8581 | module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0); |
| 8582 | MODULE_PARM_DESC(bluetooth_state, |
| 8583 | "Initial state of the emulated bluetooth switch"); |
| 8584 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8585 | module_param(dbg_wwanemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8586 | MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation"); |
| 8587 | module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0); |
| 8588 | MODULE_PARM_DESC(wwan_state, |
| 8589 | "Initial state of the emulated WWAN switch"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8590 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8591 | module_param(dbg_uwbemul, uint, 0444); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8592 | MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation"); |
| 8593 | module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0); |
| 8594 | MODULE_PARM_DESC(uwb_state, |
| 8595 | "Initial state of the emulated UWB switch"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8596 | #endif |
| 8597 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8598 | static void thinkpad_acpi_module_exit(void) |
| 8599 | { |
| 8600 | struct ibm_struct *ibm, *itmp; |
| 8601 | |
| 8602 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 8603 | |
| 8604 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 8605 | &tpacpi_all_drivers, |
| 8606 | all_drivers) { |
| 8607 | ibm_exit(ibm); |
| 8608 | } |
| 8609 | |
| 8610 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 8611 | |
| 8612 | if (tpacpi_inputdev) { |
| 8613 | if (tp_features.input_device_registered) |
| 8614 | input_unregister_device(tpacpi_inputdev); |
| 8615 | else |
| 8616 | input_free_device(tpacpi_inputdev); |
| 8617 | } |
| 8618 | |
| 8619 | if (tpacpi_hwmon) |
| 8620 | hwmon_device_unregister(tpacpi_hwmon); |
| 8621 | |
| 8622 | if (tp_features.sensors_pdev_attrs_registered) |
| 8623 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 8624 | &dev_attr_thinkpad_acpi_pdev_name); |
| 8625 | if (tpacpi_sensors_pdev) |
| 8626 | platform_device_unregister(tpacpi_sensors_pdev); |
| 8627 | if (tpacpi_pdev) |
| 8628 | platform_device_unregister(tpacpi_pdev); |
| 8629 | |
| 8630 | if (tp_features.sensors_pdrv_attrs_registered) |
| 8631 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 8632 | if (tp_features.platform_drv_attrs_registered) |
| 8633 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 8634 | |
| 8635 | if (tp_features.sensors_pdrv_registered) |
| 8636 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 8637 | |
| 8638 | if (tp_features.platform_drv_registered) |
| 8639 | platform_driver_unregister(&tpacpi_pdriver); |
| 8640 | |
| 8641 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8642 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8643 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8644 | if (tpacpi_wq) |
| 8645 | destroy_workqueue(tpacpi_wq); |
| 8646 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8647 | kfree(thinkpad_id.bios_version_str); |
| 8648 | kfree(thinkpad_id.ec_version_str); |
| 8649 | kfree(thinkpad_id.model_str); |
| 8650 | } |
| 8651 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 8652 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8653 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8654 | { |
| 8655 | int ret, i; |
| 8656 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 8657 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 8658 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8659 | /* Parameter checking */ |
| 8660 | if (hotkey_report_mode > 2) |
| 8661 | return -EINVAL; |
| 8662 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8663 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8664 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8665 | ret = get_thinkpad_model_data(&thinkpad_id); |
| 8666 | if (ret) { |
| 8667 | printk(TPACPI_ERR |
| 8668 | "unable to get DMI data: %d\n", ret); |
| 8669 | thinkpad_acpi_module_exit(); |
| 8670 | return ret; |
| 8671 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8672 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8673 | if (ret) { |
| 8674 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8675 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8677 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8678 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8679 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8680 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 8681 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8682 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8683 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
| 8684 | if (!tpacpi_wq) { |
| 8685 | thinkpad_acpi_module_exit(); |
| 8686 | return -ENOMEM; |
| 8687 | } |
| 8688 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8689 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8690 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8691 | printk(TPACPI_ERR |
| 8692 | "unable to create proc dir " TPACPI_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8693 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8694 | return -ENODEV; |
| 8695 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8696 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8697 | ret = platform_driver_register(&tpacpi_pdriver); |
| 8698 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8699 | printk(TPACPI_ERR |
| 8700 | "unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8701 | thinkpad_acpi_module_exit(); |
| 8702 | return ret; |
| 8703 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 8704 | tp_features.platform_drv_registered = 1; |
| 8705 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8706 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 8707 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8708 | printk(TPACPI_ERR |
| 8709 | "unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8710 | thinkpad_acpi_module_exit(); |
| 8711 | return ret; |
| 8712 | } |
| 8713 | tp_features.sensors_pdrv_registered = 1; |
| 8714 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8715 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8716 | if (!ret) { |
| 8717 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8718 | ret = tpacpi_create_driver_attributes( |
| 8719 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8720 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8721 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8722 | printk(TPACPI_ERR |
| 8723 | "unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8724 | thinkpad_acpi_module_exit(); |
| 8725 | return ret; |
| 8726 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8727 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8728 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8729 | |
| 8730 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8731 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8732 | NULL, 0); |
| 8733 | if (IS_ERR(tpacpi_pdev)) { |
| 8734 | ret = PTR_ERR(tpacpi_pdev); |
| 8735 | tpacpi_pdev = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8736 | printk(TPACPI_ERR "unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8737 | thinkpad_acpi_module_exit(); |
| 8738 | return ret; |
| 8739 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8740 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8741 | TPACPI_HWMON_DRVR_NAME, |
| 8742 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8743 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 8744 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 8745 | tpacpi_sensors_pdev = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8746 | printk(TPACPI_ERR |
| 8747 | "unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8748 | thinkpad_acpi_module_exit(); |
| 8749 | return ret; |
| 8750 | } |
| 8751 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 8752 | &dev_attr_thinkpad_acpi_pdev_name); |
| 8753 | if (ret) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8754 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8755 | "unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8756 | thinkpad_acpi_module_exit(); |
| 8757 | return ret; |
| 8758 | } |
| 8759 | tp_features.sensors_pdev_attrs_registered = 1; |
| 8760 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8761 | if (IS_ERR(tpacpi_hwmon)) { |
| 8762 | ret = PTR_ERR(tpacpi_hwmon); |
| 8763 | tpacpi_hwmon = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8764 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8765 | thinkpad_acpi_module_exit(); |
| 8766 | return ret; |
| 8767 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 8768 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8769 | tpacpi_inputdev = input_allocate_device(); |
| 8770 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8771 | printk(TPACPI_ERR "unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8772 | thinkpad_acpi_module_exit(); |
| 8773 | return -ENOMEM; |
| 8774 | } else { |
| 8775 | /* Prepare input device, but don't register */ |
| 8776 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8777 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8778 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 8779 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
| 8780 | thinkpad_id.vendor : |
| 8781 | PCI_VENDOR_ID_IBM; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8782 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 8783 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
Henrique de Moraes Holschuh | d112ef9 | 2009-12-09 01:36:26 +0000 | [diff] [blame] | 8784 | tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8785 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8786 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 8787 | ret = ibm_init(&ibms_init[i]); |
| 8788 | if (ret >= 0 && *ibms_init[i].param) |
| 8789 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8790 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8791 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8792 | return ret; |
| 8793 | } |
| 8794 | } |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8795 | ret = input_register_device(tpacpi_inputdev); |
| 8796 | if (ret < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8797 | printk(TPACPI_ERR "unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8798 | thinkpad_acpi_module_exit(); |
| 8799 | return ret; |
| 8800 | } else { |
| 8801 | tp_features.input_device_registered = 1; |
| 8802 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8803 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 8804 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8805 | return 0; |
| 8806 | } |
| 8807 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 8808 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 8809 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8810 | /* |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 8811 | * This will autoload the driver in almost every ThinkPad |
| 8812 | * in widespread use. |
| 8813 | * |
| 8814 | * Only _VERY_ old models, like the 240, 240x and 570 lack |
| 8815 | * the HKEY event interface. |
| 8816 | */ |
| 8817 | MODULE_DEVICE_TABLE(acpi, ibm_htk_device_ids); |
| 8818 | |
| 8819 | /* |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8820 | * DMI matching for module autoloading |
| 8821 | * |
| 8822 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 8823 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 8824 | * |
| 8825 | * Only models listed in thinkwiki will be supported, so add yours |
| 8826 | * if it is not there yet. |
| 8827 | */ |
| 8828 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
Mathieu Chouquet-Stringer | b36a50f | 2009-03-14 16:35:26 +0100 | [diff] [blame] | 8829 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*") |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8830 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8831 | /* Ancient thinkpad BIOSes have to be identified by |
| 8832 | * BIOS type or model number, and there are far less |
| 8833 | * BIOS types than model numbers... */ |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 8834 | IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8835 | |
Henrique de Moraes Holschuh | f68f53a | 2009-04-14 02:44:12 +0000 | [diff] [blame] | 8836 | MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>"); |
| 8837 | MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8838 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 8839 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8840 | MODULE_LICENSE("GPL"); |
| 8841 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8842 | module_init(thinkpad_acpi_module_init); |
| 8843 | module_exit(thinkpad_acpi_module_exit); |