Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 2 | * thinkpad_acpi.c - ThinkPad ACPI Extras |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> |
Henrique de Moraes Holschuh | 1c762ca | 2009-04-04 04:25:42 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
Henrique de Moraes Holschuh | a62bc91 | 2007-03-23 17:33:58 -0300 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 21 | * 02110-1301, USA. |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 22 | */ |
| 23 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 25 | |
Henrique de Moraes Holschuh | 5d2eb14 | 2009-12-15 21:51:13 -0200 | [diff] [blame] | 26 | #define TPACPI_VERSION "0.24" |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 27 | #define TPACPI_SYSFS_VERSION 0x020700 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 28 | |
| 29 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * Changelog: |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 31 | * 2007-10-20 changelog trimmed down |
| 32 | * |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 33 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
| 34 | * drivers/misc. |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 35 | * |
| 36 | * 2006-11-22 0.13 new maintainer |
| 37 | * changelog now lives in git commit history, and will |
| 38 | * not be updated further in-file. |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 39 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 40 | * 2005-03-17 0.11 support for 600e, 770x |
| 41 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 42 | * |
| 43 | * 2005-01-16 0.9 use MODULE_VERSION |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 44 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
| 45 | * fix parameter passing on module loading |
| 46 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
| 47 | * thanks to Jim Radford <radford@blackbean.org> |
| 48 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
| 49 | * thanks to Chris Wright <chrisw@osdl.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | */ |
| 51 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 52 | #include <linux/kernel.h> |
| 53 | #include <linux/module.h> |
| 54 | #include <linux/init.h> |
| 55 | #include <linux/types.h> |
| 56 | #include <linux/string.h> |
| 57 | #include <linux/list.h> |
| 58 | #include <linux/mutex.h> |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 59 | #include <linux/sched.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 60 | #include <linux/kthread.h> |
| 61 | #include <linux/freezer.h> |
| 62 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 63 | #include <linux/slab.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 64 | |
| 65 | #include <linux/nvram.h> |
| 66 | #include <linux/proc_fs.h> |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 67 | #include <linux/seq_file.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 68 | #include <linux/sysfs.h> |
| 69 | #include <linux/backlight.h> |
| 70 | #include <linux/fb.h> |
| 71 | #include <linux/platform_device.h> |
| 72 | #include <linux/hwmon.h> |
| 73 | #include <linux/hwmon-sysfs.h> |
| 74 | #include <linux/input.h> |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 75 | #include <linux/leds.h> |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 76 | #include <linux/rfkill.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 77 | #include <asm/uaccess.h> |
| 78 | |
| 79 | #include <linux/dmi.h> |
| 80 | #include <linux/jiffies.h> |
| 81 | #include <linux/workqueue.h> |
| 82 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 83 | #include <sound/core.h> |
| 84 | #include <sound/control.h> |
| 85 | #include <sound/initval.h> |
| 86 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 87 | #include <acpi/acpi_drivers.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 88 | |
| 89 | #include <linux/pci_ids.h> |
| 90 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 91 | |
| 92 | /* ThinkPad CMOS commands */ |
| 93 | #define TP_CMOS_VOLUME_DOWN 0 |
| 94 | #define TP_CMOS_VOLUME_UP 1 |
| 95 | #define TP_CMOS_VOLUME_MUTE 2 |
| 96 | #define TP_CMOS_BRIGHTNESS_UP 4 |
| 97 | #define TP_CMOS_BRIGHTNESS_DOWN 5 |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 98 | #define TP_CMOS_THINKLIGHT_ON 12 |
| 99 | #define TP_CMOS_THINKLIGHT_OFF 13 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 100 | |
| 101 | /* NVRAM Addresses */ |
| 102 | enum tp_nvram_addr { |
| 103 | TP_NVRAM_ADDR_HK2 = 0x57, |
| 104 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, |
| 105 | TP_NVRAM_ADDR_VIDEO = 0x59, |
| 106 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, |
| 107 | TP_NVRAM_ADDR_MIXER = 0x60, |
| 108 | }; |
| 109 | |
| 110 | /* NVRAM bit masks */ |
| 111 | enum { |
| 112 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, |
| 113 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, |
| 114 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, |
| 115 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, |
| 116 | TP_NVRAM_MASK_THINKLIGHT = 0x10, |
| 117 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, |
| 118 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, |
| 119 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, |
| 120 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, |
| 121 | TP_NVRAM_MASK_MUTE = 0x40, |
| 122 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, |
| 123 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, |
| 124 | TP_NVRAM_POS_LEVEL_VOLUME = 0, |
| 125 | }; |
| 126 | |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 127 | /* Misc NVRAM-related */ |
| 128 | enum { |
| 129 | TP_NVRAM_LEVEL_VOLUME_MAX = 14, |
| 130 | }; |
| 131 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 132 | /* ACPI HIDs */ |
Manoj Iyer | 9fbdaeb | 2011-05-08 18:04:29 -0400 | [diff] [blame] | 133 | #define TPACPI_ACPI_IBM_HKEY_HID "IBM0068" |
| 134 | #define TPACPI_ACPI_LENOVO_HKEY_HID "LEN0068" |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 135 | #define TPACPI_ACPI_EC_HID "PNP0C09" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 136 | |
| 137 | /* Input IDs */ |
| 138 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ |
| 139 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 |
| 140 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 141 | /* ACPI \WGSV commands */ |
| 142 | enum { |
| 143 | TP_ACPI_WGSV_GET_STATE = 0x01, /* Get state information */ |
| 144 | TP_ACPI_WGSV_PWR_ON_ON_RESUME = 0x02, /* Resume WWAN powered on */ |
| 145 | TP_ACPI_WGSV_PWR_OFF_ON_RESUME = 0x03, /* Resume WWAN powered off */ |
| 146 | TP_ACPI_WGSV_SAVE_STATE = 0x04, /* Save state for S4/S5 */ |
| 147 | }; |
| 148 | |
| 149 | /* TP_ACPI_WGSV_GET_STATE bits */ |
| 150 | enum { |
| 151 | TP_ACPI_WGSV_STATE_WWANEXIST = 0x0001, /* WWAN hw available */ |
| 152 | TP_ACPI_WGSV_STATE_WWANPWR = 0x0002, /* WWAN radio enabled */ |
| 153 | TP_ACPI_WGSV_STATE_WWANPWRRES = 0x0004, /* WWAN state at resume */ |
| 154 | TP_ACPI_WGSV_STATE_WWANBIOSOFF = 0x0008, /* WWAN disabled in BIOS */ |
| 155 | TP_ACPI_WGSV_STATE_BLTHEXIST = 0x0001, /* BLTH hw available */ |
| 156 | TP_ACPI_WGSV_STATE_BLTHPWR = 0x0002, /* BLTH radio enabled */ |
| 157 | TP_ACPI_WGSV_STATE_BLTHPWRRES = 0x0004, /* BLTH state at resume */ |
| 158 | TP_ACPI_WGSV_STATE_BLTHBIOSOFF = 0x0008, /* BLTH disabled in BIOS */ |
| 159 | TP_ACPI_WGSV_STATE_UWBEXIST = 0x0010, /* UWB hw available */ |
| 160 | TP_ACPI_WGSV_STATE_UWBPWR = 0x0020, /* UWB radio enabled */ |
| 161 | }; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 162 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 163 | /* HKEY events */ |
| 164 | enum tpacpi_hkey_event_t { |
| 165 | /* Hotkey-related */ |
| 166 | TP_HKEY_EV_HOTKEY_BASE = 0x1001, /* first hotkey (FN+F1) */ |
| 167 | TP_HKEY_EV_BRGHT_UP = 0x1010, /* Brightness up */ |
| 168 | TP_HKEY_EV_BRGHT_DOWN = 0x1011, /* Brightness down */ |
| 169 | TP_HKEY_EV_VOL_UP = 0x1015, /* Volume up or unmute */ |
| 170 | TP_HKEY_EV_VOL_DOWN = 0x1016, /* Volume down or unmute */ |
| 171 | TP_HKEY_EV_VOL_MUTE = 0x1017, /* Mixer output mute */ |
| 172 | |
| 173 | /* Reasons for waking up from S3/S4 */ |
| 174 | TP_HKEY_EV_WKUP_S3_UNDOCK = 0x2304, /* undock requested, S3 */ |
| 175 | TP_HKEY_EV_WKUP_S4_UNDOCK = 0x2404, /* undock requested, S4 */ |
| 176 | TP_HKEY_EV_WKUP_S3_BAYEJ = 0x2305, /* bay ejection req, S3 */ |
| 177 | TP_HKEY_EV_WKUP_S4_BAYEJ = 0x2405, /* bay ejection req, S4 */ |
| 178 | TP_HKEY_EV_WKUP_S3_BATLOW = 0x2313, /* battery empty, S3 */ |
| 179 | TP_HKEY_EV_WKUP_S4_BATLOW = 0x2413, /* battery empty, S4 */ |
| 180 | |
| 181 | /* Auto-sleep after eject request */ |
| 182 | TP_HKEY_EV_BAYEJ_ACK = 0x3003, /* bay ejection complete */ |
| 183 | TP_HKEY_EV_UNDOCK_ACK = 0x4003, /* undock complete */ |
| 184 | |
| 185 | /* Misc bay events */ |
| 186 | TP_HKEY_EV_OPTDRV_EJ = 0x3006, /* opt. drive tray ejected */ |
Henrique de Moraes Holschuh | a50245a | 2011-06-05 16:22:35 -0300 | [diff] [blame] | 187 | TP_HKEY_EV_HOTPLUG_DOCK = 0x4010, /* docked into hotplug dock |
| 188 | or port replicator */ |
| 189 | TP_HKEY_EV_HOTPLUG_UNDOCK = 0x4011, /* undocked from hotplug |
| 190 | dock or port replicator */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 191 | |
| 192 | /* User-interface events */ |
| 193 | TP_HKEY_EV_LID_CLOSE = 0x5001, /* laptop lid closed */ |
| 194 | TP_HKEY_EV_LID_OPEN = 0x5002, /* laptop lid opened */ |
| 195 | TP_HKEY_EV_TABLET_TABLET = 0x5009, /* tablet swivel up */ |
| 196 | TP_HKEY_EV_TABLET_NOTEBOOK = 0x500a, /* tablet swivel down */ |
| 197 | TP_HKEY_EV_PEN_INSERTED = 0x500b, /* tablet pen inserted */ |
| 198 | TP_HKEY_EV_PEN_REMOVED = 0x500c, /* tablet pen removed */ |
| 199 | TP_HKEY_EV_BRGHT_CHANGED = 0x5010, /* backlight control event */ |
| 200 | |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 201 | /* Key-related user-interface events */ |
| 202 | TP_HKEY_EV_KEY_NUMLOCK = 0x6000, /* NumLock key pressed */ |
| 203 | TP_HKEY_EV_KEY_FN = 0x6005, /* Fn key pressed? E420 */ |
| 204 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 205 | /* Thermal events */ |
| 206 | TP_HKEY_EV_ALARM_BAT_HOT = 0x6011, /* battery too hot */ |
| 207 | TP_HKEY_EV_ALARM_BAT_XHOT = 0x6012, /* battery critically hot */ |
| 208 | TP_HKEY_EV_ALARM_SENSOR_HOT = 0x6021, /* sensor too hot */ |
| 209 | TP_HKEY_EV_ALARM_SENSOR_XHOT = 0x6022, /* sensor critically hot */ |
| 210 | TP_HKEY_EV_THM_TABLE_CHANGED = 0x6030, /* thermal table changed */ |
| 211 | |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 212 | TP_HKEY_EV_UNK_6040 = 0x6040, /* Related to AC change? |
| 213 | some sort of APM hint, |
| 214 | W520 */ |
| 215 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 216 | /* Misc */ |
| 217 | TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */ |
| 218 | }; |
| 219 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 220 | /**************************************************************************** |
| 221 | * Main driver |
| 222 | */ |
| 223 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 224 | #define TPACPI_NAME "thinkpad" |
| 225 | #define TPACPI_DESC "ThinkPad ACPI Extras" |
| 226 | #define TPACPI_FILE TPACPI_NAME "_acpi" |
| 227 | #define TPACPI_URL "http://ibm-acpi.sf.net/" |
| 228 | #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 229 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 230 | #define TPACPI_PROC_DIR "ibm" |
| 231 | #define TPACPI_ACPI_EVENT_PREFIX "ibm" |
| 232 | #define TPACPI_DRVR_NAME TPACPI_FILE |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 233 | #define TPACPI_DRVR_SHORTNAME "tpacpi" |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 234 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 235 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 236 | #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd" |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 237 | #define TPACPI_WORKQUEUE_NAME "ktpacpid" |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 238 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 239 | #define TPACPI_MAX_ACPI_ARGS 3 |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 240 | |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 241 | /* Debugging printk groups */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 242 | #define TPACPI_DBG_ALL 0xffff |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 243 | #define TPACPI_DBG_DISCLOSETASK 0x8000 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 244 | #define TPACPI_DBG_INIT 0x0001 |
| 245 | #define TPACPI_DBG_EXIT 0x0002 |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 246 | #define TPACPI_DBG_RFKILL 0x0004 |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 247 | #define TPACPI_DBG_HKEY 0x0008 |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 248 | #define TPACPI_DBG_FAN 0x0010 |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 249 | #define TPACPI_DBG_BRGHT 0x0020 |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 250 | #define TPACPI_DBG_MIXER 0x0040 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 251 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 252 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 253 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 254 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 255 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 256 | |
| 257 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 258 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 259 | */ |
| 260 | |
| 261 | struct ibm_struct; |
| 262 | |
| 263 | struct tp_acpi_drv_struct { |
| 264 | const struct acpi_device_id *hid; |
| 265 | struct acpi_driver *driver; |
| 266 | |
| 267 | void (*notify) (struct ibm_struct *, u32); |
| 268 | acpi_handle *handle; |
| 269 | u32 type; |
| 270 | struct acpi_device *device; |
| 271 | }; |
| 272 | |
| 273 | struct ibm_struct { |
| 274 | char *name; |
| 275 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 276 | int (*read) (struct seq_file *); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 277 | int (*write) (char *); |
| 278 | void (*exit) (void); |
| 279 | void (*resume) (void); |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 280 | void (*suspend) (void); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 281 | void (*shutdown) (void); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 282 | |
| 283 | struct list_head all_drivers; |
| 284 | |
| 285 | struct tp_acpi_drv_struct *acpi; |
| 286 | |
| 287 | struct { |
| 288 | u8 acpi_driver_registered:1; |
| 289 | u8 acpi_notify_installed:1; |
| 290 | u8 proc_created:1; |
| 291 | u8 init_called:1; |
| 292 | u8 experimental:1; |
| 293 | } flags; |
| 294 | }; |
| 295 | |
| 296 | struct ibm_init_struct { |
| 297 | char param[32]; |
| 298 | |
| 299 | int (*init) (struct ibm_init_struct *); |
Al Viro | d161a13 | 2011-07-24 03:36:29 -0400 | [diff] [blame] | 300 | umode_t base_procfs_mode; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 301 | struct ibm_struct *data; |
| 302 | }; |
| 303 | |
| 304 | static struct { |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 305 | u32 bluetooth:1; |
| 306 | u32 hotkey:1; |
| 307 | u32 hotkey_mask:1; |
| 308 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 309 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 310 | u32 light:1; |
| 311 | u32 light_status:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 312 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 313 | u32 bright_unkfw:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 314 | u32 wan:1; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 315 | u32 uwb:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 316 | u32 fan_ctrl_status_undef:1; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 317 | u32 second_fan:1; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 318 | u32 beep_needs_two_args:1; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 319 | u32 mixer_no_level_control:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 320 | u32 input_device_registered:1; |
| 321 | u32 platform_drv_registered:1; |
| 322 | u32 platform_drv_attrs_registered:1; |
| 323 | u32 sensors_pdrv_registered:1; |
| 324 | u32 sensors_pdrv_attrs_registered:1; |
| 325 | u32 sensors_pdev_attrs_registered:1; |
| 326 | u32 hotkey_poll_active:1; |
| 327 | } tp_features; |
| 328 | |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 329 | static struct { |
| 330 | u16 hotkey_mask_ff:1; |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 331 | u16 volume_ctrl_forbidden:1; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 332 | } tp_warned; |
| 333 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 334 | struct thinkpad_id_data { |
| 335 | unsigned int vendor; /* ThinkPad vendor: |
| 336 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 337 | |
| 338 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 339 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 340 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 341 | u16 bios_model; /* 1Y = 0x5931, 0 = unknown */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 342 | u16 ec_model; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 343 | u16 bios_release; /* 1ZETK1WW = 0x314b, 0 = unknown */ |
| 344 | u16 ec_release; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 345 | |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 346 | char *model_str; /* ThinkPad T43 */ |
| 347 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 348 | }; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 349 | static struct thinkpad_id_data thinkpad_id; |
| 350 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 351 | static enum { |
| 352 | TPACPI_LIFE_INIT = 0, |
| 353 | TPACPI_LIFE_RUNNING, |
| 354 | TPACPI_LIFE_EXITING, |
| 355 | } tpacpi_lifecycle; |
| 356 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 357 | static int experimental; |
| 358 | static u32 dbg_level; |
| 359 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 360 | static struct workqueue_struct *tpacpi_wq; |
| 361 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 362 | enum led_status_t { |
| 363 | TPACPI_LED_OFF = 0, |
| 364 | TPACPI_LED_ON, |
| 365 | TPACPI_LED_BLINK, |
| 366 | }; |
| 367 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 368 | /* Special LED class that can defer work */ |
| 369 | struct tpacpi_led_classdev { |
| 370 | struct led_classdev led_classdev; |
| 371 | struct work_struct work; |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 372 | enum led_status_t new_state; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 373 | unsigned int led; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 374 | }; |
| 375 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 376 | /* brightness level capabilities */ |
| 377 | static unsigned int bright_maxlvl; /* 0 = unknown */ |
| 378 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 379 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 380 | static int dbg_wlswemul; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 381 | static bool tpacpi_wlsw_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 382 | static int dbg_bluetoothemul; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 383 | static bool tpacpi_bluetooth_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 384 | static int dbg_wwanemul; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 385 | static bool tpacpi_wwan_emulstate; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 386 | static int dbg_uwbemul; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 387 | static bool tpacpi_uwb_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 388 | #endif |
| 389 | |
| 390 | |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 391 | /************************************************************************* |
| 392 | * Debugging helpers |
| 393 | */ |
| 394 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 395 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 396 | do { \ |
| 397 | if (dbg_level & (a_dbg_level)) \ |
| 398 | printk(KERN_DEBUG pr_fmt("%s: " format), \ |
| 399 | __func__, ##arg); \ |
| 400 | } while (0) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 401 | |
| 402 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 403 | #define vdbg_printk dbg_printk |
| 404 | static const char *str_supported(int is_supported); |
| 405 | #else |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 406 | static inline const char *str_supported(int is_supported) { return ""; } |
| 407 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 408 | no_printk(format, ##arg) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 409 | #endif |
| 410 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 411 | static void tpacpi_log_usertask(const char * const what) |
| 412 | { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 413 | printk(KERN_DEBUG pr_fmt("%s: access by process with PID %d\n"), |
| 414 | what, task_tgid_vnr(current)); |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 417 | #define tpacpi_disclose_usertask(what, format, arg...) \ |
| 418 | do { \ |
| 419 | if (unlikely((dbg_level & TPACPI_DBG_DISCLOSETASK) && \ |
| 420 | (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \ |
| 421 | printk(KERN_DEBUG pr_fmt("%s: PID %d: " format), \ |
| 422 | what, task_tgid_vnr(current), ## arg); \ |
| 423 | } \ |
| 424 | } while (0) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 425 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 426 | /* |
| 427 | * Quirk handling helpers |
| 428 | * |
| 429 | * ThinkPad IDs and versions seen in the field so far |
| 430 | * are two-characters from the set [0-9A-Z], i.e. base 36. |
| 431 | * |
| 432 | * We use values well outside that range as specials. |
| 433 | */ |
| 434 | |
| 435 | #define TPACPI_MATCH_ANY 0xffffU |
| 436 | #define TPACPI_MATCH_UNKNOWN 0U |
| 437 | |
| 438 | /* TPID('1', 'Y') == 0x5931 */ |
| 439 | #define TPID(__c1, __c2) (((__c2) << 8) | (__c1)) |
| 440 | |
| 441 | #define TPACPI_Q_IBM(__id1, __id2, __quirk) \ |
| 442 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 443 | .bios = TPID(__id1, __id2), \ |
| 444 | .ec = TPACPI_MATCH_ANY, \ |
| 445 | .quirks = (__quirk) } |
| 446 | |
| 447 | #define TPACPI_Q_LNV(__id1, __id2, __quirk) \ |
| 448 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 449 | .bios = TPID(__id1, __id2), \ |
| 450 | .ec = TPACPI_MATCH_ANY, \ |
| 451 | .quirks = (__quirk) } |
| 452 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 453 | #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \ |
| 454 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 455 | .bios = TPACPI_MATCH_ANY, \ |
| 456 | .ec = TPID(__id1, __id2), \ |
| 457 | .quirks = (__quirk) } |
| 458 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 459 | struct tpacpi_quirk { |
| 460 | unsigned int vendor; |
| 461 | u16 bios; |
| 462 | u16 ec; |
| 463 | unsigned long quirks; |
| 464 | }; |
| 465 | |
| 466 | /** |
| 467 | * tpacpi_check_quirks() - search BIOS/EC version on a list |
| 468 | * @qlist: array of &struct tpacpi_quirk |
| 469 | * @qlist_size: number of elements in @qlist |
| 470 | * |
| 471 | * Iterates over a quirks list until one is found that matches the |
| 472 | * ThinkPad's vendor, BIOS and EC model. |
| 473 | * |
| 474 | * Returns 0 if nothing matches, otherwise returns the quirks field of |
| 475 | * the matching &struct tpacpi_quirk entry. |
| 476 | * |
| 477 | * The match criteria is: vendor, ec and bios much match. |
| 478 | */ |
| 479 | static unsigned long __init tpacpi_check_quirks( |
| 480 | const struct tpacpi_quirk *qlist, |
| 481 | unsigned int qlist_size) |
| 482 | { |
| 483 | while (qlist_size) { |
| 484 | if ((qlist->vendor == thinkpad_id.vendor || |
| 485 | qlist->vendor == TPACPI_MATCH_ANY) && |
| 486 | (qlist->bios == thinkpad_id.bios_model || |
| 487 | qlist->bios == TPACPI_MATCH_ANY) && |
| 488 | (qlist->ec == thinkpad_id.ec_model || |
| 489 | qlist->ec == TPACPI_MATCH_ANY)) |
| 490 | return qlist->quirks; |
| 491 | |
| 492 | qlist_size--; |
| 493 | qlist++; |
| 494 | } |
| 495 | return 0; |
| 496 | } |
| 497 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 498 | static inline bool __pure __init tpacpi_is_lenovo(void) |
| 499 | { |
| 500 | return thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO; |
| 501 | } |
| 502 | |
| 503 | static inline bool __pure __init tpacpi_is_ibm(void) |
| 504 | { |
| 505 | return thinkpad_id.vendor == PCI_VENDOR_ID_IBM; |
| 506 | } |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 507 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 508 | /**************************************************************************** |
| 509 | **************************************************************************** |
| 510 | * |
| 511 | * ACPI Helpers and device model |
| 512 | * |
| 513 | **************************************************************************** |
| 514 | ****************************************************************************/ |
| 515 | |
| 516 | /************************************************************************* |
| 517 | * ACPI basic handles |
| 518 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 520 | static acpi_handle root_handle; |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 521 | static acpi_handle ec_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 523 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | static acpi_handle object##_handle; \ |
Andi Kleen | 3bd0189 | 2012-10-04 17:12:01 -0700 | [diff] [blame] | 525 | static const acpi_handle * const object##_parent __initconst = \ |
Henrique de Moraes Holschuh | ef07a5ab | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 526 | &parent##_handle; \ |
| 527 | static char *object##_paths[] __initdata = { paths } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 529 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 530 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 532 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 533 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 534 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 535 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 536 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 537 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 538 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 539 | "^HKEY", /* R30, R31 */ |
| 540 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 541 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 542 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 543 | /************************************************************************* |
| 544 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 545 | */ |
| 546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | static int acpi_evalf(acpi_handle handle, |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 548 | int *res, char *method, char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
| 550 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 551 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 552 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 553 | struct acpi_buffer result, *resultp; |
| 554 | union acpi_object out_obj; |
| 555 | acpi_status status; |
| 556 | va_list ap; |
| 557 | char res_type; |
| 558 | int success; |
| 559 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | if (!*fmt) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 562 | pr_err("acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | if (*fmt == 'q') { |
| 567 | quiet = 1; |
| 568 | fmt++; |
| 569 | } else |
| 570 | quiet = 0; |
| 571 | |
| 572 | res_type = *(fmt++); |
| 573 | |
| 574 | params.count = 0; |
| 575 | params.pointer = &in_objs[0]; |
| 576 | |
| 577 | va_start(ap, fmt); |
| 578 | while (*fmt) { |
| 579 | char c = *(fmt++); |
| 580 | switch (c) { |
| 581 | case 'd': /* int */ |
| 582 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 583 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 584 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 585 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | default: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 587 | pr_err("acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | "with invalid format character '%c'\n", c); |
Jesper Juhl | 2136585 | 2010-12-24 19:56:28 +0100 | [diff] [blame] | 589 | va_end(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | } |
| 593 | va_end(ap); |
| 594 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 595 | if (res_type != 'v') { |
| 596 | result.length = sizeof(out_obj); |
| 597 | result.pointer = &out_obj; |
| 598 | resultp = &result; |
| 599 | } else |
| 600 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 602 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
| 604 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 605 | case 'd': /* int */ |
Henrique de Moraes Holschuh | 263f4a3 | 2010-05-16 19:45:45 -0300 | [diff] [blame] | 606 | success = (status == AE_OK && |
| 607 | out_obj.type == ACPI_TYPE_INTEGER); |
| 608 | if (success && res) |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 609 | *res = out_obj.integer.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 611 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | success = status == AE_OK; |
| 613 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 614 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | default: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 616 | pr_err("acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | "with invalid format character '%c'\n", res_type); |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | if (!success && !quiet) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 622 | pr_err("acpi_evalf(%s, %s, ...) failed: %s\n", |
Henrique de Moraes Holschuh | 263f4a3 | 2010-05-16 19:45:45 -0300 | [diff] [blame] | 623 | method, fmt0, acpi_format_exception(status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | return success; |
| 626 | } |
| 627 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 628 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 629 | { |
| 630 | int v; |
| 631 | |
| 632 | if (ecrd_handle) { |
| 633 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 634 | return 0; |
| 635 | *p = v; |
| 636 | } else { |
| 637 | if (ec_read(i, p) < 0) |
| 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | return 1; |
| 642 | } |
| 643 | |
| 644 | static int acpi_ec_write(int i, u8 v) |
| 645 | { |
| 646 | if (ecwr_handle) { |
| 647 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 648 | return 0; |
| 649 | } else { |
| 650 | if (ec_write(i, v) < 0) |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | return 1; |
| 655 | } |
| 656 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 657 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 658 | { |
| 659 | if (!cmos_handle) |
| 660 | return -ENXIO; |
| 661 | |
| 662 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 663 | return -EIO; |
| 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 668 | /************************************************************************* |
| 669 | * ACPI device model |
| 670 | */ |
| 671 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 672 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 673 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | ef07a5ab | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 674 | object##_paths, ARRAY_SIZE(object##_paths)) |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 675 | |
Henrique de Moraes Holschuh | ef07a5ab | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 676 | static void __init drv_acpi_handle_init(const char *name, |
| 677 | acpi_handle *handle, const acpi_handle parent, |
| 678 | char **paths, const int num_paths) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 679 | { |
| 680 | int i; |
| 681 | acpi_status status; |
| 682 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 683 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 684 | name); |
| 685 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 686 | for (i = 0; i < num_paths; i++) { |
| 687 | status = acpi_get_handle(parent, paths[i], handle); |
| 688 | if (ACPI_SUCCESS(status)) { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 689 | dbg_printk(TPACPI_DBG_INIT, |
| 690 | "Found ACPI handle %s for %s\n", |
Henrique de Moraes Holschuh | ef07a5ab | 2010-05-16 19:45:54 -0300 | [diff] [blame] | 691 | paths[i], name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 692 | return; |
| 693 | } |
| 694 | } |
| 695 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 696 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 697 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 698 | *handle = NULL; |
| 699 | } |
| 700 | |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 701 | static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle, |
| 702 | u32 level, void *context, void **return_value) |
| 703 | { |
| 704 | *(acpi_handle *)return_value = handle; |
| 705 | |
| 706 | return AE_CTRL_TERMINATE; |
| 707 | } |
| 708 | |
| 709 | static void __init tpacpi_acpi_handle_locate(const char *name, |
| 710 | const char *hid, |
| 711 | acpi_handle *handle) |
| 712 | { |
| 713 | acpi_status status; |
| 714 | acpi_handle device_found; |
| 715 | |
| 716 | BUG_ON(!name || !hid || !handle); |
| 717 | vdbg_printk(TPACPI_DBG_INIT, |
| 718 | "trying to locate ACPI handle for %s, using HID %s\n", |
| 719 | name, hid); |
| 720 | |
| 721 | memset(&device_found, 0, sizeof(device_found)); |
| 722 | status = acpi_get_devices(hid, tpacpi_acpi_handle_locate_callback, |
| 723 | (void *)name, &device_found); |
| 724 | |
| 725 | *handle = NULL; |
| 726 | |
| 727 | if (ACPI_SUCCESS(status)) { |
| 728 | *handle = device_found; |
| 729 | dbg_printk(TPACPI_DBG_INIT, |
| 730 | "Found ACPI handle for %s\n", name); |
| 731 | } else { |
| 732 | vdbg_printk(TPACPI_DBG_INIT, |
| 733 | "Could not locate an ACPI handle for %s: %s\n", |
| 734 | name, acpi_format_exception(status)); |
| 735 | } |
| 736 | } |
| 737 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 738 | 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] | 739 | { |
| 740 | struct ibm_struct *ibm = data; |
| 741 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 742 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 743 | return; |
| 744 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 745 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 746 | return; |
| 747 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 748 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 749 | } |
| 750 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 751 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 752 | { |
| 753 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 754 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 755 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 756 | BUG_ON(!ibm->acpi); |
| 757 | |
| 758 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 759 | return 0; |
| 760 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 761 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 762 | "setting up ACPI notify for %s\n", ibm->name); |
| 763 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 764 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 765 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 766 | pr_err("acpi_bus_get_device(%s) failed: %d\n", ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 767 | return -ENODEV; |
| 768 | } |
| 769 | |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 770 | ibm->acpi->device->driver_data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 771 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 772 | TPACPI_ACPI_EVENT_PREFIX, |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 773 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 774 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 775 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 776 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 777 | if (ACPI_FAILURE(status)) { |
| 778 | if (status == AE_ALREADY_EXISTS) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 779 | pr_notice("another device driver is already " |
| 780 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 781 | } else { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 782 | pr_err("acpi_install_notify_handler(%s) failed: %s\n", |
Henrique de Moraes Holschuh | 72f1992 | 2010-05-16 19:45:48 -0300 | [diff] [blame] | 783 | ibm->name, acpi_format_exception(status)); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 784 | } |
| 785 | return -ENODEV; |
| 786 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 787 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 788 | return 0; |
| 789 | } |
| 790 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 791 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 792 | { |
| 793 | return 0; |
| 794 | } |
| 795 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 796 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 797 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 798 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 799 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 800 | dbg_printk(TPACPI_DBG_INIT, |
| 801 | "registering %s as an ACPI driver\n", ibm->name); |
| 802 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 803 | BUG_ON(!ibm->acpi); |
| 804 | |
| 805 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 806 | if (!ibm->acpi->driver) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 807 | pr_err("failed to allocate memory for ibm->acpi->driver\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 808 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 809 | } |
| 810 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 811 | 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] | 812 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 813 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 814 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 815 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 816 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 817 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 818 | pr_err("acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 819 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 820 | kfree(ibm->acpi->driver); |
| 821 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 822 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 823 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 824 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 825 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | |
| 829 | /**************************************************************************** |
| 830 | **************************************************************************** |
| 831 | * |
| 832 | * Procfs Helpers |
| 833 | * |
| 834 | **************************************************************************** |
| 835 | ****************************************************************************/ |
| 836 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 837 | static int dispatch_proc_show(struct seq_file *m, void *v) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 838 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 839 | struct ibm_struct *ibm = m->private; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 840 | |
| 841 | if (!ibm || !ibm->read) |
| 842 | return -EINVAL; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 843 | return ibm->read(m); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 844 | } |
| 845 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 846 | static int dispatch_proc_open(struct inode *inode, struct file *file) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 847 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 848 | return single_open(file, dispatch_proc_show, PDE(inode)->data); |
| 849 | } |
| 850 | |
| 851 | static ssize_t dispatch_proc_write(struct file *file, |
| 852 | const char __user *userbuf, |
| 853 | size_t count, loff_t *pos) |
| 854 | { |
| 855 | struct ibm_struct *ibm = PDE(file->f_path.dentry->d_inode)->data; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 856 | char *kernbuf; |
| 857 | int ret; |
| 858 | |
| 859 | if (!ibm || !ibm->write) |
| 860 | return -EINVAL; |
Michael Buesch | 5b05d46 | 2009-08-01 12:04:19 -0300 | [diff] [blame] | 861 | if (count > PAGE_SIZE - 2) |
| 862 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 863 | |
| 864 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 865 | if (!kernbuf) |
| 866 | return -ENOMEM; |
| 867 | |
| 868 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 869 | kfree(kernbuf); |
| 870 | return -EFAULT; |
| 871 | } |
| 872 | |
| 873 | kernbuf[count] = 0; |
| 874 | strcat(kernbuf, ","); |
| 875 | ret = ibm->write(kernbuf); |
| 876 | if (ret == 0) |
| 877 | ret = count; |
| 878 | |
| 879 | kfree(kernbuf); |
| 880 | |
| 881 | return ret; |
| 882 | } |
| 883 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 884 | static const struct file_operations dispatch_proc_fops = { |
| 885 | .owner = THIS_MODULE, |
| 886 | .open = dispatch_proc_open, |
| 887 | .read = seq_read, |
| 888 | .llseek = seq_lseek, |
| 889 | .release = single_release, |
| 890 | .write = dispatch_proc_write, |
| 891 | }; |
| 892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | static char *next_cmd(char **cmds) |
| 894 | { |
| 895 | char *start = *cmds; |
| 896 | char *end; |
| 897 | |
| 898 | while ((end = strchr(start, ',')) && end == start) |
| 899 | start = end + 1; |
| 900 | |
| 901 | if (!end) |
| 902 | return NULL; |
| 903 | |
| 904 | *end = 0; |
| 905 | *cmds = end + 1; |
| 906 | return start; |
| 907 | } |
| 908 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 909 | |
| 910 | /**************************************************************************** |
| 911 | **************************************************************************** |
| 912 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 913 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 914 | * |
| 915 | **************************************************************************** |
| 916 | ****************************************************************************/ |
| 917 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 918 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 919 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 920 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 921 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 922 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 923 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 924 | |
Rafael J. Wysocki | 3567a4e2 | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 925 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | 4959a78 | 2012-06-27 23:19:01 +0200 | [diff] [blame] | 926 | static int tpacpi_suspend_handler(struct device *dev) |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 927 | { |
| 928 | struct ibm_struct *ibm, *itmp; |
| 929 | |
| 930 | list_for_each_entry_safe(ibm, itmp, |
| 931 | &tpacpi_all_drivers, |
| 932 | all_drivers) { |
| 933 | if (ibm->suspend) |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 934 | (ibm->suspend)(); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | return 0; |
| 938 | } |
| 939 | |
Rafael J. Wysocki | 4959a78 | 2012-06-27 23:19:01 +0200 | [diff] [blame] | 940 | static int tpacpi_resume_handler(struct device *dev) |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 941 | { |
| 942 | struct ibm_struct *ibm, *itmp; |
| 943 | |
| 944 | list_for_each_entry_safe(ibm, itmp, |
| 945 | &tpacpi_all_drivers, |
| 946 | all_drivers) { |
| 947 | if (ibm->resume) |
| 948 | (ibm->resume)(); |
| 949 | } |
| 950 | |
| 951 | return 0; |
| 952 | } |
Rafael J. Wysocki | 3567a4e2 | 2012-08-09 23:00:13 +0200 | [diff] [blame] | 953 | #endif |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 954 | |
Rafael J. Wysocki | 4959a78 | 2012-06-27 23:19:01 +0200 | [diff] [blame] | 955 | static SIMPLE_DEV_PM_OPS(tpacpi_pm, |
| 956 | tpacpi_suspend_handler, tpacpi_resume_handler); |
| 957 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 958 | static void tpacpi_shutdown_handler(struct platform_device *pdev) |
| 959 | { |
| 960 | struct ibm_struct *ibm, *itmp; |
| 961 | |
| 962 | list_for_each_entry_safe(ibm, itmp, |
| 963 | &tpacpi_all_drivers, |
| 964 | all_drivers) { |
| 965 | if (ibm->shutdown) |
| 966 | (ibm->shutdown)(); |
| 967 | } |
| 968 | } |
| 969 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 970 | static struct platform_driver tpacpi_pdriver = { |
| 971 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 972 | .name = TPACPI_DRVR_NAME, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 973 | .owner = THIS_MODULE, |
Rafael J. Wysocki | 4959a78 | 2012-06-27 23:19:01 +0200 | [diff] [blame] | 974 | .pm = &tpacpi_pm, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 975 | }, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 976 | .shutdown = tpacpi_shutdown_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 977 | }; |
| 978 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 979 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 980 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 981 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 982 | .owner = THIS_MODULE, |
| 983 | }, |
| 984 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 985 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 986 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 987 | * sysfs support helpers |
| 988 | */ |
| 989 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 990 | struct attribute_set { |
| 991 | unsigned int members, max_members; |
| 992 | struct attribute_group group; |
| 993 | }; |
| 994 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 995 | struct attribute_set_obj { |
| 996 | struct attribute_set s; |
| 997 | struct attribute *a; |
| 998 | } __attribute__((packed)); |
| 999 | |
| 1000 | 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] | 1001 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1002 | { |
| 1003 | struct attribute_set_obj *sobj; |
| 1004 | |
| 1005 | if (max_members == 0) |
| 1006 | return NULL; |
| 1007 | |
| 1008 | /* Allocates space for implicit NULL at the end too */ |
| 1009 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 1010 | max_members * sizeof(struct attribute *), |
| 1011 | GFP_KERNEL); |
| 1012 | if (!sobj) |
| 1013 | return NULL; |
| 1014 | sobj->s.max_members = max_members; |
| 1015 | sobj->s.group.attrs = &sobj->a; |
| 1016 | sobj->s.group.name = name; |
| 1017 | |
| 1018 | return &sobj->s; |
| 1019 | } |
| 1020 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1021 | #define destroy_attr_set(_set) \ |
| 1022 | kfree(_set); |
| 1023 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1024 | /* 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] | 1025 | 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] | 1026 | { |
| 1027 | if (!s || !attr) |
| 1028 | return -EINVAL; |
| 1029 | |
| 1030 | if (s->members >= s->max_members) |
| 1031 | return -ENOMEM; |
| 1032 | |
| 1033 | s->group.attrs[s->members] = attr; |
| 1034 | s->members++; |
| 1035 | |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1039 | 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] | 1040 | struct attribute **attr, |
| 1041 | unsigned int count) |
| 1042 | { |
| 1043 | int i, res; |
| 1044 | |
| 1045 | for (i = 0; i < count; i++) { |
| 1046 | res = add_to_attr_set(s, attr[i]); |
| 1047 | if (res) |
| 1048 | return res; |
| 1049 | } |
| 1050 | |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1054 | 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] | 1055 | { |
| 1056 | sysfs_remove_group(kobj, &s->group); |
| 1057 | destroy_attr_set(s); |
| 1058 | } |
| 1059 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1060 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 1061 | sysfs_create_group(_kobj, &_attr_set->group) |
| 1062 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1063 | static int parse_strtoul(const char *buf, |
| 1064 | unsigned long max, unsigned long *value) |
| 1065 | { |
| 1066 | char *endp; |
| 1067 | |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 1068 | *value = simple_strtoul(skip_spaces(buf), &endp, 0); |
| 1069 | endp = skip_spaces(endp); |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1070 | if (*endp || *value > max) |
| 1071 | return -EINVAL; |
| 1072 | |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
Henrique de Moraes Holschuh | d64c81c4 | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 1076 | static void tpacpi_disable_brightness_delay(void) |
| 1077 | { |
| 1078 | if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0)) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1079 | pr_notice("ACPI backlight control delay disabled\n"); |
Henrique de Moraes Holschuh | d64c81c4 | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 1080 | } |
| 1081 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1082 | static void printk_deprecated_attribute(const char * const what, |
| 1083 | const char * const details) |
| 1084 | { |
| 1085 | tpacpi_log_usertask("deprecated sysfs attribute"); |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1086 | pr_warn("WARNING: sysfs attribute %s is deprecated and " |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1087 | "will be removed. %s\n", |
| 1088 | what, details); |
| 1089 | } |
| 1090 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1091 | /************************************************************************* |
| 1092 | * rfkill and radio control support helpers |
| 1093 | */ |
| 1094 | |
| 1095 | /* |
| 1096 | * ThinkPad-ACPI firmware handling model: |
| 1097 | * |
| 1098 | * WLSW (master wireless switch) is event-driven, and is common to all |
| 1099 | * firmware-controlled radios. It cannot be controlled, just monitored, |
| 1100 | * as expected. It overrides all radio state in firmware |
| 1101 | * |
| 1102 | * The kernel, a masked-off hotkey, and WLSW can change the radio state |
| 1103 | * (TODO: verify how WLSW interacts with the returned radio state). |
| 1104 | * |
| 1105 | * The only time there are shadow radio state changes, is when |
| 1106 | * masked-off hotkeys are used. |
| 1107 | */ |
| 1108 | |
| 1109 | /* |
| 1110 | * Internal driver API for radio state: |
| 1111 | * |
| 1112 | * int: < 0 = error, otherwise enum tpacpi_rfkill_state |
| 1113 | * bool: true means radio blocked (off) |
| 1114 | */ |
| 1115 | enum tpacpi_rfkill_state { |
| 1116 | TPACPI_RFK_RADIO_OFF = 0, |
| 1117 | TPACPI_RFK_RADIO_ON |
| 1118 | }; |
| 1119 | |
| 1120 | /* rfkill switches */ |
| 1121 | enum tpacpi_rfk_id { |
| 1122 | TPACPI_RFK_BLUETOOTH_SW_ID = 0, |
| 1123 | TPACPI_RFK_WWAN_SW_ID, |
| 1124 | TPACPI_RFK_UWB_SW_ID, |
| 1125 | TPACPI_RFK_SW_MAX |
| 1126 | }; |
| 1127 | |
| 1128 | static const char *tpacpi_rfkill_names[] = { |
| 1129 | [TPACPI_RFK_BLUETOOTH_SW_ID] = "bluetooth", |
| 1130 | [TPACPI_RFK_WWAN_SW_ID] = "wwan", |
| 1131 | [TPACPI_RFK_UWB_SW_ID] = "uwb", |
| 1132 | [TPACPI_RFK_SW_MAX] = NULL |
| 1133 | }; |
| 1134 | |
| 1135 | /* ThinkPad-ACPI rfkill subdriver */ |
| 1136 | struct tpacpi_rfk { |
| 1137 | struct rfkill *rfkill; |
| 1138 | enum tpacpi_rfk_id id; |
| 1139 | const struct tpacpi_rfk_ops *ops; |
| 1140 | }; |
| 1141 | |
| 1142 | struct tpacpi_rfk_ops { |
| 1143 | /* firmware interface */ |
| 1144 | int (*get_status)(void); |
| 1145 | int (*set_status)(const enum tpacpi_rfkill_state); |
| 1146 | }; |
| 1147 | |
| 1148 | static struct tpacpi_rfk *tpacpi_rfkill_switches[TPACPI_RFK_SW_MAX]; |
| 1149 | |
| 1150 | /* Query FW and update rfkill sw state for a given rfkill switch */ |
| 1151 | static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk *tp_rfk) |
| 1152 | { |
| 1153 | int status; |
| 1154 | |
| 1155 | if (!tp_rfk) |
| 1156 | return -ENODEV; |
| 1157 | |
| 1158 | status = (tp_rfk->ops->get_status)(); |
| 1159 | if (status < 0) |
| 1160 | return status; |
| 1161 | |
| 1162 | rfkill_set_sw_state(tp_rfk->rfkill, |
| 1163 | (status == TPACPI_RFK_RADIO_OFF)); |
| 1164 | |
| 1165 | return status; |
| 1166 | } |
| 1167 | |
| 1168 | /* Query FW and update rfkill sw state for all rfkill switches */ |
| 1169 | static void tpacpi_rfk_update_swstate_all(void) |
| 1170 | { |
| 1171 | unsigned int i; |
| 1172 | |
| 1173 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) |
| 1174 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[i]); |
| 1175 | } |
| 1176 | |
| 1177 | /* |
| 1178 | * Sync the HW-blocking state of all rfkill switches, |
| 1179 | * do notice it causes the rfkill core to schedule uevents |
| 1180 | */ |
| 1181 | static void tpacpi_rfk_update_hwblock_state(bool blocked) |
| 1182 | { |
| 1183 | unsigned int i; |
| 1184 | struct tpacpi_rfk *tp_rfk; |
| 1185 | |
| 1186 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) { |
| 1187 | tp_rfk = tpacpi_rfkill_switches[i]; |
| 1188 | if (tp_rfk) { |
| 1189 | if (rfkill_set_hw_state(tp_rfk->rfkill, |
| 1190 | blocked)) { |
| 1191 | /* ignore -- we track sw block */ |
| 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | /* Call to get the WLSW state from the firmware */ |
| 1198 | static int hotkey_get_wlsw(void); |
| 1199 | |
| 1200 | /* Call to query WLSW state and update all rfkill switches */ |
| 1201 | static bool tpacpi_rfk_check_hwblock_state(void) |
| 1202 | { |
| 1203 | int res = hotkey_get_wlsw(); |
| 1204 | int hw_blocked; |
| 1205 | |
| 1206 | /* When unknown or unsupported, we have to assume it is unblocked */ |
| 1207 | if (res < 0) |
| 1208 | return false; |
| 1209 | |
| 1210 | hw_blocked = (res == TPACPI_RFK_RADIO_OFF); |
| 1211 | tpacpi_rfk_update_hwblock_state(hw_blocked); |
| 1212 | |
| 1213 | return hw_blocked; |
| 1214 | } |
| 1215 | |
| 1216 | static int tpacpi_rfk_hook_set_block(void *data, bool blocked) |
| 1217 | { |
| 1218 | struct tpacpi_rfk *tp_rfk = data; |
| 1219 | int res; |
| 1220 | |
| 1221 | dbg_printk(TPACPI_DBG_RFKILL, |
| 1222 | "request to change radio state to %s\n", |
| 1223 | blocked ? "blocked" : "unblocked"); |
| 1224 | |
| 1225 | /* try to set radio state */ |
| 1226 | res = (tp_rfk->ops->set_status)(blocked ? |
| 1227 | TPACPI_RFK_RADIO_OFF : TPACPI_RFK_RADIO_ON); |
| 1228 | |
| 1229 | /* and update the rfkill core with whatever the FW really did */ |
| 1230 | tpacpi_rfk_update_swstate(tp_rfk); |
| 1231 | |
| 1232 | return (res < 0) ? res : 0; |
| 1233 | } |
| 1234 | |
| 1235 | static const struct rfkill_ops tpacpi_rfk_rfkill_ops = { |
| 1236 | .set_block = tpacpi_rfk_hook_set_block, |
| 1237 | }; |
| 1238 | |
| 1239 | static int __init tpacpi_new_rfkill(const enum tpacpi_rfk_id id, |
| 1240 | const struct tpacpi_rfk_ops *tp_rfkops, |
| 1241 | const enum rfkill_type rfktype, |
| 1242 | const char *name, |
| 1243 | const bool set_default) |
| 1244 | { |
| 1245 | struct tpacpi_rfk *atp_rfk; |
| 1246 | int res; |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1247 | bool sw_state = false; |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1248 | bool hw_state; |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1249 | int sw_status; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1250 | |
| 1251 | BUG_ON(id >= TPACPI_RFK_SW_MAX || tpacpi_rfkill_switches[id]); |
| 1252 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1253 | atp_rfk = kzalloc(sizeof(struct tpacpi_rfk), GFP_KERNEL); |
| 1254 | if (atp_rfk) |
| 1255 | atp_rfk->rfkill = rfkill_alloc(name, |
| 1256 | &tpacpi_pdev->dev, |
| 1257 | rfktype, |
| 1258 | &tpacpi_rfk_rfkill_ops, |
| 1259 | atp_rfk); |
| 1260 | if (!atp_rfk || !atp_rfk->rfkill) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1261 | pr_err("failed to allocate memory for rfkill class\n"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1262 | kfree(atp_rfk); |
| 1263 | return -ENOMEM; |
| 1264 | } |
| 1265 | |
| 1266 | atp_rfk->id = id; |
| 1267 | atp_rfk->ops = tp_rfkops; |
| 1268 | |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1269 | sw_status = (tp_rfkops->get_status)(); |
| 1270 | if (sw_status < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1271 | pr_err("failed to read initial state for %s, error %d\n", |
| 1272 | name, sw_status); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1273 | } else { |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1274 | sw_state = (sw_status == TPACPI_RFK_RADIO_OFF); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1275 | if (set_default) { |
| 1276 | /* try to keep the initial state, since we ask the |
| 1277 | * firmware to preserve it across S5 in NVRAM */ |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1278 | rfkill_init_sw_state(atp_rfk->rfkill, sw_state); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1279 | } |
| 1280 | } |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1281 | hw_state = tpacpi_rfk_check_hwblock_state(); |
| 1282 | rfkill_set_hw_state(atp_rfk->rfkill, hw_state); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1283 | |
| 1284 | res = rfkill_register(atp_rfk->rfkill); |
| 1285 | if (res < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1286 | pr_err("failed to register %s rfkill switch: %d\n", name, res); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1287 | rfkill_destroy(atp_rfk->rfkill); |
| 1288 | kfree(atp_rfk); |
| 1289 | return res; |
| 1290 | } |
| 1291 | |
| 1292 | tpacpi_rfkill_switches[id] = atp_rfk; |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1293 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1294 | pr_info("rfkill switch %s: radio is %sblocked\n", |
Henrique de Moraes Holschuh | 5451a92 | 2009-12-15 21:51:07 -0200 | [diff] [blame] | 1295 | name, (sw_state || hw_state) ? "" : "un"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1296 | return 0; |
| 1297 | } |
| 1298 | |
| 1299 | static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id) |
| 1300 | { |
| 1301 | struct tpacpi_rfk *tp_rfk; |
| 1302 | |
| 1303 | BUG_ON(id >= TPACPI_RFK_SW_MAX); |
| 1304 | |
| 1305 | tp_rfk = tpacpi_rfkill_switches[id]; |
| 1306 | if (tp_rfk) { |
| 1307 | rfkill_unregister(tp_rfk->rfkill); |
Corentin Chary | 5f0dadb | 2009-09-14 12:43:52 +0200 | [diff] [blame] | 1308 | rfkill_destroy(tp_rfk->rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1309 | tpacpi_rfkill_switches[id] = NULL; |
| 1310 | kfree(tp_rfk); |
| 1311 | } |
| 1312 | } |
| 1313 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1314 | static void printk_deprecated_rfkill_attribute(const char * const what) |
| 1315 | { |
| 1316 | printk_deprecated_attribute(what, |
| 1317 | "Please switch to generic rfkill before year 2010"); |
| 1318 | } |
| 1319 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1320 | /* sysfs <radio> enable ------------------------------------------------ */ |
| 1321 | static ssize_t tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id, |
| 1322 | struct device_attribute *attr, |
| 1323 | char *buf) |
| 1324 | { |
| 1325 | int status; |
| 1326 | |
| 1327 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1328 | |
| 1329 | /* This is in the ABI... */ |
| 1330 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1331 | status = TPACPI_RFK_RADIO_OFF; |
| 1332 | } else { |
| 1333 | status = tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1334 | if (status < 0) |
| 1335 | return status; |
| 1336 | } |
| 1337 | |
| 1338 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1339 | (status == TPACPI_RFK_RADIO_ON) ? 1 : 0); |
| 1340 | } |
| 1341 | |
| 1342 | static ssize_t tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id, |
| 1343 | struct device_attribute *attr, |
| 1344 | const char *buf, size_t count) |
| 1345 | { |
| 1346 | unsigned long t; |
| 1347 | int res; |
| 1348 | |
| 1349 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1350 | |
| 1351 | if (parse_strtoul(buf, 1, &t)) |
| 1352 | return -EINVAL; |
| 1353 | |
| 1354 | tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); |
| 1355 | |
| 1356 | /* This is in the ABI... */ |
| 1357 | if (tpacpi_rfk_check_hwblock_state() && !!t) |
| 1358 | return -EPERM; |
| 1359 | |
| 1360 | res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? |
| 1361 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF); |
| 1362 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1363 | |
| 1364 | return (res < 0) ? res : count; |
| 1365 | } |
| 1366 | |
| 1367 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1368 | static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id, struct seq_file *m) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1369 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1370 | if (id >= TPACPI_RFK_SW_MAX) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1371 | seq_printf(m, "status:\t\tnot supported\n"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1372 | else { |
| 1373 | int status; |
| 1374 | |
| 1375 | /* This is in the ABI... */ |
| 1376 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1377 | status = TPACPI_RFK_RADIO_OFF; |
| 1378 | } else { |
| 1379 | status = tpacpi_rfk_update_swstate( |
| 1380 | tpacpi_rfkill_switches[id]); |
| 1381 | if (status < 0) |
| 1382 | return status; |
| 1383 | } |
| 1384 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1385 | seq_printf(m, "status:\t\t%s\n", |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1386 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1387 | "enabled" : "disabled"); |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1388 | seq_printf(m, "commands:\tenable, disable\n"); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1389 | } |
| 1390 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1391 | return 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf) |
| 1395 | { |
| 1396 | char *cmd; |
| 1397 | int status = -1; |
| 1398 | int res = 0; |
| 1399 | |
| 1400 | if (id >= TPACPI_RFK_SW_MAX) |
| 1401 | return -ENODEV; |
| 1402 | |
| 1403 | while ((cmd = next_cmd(&buf))) { |
| 1404 | if (strlencmp(cmd, "enable") == 0) |
| 1405 | status = TPACPI_RFK_RADIO_ON; |
| 1406 | else if (strlencmp(cmd, "disable") == 0) |
| 1407 | status = TPACPI_RFK_RADIO_OFF; |
| 1408 | else |
| 1409 | return -EINVAL; |
| 1410 | } |
| 1411 | |
| 1412 | if (status != -1) { |
| 1413 | tpacpi_disclose_usertask("procfs", "attempt to %s %s\n", |
| 1414 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1415 | "enable" : "disable", |
| 1416 | tpacpi_rfkill_names[id]); |
| 1417 | res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); |
| 1418 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1419 | } |
| 1420 | |
| 1421 | return res; |
| 1422 | } |
| 1423 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1424 | /************************************************************************* |
| 1425 | * thinkpad-acpi driver attributes |
| 1426 | */ |
| 1427 | |
| 1428 | /* interface_version --------------------------------------------------- */ |
| 1429 | static ssize_t tpacpi_driver_interface_version_show( |
| 1430 | struct device_driver *drv, |
| 1431 | char *buf) |
| 1432 | { |
| 1433 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 1434 | } |
| 1435 | |
| 1436 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 1437 | tpacpi_driver_interface_version_show, NULL); |
| 1438 | |
| 1439 | /* debug_level --------------------------------------------------------- */ |
| 1440 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 1441 | char *buf) |
| 1442 | { |
| 1443 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 1444 | } |
| 1445 | |
| 1446 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 1447 | const char *buf, size_t count) |
| 1448 | { |
| 1449 | unsigned long t; |
| 1450 | |
| 1451 | if (parse_strtoul(buf, 0xffff, &t)) |
| 1452 | return -EINVAL; |
| 1453 | |
| 1454 | dbg_level = t; |
| 1455 | |
| 1456 | return count; |
| 1457 | } |
| 1458 | |
| 1459 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1460 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 1461 | |
| 1462 | /* version ------------------------------------------------------------- */ |
| 1463 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 1464 | char *buf) |
| 1465 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1466 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 1467 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | static DRIVER_ATTR(version, S_IRUGO, |
| 1471 | tpacpi_driver_version_show, NULL); |
| 1472 | |
| 1473 | /* --------------------------------------------------------------------- */ |
| 1474 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1475 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1476 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1477 | /* wlsw_emulstate ------------------------------------------------------ */ |
| 1478 | static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv, |
| 1479 | char *buf) |
| 1480 | { |
| 1481 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate); |
| 1482 | } |
| 1483 | |
| 1484 | static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv, |
| 1485 | const char *buf, size_t count) |
| 1486 | { |
| 1487 | unsigned long t; |
| 1488 | |
| 1489 | if (parse_strtoul(buf, 1, &t)) |
| 1490 | return -EINVAL; |
| 1491 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1492 | if (tpacpi_wlsw_emulstate != !!t) { |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1493 | tpacpi_wlsw_emulstate = !!t; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1494 | tpacpi_rfk_update_hwblock_state(!t); /* negative logic */ |
| 1495 | } |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1496 | |
| 1497 | return count; |
| 1498 | } |
| 1499 | |
| 1500 | static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO, |
| 1501 | tpacpi_driver_wlsw_emulstate_show, |
| 1502 | tpacpi_driver_wlsw_emulstate_store); |
| 1503 | |
| 1504 | /* bluetooth_emulstate ------------------------------------------------- */ |
| 1505 | static ssize_t tpacpi_driver_bluetooth_emulstate_show( |
| 1506 | struct device_driver *drv, |
| 1507 | char *buf) |
| 1508 | { |
| 1509 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate); |
| 1510 | } |
| 1511 | |
| 1512 | static ssize_t tpacpi_driver_bluetooth_emulstate_store( |
| 1513 | struct device_driver *drv, |
| 1514 | const char *buf, size_t count) |
| 1515 | { |
| 1516 | unsigned long t; |
| 1517 | |
| 1518 | if (parse_strtoul(buf, 1, &t)) |
| 1519 | return -EINVAL; |
| 1520 | |
| 1521 | tpacpi_bluetooth_emulstate = !!t; |
| 1522 | |
| 1523 | return count; |
| 1524 | } |
| 1525 | |
| 1526 | static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO, |
| 1527 | tpacpi_driver_bluetooth_emulstate_show, |
| 1528 | tpacpi_driver_bluetooth_emulstate_store); |
| 1529 | |
| 1530 | /* wwan_emulstate ------------------------------------------------- */ |
| 1531 | static ssize_t tpacpi_driver_wwan_emulstate_show( |
| 1532 | struct device_driver *drv, |
| 1533 | char *buf) |
| 1534 | { |
| 1535 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate); |
| 1536 | } |
| 1537 | |
| 1538 | static ssize_t tpacpi_driver_wwan_emulstate_store( |
| 1539 | struct device_driver *drv, |
| 1540 | const char *buf, size_t count) |
| 1541 | { |
| 1542 | unsigned long t; |
| 1543 | |
| 1544 | if (parse_strtoul(buf, 1, &t)) |
| 1545 | return -EINVAL; |
| 1546 | |
| 1547 | tpacpi_wwan_emulstate = !!t; |
| 1548 | |
| 1549 | return count; |
| 1550 | } |
| 1551 | |
| 1552 | static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO, |
| 1553 | tpacpi_driver_wwan_emulstate_show, |
| 1554 | tpacpi_driver_wwan_emulstate_store); |
| 1555 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1556 | /* uwb_emulstate ------------------------------------------------- */ |
| 1557 | static ssize_t tpacpi_driver_uwb_emulstate_show( |
| 1558 | struct device_driver *drv, |
| 1559 | char *buf) |
| 1560 | { |
| 1561 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate); |
| 1562 | } |
| 1563 | |
| 1564 | static ssize_t tpacpi_driver_uwb_emulstate_store( |
| 1565 | struct device_driver *drv, |
| 1566 | const char *buf, size_t count) |
| 1567 | { |
| 1568 | unsigned long t; |
| 1569 | |
| 1570 | if (parse_strtoul(buf, 1, &t)) |
| 1571 | return -EINVAL; |
| 1572 | |
| 1573 | tpacpi_uwb_emulstate = !!t; |
| 1574 | |
| 1575 | return count; |
| 1576 | } |
| 1577 | |
| 1578 | static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO, |
| 1579 | tpacpi_driver_uwb_emulstate_show, |
| 1580 | tpacpi_driver_uwb_emulstate_store); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1581 | #endif |
| 1582 | |
| 1583 | /* --------------------------------------------------------------------- */ |
| 1584 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1585 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1586 | &driver_attr_debug_level, &driver_attr_version, |
| 1587 | &driver_attr_interface_version, |
| 1588 | }; |
| 1589 | |
| 1590 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 1591 | { |
| 1592 | int i, res; |
| 1593 | |
| 1594 | i = 0; |
| 1595 | res = 0; |
| 1596 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 1597 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 1598 | i++; |
| 1599 | } |
| 1600 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1601 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1602 | if (!res && dbg_wlswemul) |
| 1603 | res = driver_create_file(drv, &driver_attr_wlsw_emulstate); |
| 1604 | if (!res && dbg_bluetoothemul) |
| 1605 | res = driver_create_file(drv, &driver_attr_bluetooth_emulstate); |
| 1606 | if (!res && dbg_wwanemul) |
| 1607 | res = driver_create_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1608 | if (!res && dbg_uwbemul) |
| 1609 | res = driver_create_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1610 | #endif |
| 1611 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1612 | return res; |
| 1613 | } |
| 1614 | |
| 1615 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 1616 | { |
| 1617 | int i; |
| 1618 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1619 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1620 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1621 | |
| 1622 | #ifdef THINKPAD_ACPI_DEBUGFACILITIES |
| 1623 | driver_remove_file(drv, &driver_attr_wlsw_emulstate); |
| 1624 | driver_remove_file(drv, &driver_attr_bluetooth_emulstate); |
| 1625 | driver_remove_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1626 | driver_remove_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1627 | #endif |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1628 | } |
| 1629 | |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1630 | /************************************************************************* |
| 1631 | * Firmware Data |
| 1632 | */ |
| 1633 | |
| 1634 | /* |
| 1635 | * Table of recommended minimum BIOS versions |
| 1636 | * |
| 1637 | * Reasons for listing: |
Uwe Kleine-König | 9ddc5b6 | 2010-01-20 17:02:24 +0100 | [diff] [blame] | 1638 | * 1. Stable BIOS, listed because the unknown amount of |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1639 | * bugs and bad ACPI behaviour on older versions |
| 1640 | * |
| 1641 | * 2. BIOS or EC fw with known bugs that trigger on Linux |
| 1642 | * |
| 1643 | * 3. BIOS with known reduced functionality in older versions |
| 1644 | * |
| 1645 | * We recommend the latest BIOS and EC version. |
| 1646 | * We only support the latest BIOS and EC fw version as a rule. |
| 1647 | * |
| 1648 | * Sources: IBM ThinkPad Public Web Documents (update changelogs), |
| 1649 | * Information from users in ThinkWiki |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1650 | * |
| 1651 | * WARNING: we use this table also to detect that the machine is |
| 1652 | * 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] | 1653 | */ |
| 1654 | |
| 1655 | #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \ |
| 1656 | { .vendor = (__v), \ |
| 1657 | .bios = TPID(__id1, __id2), \ |
| 1658 | .ec = TPACPI_MATCH_ANY, \ |
| 1659 | .quirks = TPACPI_MATCH_ANY << 16 \ |
| 1660 | | (__bv1) << 8 | (__bv2) } |
| 1661 | |
| 1662 | #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1663 | __eid, __ev1, __ev2) \ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1664 | { .vendor = (__v), \ |
| 1665 | .bios = TPID(__bid1, __bid2), \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1666 | .ec = __eid, \ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1667 | .quirks = (__ev1) << 24 | (__ev2) << 16 \ |
| 1668 | | (__bv1) << 8 | (__bv2) } |
| 1669 | |
| 1670 | #define TPV_QI0(__id1, __id2, __bv1, __bv2) \ |
| 1671 | TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2) |
| 1672 | |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1673 | /* Outdated IBM BIOSes often lack the EC id string */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1674 | #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1675 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1676 | __bv1, __bv2, TPID(__id1, __id2), \ |
| 1677 | __ev1, __ev2), \ |
| 1678 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
| 1679 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ |
| 1680 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1681 | |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1682 | /* Outdated IBM BIOSes often lack the EC id string */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1683 | #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \ |
| 1684 | __eid1, __eid2, __ev1, __ev2) \ |
| 1685 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1686 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
| 1687 | __ev1, __ev2), \ |
| 1688 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
| 1689 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ |
| 1690 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1691 | |
| 1692 | #define TPV_QL0(__id1, __id2, __bv1, __bv2) \ |
| 1693 | TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2) |
| 1694 | |
| 1695 | #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1696 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1697 | __bv1, __bv2, TPID(__id1, __id2), \ |
| 1698 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1699 | |
| 1700 | #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \ |
| 1701 | __eid1, __eid2, __ev1, __ev2) \ |
| 1702 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \ |
Henrique de Moraes Holschuh | 275014a | 2009-11-17 14:07:22 -0800 | [diff] [blame] | 1703 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
| 1704 | __ev1, __ev2) |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1705 | |
| 1706 | static const struct tpacpi_quirk tpacpi_bios_version_qtable[] __initconst = { |
| 1707 | /* Numeric models ------------------ */ |
| 1708 | /* FW MODEL BIOS VERS */ |
| 1709 | TPV_QI0('I', 'M', '6', '5'), /* 570 */ |
| 1710 | TPV_QI0('I', 'U', '2', '6'), /* 570E */ |
| 1711 | TPV_QI0('I', 'B', '5', '4'), /* 600 */ |
| 1712 | TPV_QI0('I', 'H', '4', '7'), /* 600E */ |
| 1713 | TPV_QI0('I', 'N', '3', '6'), /* 600E */ |
| 1714 | TPV_QI0('I', 'T', '5', '5'), /* 600X */ |
| 1715 | TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */ |
| 1716 | TPV_QI0('I', 'I', '4', '2'), /* 770X */ |
| 1717 | TPV_QI0('I', 'O', '2', '3'), /* 770Z */ |
| 1718 | |
| 1719 | /* A-series ------------------------- */ |
| 1720 | /* FW MODEL BIOS VERS EC VERS */ |
| 1721 | TPV_QI0('I', 'W', '5', '9'), /* A20m */ |
| 1722 | TPV_QI0('I', 'V', '6', '9'), /* A20p */ |
| 1723 | TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */ |
| 1724 | TPV_QI0('K', 'U', '3', '6'), /* A21e */ |
| 1725 | TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */ |
| 1726 | TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */ |
| 1727 | TPV_QI0('1', 'B', '1', '7'), /* A22e */ |
| 1728 | TPV_QI0('1', '3', '2', '0'), /* A22m */ |
| 1729 | TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */ |
| 1730 | TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */ |
| 1731 | TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */ |
| 1732 | |
| 1733 | /* G-series ------------------------- */ |
| 1734 | /* FW MODEL BIOS VERS */ |
| 1735 | TPV_QI0('1', 'T', 'A', '6'), /* G40 */ |
| 1736 | TPV_QI0('1', 'X', '5', '7'), /* G41 */ |
| 1737 | |
| 1738 | /* R-series, T-series --------------- */ |
| 1739 | /* FW MODEL BIOS VERS EC VERS */ |
| 1740 | TPV_QI0('1', 'C', 'F', '0'), /* R30 */ |
| 1741 | TPV_QI0('1', 'F', 'F', '1'), /* R31 */ |
| 1742 | TPV_QI0('1', 'M', '9', '7'), /* R32 */ |
| 1743 | TPV_QI0('1', 'O', '6', '1'), /* R40 */ |
| 1744 | TPV_QI0('1', 'P', '6', '5'), /* R40 */ |
| 1745 | TPV_QI0('1', 'S', '7', '0'), /* R40e */ |
| 1746 | TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51, |
| 1747 | T40/p, T41/p, T42/p (1) */ |
| 1748 | TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */ |
| 1749 | TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */ |
| 1750 | TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */ |
| 1751 | TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */ |
| 1752 | |
| 1753 | TPV_QI0('I', 'Y', '6', '1'), /* T20 */ |
| 1754 | TPV_QI0('K', 'Z', '3', '4'), /* T21 */ |
| 1755 | TPV_QI0('1', '6', '3', '2'), /* T22 */ |
| 1756 | TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */ |
| 1757 | TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */ |
| 1758 | TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */ |
| 1759 | |
| 1760 | TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */ |
| 1761 | TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */ |
Henrique de Moraes Holschuh | 90765c6 | 2009-12-09 01:36:23 +0000 | [diff] [blame] | 1762 | TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1763 | |
| 1764 | /* BIOS FW BIOS VERS EC FW EC VERS */ |
| 1765 | TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */ |
| 1766 | TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */ |
| 1767 | |
| 1768 | /* X-series ------------------------- */ |
| 1769 | /* FW MODEL BIOS VERS EC VERS */ |
| 1770 | TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */ |
| 1771 | TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */ |
| 1772 | TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */ |
| 1773 | TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */ |
| 1774 | TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */ |
| 1775 | TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */ |
| 1776 | TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */ |
| 1777 | |
Henrique de Moraes Holschuh | 90765c6 | 2009-12-09 01:36:23 +0000 | [diff] [blame] | 1778 | TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */ |
| 1779 | TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */ |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1780 | |
| 1781 | /* (0) - older versions lack DMI EC fw string and functionality */ |
| 1782 | /* (1) - older versions known to lack functionality */ |
| 1783 | }; |
| 1784 | |
| 1785 | #undef TPV_QL1 |
| 1786 | #undef TPV_QL0 |
| 1787 | #undef TPV_QI2 |
| 1788 | #undef TPV_QI1 |
| 1789 | #undef TPV_QI0 |
| 1790 | #undef TPV_Q_X |
| 1791 | #undef TPV_Q |
| 1792 | |
| 1793 | static void __init tpacpi_check_outdated_fw(void) |
| 1794 | { |
| 1795 | unsigned long fwvers; |
| 1796 | u16 ec_version, bios_version; |
| 1797 | |
| 1798 | fwvers = tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1799 | ARRAY_SIZE(tpacpi_bios_version_qtable)); |
| 1800 | |
| 1801 | if (!fwvers) |
| 1802 | return; |
| 1803 | |
| 1804 | bios_version = fwvers & 0xffffU; |
| 1805 | ec_version = (fwvers >> 16) & 0xffffU; |
| 1806 | |
| 1807 | /* note that unknown versions are set to 0x0000 and we use that */ |
| 1808 | if ((bios_version > thinkpad_id.bios_release) || |
| 1809 | (ec_version > thinkpad_id.ec_release && |
| 1810 | ec_version != TPACPI_MATCH_ANY)) { |
| 1811 | /* |
| 1812 | * The changelogs would let us track down the exact |
| 1813 | * reason, but it is just too much of a pain to track |
| 1814 | * it. We only list BIOSes that are either really |
| 1815 | * broken, or really stable to begin with, so it is |
| 1816 | * best if the user upgrades the firmware anyway. |
| 1817 | */ |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 1818 | pr_warn("WARNING: Outdated ThinkPad BIOS/EC firmware\n"); |
| 1819 | pr_warn("WARNING: This firmware may be missing critical bug " |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1820 | "fixes and/or important features\n"); |
| 1821 | } |
| 1822 | } |
| 1823 | |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1824 | static bool __init tpacpi_is_fw_known(void) |
| 1825 | { |
| 1826 | return tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1827 | ARRAY_SIZE(tpacpi_bios_version_qtable)) != 0; |
| 1828 | } |
| 1829 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1830 | /**************************************************************************** |
| 1831 | **************************************************************************** |
| 1832 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1833 | * Subdrivers |
| 1834 | * |
| 1835 | **************************************************************************** |
| 1836 | ****************************************************************************/ |
| 1837 | |
| 1838 | /************************************************************************* |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 1839 | * thinkpad-acpi metadata subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1840 | */ |
| 1841 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1842 | static int thinkpad_acpi_driver_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 1844 | seq_printf(m, "driver:\t\t%s\n", TPACPI_DESC); |
| 1845 | seq_printf(m, "version:\t%s\n", TPACPI_VERSION); |
| 1846 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1849 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1850 | .name = "driver", |
| 1851 | .read = thinkpad_acpi_driver_read, |
| 1852 | }; |
| 1853 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1854 | /************************************************************************* |
| 1855 | * Hotkey subdriver |
| 1856 | */ |
| 1857 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1858 | /* |
| 1859 | * ThinkPad firmware event model |
| 1860 | * |
| 1861 | * The ThinkPad firmware has two main event interfaces: normal ACPI |
| 1862 | * notifications (which follow the ACPI standard), and a private event |
| 1863 | * interface. |
| 1864 | * |
| 1865 | * The private event interface also issues events for the hotkeys. As |
| 1866 | * the driver gained features, the event handling code ended up being |
| 1867 | * built around the hotkey subdriver. This will need to be refactored |
| 1868 | * to a more formal event API eventually. |
| 1869 | * |
| 1870 | * Some "hotkeys" are actually supposed to be used as event reports, |
| 1871 | * such as "brightness has changed", "volume has changed", depending on |
| 1872 | * the ThinkPad model and how the firmware is operating. |
| 1873 | * |
| 1874 | * Unlike other classes, hotkey-class events have mask/unmask control on |
| 1875 | * non-ancient firmware. However, how it behaves changes a lot with the |
| 1876 | * firmware model and version. |
| 1877 | */ |
| 1878 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1879 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1880 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1881 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1882 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1883 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1884 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1885 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1886 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1887 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1888 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1889 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1890 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1891 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1892 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1893 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1894 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1895 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1896 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1897 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1898 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1899 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1900 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1901 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1902 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1903 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
Henrique de Moraes Holschuh | 34a656d2 | 2010-08-09 23:48:20 -0300 | [diff] [blame] | 1904 | TP_ACPI_HOTKEYSCAN_UNK1, |
| 1905 | TP_ACPI_HOTKEYSCAN_UNK2, |
| 1906 | TP_ACPI_HOTKEYSCAN_UNK3, |
| 1907 | TP_ACPI_HOTKEYSCAN_UNK4, |
| 1908 | TP_ACPI_HOTKEYSCAN_UNK5, |
| 1909 | TP_ACPI_HOTKEYSCAN_UNK6, |
| 1910 | TP_ACPI_HOTKEYSCAN_UNK7, |
| 1911 | TP_ACPI_HOTKEYSCAN_UNK8, |
| 1912 | |
| 1913 | /* Hotkey keymap size */ |
| 1914 | TPACPI_HOTKEY_MAP_LEN |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1915 | }; |
| 1916 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1917 | enum { /* Keys/events available through NVRAM polling */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1918 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1919 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1920 | }; |
| 1921 | |
| 1922 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1923 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1924 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1925 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1926 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1927 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1928 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1929 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1930 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1931 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1932 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1933 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1934 | }; |
| 1935 | |
| 1936 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1937 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1938 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1939 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1940 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1941 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1942 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1943 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1944 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1945 | TP_ACPI_HKEY_MUTE_MASK, |
| 1946 | }; |
| 1947 | |
| 1948 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1949 | struct tp_nvram_state { |
| 1950 | u16 thinkpad_toggle:1; |
| 1951 | u16 zoom_toggle:1; |
| 1952 | u16 display_toggle:1; |
| 1953 | u16 thinklight_toggle:1; |
| 1954 | u16 hibernate_toggle:1; |
| 1955 | u16 displayexp_toggle:1; |
| 1956 | u16 display_state:1; |
| 1957 | u16 brightness_toggle:1; |
| 1958 | u16 volume_toggle:1; |
| 1959 | u16 mute:1; |
| 1960 | |
| 1961 | u8 brightness_level; |
| 1962 | u8 volume_level; |
| 1963 | }; |
| 1964 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1965 | /* kthread for the hotkey poller */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1966 | static struct task_struct *tpacpi_hotkey_task; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1967 | |
| 1968 | /* 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] | 1969 | static struct mutex hotkey_thread_mutex; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1970 | |
| 1971 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 1972 | * Acquire mutex to write poller control variables as an |
| 1973 | * atomic block. |
| 1974 | * |
| 1975 | * Increment hotkey_config_change when changing them if you |
| 1976 | * want the kthread to forget old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1977 | * |
| 1978 | * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 1979 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1980 | static struct mutex hotkey_thread_data_mutex; |
| 1981 | static unsigned int hotkey_config_change; |
| 1982 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1983 | /* |
| 1984 | * hotkey poller control variables |
| 1985 | * |
| 1986 | * 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] | 1987 | * |
| 1988 | * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 1989 | * should be used only when the changes need to be taken as |
| 1990 | * a block, OR when one needs to force the kthread to forget |
| 1991 | * old state. |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1992 | */ |
| 1993 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 1994 | static unsigned int hotkey_poll_freq = 10; /* Hz */ |
| 1995 | |
| 1996 | #define HOTKEY_CONFIG_CRITICAL_START \ |
| 1997 | do { \ |
| 1998 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 1999 | hotkey_config_change++; \ |
| 2000 | } while (0); |
| 2001 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 2002 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2003 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2004 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2005 | |
| 2006 | #define hotkey_source_mask 0U |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2007 | #define HOTKEY_CONFIG_CRITICAL_START |
| 2008 | #define HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2009 | |
| 2010 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2011 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2012 | static struct mutex hotkey_mutex; |
| 2013 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2014 | static enum { /* Reasons for waking up */ |
| 2015 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 2016 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 2017 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 2018 | } hotkey_wakeup_reason; |
| 2019 | |
| 2020 | static int hotkey_autosleep_ack; |
| 2021 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2022 | static u32 hotkey_orig_mask; /* events the BIOS had enabled */ |
| 2023 | static u32 hotkey_all_mask; /* all events supported in fw */ |
| 2024 | static u32 hotkey_reserved_mask; /* events better left disabled */ |
| 2025 | static u32 hotkey_driver_mask; /* events needed by the driver */ |
| 2026 | static u32 hotkey_user_mask; /* events visible to userspace */ |
| 2027 | static u32 hotkey_acpi_mask; /* events enabled in firmware */ |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2028 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 2029 | static unsigned int hotkey_report_mode; |
| 2030 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2031 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2032 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 2033 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2034 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2035 | static void tpacpi_driver_event(const unsigned int hkey_event); |
| 2036 | static void hotkey_driver_event(const unsigned int scancode); |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2037 | static void hotkey_poll_setup(const bool may_warn); |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2038 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2039 | /* HKEY.MHKG() return bits */ |
| 2040 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 2041 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2042 | static int hotkey_get_wlsw(void) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2043 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2044 | int status; |
| 2045 | |
| 2046 | if (!tp_features.hotkey_wlsw) |
| 2047 | return -ENODEV; |
| 2048 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2049 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2050 | if (dbg_wlswemul) |
| 2051 | return (tpacpi_wlsw_emulstate) ? |
| 2052 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2053 | #endif |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2054 | |
| 2055 | if (!acpi_evalf(hkey_handle, &status, "WLSW", "d")) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2056 | return -EIO; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2057 | |
| 2058 | return (status) ? TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2059 | } |
| 2060 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2061 | static int hotkey_get_tablet_mode(int *status) |
| 2062 | { |
| 2063 | int s; |
| 2064 | |
| 2065 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 2066 | return -EIO; |
| 2067 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 2068 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 2069 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2070 | } |
| 2071 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2072 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2073 | * Reads current event mask from firmware, and updates |
| 2074 | * hotkey_acpi_mask accordingly. Also resets any bits |
| 2075 | * from hotkey_user_mask that are unavailable to be |
| 2076 | * delivered (shadow requirement of the userspace ABI). |
| 2077 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2078 | * Call with hotkey_mutex held |
| 2079 | */ |
| 2080 | static int hotkey_mask_get(void) |
| 2081 | { |
| 2082 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2083 | u32 m = 0; |
| 2084 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2085 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2086 | return -EIO; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2087 | |
| 2088 | hotkey_acpi_mask = m; |
| 2089 | } else { |
| 2090 | /* no mask support doesn't mean no event support... */ |
| 2091 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2092 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2093 | |
| 2094 | /* sync userspace-visible mask */ |
| 2095 | hotkey_user_mask &= (hotkey_acpi_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2096 | |
| 2097 | return 0; |
| 2098 | } |
| 2099 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2100 | void static hotkey_mask_warn_incomplete_mask(void) |
| 2101 | { |
| 2102 | /* log only what the user can fix... */ |
| 2103 | const u32 wantedmask = hotkey_driver_mask & |
| 2104 | ~(hotkey_acpi_mask | hotkey_source_mask) & |
| 2105 | (hotkey_all_mask | TPACPI_HKEY_NVRAM_KNOWN_MASK); |
| 2106 | |
| 2107 | if (wantedmask) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2108 | pr_notice("required events 0x%08x not enabled!\n", wantedmask); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2109 | } |
| 2110 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2111 | /* |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2112 | * Set the firmware mask when supported |
| 2113 | * |
| 2114 | * Also calls hotkey_mask_get to update hotkey_acpi_mask. |
| 2115 | * |
| 2116 | * NOTE: does not set bits in hotkey_user_mask, but may reset them. |
| 2117 | * |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2118 | * Call with hotkey_mutex held |
| 2119 | */ |
| 2120 | static int hotkey_mask_set(u32 mask) |
| 2121 | { |
| 2122 | int i; |
| 2123 | int rc = 0; |
| 2124 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2125 | const u32 fwmask = mask & ~hotkey_source_mask; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 2126 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2127 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2128 | for (i = 0; i < 32; i++) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2129 | if (!acpi_evalf(hkey_handle, |
| 2130 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2131 | !!(mask & (1 << i)))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2132 | rc = -EIO; |
| 2133 | break; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2134 | } |
| 2135 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2136 | } |
| 2137 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2138 | /* |
| 2139 | * We *must* make an inconditional call to hotkey_mask_get to |
| 2140 | * refresh hotkey_acpi_mask and update hotkey_user_mask |
| 2141 | * |
| 2142 | * Take the opportunity to also log when we cannot _enable_ |
| 2143 | * a given event. |
| 2144 | */ |
| 2145 | if (!hotkey_mask_get() && !rc && (fwmask & ~hotkey_acpi_mask)) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2146 | pr_notice("asked for hotkey mask 0x%08x, but " |
| 2147 | "firmware forced it to 0x%08x\n", |
| 2148 | fwmask, hotkey_acpi_mask); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2149 | } |
| 2150 | |
Henrique de Moraes Holschuh | 6b30eb7 | 2009-12-09 01:36:25 +0000 | [diff] [blame] | 2151 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING) |
| 2152 | hotkey_mask_warn_incomplete_mask(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2153 | |
| 2154 | return rc; |
| 2155 | } |
| 2156 | |
| 2157 | /* |
| 2158 | * Sets hotkey_user_mask and tries to set the firmware mask |
| 2159 | * |
| 2160 | * Call with hotkey_mutex held |
| 2161 | */ |
| 2162 | static int hotkey_user_mask_set(const u32 mask) |
| 2163 | { |
| 2164 | int rc; |
| 2165 | |
| 2166 | /* Give people a chance to notice they are doing something that |
| 2167 | * is bound to go boom on their users sooner or later */ |
| 2168 | if (!tp_warned.hotkey_mask_ff && |
| 2169 | (mask == 0xffff || mask == 0xffffff || |
| 2170 | mask == 0xffffffff)) { |
| 2171 | tp_warned.hotkey_mask_ff = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2172 | pr_notice("setting the hotkey mask to 0x%08x is likely " |
| 2173 | "not the best way to go about it\n", mask); |
| 2174 | pr_notice("please consider using the driver defaults, " |
| 2175 | "and refer to up-to-date thinkpad-acpi " |
| 2176 | "documentation\n"); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | /* Try to enable what the user asked for, plus whatever we need. |
| 2180 | * this syncs everything but won't enable bits in hotkey_user_mask */ |
| 2181 | rc = hotkey_mask_set((mask | hotkey_driver_mask) & ~hotkey_source_mask); |
| 2182 | |
| 2183 | /* Enable the available bits in hotkey_user_mask */ |
| 2184 | hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask); |
| 2185 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2186 | return rc; |
| 2187 | } |
| 2188 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2189 | /* |
| 2190 | * Sets the driver hotkey mask. |
| 2191 | * |
| 2192 | * Can be called even if the hotkey subdriver is inactive |
| 2193 | */ |
| 2194 | static int tpacpi_hotkey_driver_mask_set(const u32 mask) |
| 2195 | { |
| 2196 | int rc; |
| 2197 | |
| 2198 | /* Do the right thing if hotkey_init has not been called yet */ |
| 2199 | if (!tp_features.hotkey) { |
| 2200 | hotkey_driver_mask = mask; |
| 2201 | return 0; |
| 2202 | } |
| 2203 | |
| 2204 | mutex_lock(&hotkey_mutex); |
| 2205 | |
| 2206 | HOTKEY_CONFIG_CRITICAL_START |
| 2207 | hotkey_driver_mask = mask; |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2208 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2209 | hotkey_source_mask |= (mask & ~hotkey_all_mask); |
Henrique de Moraes Holschuh | b684a36 | 2009-09-26 21:42:49 -0300 | [diff] [blame] | 2210 | #endif |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2211 | HOTKEY_CONFIG_CRITICAL_END |
| 2212 | |
| 2213 | rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) & |
| 2214 | ~hotkey_source_mask); |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2215 | hotkey_poll_setup(true); |
| 2216 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2217 | mutex_unlock(&hotkey_mutex); |
| 2218 | |
| 2219 | return rc; |
| 2220 | } |
| 2221 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2222 | static int hotkey_status_get(int *status) |
| 2223 | { |
| 2224 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 2225 | return -EIO; |
| 2226 | |
| 2227 | return 0; |
| 2228 | } |
| 2229 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2230 | static int hotkey_status_set(bool enable) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2231 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2232 | 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] | 2233 | return -EIO; |
| 2234 | |
| 2235 | return 0; |
| 2236 | } |
| 2237 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2238 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2239 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2240 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2241 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2242 | if (tp_features.hotkey_tablet && |
| 2243 | !hotkey_get_tablet_mode(&state)) { |
| 2244 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2245 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2246 | input_report_switch(tpacpi_inputdev, |
| 2247 | SW_TABLET_MODE, !!state); |
| 2248 | input_sync(tpacpi_inputdev); |
| 2249 | |
| 2250 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2251 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2252 | } |
| 2253 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2254 | /* Do NOT call without validating scancode first */ |
| 2255 | static void tpacpi_input_send_key(const unsigned int scancode) |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2256 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2257 | const unsigned int keycode = hotkey_keycode_map[scancode]; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2258 | |
| 2259 | if (keycode != KEY_RESERVED) { |
| 2260 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2261 | |
Seth Forshee | 5ffba7e | 2011-01-14 15:54:39 -0600 | [diff] [blame] | 2262 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2263 | input_report_key(tpacpi_inputdev, keycode, 1); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2264 | input_sync(tpacpi_inputdev); |
| 2265 | |
Seth Forshee | 5ffba7e | 2011-01-14 15:54:39 -0600 | [diff] [blame] | 2266 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2267 | input_report_key(tpacpi_inputdev, keycode, 0); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2268 | input_sync(tpacpi_inputdev); |
| 2269 | |
| 2270 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2271 | } |
| 2272 | } |
| 2273 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2274 | /* Do NOT call without validating scancode first */ |
| 2275 | static void tpacpi_input_send_key_masked(const unsigned int scancode) |
| 2276 | { |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 2277 | hotkey_driver_event(scancode); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2278 | if (hotkey_user_mask & (1 << scancode)) |
| 2279 | tpacpi_input_send_key(scancode); |
| 2280 | } |
| 2281 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2282 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2283 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 2284 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2285 | /* Do NOT call without validating scancode first */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2286 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 2287 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2288 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2289 | if (hotkey_report_mode < 2) { |
| 2290 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 2291 | 0x80, TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2292 | } |
| 2293 | } |
| 2294 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2295 | 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] | 2296 | { |
| 2297 | u8 d; |
| 2298 | |
| 2299 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 2300 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 2301 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 2302 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 2303 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 2304 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 2305 | } |
| 2306 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 2307 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 2308 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 2309 | } |
| 2310 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 2311 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 2312 | n->displayexp_toggle = |
| 2313 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 2314 | } |
| 2315 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 2316 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 2317 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 2318 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 2319 | n->brightness_toggle = |
| 2320 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 2321 | } |
| 2322 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 2323 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 2324 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 2325 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 2326 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 2327 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 2328 | } |
| 2329 | } |
| 2330 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2331 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
| 2332 | struct tp_nvram_state *newn, |
| 2333 | const u32 event_mask) |
| 2334 | { |
| 2335 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2336 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2337 | do { \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2338 | if ((event_mask & (1 << __scancode)) && \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2339 | oldn->__member != newn->__member) \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2340 | tpacpi_hotkey_send_key(__scancode); \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2341 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2342 | |
| 2343 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2344 | do { \ |
| 2345 | if (event_mask & (1 << __scancode)) \ |
| 2346 | tpacpi_hotkey_send_key(__scancode); \ |
| 2347 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2348 | |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2349 | void issue_volchange(const unsigned int oldvol, |
| 2350 | const unsigned int newvol) |
| 2351 | { |
| 2352 | unsigned int i = oldvol; |
| 2353 | |
| 2354 | while (i > newvol) { |
| 2355 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2356 | i--; |
| 2357 | } |
| 2358 | while (i < newvol) { |
| 2359 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2360 | i++; |
| 2361 | } |
| 2362 | } |
| 2363 | |
Henrique de Moraes Holschuh | 2899902 | 2010-05-16 19:45:36 -0300 | [diff] [blame] | 2364 | void issue_brightnesschange(const unsigned int oldbrt, |
| 2365 | const unsigned int newbrt) |
| 2366 | { |
| 2367 | unsigned int i = oldbrt; |
| 2368 | |
| 2369 | while (i > newbrt) { |
| 2370 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2371 | i--; |
| 2372 | } |
| 2373 | while (i < newbrt) { |
| 2374 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2375 | i++; |
| 2376 | } |
| 2377 | } |
| 2378 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2379 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 2380 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 2381 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 2382 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 2383 | |
| 2384 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 2385 | |
| 2386 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 2387 | |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2388 | /* |
| 2389 | * Handle volume |
| 2390 | * |
| 2391 | * This code is supposed to duplicate the IBM firmware behaviour: |
| 2392 | * - Pressing MUTE issues mute hotkey message, even when already mute |
| 2393 | * - Pressing Volume up/down issues volume up/down hotkey messages, |
Lucas De Marchi | c844033 | 2011-03-17 17:18:22 -0300 | [diff] [blame] | 2394 | * even when already at maximum or minimum volume |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2395 | * - The act of unmuting issues volume up/down notification, |
| 2396 | * depending which key was used to unmute |
| 2397 | * |
| 2398 | * We are constrained to what the NVRAM can tell us, which is not much |
| 2399 | * and certainly not enough if more than one volume hotkey was pressed |
| 2400 | * since the last poll cycle. |
| 2401 | * |
| 2402 | * Just to make our life interesting, some newer Lenovo ThinkPads have |
| 2403 | * bugs in the BIOS and may fail to update volume_toggle properly. |
| 2404 | */ |
| 2405 | if (newn->mute) { |
| 2406 | /* muted */ |
| 2407 | if (!oldn->mute || |
| 2408 | oldn->volume_toggle != newn->volume_toggle || |
| 2409 | oldn->volume_level != newn->volume_level) { |
| 2410 | /* recently muted, or repeated mute keypress, or |
| 2411 | * multiple presses ending in mute */ |
| 2412 | issue_volchange(oldn->volume_level, newn->volume_level); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2413 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2414 | } |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2415 | } else { |
| 2416 | /* unmute */ |
| 2417 | if (oldn->mute) { |
| 2418 | /* recently unmuted, issue 'unmute' keypress */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2419 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2420 | } |
| 2421 | if (oldn->volume_level != newn->volume_level) { |
| 2422 | issue_volchange(oldn->volume_level, newn->volume_level); |
| 2423 | } else if (oldn->volume_toggle != newn->volume_toggle) { |
| 2424 | /* repeated vol up/down keypress at end of scale ? */ |
| 2425 | if (newn->volume_level == 0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2426 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
Henrique de Moraes Holschuh | 5d756db | 2010-05-16 19:45:28 -0300 | [diff] [blame] | 2427 | else if (newn->volume_level >= TP_NVRAM_LEVEL_VOLUME_MAX) |
| 2428 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | /* handle brightness */ |
Henrique de Moraes Holschuh | 2899902 | 2010-05-16 19:45:36 -0300 | [diff] [blame] | 2433 | if (oldn->brightness_level != newn->brightness_level) { |
| 2434 | issue_brightnesschange(oldn->brightness_level, |
| 2435 | newn->brightness_level); |
| 2436 | } else if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 2437 | /* repeated key presses that didn't change state */ |
| 2438 | if (newn->brightness_level == 0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2439 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | 2899902 | 2010-05-16 19:45:36 -0300 | [diff] [blame] | 2440 | else if (newn->brightness_level >= bright_maxlvl |
| 2441 | && !tp_features.bright_unkfw) |
| 2442 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2443 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2444 | |
| 2445 | #undef TPACPI_COMPARE_KEY |
| 2446 | #undef TPACPI_MAY_SEND_KEY |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2447 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2448 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2449 | /* |
| 2450 | * Polling driver |
| 2451 | * |
| 2452 | * We track all events in hotkey_source_mask all the time, since |
| 2453 | * most of them are edge-based. We only issue those requested by |
| 2454 | * hotkey_user_mask or hotkey_driver_mask, though. |
| 2455 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2456 | static int hotkey_kthread(void *data) |
| 2457 | { |
| 2458 | struct tp_nvram_state s[2]; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2459 | u32 poll_mask, event_mask; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2460 | unsigned int si, so; |
| 2461 | unsigned long t; |
Tejun Heo | 8a32c44 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 2462 | unsigned int change_detector; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2463 | unsigned int poll_freq; |
Tejun Heo | 8a32c44 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 2464 | bool was_frozen; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2465 | |
| 2466 | mutex_lock(&hotkey_thread_mutex); |
| 2467 | |
| 2468 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 2469 | goto exit; |
| 2470 | |
| 2471 | set_freezable(); |
| 2472 | |
| 2473 | so = 0; |
| 2474 | si = 1; |
| 2475 | t = 0; |
| 2476 | |
| 2477 | /* Initial state for compares */ |
| 2478 | mutex_lock(&hotkey_thread_data_mutex); |
| 2479 | change_detector = hotkey_config_change; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2480 | poll_mask = hotkey_source_mask; |
| 2481 | event_mask = hotkey_source_mask & |
| 2482 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2483 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2484 | mutex_unlock(&hotkey_thread_data_mutex); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2485 | hotkey_read_nvram(&s[so], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2486 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2487 | while (!kthread_should_stop()) { |
| 2488 | if (t == 0) { |
| 2489 | if (likely(poll_freq)) |
| 2490 | t = 1000/poll_freq; |
| 2491 | else |
| 2492 | t = 100; /* should never happen... */ |
| 2493 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2494 | t = msleep_interruptible(t); |
Tejun Heo | 8a32c44 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 2495 | if (unlikely(kthread_freezable_should_stop(&was_frozen))) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2496 | break; |
Tejun Heo | 8a32c44 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 2497 | |
| 2498 | if (t > 0 && !was_frozen) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2499 | continue; |
| 2500 | |
| 2501 | mutex_lock(&hotkey_thread_data_mutex); |
Tejun Heo | 8a32c44 | 2011-11-21 12:32:23 -0800 | [diff] [blame] | 2502 | if (was_frozen || hotkey_config_change != change_detector) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2503 | /* forget old state on thaw or config change */ |
| 2504 | si = so; |
| 2505 | t = 0; |
| 2506 | change_detector = hotkey_config_change; |
| 2507 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2508 | poll_mask = hotkey_source_mask; |
| 2509 | event_mask = hotkey_source_mask & |
| 2510 | (hotkey_driver_mask | hotkey_user_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2511 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2512 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2513 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2514 | if (likely(poll_mask)) { |
| 2515 | hotkey_read_nvram(&s[si], poll_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2516 | if (likely(si != so)) { |
| 2517 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2518 | event_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | |
| 2522 | so = si; |
| 2523 | si ^= 1; |
| 2524 | } |
| 2525 | |
| 2526 | exit: |
| 2527 | mutex_unlock(&hotkey_thread_mutex); |
| 2528 | return 0; |
| 2529 | } |
| 2530 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2531 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2532 | static void hotkey_poll_stop_sync(void) |
| 2533 | { |
| 2534 | if (tpacpi_hotkey_task) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2535 | kthread_stop(tpacpi_hotkey_task); |
| 2536 | tpacpi_hotkey_task = NULL; |
| 2537 | mutex_lock(&hotkey_thread_mutex); |
| 2538 | /* at this point, the thread did exit */ |
| 2539 | mutex_unlock(&hotkey_thread_mutex); |
| 2540 | } |
| 2541 | } |
| 2542 | |
| 2543 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2544 | static void hotkey_poll_setup(const bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2545 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2546 | const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask; |
| 2547 | 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] | 2548 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2549 | if (hotkey_poll_freq > 0 && |
| 2550 | (poll_driver_mask || |
| 2551 | (poll_user_mask && tpacpi_inputdev->users > 0))) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2552 | if (!tpacpi_hotkey_task) { |
| 2553 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 2554 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2555 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 2556 | tpacpi_hotkey_task = NULL; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2557 | pr_err("could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2558 | "for hotkey polling\n"); |
| 2559 | } |
| 2560 | } |
| 2561 | } else { |
| 2562 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2563 | if (may_warn && (poll_driver_mask || poll_user_mask) && |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2564 | hotkey_poll_freq == 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2565 | pr_notice("hot keys 0x%08x and/or events 0x%08x " |
| 2566 | "require polling, which is currently " |
| 2567 | "disabled\n", |
| 2568 | poll_user_mask, poll_driver_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2569 | } |
| 2570 | } |
| 2571 | } |
| 2572 | |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2573 | static void hotkey_poll_setup_safe(const bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2574 | { |
| 2575 | mutex_lock(&hotkey_mutex); |
| 2576 | hotkey_poll_setup(may_warn); |
| 2577 | mutex_unlock(&hotkey_mutex); |
| 2578 | } |
| 2579 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2580 | /* call with hotkey_mutex held */ |
| 2581 | static void hotkey_poll_set_freq(unsigned int freq) |
| 2582 | { |
| 2583 | if (!freq) |
| 2584 | hotkey_poll_stop_sync(); |
| 2585 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2586 | hotkey_poll_freq = freq; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2587 | } |
| 2588 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2589 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2590 | |
Henrique de Moraes Holschuh | 7f0cf71 | 2010-02-25 21:29:00 -0300 | [diff] [blame] | 2591 | static void hotkey_poll_setup(const bool __unused) |
| 2592 | { |
| 2593 | } |
| 2594 | |
| 2595 | static void hotkey_poll_setup_safe(const bool __unused) |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2596 | { |
| 2597 | } |
| 2598 | |
| 2599 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2600 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2601 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 2602 | { |
| 2603 | switch (tpacpi_lifecycle) { |
| 2604 | case TPACPI_LIFE_INIT: |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2605 | case TPACPI_LIFE_RUNNING: |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2606 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2607 | return 0; |
Henrique de Moraes Holschuh | b589ea4 | 2010-02-25 21:28:58 -0300 | [diff] [blame] | 2608 | case TPACPI_LIFE_EXITING: |
| 2609 | return -EBUSY; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 2613 | BUG(); |
| 2614 | return -EBUSY; |
| 2615 | } |
| 2616 | |
| 2617 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 2618 | { |
| 2619 | /* disable hotkey polling when possible */ |
Henrique de Moraes Holschuh | b589ea4 | 2010-02-25 21:28:58 -0300 | [diff] [blame] | 2620 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING && |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2621 | !(hotkey_source_mask & hotkey_driver_mask)) |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2622 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2623 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2624 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2625 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 2626 | static ssize_t hotkey_enable_show(struct device *dev, |
| 2627 | struct device_attribute *attr, |
| 2628 | char *buf) |
| 2629 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2630 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2631 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2632 | printk_deprecated_attribute("hotkey_enable", |
| 2633 | "Hotkey reporting is always enabled"); |
| 2634 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2635 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2636 | if (res) |
| 2637 | return res; |
| 2638 | |
| 2639 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 2640 | } |
| 2641 | |
| 2642 | static ssize_t hotkey_enable_store(struct device *dev, |
| 2643 | struct device_attribute *attr, |
| 2644 | const char *buf, size_t count) |
| 2645 | { |
| 2646 | unsigned long t; |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2647 | |
| 2648 | printk_deprecated_attribute("hotkey_enable", |
| 2649 | "Hotkeys can be disabled through hotkey_mask"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2650 | |
| 2651 | if (parse_strtoul(buf, 1, &t)) |
| 2652 | return -EINVAL; |
| 2653 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2654 | if (t == 0) |
| 2655 | return -EPERM; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2656 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2657 | return count; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2661 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2662 | hotkey_enable_show, hotkey_enable_store); |
| 2663 | |
| 2664 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 2665 | static ssize_t hotkey_mask_show(struct device *dev, |
| 2666 | struct device_attribute *attr, |
| 2667 | char *buf) |
| 2668 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2669 | 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] | 2670 | } |
| 2671 | |
| 2672 | static ssize_t hotkey_mask_store(struct device *dev, |
| 2673 | struct device_attribute *attr, |
| 2674 | const char *buf, size_t count) |
| 2675 | { |
| 2676 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2677 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2678 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2679 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2680 | return -EINVAL; |
| 2681 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2682 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2683 | return -ERESTARTSYS; |
| 2684 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2685 | res = hotkey_user_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2686 | |
| 2687 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2688 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2689 | #endif |
| 2690 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2691 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2692 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2693 | tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t); |
| 2694 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2695 | return (res) ? res : count; |
| 2696 | } |
| 2697 | |
| 2698 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2699 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2700 | hotkey_mask_show, hotkey_mask_store); |
| 2701 | |
| 2702 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 2703 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 2704 | struct device_attribute *attr, |
| 2705 | char *buf) |
| 2706 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2707 | return sprintf(buf, "0\n"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2711 | __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] | 2712 | |
| 2713 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 2714 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 2715 | struct device_attribute *attr, |
| 2716 | char *buf) |
| 2717 | { |
Henrique de Moraes Holschuh | 06777be | 2009-09-12 15:22:15 -0300 | [diff] [blame] | 2718 | printk_deprecated_attribute("hotkey_bios_mask", |
| 2719 | "This attribute is useless."); |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2720 | 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] | 2721 | } |
| 2722 | |
| 2723 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2724 | __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] | 2725 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2726 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 2727 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 2728 | struct device_attribute *attr, |
| 2729 | char *buf) |
| 2730 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2731 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 2732 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 2736 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 2737 | |
| 2738 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 2739 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 2740 | struct device_attribute *attr, |
| 2741 | char *buf) |
| 2742 | { |
| 2743 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2744 | (hotkey_all_mask | hotkey_source_mask) |
| 2745 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 2749 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 2750 | hotkey_recommended_mask_show, NULL); |
| 2751 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2752 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2753 | |
| 2754 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 2755 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 2756 | struct device_attribute *attr, |
| 2757 | char *buf) |
| 2758 | { |
| 2759 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 2760 | } |
| 2761 | |
| 2762 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 2763 | struct device_attribute *attr, |
| 2764 | const char *buf, size_t count) |
| 2765 | { |
| 2766 | unsigned long t; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2767 | u32 r_ev; |
| 2768 | int rc; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2769 | |
| 2770 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 2771 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 2772 | return -EINVAL; |
| 2773 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2774 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2775 | return -ERESTARTSYS; |
| 2776 | |
| 2777 | HOTKEY_CONFIG_CRITICAL_START |
| 2778 | hotkey_source_mask = t; |
| 2779 | HOTKEY_CONFIG_CRITICAL_END |
| 2780 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2781 | rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) & |
| 2782 | ~hotkey_source_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2783 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2784 | |
| 2785 | /* check if events needed by the driver got disabled */ |
| 2786 | r_ev = hotkey_driver_mask & ~(hotkey_acpi_mask & hotkey_all_mask) |
| 2787 | & ~hotkey_source_mask & TPACPI_HKEY_NVRAM_KNOWN_MASK; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2788 | |
| 2789 | mutex_unlock(&hotkey_mutex); |
| 2790 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2791 | if (rc < 0) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2792 | pr_err("hotkey_source_mask: " |
| 2793 | "failed to update the firmware event mask!\n"); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2794 | |
| 2795 | if (r_ev) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 2796 | pr_notice("hotkey_source_mask: " |
| 2797 | "some important events were disabled: 0x%04x\n", |
| 2798 | r_ev); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2799 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2800 | tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); |
| 2801 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2802 | return (rc < 0) ? rc : count; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 2806 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 2807 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 2808 | |
| 2809 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 2810 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 2811 | struct device_attribute *attr, |
| 2812 | char *buf) |
| 2813 | { |
| 2814 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 2815 | } |
| 2816 | |
| 2817 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 2818 | struct device_attribute *attr, |
| 2819 | const char *buf, size_t count) |
| 2820 | { |
| 2821 | unsigned long t; |
| 2822 | |
| 2823 | if (parse_strtoul(buf, 25, &t)) |
| 2824 | return -EINVAL; |
| 2825 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2826 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2827 | return -ERESTARTSYS; |
| 2828 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2829 | hotkey_poll_set_freq(t); |
| 2830 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2831 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2832 | mutex_unlock(&hotkey_mutex); |
| 2833 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2834 | tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t); |
| 2835 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2836 | return count; |
| 2837 | } |
| 2838 | |
| 2839 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 2840 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 2841 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 2842 | |
| 2843 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2844 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2845 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2846 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 2847 | struct device_attribute *attr, |
| 2848 | char *buf) |
| 2849 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2850 | int res; |
| 2851 | res = hotkey_get_wlsw(); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2852 | if (res < 0) |
| 2853 | return res; |
| 2854 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2855 | /* Opportunistic update */ |
| 2856 | tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF)); |
| 2857 | |
| 2858 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2859 | (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 2863 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 2864 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2865 | static void hotkey_radio_sw_notify_change(void) |
| 2866 | { |
| 2867 | if (tp_features.hotkey_wlsw) |
| 2868 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2869 | "hotkey_radio_sw"); |
| 2870 | } |
| 2871 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2872 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 2873 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 2874 | struct device_attribute *attr, |
| 2875 | char *buf) |
| 2876 | { |
| 2877 | int res, s; |
| 2878 | res = hotkey_get_tablet_mode(&s); |
| 2879 | if (res < 0) |
| 2880 | return res; |
| 2881 | |
| 2882 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 2883 | } |
| 2884 | |
| 2885 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 2886 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 2887 | |
| 2888 | static void hotkey_tablet_mode_notify_change(void) |
| 2889 | { |
| 2890 | if (tp_features.hotkey_tablet) |
| 2891 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2892 | "hotkey_tablet_mode"); |
| 2893 | } |
| 2894 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2895 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 2896 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 2897 | struct device_attribute *attr, |
| 2898 | char *buf) |
| 2899 | { |
| 2900 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2901 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 2902 | } |
| 2903 | |
| 2904 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 2905 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 2906 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2907 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2908 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 2909 | struct device_attribute *attr, |
| 2910 | char *buf) |
| 2911 | { |
| 2912 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 2913 | } |
| 2914 | |
| 2915 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 2916 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 2917 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2918 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2919 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2920 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2921 | "wakeup_reason"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2925 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 2926 | struct device_attribute *attr, |
| 2927 | char *buf) |
| 2928 | { |
| 2929 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 2930 | } |
| 2931 | |
| 2932 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 2933 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 2934 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 2935 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2936 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2937 | { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2938 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2939 | "wakeup_hotunplug_complete"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2940 | } |
| 2941 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2942 | /* --------------------------------------------------------------------- */ |
| 2943 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2944 | static struct attribute *hotkey_attributes[] __initdata = { |
| 2945 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2946 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2947 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2948 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2949 | &dev_attr_hotkey_wakeup_reason.attr, |
| 2950 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2951 | &dev_attr_hotkey_mask.attr, |
| 2952 | &dev_attr_hotkey_all_mask.attr, |
| 2953 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 2954 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2955 | &dev_attr_hotkey_source_mask.attr, |
| 2956 | &dev_attr_hotkey_poll_freq.attr, |
| 2957 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2958 | }; |
| 2959 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2960 | /* |
| 2961 | * Sync both the hw and sw blocking state of all switches |
| 2962 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2963 | static void tpacpi_send_radiosw_update(void) |
| 2964 | { |
| 2965 | int wlsw; |
| 2966 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2967 | /* |
| 2968 | * We must sync all rfkill controllers *before* issuing any |
| 2969 | * rfkill input events, or we will race the rfkill core input |
| 2970 | * handler. |
| 2971 | * |
Lucas De Marchi | c844033 | 2011-03-17 17:18:22 -0300 | [diff] [blame] | 2972 | * tpacpi_inputdev_send_mutex works as a synchronization point |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2973 | * for the above. |
| 2974 | * |
| 2975 | * We optimize to avoid numerous calls to hotkey_get_wlsw. |
| 2976 | */ |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 2977 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2978 | wlsw = hotkey_get_wlsw(); |
| 2979 | |
| 2980 | /* Sync hw blocking state first if it is hw-blocked */ |
| 2981 | if (wlsw == TPACPI_RFK_RADIO_OFF) |
| 2982 | tpacpi_rfk_update_hwblock_state(true); |
| 2983 | |
| 2984 | /* Sync sw blocking state */ |
| 2985 | tpacpi_rfk_update_swstate_all(); |
| 2986 | |
| 2987 | /* Sync hw blocking state last if it is hw-unblocked */ |
| 2988 | if (wlsw == TPACPI_RFK_RADIO_ON) |
| 2989 | tpacpi_rfk_update_hwblock_state(false); |
| 2990 | |
| 2991 | /* Issue rfkill input event for WLSW switch */ |
| 2992 | if (!(wlsw < 0)) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2993 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2994 | |
| 2995 | input_report_switch(tpacpi_inputdev, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2996 | SW_RFKILL_ALL, (wlsw > 0)); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2997 | input_sync(tpacpi_inputdev); |
| 2998 | |
| 2999 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 3000 | } |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3001 | |
| 3002 | /* |
| 3003 | * this can be unconditional, as we will poll state again |
| 3004 | * if userspace uses the notify to read data |
| 3005 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3006 | hotkey_radio_sw_notify_change(); |
| 3007 | } |
| 3008 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3009 | static void hotkey_exit(void) |
| 3010 | { |
| 3011 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3012 | mutex_lock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3013 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3014 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3015 | #endif |
| 3016 | |
| 3017 | if (hotkey_dev_attributes) |
| 3018 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3019 | |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3020 | dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3021 | "restoring original HKEY status and mask\n"); |
| 3022 | /* yes, there is a bitwise or below, we want the |
| 3023 | * functions to be called even if one of them fail */ |
| 3024 | if (((tp_features.hotkey_mask && |
| 3025 | hotkey_mask_set(hotkey_orig_mask)) | |
| 3026 | hotkey_status_set(false)) != 0) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3027 | pr_err("failed to restore hot key mask " |
Henrique de Moraes Holschuh | 4be7300 | 2009-09-20 14:09:23 -0300 | [diff] [blame] | 3028 | "to BIOS defaults\n"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3029 | } |
| 3030 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3031 | static void __init hotkey_unmap(const unsigned int scancode) |
| 3032 | { |
| 3033 | if (hotkey_keycode_map[scancode] != KEY_RESERVED) { |
| 3034 | clear_bit(hotkey_keycode_map[scancode], |
| 3035 | tpacpi_inputdev->keybit); |
| 3036 | hotkey_keycode_map[scancode] = KEY_RESERVED; |
| 3037 | } |
| 3038 | } |
| 3039 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3040 | /* |
| 3041 | * HKEY quirks: |
| 3042 | * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12 |
| 3043 | */ |
| 3044 | |
| 3045 | #define TPACPI_HK_Q_INIMASK 0x0001 |
| 3046 | |
| 3047 | static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = { |
| 3048 | TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3049 | TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK), /* 600E */ |
| 3050 | TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK), /* 770, 770E, 770ED */ |
| 3051 | TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK), /* A20m */ |
| 3052 | TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK), /* A20p */ |
| 3053 | TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK), /* A21e, A22e */ |
| 3054 | TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK), /* A21e */ |
| 3055 | TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK), /* A21m, A22m */ |
| 3056 | TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK), /* A21p, A22p */ |
| 3057 | TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK), /* A22e */ |
| 3058 | TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK), /* A22m */ |
| 3059 | TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK), /* A30/p (0) */ |
| 3060 | TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK), /* R30 */ |
| 3061 | TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK), /* R31 */ |
| 3062 | TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK), /* T20 */ |
| 3063 | TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK), /* T21 */ |
| 3064 | TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK), /* T22 */ |
| 3065 | TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK), /* X20, X21 */ |
| 3066 | TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */ |
| 3067 | }; |
| 3068 | |
Henrique de Moraes Holschuh | fc6e756 | 2010-09-17 21:53:41 -0300 | [diff] [blame] | 3069 | typedef u16 tpacpi_keymap_entry_t; |
| 3070 | typedef tpacpi_keymap_entry_t tpacpi_keymap_t[TPACPI_HOTKEY_MAP_LEN]; |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3071 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3072 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3073 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3074 | /* Requirements for changing the default keymaps: |
| 3075 | * |
| 3076 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 3077 | * good reasons. Do not change them unless you have deep |
| 3078 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 3079 | * the various ThinkPad models. The driver behaves |
| 3080 | * differently for KEY_RESERVED: such keys have their |
| 3081 | * hot key mask *unset* in mask_recommended, and also |
| 3082 | * in the initial hot key mask programmed into the |
| 3083 | * firmware at driver load time, which means the firm- |
| 3084 | * ware may react very differently if you change them to |
| 3085 | * something else; |
| 3086 | * |
| 3087 | * 2. You must be subscribed to the linux-thinkpad and |
| 3088 | * ibm-acpi-devel mailing lists, and you should read the |
| 3089 | * list archives since 2007 if you want to change the |
| 3090 | * keymaps. This requirement exists so that you will |
| 3091 | * know the past history of problems with the thinkpad- |
| 3092 | * acpi driver keymaps, and also that you will be |
| 3093 | * listening to any bug reports; |
| 3094 | * |
| 3095 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 3096 | * for merging, *ever*. Send them to the linux-acpi |
| 3097 | * mailinglist for comments. Merging is to be done only |
| 3098 | * through acpi-test and the ACPI maintainer. |
| 3099 | * |
| 3100 | * If the above is too much to ask, don't change the keymap. |
| 3101 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 3102 | */ |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3103 | |
| 3104 | enum keymap_index { |
| 3105 | TPACPI_KEYMAP_IBM_GENERIC = 0, |
| 3106 | TPACPI_KEYMAP_LENOVO_GENERIC, |
| 3107 | }; |
| 3108 | |
| 3109 | static const tpacpi_keymap_t tpacpi_keymaps[] __initconst = { |
| 3110 | /* Generic keymap for IBM ThinkPads */ |
| 3111 | [TPACPI_KEYMAP_IBM_GENERIC] = { |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3112 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3113 | KEY_FN_F1, KEY_BATTERY, KEY_COFFEE, KEY_SLEEP, |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3114 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 3115 | 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] | 3116 | |
| 3117 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3118 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3119 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3120 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3121 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3122 | /* brightness: firmware always reacts to them */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3123 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3124 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3125 | |
| 3126 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3127 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3128 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3129 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3130 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3131 | |
| 3132 | /* Volume: firmware always react to it and reprograms |
| 3133 | * the built-in *extra* mixer. Never map it to control |
| 3134 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3135 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3136 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3137 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3138 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3139 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3140 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3141 | /* (assignments unknown, please report if found) */ |
| 3142 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 3143 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3144 | }, |
| 3145 | |
| 3146 | /* Generic keymap for Lenovo ThinkPads */ |
| 3147 | [TPACPI_KEYMAP_LENOVO_GENERIC] = { |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3148 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 3149 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
Jens Taprogge | 2b75426 | 2010-08-09 23:48:22 -0300 | [diff] [blame] | 3150 | KEY_WLAN, KEY_CAMERA, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3151 | 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] | 3152 | |
| 3153 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3154 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 3155 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 3156 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3157 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3158 | /* These should be enabled --only-- when ACPI video |
| 3159 | * is disabled (i.e. in "vendor" mode), and are handled |
| 3160 | * in a special way by the init code */ |
| 3161 | KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ |
| 3162 | KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3163 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3164 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3165 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3166 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 3167 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3168 | |
| 3169 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 3170 | * react to it and reprograms the built-in *extra* mixer. |
| 3171 | * Never map it to control another mixer by default. |
| 3172 | * |
| 3173 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 3174 | * these over the regular keyboard, so these are no-ops, |
| 3175 | * but there are still weird bugs re. MUTE, so do not |
| 3176 | * change unless you get test reports from all Lenovo |
| 3177 | * models. May cause the BIOS to interfere with the |
| 3178 | * HDA mixer. |
| 3179 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 3180 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 3181 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 3182 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3183 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3184 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 3185 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3186 | /* (assignments unknown, please report if found) */ |
Andy Lutomirski | 3300955 | 2011-05-24 15:16:43 -0400 | [diff] [blame] | 3187 | KEY_UNKNOWN, KEY_UNKNOWN, |
| 3188 | |
| 3189 | /* |
| 3190 | * The mic mute button only sends 0x1a. It does not |
| 3191 | * automatically mute the mic or change the mute light. |
| 3192 | */ |
| 3193 | KEY_MICMUTE, /* 0x1a: Mic mute (since ?400 or so) */ |
| 3194 | |
| 3195 | /* (assignments unknown, please report if found) */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3196 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
Andy Lutomirski | 3300955 | 2011-05-24 15:16:43 -0400 | [diff] [blame] | 3197 | KEY_UNKNOWN, |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3198 | }, |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3199 | }; |
| 3200 | |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3201 | static const struct tpacpi_quirk tpacpi_keymap_qtable[] __initconst = { |
| 3202 | /* Generic maps (fallback) */ |
| 3203 | { |
| 3204 | .vendor = PCI_VENDOR_ID_IBM, |
| 3205 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 3206 | .quirks = TPACPI_KEYMAP_IBM_GENERIC, |
| 3207 | }, |
| 3208 | { |
| 3209 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 3210 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 3211 | .quirks = TPACPI_KEYMAP_LENOVO_GENERIC, |
| 3212 | }, |
| 3213 | }; |
| 3214 | |
| 3215 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(tpacpi_keymap_t) |
Henrique de Moraes Holschuh | fc6e756 | 2010-09-17 21:53:41 -0300 | [diff] [blame] | 3216 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(tpacpi_keymap_entry_t) |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3217 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3218 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3219 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 3220 | int hkeyv; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3221 | bool radiosw_state = false; |
| 3222 | bool tabletsw_state = false; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3223 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3224 | unsigned long quirks; |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3225 | unsigned long keymap_id; |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3226 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3227 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3228 | "initializing hotkey subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3229 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3230 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3231 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 3232 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3233 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3234 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3235 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3236 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 3237 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 3238 | mutex_init(&hotkey_thread_mutex); |
| 3239 | mutex_init(&hotkey_thread_data_mutex); |
| 3240 | #endif |
| 3241 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3242 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3243 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3244 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3245 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3246 | "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3247 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3248 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3249 | if (!tp_features.hotkey) |
| 3250 | return 1; |
| 3251 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3252 | quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, |
| 3253 | ARRAY_SIZE(tpacpi_hotkey_qtable)); |
| 3254 | |
Henrique de Moraes Holschuh | d64c81c4 | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3255 | tpacpi_disable_brightness_delay(); |
| 3256 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3257 | /* MUST have enough space for all attributes to be added to |
| 3258 | * hotkey_dev_attributes */ |
| 3259 | hotkey_dev_attributes = create_attr_set( |
| 3260 | ARRAY_SIZE(hotkey_attributes) + 2, |
| 3261 | NULL); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3262 | if (!hotkey_dev_attributes) |
| 3263 | return -ENOMEM; |
| 3264 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 3265 | hotkey_attributes, |
| 3266 | ARRAY_SIZE(hotkey_attributes)); |
| 3267 | if (res) |
| 3268 | goto err_exit; |
| 3269 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3270 | /* 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] | 3271 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 3272 | for HKEY interface version 0x100 */ |
| 3273 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 3274 | if ((hkeyv >> 8) != 1) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3275 | pr_err("unknown version of the HKEY interface: 0x%x\n", |
| 3276 | hkeyv); |
| 3277 | pr_err("please report this to %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3278 | } else { |
| 3279 | /* |
| 3280 | * MHKV 0x100 in A31, R40, R40e, |
| 3281 | * T4x, X31, and later |
| 3282 | */ |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3283 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3284 | "firmware HKEY interface version: 0x%x\n", |
| 3285 | hkeyv); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3286 | |
| 3287 | /* Paranoia check AND init hotkey_all_mask */ |
| 3288 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
| 3289 | "MHKA", "qd")) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3290 | pr_err("missing MHKA handler, " |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3291 | "please report this to %s\n", |
| 3292 | TPACPI_MAIL); |
| 3293 | /* Fallback: pre-init for FN+F3,F4,F12 */ |
| 3294 | hotkey_all_mask = 0x080cU; |
| 3295 | } else { |
| 3296 | tp_features.hotkey_mask = 1; |
| 3297 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3298 | } |
| 3299 | } |
| 3300 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3301 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3302 | "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3303 | str_supported(tp_features.hotkey_mask)); |
| 3304 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3305 | /* Init hotkey_all_mask if not initialized yet */ |
| 3306 | if (!tp_features.hotkey_mask && !hotkey_all_mask && |
| 3307 | (quirks & TPACPI_HK_Q_INIMASK)) |
| 3308 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3309 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3310 | /* Init hotkey_acpi_mask and hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3311 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3312 | /* hotkey_source_mask *must* be zero for |
| 3313 | * the first hotkey_mask_get to return hotkey_orig_mask */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3314 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3315 | if (res) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3316 | goto err_exit; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3317 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3318 | hotkey_orig_mask = hotkey_acpi_mask; |
| 3319 | } else { |
| 3320 | hotkey_orig_mask = hotkey_all_mask; |
| 3321 | hotkey_acpi_mask = hotkey_all_mask; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3322 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3323 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3324 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3325 | if (dbg_wlswemul) { |
| 3326 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3327 | radiosw_state = !!tpacpi_wlsw_emulstate; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3328 | pr_info("radio switch emulation enabled\n"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3329 | } else |
| 3330 | #endif |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3331 | /* Not all thinkpads have a hardware radio switch */ |
| 3332 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 3333 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3334 | radiosw_state = !!status; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3335 | pr_info("radio switch found; radios are %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3336 | enabled(status, 0)); |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3337 | } |
| 3338 | if (tp_features.hotkey_wlsw) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3339 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3340 | &dev_attr_hotkey_radio_sw.attr); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3341 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3342 | /* For X41t, X60t, X61t Tablets... */ |
| 3343 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 3344 | tp_features.hotkey_tablet = 1; |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3345 | tabletsw_state = !!(status & TP_HOTKEY_TABLET_MASK); |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3346 | pr_info("possible tablet mode switch found; " |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3347 | "ThinkPad in %s mode\n", |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3348 | (tabletsw_state) ? "tablet" : "laptop"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3349 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3350 | &dev_attr_hotkey_tablet_mode.attr); |
| 3351 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3352 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3353 | if (!res) |
| 3354 | res = register_attr_set_with_sysfs( |
| 3355 | hotkey_dev_attributes, |
| 3356 | &tpacpi_pdev->dev.kobj); |
| 3357 | if (res) |
| 3358 | goto err_exit; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3359 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3360 | /* Set up key map */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3361 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 3362 | GFP_KERNEL); |
| 3363 | if (!hotkey_keycode_map) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3364 | pr_err("failed to allocate memory for key map\n"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3365 | res = -ENOMEM; |
| 3366 | goto err_exit; |
| 3367 | } |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3368 | |
Henrique de Moraes Holschuh | d1e14dc | 2010-08-09 23:48:21 -0300 | [diff] [blame] | 3369 | keymap_id = tpacpi_check_quirks(tpacpi_keymap_qtable, |
| 3370 | ARRAY_SIZE(tpacpi_keymap_qtable)); |
| 3371 | BUG_ON(keymap_id >= ARRAY_SIZE(tpacpi_keymaps)); |
| 3372 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3373 | "using keymap number %lu\n", keymap_id); |
| 3374 | |
| 3375 | memcpy(hotkey_keycode_map, &tpacpi_keymaps[keymap_id], |
| 3376 | TPACPI_HOTKEY_MAP_SIZE); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3377 | |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3378 | input_set_capability(tpacpi_inputdev, EV_MSC, MSC_SCAN); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3379 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 3380 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 3381 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 3382 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
| 3383 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3384 | input_set_capability(tpacpi_inputdev, EV_KEY, |
| 3385 | hotkey_keycode_map[i]); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3386 | } else { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3387 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 3388 | hotkey_reserved_mask |= 1 << i; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3389 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3390 | } |
| 3391 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3392 | if (tp_features.hotkey_wlsw) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3393 | input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL); |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3394 | input_report_switch(tpacpi_inputdev, |
| 3395 | SW_RFKILL_ALL, radiosw_state); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3396 | } |
| 3397 | if (tp_features.hotkey_tablet) { |
Henrique de Moraes Holschuh | 792979c | 2009-12-09 01:36:29 +0000 | [diff] [blame] | 3398 | input_set_capability(tpacpi_inputdev, EV_SW, SW_TABLET_MODE); |
Henrique de Moraes Holschuh | d89a727 | 2009-12-15 21:51:06 -0200 | [diff] [blame] | 3399 | input_report_switch(tpacpi_inputdev, |
| 3400 | SW_TABLET_MODE, tabletsw_state); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3401 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3402 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3403 | /* Do not issue duplicate brightness change events to |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 3404 | * userspace. tpacpi_detect_brightness_capabilities() must have |
| 3405 | * been called before this point */ |
Alex Hung | ff41319 | 2012-04-24 16:40:52 +0800 | [diff] [blame] | 3406 | if (acpi_video_backlight_support()) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3407 | pr_info("This ThinkPad has standard ACPI backlight " |
| 3408 | "brightness control, supported by the ACPI " |
| 3409 | "video driver\n"); |
| 3410 | pr_notice("Disabling thinkpad-acpi brightness events " |
| 3411 | "by default...\n"); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3412 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3413 | /* Disable brightness up/down on Lenovo thinkpads when |
| 3414 | * ACPI is handling them, otherwise it is plain impossible |
| 3415 | * for userspace to do something even remotely sane */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3416 | hotkey_reserved_mask |= |
| 3417 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 3418 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3419 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 3420 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3421 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3422 | |
Henrique de Moraes Holschuh | 230d8cf25 | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3423 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3424 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 3425 | & ~hotkey_all_mask |
| 3426 | & ~hotkey_reserved_mask; |
Henrique de Moraes Holschuh | 230d8cf25 | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3427 | |
| 3428 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3429 | "hotkey source mask 0x%08x, polling freq %u\n", |
| 3430 | hotkey_source_mask, hotkey_poll_freq); |
| 3431 | #endif |
| 3432 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3433 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3434 | "enabling firmware HKEY event interface...\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3435 | res = hotkey_status_set(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3436 | if (res) { |
| 3437 | hotkey_exit(); |
| 3438 | return res; |
| 3439 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3440 | res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask) |
| 3441 | | hotkey_driver_mask) |
| 3442 | & ~hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3443 | if (res < 0 && res != -ENXIO) { |
| 3444 | hotkey_exit(); |
| 3445 | return res; |
| 3446 | } |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3447 | hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask) |
| 3448 | & ~hotkey_reserved_mask; |
| 3449 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3450 | "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n", |
| 3451 | hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3452 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3453 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3454 | "legacy ibm/hotkey event reporting over procfs %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3455 | (hotkey_report_mode < 2) ? |
| 3456 | "enabled" : "disabled"); |
| 3457 | |
| 3458 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 3459 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 3460 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3461 | hotkey_poll_setup_safe(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3462 | |
| 3463 | return 0; |
| 3464 | |
| 3465 | err_exit: |
| 3466 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3467 | hotkey_dev_attributes = NULL; |
| 3468 | |
| 3469 | return (res < 0)? res : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3470 | } |
| 3471 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3472 | static bool hotkey_notify_hotkey(const u32 hkey, |
| 3473 | bool *send_acpi_ev, |
| 3474 | bool *ignore_acpi_ev) |
| 3475 | { |
| 3476 | /* 0x1000-0x1FFF: key presses */ |
| 3477 | unsigned int scancode = hkey & 0xfff; |
| 3478 | *send_acpi_ev = true; |
| 3479 | *ignore_acpi_ev = false; |
| 3480 | |
Henrique de Moraes Holschuh | 34a656d2 | 2010-08-09 23:48:20 -0300 | [diff] [blame] | 3481 | /* HKEY event 0x1001 is scancode 0x00 */ |
| 3482 | if (scancode > 0 && scancode <= TPACPI_HOTKEY_MAP_LEN) { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3483 | scancode--; |
| 3484 | if (!(hotkey_source_mask & (1 << scancode))) { |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3485 | tpacpi_input_send_key_masked(scancode); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3486 | *send_acpi_ev = false; |
| 3487 | } else { |
| 3488 | *ignore_acpi_ev = true; |
| 3489 | } |
| 3490 | return true; |
| 3491 | } |
| 3492 | return false; |
| 3493 | } |
| 3494 | |
| 3495 | static bool hotkey_notify_wakeup(const u32 hkey, |
| 3496 | bool *send_acpi_ev, |
| 3497 | bool *ignore_acpi_ev) |
| 3498 | { |
| 3499 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3500 | *send_acpi_ev = true; |
| 3501 | *ignore_acpi_ev = false; |
| 3502 | |
| 3503 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3504 | case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */ |
| 3505 | case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3506 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 3507 | *ignore_acpi_ev = true; |
| 3508 | break; |
| 3509 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3510 | case TP_HKEY_EV_WKUP_S3_BAYEJ: /* suspend, bay eject */ |
| 3511 | case TP_HKEY_EV_WKUP_S4_BAYEJ: /* hibernation, bay eject */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3512 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 3513 | *ignore_acpi_ev = true; |
| 3514 | break; |
| 3515 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3516 | case TP_HKEY_EV_WKUP_S3_BATLOW: /* Battery on critical low level/S3 */ |
| 3517 | case TP_HKEY_EV_WKUP_S4_BATLOW: /* Battery on critical low level/S4 */ |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3518 | pr_alert("EMERGENCY WAKEUP: battery almost empty\n"); |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3519 | /* how to auto-heal: */ |
| 3520 | /* 2313: woke up from S3, go to S4/S5 */ |
| 3521 | /* 2413: woke up from S4, go to S5 */ |
| 3522 | break; |
| 3523 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3524 | default: |
| 3525 | return false; |
| 3526 | } |
| 3527 | |
| 3528 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3529 | pr_info("woke up due to a hot-unplug request...\n"); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3530 | hotkey_wakeup_reason_notify_change(); |
| 3531 | } |
| 3532 | return true; |
| 3533 | } |
| 3534 | |
Henrique de Moraes Holschuh | a50245a | 2011-06-05 16:22:35 -0300 | [diff] [blame] | 3535 | static bool hotkey_notify_dockevent(const u32 hkey, |
| 3536 | bool *send_acpi_ev, |
| 3537 | bool *ignore_acpi_ev) |
| 3538 | { |
| 3539 | /* 0x4000-0x4FFF: dock-related events */ |
| 3540 | *send_acpi_ev = true; |
| 3541 | *ignore_acpi_ev = false; |
| 3542 | |
| 3543 | switch (hkey) { |
| 3544 | case TP_HKEY_EV_UNDOCK_ACK: |
| 3545 | /* ACPI undock operation completed after wakeup */ |
| 3546 | hotkey_autosleep_ack = 1; |
| 3547 | pr_info("undocked\n"); |
| 3548 | hotkey_wakeup_hotunplug_complete_notify_change(); |
| 3549 | return true; |
| 3550 | |
| 3551 | case TP_HKEY_EV_HOTPLUG_DOCK: /* docked to port replicator */ |
| 3552 | pr_info("docked into hotplug port replicator\n"); |
| 3553 | return true; |
| 3554 | case TP_HKEY_EV_HOTPLUG_UNDOCK: /* undocked from port replicator */ |
| 3555 | pr_info("undocked from hotplug port replicator\n"); |
| 3556 | return true; |
| 3557 | |
| 3558 | default: |
| 3559 | return false; |
| 3560 | } |
| 3561 | } |
| 3562 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3563 | static bool hotkey_notify_usrevent(const u32 hkey, |
| 3564 | bool *send_acpi_ev, |
| 3565 | bool *ignore_acpi_ev) |
| 3566 | { |
| 3567 | /* 0x5000-0x5FFF: human interface helpers */ |
| 3568 | *send_acpi_ev = true; |
| 3569 | *ignore_acpi_ev = false; |
| 3570 | |
| 3571 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3572 | case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */ |
| 3573 | 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] | 3574 | return true; |
| 3575 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3576 | case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */ |
| 3577 | case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3578 | tpacpi_input_send_tabletsw(); |
| 3579 | hotkey_tablet_mode_notify_change(); |
| 3580 | *send_acpi_ev = false; |
| 3581 | return true; |
| 3582 | |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3583 | case TP_HKEY_EV_LID_CLOSE: /* Lid closed */ |
| 3584 | case TP_HKEY_EV_LID_OPEN: /* Lid opened */ |
| 3585 | case TP_HKEY_EV_BRGHT_CHANGED: /* brightness changed */ |
Henrique de Moraes Holschuh | 176dd98 | 2009-09-20 14:09:24 -0300 | [diff] [blame] | 3586 | /* do not propagate these events */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3587 | *ignore_acpi_ev = true; |
| 3588 | return true; |
| 3589 | |
| 3590 | default: |
| 3591 | return false; |
| 3592 | } |
| 3593 | } |
| 3594 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3595 | static void thermal_dump_all_sensors(void); |
| 3596 | |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3597 | static bool hotkey_notify_6xxx(const u32 hkey, |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3598 | bool *send_acpi_ev, |
| 3599 | bool *ignore_acpi_ev) |
| 3600 | { |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3601 | bool known = true; |
| 3602 | |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3603 | /* 0x6000-0x6FFF: thermal alarms/notices and keyboard events */ |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3604 | *send_acpi_ev = true; |
| 3605 | *ignore_acpi_ev = false; |
| 3606 | |
| 3607 | switch (hkey) { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3608 | case TP_HKEY_EV_THM_TABLE_CHANGED: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3609 | pr_info("EC reports that Thermal Table has changed\n"); |
Henrique de Moraes Holschuh | 54926ce | 2009-01-11 03:01:09 -0200 | [diff] [blame] | 3610 | /* recommended action: do nothing, we don't have |
| 3611 | * Lenovo ATM information */ |
| 3612 | return true; |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3613 | case TP_HKEY_EV_ALARM_BAT_HOT: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3614 | pr_crit("THERMAL ALARM: battery is too hot!\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3615 | /* recommended action: warn user through gui */ |
| 3616 | break; |
| 3617 | case TP_HKEY_EV_ALARM_BAT_XHOT: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3618 | pr_alert("THERMAL EMERGENCY: battery is extremely hot!\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3619 | /* recommended action: immediate sleep/hibernate */ |
| 3620 | break; |
| 3621 | case TP_HKEY_EV_ALARM_SENSOR_HOT: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3622 | pr_crit("THERMAL ALARM: " |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3623 | "a sensor reports something is too hot!\n"); |
| 3624 | /* recommended action: warn user through gui, that */ |
| 3625 | /* some internal component is too hot */ |
| 3626 | break; |
| 3627 | case TP_HKEY_EV_ALARM_SENSOR_XHOT: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3628 | pr_alert("THERMAL EMERGENCY: " |
| 3629 | "a sensor reports something is extremely hot!\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3630 | /* recommended action: immediate sleep/hibernate */ |
| 3631 | break; |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3632 | |
| 3633 | case TP_HKEY_EV_KEY_NUMLOCK: |
| 3634 | case TP_HKEY_EV_KEY_FN: |
| 3635 | /* key press events, we just ignore them as long as the EC |
| 3636 | * is still reporting them in the normal keyboard stream */ |
| 3637 | *send_acpi_ev = false; |
| 3638 | *ignore_acpi_ev = true; |
| 3639 | return true; |
| 3640 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3641 | default: |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3642 | pr_warn("unknown possible thermal alarm or keyboard event received\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3643 | known = false; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3644 | } |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 3645 | |
| 3646 | thermal_dump_all_sensors(); |
| 3647 | |
| 3648 | return known; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3649 | } |
| 3650 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3651 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 3652 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3653 | u32 hkey; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3654 | bool send_acpi_ev; |
| 3655 | bool ignore_acpi_ev; |
| 3656 | bool known_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3657 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3658 | if (event != 0x80) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3659 | pr_err("unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3660 | /* forward it to userspace, maybe it knows how to handle it */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3661 | acpi_bus_generate_netlink_event( |
| 3662 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3663 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3664 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3665 | return; |
| 3666 | } |
| 3667 | |
| 3668 | while (1) { |
| 3669 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3670 | pr_err("failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3671 | return; |
| 3672 | } |
| 3673 | |
| 3674 | if (hkey == 0) { |
| 3675 | /* queue empty */ |
| 3676 | return; |
| 3677 | } |
| 3678 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3679 | send_acpi_ev = true; |
| 3680 | ignore_acpi_ev = false; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3681 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3682 | switch (hkey >> 12) { |
| 3683 | case 1: |
| 3684 | /* 0x1000-0x1FFF: key presses */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3685 | known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev, |
| 3686 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3687 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3688 | case 2: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3689 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3690 | known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev, |
| 3691 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3692 | break; |
| 3693 | case 3: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3694 | /* 0x3000-0x3FFF: bay-related wakeups */ |
Henrique de Moraes Holschuh | bf8b29c | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 3695 | switch (hkey) { |
| 3696 | case TP_HKEY_EV_BAYEJ_ACK: |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3697 | hotkey_autosleep_ack = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3698 | pr_info("bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3699 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3700 | known_ev = true; |
Henrique de Moraes Holschuh | bf8b29c | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 3701 | break; |
| 3702 | case TP_HKEY_EV_OPTDRV_EJ: |
| 3703 | /* FIXME: kick libata if SATA link offline */ |
| 3704 | known_ev = true; |
| 3705 | break; |
| 3706 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3707 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3708 | } |
| 3709 | break; |
| 3710 | case 4: |
Henrique de Moraes Holschuh | a50245a | 2011-06-05 16:22:35 -0300 | [diff] [blame] | 3711 | /* 0x4000-0x4FFF: dock-related events */ |
| 3712 | known_ev = hotkey_notify_dockevent(hkey, &send_acpi_ev, |
| 3713 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3714 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3715 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 3716 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3717 | known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev, |
| 3718 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3719 | break; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3720 | case 6: |
Henrique de Moraes Holschuh | 2d43f67 | 2011-06-05 16:22:34 -0300 | [diff] [blame] | 3721 | /* 0x6000-0x6FFF: thermal alarms/notices and |
| 3722 | * keyboard events */ |
| 3723 | known_ev = hotkey_notify_6xxx(hkey, &send_acpi_ev, |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3724 | &ignore_acpi_ev); |
| 3725 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3726 | case 7: |
| 3727 | /* 0x7000-0x7FFF: misc */ |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 3728 | if (tp_features.hotkey_wlsw && |
| 3729 | hkey == TP_HKEY_EV_RFKILL_CHANGED) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3730 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3731 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3732 | known_ev = true; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3733 | break; |
| 3734 | } |
| 3735 | /* fallthrough to default */ |
| 3736 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3737 | known_ev = false; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3738 | } |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3739 | if (!known_ev) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3740 | pr_notice("unhandled HKEY event 0x%04x\n", hkey); |
| 3741 | pr_notice("please report the conditions when this " |
| 3742 | "event happened to %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3743 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3744 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3745 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3746 | if (!ignore_acpi_ev && |
| 3747 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 3748 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 3749 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3750 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3751 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3752 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3753 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3754 | acpi_bus_generate_netlink_event( |
| 3755 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3756 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3757 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3758 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3759 | } |
| 3760 | } |
| 3761 | |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 3762 | static void hotkey_suspend(void) |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3763 | { |
| 3764 | /* Do these on suspend, we get the events on early resume! */ |
| 3765 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 3766 | hotkey_autosleep_ack = 0; |
| 3767 | } |
| 3768 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3769 | static void hotkey_resume(void) |
| 3770 | { |
Henrique de Moraes Holschuh | d64c81c4 | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3771 | tpacpi_disable_brightness_delay(); |
| 3772 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3773 | if (hotkey_status_set(true) < 0 || |
| 3774 | hotkey_mask_set(hotkey_acpi_mask) < 0) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3775 | pr_err("error while attempting to reset the event " |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3776 | "firmware interface\n"); |
| 3777 | |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3778 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3779 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3780 | hotkey_wakeup_reason_notify_change(); |
| 3781 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3782 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3783 | } |
| 3784 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3785 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3786 | static int hotkey_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3788 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3790 | if (!tp_features.hotkey) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3791 | seq_printf(m, "status:\t\tnot supported\n"); |
| 3792 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3793 | } |
| 3794 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3795 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3796 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3797 | res = hotkey_status_get(&status); |
| 3798 | if (!res) |
| 3799 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3800 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3801 | if (res) |
| 3802 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3804 | seq_printf(m, "status:\t\t%s\n", enabled(status, 0)); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3805 | if (hotkey_all_mask) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3806 | seq_printf(m, "mask:\t\t0x%08x\n", hotkey_user_mask); |
| 3807 | seq_printf(m, "commands:\tenable, disable, reset, <mask>\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | } else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3809 | seq_printf(m, "mask:\t\tnot supported\n"); |
| 3810 | seq_printf(m, "commands:\tenable, disable, reset\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 3813 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | } |
| 3815 | |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3816 | static void hotkey_enabledisable_warn(bool enable) |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3817 | { |
| 3818 | tpacpi_log_usertask("procfs hotkey enable/disable"); |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3819 | if (!WARN((tpacpi_lifecycle == TPACPI_LIFE_RUNNING || !enable), |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 3820 | pr_fmt("hotkey enable/disable functionality has been " |
| 3821 | "removed from the driver. " |
| 3822 | "Hotkeys are always enabled.\n"))) |
| 3823 | pr_err("Please remove the hotkey=enable module " |
| 3824 | "parameter, it is deprecated. " |
| 3825 | "Hotkeys are always enabled.\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3828 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3830 | int res; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3831 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3834 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | return -ENODEV; |
| 3836 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3837 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3838 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3839 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3840 | mask = hotkey_user_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3841 | |
| 3842 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | while ((cmd = next_cmd(&buf))) { |
| 3844 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3845 | hotkey_enabledisable_warn(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3847 | hotkey_enabledisable_warn(0); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3848 | res = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | } else if (strlencmp(cmd, "reset") == 0) { |
Henrique de Moraes Holschuh | 20c9aa4 | 2009-09-12 15:22:16 -0300 | [diff] [blame] | 3850 | mask = (hotkey_all_mask | hotkey_source_mask) |
| 3851 | & ~hotkey_reserved_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 3853 | /* mask set */ |
| 3854 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 3855 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3856 | } else { |
| 3857 | res = -EINVAL; |
| 3858 | goto errexit; |
| 3859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | } |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3861 | |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3862 | if (!res) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3863 | tpacpi_disclose_usertask("procfs hotkey", |
| 3864 | "set mask to 0x%08x\n", mask); |
Henrique de Moraes Holschuh | 0d922e3 | 2009-09-20 14:09:25 -0300 | [diff] [blame] | 3865 | res = hotkey_user_mask_set(mask); |
| 3866 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3868 | errexit: |
| 3869 | mutex_unlock(&hotkey_mutex); |
| 3870 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3871 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3873 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Manoj Iyer | 9fbdaeb | 2011-05-08 18:04:29 -0400 | [diff] [blame] | 3874 | {TPACPI_ACPI_IBM_HKEY_HID, 0}, |
| 3875 | {TPACPI_ACPI_LENOVO_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3876 | {"", 0}, |
| 3877 | }; |
| 3878 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3879 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3880 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3881 | .notify = hotkey_notify, |
| 3882 | .handle = &hkey_handle, |
| 3883 | .type = ACPI_DEVICE_NOTIFY, |
| 3884 | }; |
| 3885 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3886 | static struct ibm_struct hotkey_driver_data = { |
| 3887 | .name = "hotkey", |
| 3888 | .read = hotkey_read, |
| 3889 | .write = hotkey_write, |
| 3890 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3891 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3892 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3893 | .acpi = &ibm_hotkey_acpidriver, |
| 3894 | }; |
| 3895 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3896 | /************************************************************************* |
| 3897 | * Bluetooth subdriver |
| 3898 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3900 | enum { |
| 3901 | /* ACPI GBDC/SBDC bits */ |
| 3902 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 3903 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3904 | TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 3905 | 0 = disable, 1 = enable */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3906 | }; |
| 3907 | |
| 3908 | enum { |
| 3909 | /* ACPI \BLTH commands */ |
| 3910 | TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */ |
| 3911 | TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */ |
| 3912 | TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */ |
| 3913 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */ |
| 3914 | 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] | 3915 | }; |
| 3916 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3917 | #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" |
| 3918 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3919 | static int bluetooth_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3920 | { |
| 3921 | int status; |
| 3922 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3923 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3924 | if (dbg_bluetoothemul) |
| 3925 | return (tpacpi_bluetooth_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3926 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3927 | #endif |
| 3928 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3929 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 3930 | return -EIO; |
| 3931 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3932 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3933 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3934 | } |
| 3935 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3936 | static int bluetooth_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3937 | { |
| 3938 | int status; |
| 3939 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3940 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3941 | "will attempt to %s bluetooth\n", |
| 3942 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3943 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3944 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3945 | if (dbg_bluetoothemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3946 | tpacpi_bluetooth_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3947 | return 0; |
| 3948 | } |
| 3949 | #endif |
| 3950 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3951 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 3952 | status = TP_ACPI_BLUETOOTH_RADIOSSW |
| 3953 | | TP_ACPI_BLUETOOTH_RESUMECTRL; |
| 3954 | else |
| 3955 | status = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3956 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3957 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 3958 | return -EIO; |
| 3959 | |
| 3960 | return 0; |
| 3961 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3962 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3963 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 3964 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 3965 | struct device_attribute *attr, |
| 3966 | char *buf) |
| 3967 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3968 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3969 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 3973 | struct device_attribute *attr, |
| 3974 | const char *buf, size_t count) |
| 3975 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3976 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3977 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3978 | } |
| 3979 | |
| 3980 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 3981 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3982 | bluetooth_enable_show, bluetooth_enable_store); |
| 3983 | |
| 3984 | /* --------------------------------------------------------------------- */ |
| 3985 | |
| 3986 | static struct attribute *bluetooth_attributes[] = { |
| 3987 | &dev_attr_bluetooth_enable.attr, |
| 3988 | NULL |
| 3989 | }; |
| 3990 | |
| 3991 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3992 | .attrs = bluetooth_attributes, |
| 3993 | }; |
| 3994 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3995 | static const struct tpacpi_rfk_ops bluetooth_tprfk_ops = { |
| 3996 | .get_status = bluetooth_get_status, |
| 3997 | .set_status = bluetooth_set_status, |
| 3998 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3999 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4000 | static void bluetooth_shutdown(void) |
| 4001 | { |
| 4002 | /* Order firmware to save current state to NVRAM */ |
| 4003 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 4004 | TP_ACPI_BLTH_SAVE_STATE)) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4005 | pr_notice("failed to save bluetooth state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4006 | else |
| 4007 | vdbg_printk(TPACPI_DBG_RFKILL, |
Paul Bolle | 1f01358 | 2011-10-06 22:57:56 +0200 | [diff] [blame] | 4008 | "bluetooth state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4009 | } |
| 4010 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4011 | static void bluetooth_exit(void) |
| 4012 | { |
| 4013 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 4014 | &bluetooth_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4015 | |
| 4016 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
| 4017 | |
| 4018 | bluetooth_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4019 | } |
| 4020 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4021 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4023 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4024 | int status = 0; |
| 4025 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4026 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4027 | "initializing bluetooth subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4028 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4029 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4030 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4031 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4032 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4033 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4034 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4036 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4037 | "bluetooth is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4038 | str_supported(tp_features.bluetooth), |
| 4039 | status); |
| 4040 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4041 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4042 | if (dbg_bluetoothemul) { |
| 4043 | tp_features.bluetooth = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4044 | pr_info("bluetooth switch emulation enabled\n"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4045 | } else |
| 4046 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4047 | if (tp_features.bluetooth && |
| 4048 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 4049 | /* no bluetooth hardware present in system */ |
| 4050 | tp_features.bluetooth = 0; |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4051 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4052 | "bluetooth hardware not installed\n"); |
| 4053 | } |
| 4054 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4055 | if (!tp_features.bluetooth) |
| 4056 | return 1; |
| 4057 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4058 | res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 4059 | &bluetooth_tprfk_ops, |
| 4060 | RFKILL_TYPE_BLUETOOTH, |
| 4061 | TPACPI_RFK_BLUETOOTH_SW_NAME, |
| 4062 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4063 | if (res) |
| 4064 | return res; |
| 4065 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4066 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4067 | &bluetooth_attr_group); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4068 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4069 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4070 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4071 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4072 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4073 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4076 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4077 | static int bluetooth_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4079 | return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID, m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | } |
| 4081 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4082 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4084 | return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | } |
| 4086 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4087 | static struct ibm_struct bluetooth_driver_data = { |
| 4088 | .name = "bluetooth", |
| 4089 | .read = bluetooth_read, |
| 4090 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4091 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4092 | .shutdown = bluetooth_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4093 | }; |
| 4094 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4095 | /************************************************************************* |
| 4096 | * Wan subdriver |
| 4097 | */ |
| 4098 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4099 | enum { |
| 4100 | /* ACPI GWAN/SWAN bits */ |
| 4101 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 4102 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4103 | TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 4104 | 0 = disable, 1 = enable */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4105 | }; |
| 4106 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4107 | #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" |
| 4108 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4109 | static int wan_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4110 | { |
| 4111 | int status; |
| 4112 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4113 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4114 | if (dbg_wwanemul) |
| 4115 | return (tpacpi_wwan_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4116 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4117 | #endif |
| 4118 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4119 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 4120 | return -EIO; |
| 4121 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4122 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4123 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4124 | } |
| 4125 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4126 | static int wan_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4127 | { |
| 4128 | int status; |
| 4129 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4130 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4131 | "will attempt to %s wwan\n", |
| 4132 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4133 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4134 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4135 | if (dbg_wwanemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4136 | tpacpi_wwan_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4137 | return 0; |
| 4138 | } |
| 4139 | #endif |
| 4140 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4141 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 08fedfc | 2010-02-25 22:22:07 -0300 | [diff] [blame] | 4142 | status = TP_ACPI_WANCARD_RADIOSSW |
| 4143 | | TP_ACPI_WANCARD_RESUMECTRL; |
| 4144 | else |
| 4145 | status = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4146 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4147 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 4148 | return -EIO; |
| 4149 | |
| 4150 | return 0; |
| 4151 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4152 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4153 | /* sysfs wan enable ---------------------------------------------------- */ |
| 4154 | static ssize_t wan_enable_show(struct device *dev, |
| 4155 | struct device_attribute *attr, |
| 4156 | char *buf) |
| 4157 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4158 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID, |
| 4159 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | static ssize_t wan_enable_store(struct device *dev, |
| 4163 | struct device_attribute *attr, |
| 4164 | const char *buf, size_t count) |
| 4165 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4166 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID, |
| 4167 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 4171 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4172 | wan_enable_show, wan_enable_store); |
| 4173 | |
| 4174 | /* --------------------------------------------------------------------- */ |
| 4175 | |
| 4176 | static struct attribute *wan_attributes[] = { |
| 4177 | &dev_attr_wan_enable.attr, |
| 4178 | NULL |
| 4179 | }; |
| 4180 | |
| 4181 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4182 | .attrs = wan_attributes, |
| 4183 | }; |
| 4184 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4185 | static const struct tpacpi_rfk_ops wan_tprfk_ops = { |
| 4186 | .get_status = wan_get_status, |
| 4187 | .set_status = wan_set_status, |
| 4188 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4189 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4190 | static void wan_shutdown(void) |
| 4191 | { |
| 4192 | /* Order firmware to save current state to NVRAM */ |
| 4193 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd", |
| 4194 | TP_ACPI_WGSV_SAVE_STATE)) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4195 | pr_notice("failed to save WWAN state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4196 | else |
| 4197 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 4198 | "WWAN state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4199 | } |
| 4200 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4201 | static void wan_exit(void) |
| 4202 | { |
| 4203 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 4204 | &wan_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4205 | |
| 4206 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
| 4207 | |
| 4208 | wan_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 4209 | } |
| 4210 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4211 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4212 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4213 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4214 | int status = 0; |
| 4215 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4216 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4217 | "initializing wan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4218 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4219 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4220 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4221 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4222 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4223 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4224 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4225 | "wan is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4226 | str_supported(tp_features.wan), |
| 4227 | status); |
| 4228 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4229 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4230 | if (dbg_wwanemul) { |
| 4231 | tp_features.wan = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4232 | pr_info("wwan switch emulation enabled\n"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 4233 | } else |
| 4234 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4235 | if (tp_features.wan && |
| 4236 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 4237 | /* no wan hardware present in system */ |
| 4238 | tp_features.wan = 0; |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4239 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 4240 | "wan hardware not installed\n"); |
| 4241 | } |
| 4242 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4243 | if (!tp_features.wan) |
| 4244 | return 1; |
| 4245 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4246 | res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, |
| 4247 | &wan_tprfk_ops, |
| 4248 | RFKILL_TYPE_WWAN, |
| 4249 | TPACPI_RFK_WWAN_SW_NAME, |
| 4250 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4251 | if (res) |
| 4252 | return res; |
| 4253 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4254 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4255 | &wan_attr_group); |
| 4256 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4257 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4258 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4259 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4260 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4261 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4262 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4263 | } |
| 4264 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4265 | /* procfs -------------------------------------------------------------- */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4266 | static int wan_read(struct seq_file *m) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4267 | { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4268 | return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID, m); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | static int wan_write(char *buf) |
| 4272 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4273 | return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID, buf); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4274 | } |
| 4275 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4276 | static struct ibm_struct wan_driver_data = { |
| 4277 | .name = "wan", |
| 4278 | .read = wan_read, |
| 4279 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4280 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4281 | .shutdown = wan_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4282 | }; |
| 4283 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4284 | /************************************************************************* |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4285 | * UWB subdriver |
| 4286 | */ |
| 4287 | |
| 4288 | enum { |
| 4289 | /* ACPI GUWB/SUWB bits */ |
| 4290 | TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */ |
| 4291 | TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */ |
| 4292 | }; |
| 4293 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4294 | #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" |
| 4295 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4296 | static int uwb_get_status(void) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4297 | { |
| 4298 | int status; |
| 4299 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4300 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4301 | if (dbg_uwbemul) |
| 4302 | return (tpacpi_uwb_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4303 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4304 | #endif |
| 4305 | |
| 4306 | if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) |
| 4307 | return -EIO; |
| 4308 | |
| 4309 | return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4310 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4311 | } |
| 4312 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4313 | static int uwb_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4314 | { |
| 4315 | int status; |
| 4316 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4317 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4318 | "will attempt to %s UWB\n", |
| 4319 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4320 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4321 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4322 | if (dbg_uwbemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4323 | tpacpi_uwb_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4324 | return 0; |
| 4325 | } |
| 4326 | #endif |
| 4327 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4328 | if (state == TPACPI_RFK_RADIO_ON) |
| 4329 | status = TP_ACPI_UWB_RADIOSSW; |
| 4330 | else |
| 4331 | status = 0; |
| 4332 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4333 | if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) |
| 4334 | return -EIO; |
| 4335 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4336 | return 0; |
| 4337 | } |
| 4338 | |
| 4339 | /* --------------------------------------------------------------------- */ |
| 4340 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4341 | static const struct tpacpi_rfk_ops uwb_tprfk_ops = { |
| 4342 | .get_status = uwb_get_status, |
| 4343 | .set_status = uwb_set_status, |
| 4344 | }; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4345 | |
| 4346 | static void uwb_exit(void) |
| 4347 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4348 | tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | static int __init uwb_init(struct ibm_init_struct *iibm) |
| 4352 | { |
| 4353 | int res; |
| 4354 | int status = 0; |
| 4355 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4356 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4357 | "initializing uwb subdriver\n"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4358 | |
| 4359 | TPACPI_ACPIHANDLE_INIT(hkey); |
| 4360 | |
| 4361 | tp_features.uwb = hkey_handle && |
| 4362 | acpi_evalf(hkey_handle, &status, "GUWB", "qd"); |
| 4363 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4364 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4365 | "uwb is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4366 | str_supported(tp_features.uwb), |
| 4367 | status); |
| 4368 | |
| 4369 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4370 | if (dbg_uwbemul) { |
| 4371 | tp_features.uwb = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4372 | pr_info("uwb switch emulation enabled\n"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4373 | } else |
| 4374 | #endif |
| 4375 | if (tp_features.uwb && |
| 4376 | !(status & TP_ACPI_UWB_HWPRESENT)) { |
| 4377 | /* no uwb hardware present in system */ |
| 4378 | tp_features.uwb = 0; |
| 4379 | dbg_printk(TPACPI_DBG_INIT, |
| 4380 | "uwb hardware not installed\n"); |
| 4381 | } |
| 4382 | |
| 4383 | if (!tp_features.uwb) |
| 4384 | return 1; |
| 4385 | |
| 4386 | res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4387 | &uwb_tprfk_ops, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4388 | RFKILL_TYPE_UWB, |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4389 | TPACPI_RFK_UWB_SW_NAME, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4390 | false); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4391 | return res; |
| 4392 | } |
| 4393 | |
| 4394 | static struct ibm_struct uwb_driver_data = { |
| 4395 | .name = "uwb", |
| 4396 | .exit = uwb_exit, |
| 4397 | .flags.experimental = 1, |
| 4398 | }; |
| 4399 | |
| 4400 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4401 | * Video subdriver |
| 4402 | */ |
| 4403 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4404 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 4405 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4406 | enum video_access_mode { |
| 4407 | TPACPI_VIDEO_NONE = 0, |
| 4408 | TPACPI_VIDEO_570, /* 570 */ |
| 4409 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 4410 | TPACPI_VIDEO_NEW, /* all others */ |
| 4411 | }; |
| 4412 | |
| 4413 | enum { /* video status flags, based on VIDEO_570 */ |
| 4414 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 4415 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 4416 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 4417 | }; |
| 4418 | |
| 4419 | enum { /* TPACPI_VIDEO_570 constants */ |
| 4420 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 4421 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 4422 | * video_status_flags */ |
| 4423 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 4424 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 4425 | }; |
| 4426 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4427 | static enum video_access_mode video_supported; |
| 4428 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4429 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4430 | static int video_autosw_get(void); |
| 4431 | static int video_autosw_set(int enable); |
| 4432 | |
Joe Perches | 112a6ee | 2011-04-04 10:06:24 -0700 | [diff] [blame] | 4433 | TPACPI_HANDLE(vid, root, |
| 4434 | "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 4435 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 4436 | "\\_SB.PCI0.VID0", /* 770e */ |
| 4437 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 4438 | "\\_SB.PCI0.AGP.VGA", /* X100e and a few others */ |
| 4439 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 4440 | ); /* R30, R31 */ |
| 4441 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4442 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4443 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4444 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4446 | int ivga; |
| 4447 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4448 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 4449 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4450 | TPACPI_ACPIHANDLE_INIT(vid); |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4451 | if (tpacpi_is_ibm()) |
| 4452 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4453 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4454 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 4455 | /* G41, assume IVGA doesn't change */ |
| 4456 | vid_handle = vid2_handle; |
| 4457 | |
| 4458 | if (!vid_handle) |
| 4459 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4460 | video_supported = TPACPI_VIDEO_NONE; |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4461 | else if (tpacpi_is_ibm() && |
| 4462 | acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4463 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4464 | video_supported = TPACPI_VIDEO_570; |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4465 | else if (tpacpi_is_ibm() && |
| 4466 | acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4467 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4468 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4469 | else |
| 4470 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4471 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4473 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 4474 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 4475 | video_supported); |
| 4476 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4477 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | } |
| 4479 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4480 | static void video_exit(void) |
| 4481 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4482 | dbg_printk(TPACPI_DBG_EXIT, |
| 4483 | "restoring original video autoswitch mode\n"); |
| 4484 | if (video_autosw_set(video_orig_autosw)) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4485 | pr_err("error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4486 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4487 | } |
| 4488 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4489 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | { |
| 4491 | int status = 0; |
| 4492 | int i; |
| 4493 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4494 | switch (video_supported) { |
| 4495 | case TPACPI_VIDEO_570: |
| 4496 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 4497 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 4498 | return -EIO; |
| 4499 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 4500 | break; |
| 4501 | case TPACPI_VIDEO_770: |
| 4502 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4503 | return -EIO; |
| 4504 | if (i) |
| 4505 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4506 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4507 | return -EIO; |
| 4508 | if (i) |
| 4509 | status |= TP_ACPI_VIDEO_S_CRT; |
| 4510 | break; |
| 4511 | case TPACPI_VIDEO_NEW: |
| 4512 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 4513 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4514 | return -EIO; |
| 4515 | if (i) |
| 4516 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4518 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 4519 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4520 | return -EIO; |
| 4521 | if (i) |
| 4522 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4523 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 4524 | return -EIO; |
| 4525 | if (i) |
| 4526 | status |= TP_ACPI_VIDEO_S_DVI; |
| 4527 | break; |
| 4528 | default: |
| 4529 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4530 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | |
| 4532 | return status; |
| 4533 | } |
| 4534 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4535 | static int video_outputsw_set(int status) |
| 4536 | { |
| 4537 | int autosw; |
| 4538 | int res = 0; |
| 4539 | |
| 4540 | switch (video_supported) { |
| 4541 | case TPACPI_VIDEO_570: |
| 4542 | res = acpi_evalf(NULL, NULL, |
| 4543 | "\\_SB.PHS2", "vdd", |
| 4544 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 4545 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 4546 | break; |
| 4547 | case TPACPI_VIDEO_770: |
| 4548 | autosw = video_autosw_get(); |
| 4549 | if (autosw < 0) |
| 4550 | return autosw; |
| 4551 | |
| 4552 | res = video_autosw_set(1); |
| 4553 | if (res) |
| 4554 | return res; |
| 4555 | res = acpi_evalf(vid_handle, NULL, |
| 4556 | "ASWT", "vdd", status * 0x100, 0); |
| 4557 | if (!autosw && video_autosw_set(autosw)) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4558 | pr_err("video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4559 | return -EIO; |
| 4560 | } |
| 4561 | break; |
| 4562 | case TPACPI_VIDEO_NEW: |
| 4563 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4564 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4565 | break; |
| 4566 | default: |
| 4567 | return -ENOSYS; |
| 4568 | } |
| 4569 | |
| 4570 | return (res)? 0 : -EIO; |
| 4571 | } |
| 4572 | |
| 4573 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4575 | int autosw = 0; |
| 4576 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4577 | switch (video_supported) { |
| 4578 | case TPACPI_VIDEO_570: |
| 4579 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 4580 | return -EIO; |
| 4581 | break; |
| 4582 | case TPACPI_VIDEO_770: |
| 4583 | case TPACPI_VIDEO_NEW: |
| 4584 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 4585 | return -EIO; |
| 4586 | break; |
| 4587 | default: |
| 4588 | return -ENOSYS; |
| 4589 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4590 | |
| 4591 | return autosw & 1; |
| 4592 | } |
| 4593 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4594 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4595 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4596 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4597 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4598 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4599 | } |
| 4600 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4601 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4602 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4603 | int autosw = video_autosw_get(); |
| 4604 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4605 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4606 | if (autosw < 0) |
| 4607 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4608 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4609 | switch (video_supported) { |
| 4610 | case TPACPI_VIDEO_570: |
| 4611 | res = video_autosw_set(1); |
| 4612 | if (res) |
| 4613 | return res; |
| 4614 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 4615 | break; |
| 4616 | case TPACPI_VIDEO_770: |
| 4617 | case TPACPI_VIDEO_NEW: |
| 4618 | res = video_autosw_set(1); |
| 4619 | if (res) |
| 4620 | return res; |
| 4621 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 4622 | break; |
| 4623 | default: |
| 4624 | return -ENOSYS; |
| 4625 | } |
| 4626 | if (!autosw && video_autosw_set(autosw)) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 4627 | pr_err("video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4628 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4629 | } |
| 4630 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4631 | return (res)? 0 : -EIO; |
| 4632 | } |
| 4633 | |
| 4634 | static int video_expand_toggle(void) |
| 4635 | { |
| 4636 | switch (video_supported) { |
| 4637 | case TPACPI_VIDEO_570: |
| 4638 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 4639 | 0 : -EIO; |
| 4640 | case TPACPI_VIDEO_770: |
| 4641 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 4642 | 0 : -EIO; |
| 4643 | case TPACPI_VIDEO_NEW: |
| 4644 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 4645 | 0 : -EIO; |
| 4646 | default: |
| 4647 | return -ENOSYS; |
| 4648 | } |
| 4649 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4650 | } |
| 4651 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4652 | static int video_read(struct seq_file *m) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4653 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4654 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4655 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4656 | if (video_supported == TPACPI_VIDEO_NONE) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4657 | seq_printf(m, "status:\t\tnot supported\n"); |
| 4658 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4659 | } |
| 4660 | |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 4661 | /* Even reads can crash X.org, so... */ |
| 4662 | if (!capable(CAP_SYS_ADMIN)) |
| 4663 | return -EPERM; |
| 4664 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4665 | status = video_outputsw_get(); |
| 4666 | if (status < 0) |
| 4667 | return status; |
| 4668 | |
| 4669 | autosw = video_autosw_get(); |
| 4670 | if (autosw < 0) |
| 4671 | return autosw; |
| 4672 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4673 | seq_printf(m, "status:\t\tsupported\n"); |
| 4674 | seq_printf(m, "lcd:\t\t%s\n", enabled(status, 0)); |
| 4675 | seq_printf(m, "crt:\t\t%s\n", enabled(status, 1)); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4676 | if (video_supported == TPACPI_VIDEO_NEW) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4677 | seq_printf(m, "dvi:\t\t%s\n", enabled(status, 3)); |
| 4678 | seq_printf(m, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 4679 | seq_printf(m, "commands:\tlcd_enable, lcd_disable\n"); |
| 4680 | seq_printf(m, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4681 | if (video_supported == TPACPI_VIDEO_NEW) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4682 | seq_printf(m, "commands:\tdvi_enable, dvi_disable\n"); |
| 4683 | seq_printf(m, "commands:\tauto_enable, auto_disable\n"); |
| 4684 | seq_printf(m, "commands:\tvideo_switch, expand_toggle\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4685 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4686 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4687 | } |
| 4688 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4689 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4690 | { |
| 4691 | char *cmd; |
| 4692 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4693 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4694 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4695 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4696 | return -ENODEV; |
| 4697 | |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 4698 | /* Even reads can crash X.org, let alone writes... */ |
| 4699 | if (!capable(CAP_SYS_ADMIN)) |
| 4700 | return -EPERM; |
| 4701 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4702 | enable = 0; |
| 4703 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | |
| 4705 | while ((cmd = next_cmd(&buf))) { |
| 4706 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4707 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4709 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4711 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4713 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4714 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4715 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4716 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4717 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4718 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4719 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4721 | res = video_autosw_set(1); |
| 4722 | if (res) |
| 4723 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4725 | res = video_autosw_set(0); |
| 4726 | if (res) |
| 4727 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4728 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4729 | res = video_outputsw_cycle(); |
| 4730 | if (res) |
| 4731 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4732 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4733 | res = video_expand_toggle(); |
| 4734 | if (res) |
| 4735 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | } else |
| 4737 | return -EINVAL; |
| 4738 | } |
| 4739 | |
| 4740 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4741 | status = video_outputsw_get(); |
| 4742 | if (status < 0) |
| 4743 | return status; |
| 4744 | res = video_outputsw_set((status & ~disable) | enable); |
| 4745 | if (res) |
| 4746 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | return 0; |
| 4750 | } |
| 4751 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4752 | static struct ibm_struct video_driver_data = { |
| 4753 | .name = "video", |
| 4754 | .read = video_read, |
| 4755 | .write = video_write, |
| 4756 | .exit = video_exit, |
| 4757 | }; |
| 4758 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4759 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 4760 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4761 | /************************************************************************* |
| 4762 | * Light (thinklight) subdriver |
| 4763 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4765 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 4766 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4767 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4768 | static int light_get_status(void) |
| 4769 | { |
| 4770 | int status = 0; |
| 4771 | |
| 4772 | if (tp_features.light_status) { |
| 4773 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 4774 | return -EIO; |
| 4775 | return (!!status); |
| 4776 | } |
| 4777 | |
| 4778 | return -ENXIO; |
| 4779 | } |
| 4780 | |
| 4781 | static int light_set_status(int status) |
| 4782 | { |
| 4783 | int rc; |
| 4784 | |
| 4785 | if (tp_features.light) { |
| 4786 | if (cmos_handle) { |
| 4787 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", |
| 4788 | (status)? |
| 4789 | TP_CMOS_THINKLIGHT_ON : |
| 4790 | TP_CMOS_THINKLIGHT_OFF); |
| 4791 | } else { |
| 4792 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", |
| 4793 | (status)? 1 : 0); |
| 4794 | } |
| 4795 | return (rc)? 0 : -EIO; |
| 4796 | } |
| 4797 | |
| 4798 | return -ENXIO; |
| 4799 | } |
| 4800 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4801 | static void light_set_status_worker(struct work_struct *work) |
| 4802 | { |
| 4803 | struct tpacpi_led_classdev *data = |
| 4804 | container_of(work, struct tpacpi_led_classdev, work); |
| 4805 | |
| 4806 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4807 | light_set_status((data->new_state != TPACPI_LED_OFF)); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | static void light_sysfs_set(struct led_classdev *led_cdev, |
| 4811 | enum led_brightness brightness) |
| 4812 | { |
| 4813 | struct tpacpi_led_classdev *data = |
| 4814 | container_of(led_cdev, |
| 4815 | struct tpacpi_led_classdev, |
| 4816 | led_classdev); |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4817 | data->new_state = (brightness != LED_OFF) ? |
| 4818 | TPACPI_LED_ON : TPACPI_LED_OFF; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4819 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4820 | } |
| 4821 | |
| 4822 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) |
| 4823 | { |
| 4824 | return (light_get_status() == 1)? LED_FULL : LED_OFF; |
| 4825 | } |
| 4826 | |
| 4827 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { |
| 4828 | .led_classdev = { |
| 4829 | .name = "tpacpi::thinklight", |
| 4830 | .brightness_set = &light_sysfs_set, |
| 4831 | .brightness_get = &light_sysfs_get, |
| 4832 | } |
| 4833 | }; |
| 4834 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4835 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4837 | int rc; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4838 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4839 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 4840 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 4841 | if (tpacpi_is_ibm()) { |
| 4842 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 4843 | TPACPI_ACPIHANDLE_INIT(lght); |
| 4844 | } |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4845 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4846 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4847 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4848 | /* 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] | 4849 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4850 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4851 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4852 | /* light status not supported on |
| 4853 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4854 | tp_features.light_status = |
| 4855 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4856 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4857 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
| 4858 | str_supported(tp_features.light), |
| 4859 | str_supported(tp_features.light_status)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4860 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4861 | if (!tp_features.light) |
| 4862 | return 1; |
| 4863 | |
| 4864 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 4865 | &tpacpi_led_thinklight.led_classdev); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4866 | |
| 4867 | if (rc < 0) { |
| 4868 | tp_features.light = 0; |
| 4869 | tp_features.light_status = 0; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4870 | } else { |
| 4871 | rc = 0; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4872 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4873 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4874 | return rc; |
| 4875 | } |
| 4876 | |
| 4877 | static void light_exit(void) |
| 4878 | { |
| 4879 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); |
Tejun Heo | 6d394e1 | 2012-12-21 17:56:58 -0800 | [diff] [blame] | 4880 | flush_workqueue(tpacpi_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | } |
| 4882 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4883 | static int light_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4885 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4887 | if (!tp_features.light) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4888 | seq_printf(m, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4889 | } else if (!tp_features.light_status) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4890 | seq_printf(m, "status:\t\tunknown\n"); |
| 4891 | seq_printf(m, "commands:\ton, off\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4892 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4893 | status = light_get_status(); |
| 4894 | if (status < 0) |
| 4895 | return status; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4896 | seq_printf(m, "status:\t\t%s\n", onoff(status, 0)); |
| 4897 | seq_printf(m, "commands:\ton, off\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4900 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | } |
| 4902 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4903 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4904 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4906 | int newstatus = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4907 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4908 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4909 | return -ENODEV; |
| 4910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | while ((cmd = next_cmd(&buf))) { |
| 4912 | if (strlencmp(cmd, "on") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4913 | newstatus = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | } else if (strlencmp(cmd, "off") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4915 | newstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | } else |
| 4917 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | } |
| 4919 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4920 | return light_set_status(newstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | } |
| 4922 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4923 | static struct ibm_struct light_driver_data = { |
| 4924 | .name = "light", |
| 4925 | .read = light_read, |
| 4926 | .write = light_write, |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4927 | .exit = light_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4928 | }; |
| 4929 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4930 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4931 | * CMOS subdriver |
| 4932 | */ |
| 4933 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4934 | /* sysfs cmos_command -------------------------------------------------- */ |
| 4935 | static ssize_t cmos_command_store(struct device *dev, |
| 4936 | struct device_attribute *attr, |
| 4937 | const char *buf, size_t count) |
| 4938 | { |
| 4939 | unsigned long cmos_cmd; |
| 4940 | int res; |
| 4941 | |
| 4942 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 4943 | return -EINVAL; |
| 4944 | |
| 4945 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4946 | return (res)? res : count; |
| 4947 | } |
| 4948 | |
| 4949 | static struct device_attribute dev_attr_cmos_command = |
| 4950 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 4951 | |
| 4952 | /* --------------------------------------------------------------------- */ |
| 4953 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4954 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4955 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4956 | int res; |
| 4957 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4958 | vdbg_printk(TPACPI_DBG_INIT, |
| 4959 | "initializing cmos commands subdriver\n"); |
| 4960 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4961 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4962 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4963 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 4964 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4965 | |
| 4966 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4967 | if (res) |
| 4968 | return res; |
| 4969 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4970 | return (cmos_handle)? 0 : 1; |
| 4971 | } |
| 4972 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4973 | static void cmos_exit(void) |
| 4974 | { |
| 4975 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4976 | } |
| 4977 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4978 | static int cmos_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4979 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4980 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4981 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | if (!cmos_handle) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4983 | seq_printf(m, "status:\t\tnot supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4984 | else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4985 | seq_printf(m, "status:\t\tsupported\n"); |
| 4986 | seq_printf(m, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4987 | } |
| 4988 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 4989 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4992 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | { |
| 4994 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4995 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | |
| 4997 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4998 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 4999 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | /* cmos_cmd set */ |
| 5001 | } else |
| 5002 | return -EINVAL; |
| 5003 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 5004 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 5005 | if (res) |
| 5006 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5010 | } |
| 5011 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5012 | static struct ibm_struct cmos_driver_data = { |
| 5013 | .name = "cmos", |
| 5014 | .read = cmos_read, |
| 5015 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 5016 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5017 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5018 | |
| 5019 | /************************************************************************* |
| 5020 | * LED subdriver |
| 5021 | */ |
| 5022 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5023 | enum led_access_mode { |
| 5024 | TPACPI_LED_NONE = 0, |
| 5025 | TPACPI_LED_570, /* 570 */ |
| 5026 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 5027 | TPACPI_LED_NEW, /* all others */ |
| 5028 | }; |
| 5029 | |
| 5030 | enum { /* For TPACPI_LED_OLD */ |
| 5031 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 5032 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 5033 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 5034 | }; |
| 5035 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 5036 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5037 | |
Henrique de Moraes Holschuh | 2cbb5c8 | 2010-05-16 19:45:50 -0300 | [diff] [blame] | 5038 | static acpi_handle led_handle; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5039 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5040 | #define TPACPI_LED_NUMLEDS 16 |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5041 | static struct tpacpi_led_classdev *tpacpi_leds; |
| 5042 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; |
Harvey Harrison | e3aa51f | 2008-05-29 17:51:57 -0700 | [diff] [blame] | 5043 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5044 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
| 5045 | "tpacpi::power", |
| 5046 | "tpacpi:orange:batt", |
| 5047 | "tpacpi:green:batt", |
| 5048 | "tpacpi::dock_active", |
| 5049 | "tpacpi::bay_active", |
| 5050 | "tpacpi::dock_batt", |
| 5051 | "tpacpi::unknown_led", |
| 5052 | "tpacpi::standby", |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5053 | "tpacpi::dock_status1", |
| 5054 | "tpacpi::dock_status2", |
| 5055 | "tpacpi::unknown_led2", |
| 5056 | "tpacpi::unknown_led3", |
| 5057 | "tpacpi::thinkvantage", |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5058 | }; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5059 | #define TPACPI_SAFE_LEDS 0x1081U |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5060 | |
| 5061 | static inline bool tpacpi_is_led_restricted(const unsigned int led) |
| 5062 | { |
| 5063 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
| 5064 | return false; |
| 5065 | #else |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5066 | return (1U & (TPACPI_SAFE_LEDS >> led)) == 0; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5067 | #endif |
| 5068 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5069 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5070 | static int led_get_status(const unsigned int led) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5071 | { |
| 5072 | int status; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5073 | enum led_status_t led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5074 | |
| 5075 | switch (led_supported) { |
| 5076 | case TPACPI_LED_570: |
| 5077 | if (!acpi_evalf(ec_handle, |
| 5078 | &status, "GLED", "dd", 1 << led)) |
| 5079 | return -EIO; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5080 | led_s = (status == 0)? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5081 | TPACPI_LED_OFF : |
| 5082 | ((status == 1)? |
| 5083 | TPACPI_LED_ON : |
| 5084 | TPACPI_LED_BLINK); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5085 | tpacpi_led_state_cache[led] = led_s; |
| 5086 | return led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5087 | default: |
| 5088 | return -ENXIO; |
| 5089 | } |
| 5090 | |
| 5091 | /* not reached */ |
| 5092 | } |
| 5093 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5094 | static int led_set_status(const unsigned int led, |
| 5095 | const enum led_status_t ledstatus) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5096 | { |
| 5097 | /* off, on, blink. Index is led_status_t */ |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5098 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
| 5099 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5100 | |
| 5101 | int rc = 0; |
| 5102 | |
| 5103 | switch (led_supported) { |
| 5104 | case TPACPI_LED_570: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5105 | /* 570 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5106 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5107 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5108 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5109 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5110 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5111 | (1 << led), led_sled_arg1[ledstatus])) |
| 5112 | rc = -EIO; |
| 5113 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5114 | case TPACPI_LED_OLD: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5115 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5116 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5117 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5118 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5119 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5120 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
| 5121 | if (rc >= 0) |
| 5122 | rc = ec_write(TPACPI_LED_EC_HLBL, |
| 5123 | (ledstatus == TPACPI_LED_BLINK) << led); |
| 5124 | if (rc >= 0) |
| 5125 | rc = ec_write(TPACPI_LED_EC_HLCL, |
| 5126 | (ledstatus != TPACPI_LED_OFF) << led); |
| 5127 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5128 | case TPACPI_LED_NEW: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5129 | /* all others */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5130 | if (unlikely(led >= TPACPI_LED_NUMLEDS)) |
| 5131 | return -EINVAL; |
| 5132 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 5133 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 5134 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 5135 | led, led_led_arg1[ledstatus])) |
| 5136 | rc = -EIO; |
| 5137 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5138 | default: |
| 5139 | rc = -ENXIO; |
| 5140 | } |
| 5141 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5142 | if (!rc) |
| 5143 | tpacpi_led_state_cache[led] = ledstatus; |
| 5144 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5145 | return rc; |
| 5146 | } |
| 5147 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5148 | static void led_set_status_worker(struct work_struct *work) |
| 5149 | { |
| 5150 | struct tpacpi_led_classdev *data = |
| 5151 | container_of(work, struct tpacpi_led_classdev, work); |
| 5152 | |
| 5153 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5154 | led_set_status(data->led, data->new_state); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5155 | } |
| 5156 | |
| 5157 | static void led_sysfs_set(struct led_classdev *led_cdev, |
| 5158 | enum led_brightness brightness) |
| 5159 | { |
| 5160 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5161 | struct tpacpi_led_classdev, led_classdev); |
| 5162 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5163 | if (brightness == LED_OFF) |
| 5164 | data->new_state = TPACPI_LED_OFF; |
| 5165 | else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) |
| 5166 | data->new_state = TPACPI_LED_ON; |
| 5167 | else |
| 5168 | data->new_state = TPACPI_LED_BLINK; |
| 5169 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5170 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, |
| 5174 | unsigned long *delay_on, unsigned long *delay_off) |
| 5175 | { |
| 5176 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5177 | struct tpacpi_led_classdev, led_classdev); |
| 5178 | |
| 5179 | /* Can we choose the flash rate? */ |
| 5180 | if (*delay_on == 0 && *delay_off == 0) { |
| 5181 | /* yes. set them to the hardware blink rate (1 Hz) */ |
| 5182 | *delay_on = 500; /* ms */ |
| 5183 | *delay_off = 500; /* ms */ |
| 5184 | } else if ((*delay_on != 500) || (*delay_off != 500)) |
| 5185 | return -EINVAL; |
| 5186 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 5187 | data->new_state = TPACPI_LED_BLINK; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 5188 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5189 | |
| 5190 | return 0; |
| 5191 | } |
| 5192 | |
| 5193 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) |
| 5194 | { |
| 5195 | int rc; |
| 5196 | |
| 5197 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 5198 | struct tpacpi_led_classdev, led_classdev); |
| 5199 | |
| 5200 | rc = led_get_status(data->led); |
| 5201 | |
| 5202 | if (rc == TPACPI_LED_OFF || rc < 0) |
| 5203 | rc = LED_OFF; /* no error handling in led class :( */ |
| 5204 | else |
| 5205 | rc = LED_FULL; |
| 5206 | |
| 5207 | return rc; |
| 5208 | } |
| 5209 | |
| 5210 | static void led_exit(void) |
| 5211 | { |
| 5212 | unsigned int i; |
| 5213 | |
| 5214 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 5215 | if (tpacpi_leds[i].led_classdev.name) |
| 5216 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); |
| 5217 | } |
| 5218 | |
Li Dongyang | e03e389 | 2012-07-25 10:45:07 +1000 | [diff] [blame] | 5219 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5220 | kfree(tpacpi_leds); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5221 | } |
| 5222 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5223 | static int __init tpacpi_init_led(unsigned int led) |
| 5224 | { |
| 5225 | int rc; |
| 5226 | |
| 5227 | tpacpi_leds[led].led = led; |
| 5228 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5229 | /* LEDs with no name don't get registered */ |
| 5230 | if (!tpacpi_led_names[led]) |
| 5231 | return 0; |
| 5232 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5233 | tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set; |
| 5234 | tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set; |
| 5235 | if (led_supported == TPACPI_LED_570) |
| 5236 | tpacpi_leds[led].led_classdev.brightness_get = |
| 5237 | &led_sysfs_get; |
| 5238 | |
| 5239 | tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led]; |
| 5240 | |
| 5241 | INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker); |
| 5242 | |
| 5243 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 5244 | &tpacpi_leds[led].led_classdev); |
| 5245 | if (rc < 0) |
| 5246 | tpacpi_leds[led].led_classdev.name = NULL; |
| 5247 | |
| 5248 | return rc; |
| 5249 | } |
| 5250 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5251 | static const struct tpacpi_quirk led_useful_qtable[] __initconst = { |
| 5252 | TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */ |
| 5253 | TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */ |
| 5254 | TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */ |
| 5255 | |
| 5256 | TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */ |
| 5257 | TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */ |
| 5258 | TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */ |
| 5259 | TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */ |
| 5260 | TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */ |
| 5261 | TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */ |
| 5262 | TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */ |
| 5263 | TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */ |
| 5264 | |
| 5265 | TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */ |
| 5266 | TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */ |
| 5267 | TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */ |
| 5268 | TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */ |
| 5269 | TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */ |
| 5270 | |
| 5271 | TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */ |
| 5272 | TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */ |
| 5273 | TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */ |
| 5274 | TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */ |
| 5275 | |
| 5276 | /* (1) - may have excess leds enabled on MSB */ |
| 5277 | |
| 5278 | /* Defaults (order matters, keep last, don't reorder!) */ |
| 5279 | { /* Lenovo */ |
| 5280 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 5281 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5282 | .quirks = 0x1fffU, |
| 5283 | }, |
| 5284 | { /* IBM ThinkPads with no EC version string */ |
| 5285 | .vendor = PCI_VENDOR_ID_IBM, |
| 5286 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_UNKNOWN, |
| 5287 | .quirks = 0x00ffU, |
| 5288 | }, |
| 5289 | { /* IBM ThinkPads with EC version string */ |
| 5290 | .vendor = PCI_VENDOR_ID_IBM, |
| 5291 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5292 | .quirks = 0x00bfU, |
| 5293 | }, |
| 5294 | }; |
| 5295 | |
| 5296 | #undef TPACPI_LEDQ_IBM |
| 5297 | #undef TPACPI_LEDQ_LNV |
| 5298 | |
Henrique de Moraes Holschuh | 2cbb5c8 | 2010-05-16 19:45:50 -0300 | [diff] [blame] | 5299 | static enum led_access_mode __init led_init_detect_mode(void) |
| 5300 | { |
| 5301 | acpi_status status; |
| 5302 | |
| 5303 | if (tpacpi_is_ibm()) { |
| 5304 | /* 570 */ |
| 5305 | status = acpi_get_handle(ec_handle, "SLED", &led_handle); |
| 5306 | if (ACPI_SUCCESS(status)) |
| 5307 | return TPACPI_LED_570; |
| 5308 | |
| 5309 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 5310 | status = acpi_get_handle(ec_handle, "SYSL", &led_handle); |
| 5311 | if (ACPI_SUCCESS(status)) |
| 5312 | return TPACPI_LED_OLD; |
| 5313 | } |
| 5314 | |
| 5315 | /* most others */ |
| 5316 | status = acpi_get_handle(ec_handle, "LED", &led_handle); |
| 5317 | if (ACPI_SUCCESS(status)) |
| 5318 | return TPACPI_LED_NEW; |
| 5319 | |
| 5320 | /* R30, R31, and unknown firmwares */ |
| 5321 | led_handle = NULL; |
| 5322 | return TPACPI_LED_NONE; |
| 5323 | } |
| 5324 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5325 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5326 | { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5327 | unsigned int i; |
| 5328 | int rc; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5329 | unsigned long useful_leds; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5330 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5331 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 5332 | |
Henrique de Moraes Holschuh | 2cbb5c8 | 2010-05-16 19:45:50 -0300 | [diff] [blame] | 5333 | led_supported = led_init_detect_mode(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5334 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5335 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 5336 | str_supported(led_supported), led_supported); |
| 5337 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5338 | if (led_supported == TPACPI_LED_NONE) |
| 5339 | return 1; |
| 5340 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5341 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
| 5342 | GFP_KERNEL); |
| 5343 | if (!tpacpi_leds) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5344 | pr_err("Out of memory for LED data\n"); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5345 | return -ENOMEM; |
| 5346 | } |
| 5347 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5348 | useful_leds = tpacpi_check_quirks(led_useful_qtable, |
| 5349 | ARRAY_SIZE(led_useful_qtable)); |
| 5350 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5351 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5352 | if (!tpacpi_is_led_restricted(i) && |
| 5353 | test_bit(i, &useful_leds)) { |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5354 | rc = tpacpi_init_led(i); |
| 5355 | if (rc < 0) { |
| 5356 | led_exit(); |
| 5357 | return rc; |
| 5358 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5359 | } |
| 5360 | } |
| 5361 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5362 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5363 | pr_notice("warning: userspace override of important " |
| 5364 | "firmware LEDs is enabled\n"); |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5365 | #endif |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5366 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5367 | } |
| 5368 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5369 | #define str_led_status(s) \ |
| 5370 | ((s) == TPACPI_LED_OFF ? "off" : \ |
| 5371 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5372 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5373 | static int led_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5374 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5375 | if (!led_supported) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5376 | seq_printf(m, "status:\t\tnot supported\n"); |
| 5377 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5378 | } |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5379 | seq_printf(m, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5380 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5381 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5382 | /* 570 */ |
| 5383 | int i, status; |
| 5384 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5385 | status = led_get_status(i); |
| 5386 | if (status < 0) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5387 | return -EIO; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5388 | seq_printf(m, "%d:\t\t%s\n", |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5389 | i, str_led_status(status)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5390 | } |
| 5391 | } |
| 5392 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5393 | seq_printf(m, "commands:\t" |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5394 | "<led> on, <led> off, <led> blink (<led> is 0-15)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5395 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5396 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5397 | } |
| 5398 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5399 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | { |
| 5401 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5402 | int led, rc; |
| 5403 | enum led_status_t s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5404 | |
| 5405 | if (!led_supported) |
| 5406 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5407 | |
| 5408 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5409 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5410 | return -EINVAL; |
| 5411 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5412 | if (strstr(cmd, "off")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5413 | s = TPACPI_LED_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5414 | } else if (strstr(cmd, "on")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5415 | s = TPACPI_LED_ON; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5416 | } else if (strstr(cmd, "blink")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5417 | s = TPACPI_LED_BLINK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5418 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5419 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5420 | } |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5421 | |
| 5422 | rc = led_set_status(led, s); |
| 5423 | if (rc < 0) |
| 5424 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5428 | } |
| 5429 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5430 | static struct ibm_struct led_driver_data = { |
| 5431 | .name = "led", |
| 5432 | .read = led_read, |
| 5433 | .write = led_write, |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5434 | .exit = led_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5435 | }; |
| 5436 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5437 | /************************************************************************* |
| 5438 | * Beep subdriver |
| 5439 | */ |
| 5440 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5441 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5442 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5443 | #define TPACPI_BEEP_Q1 0x0001 |
| 5444 | |
| 5445 | static const struct tpacpi_quirk beep_quirk_table[] __initconst = { |
| 5446 | TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1), /* 570 */ |
| 5447 | TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */ |
| 5448 | }; |
| 5449 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5450 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5451 | { |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5452 | unsigned long quirks; |
| 5453 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5454 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 5455 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5456 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5457 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5458 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 5459 | str_supported(beep_handle != NULL)); |
| 5460 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5461 | quirks = tpacpi_check_quirks(beep_quirk_table, |
| 5462 | ARRAY_SIZE(beep_quirk_table)); |
| 5463 | |
| 5464 | tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); |
| 5465 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5466 | return (beep_handle)? 0 : 1; |
| 5467 | } |
| 5468 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5469 | static int beep_read(struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5470 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5471 | if (!beep_handle) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5472 | seq_printf(m, "status:\t\tnot supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5473 | else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5474 | seq_printf(m, "status:\t\tsupported\n"); |
| 5475 | seq_printf(m, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5478 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | } |
| 5480 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5481 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5482 | { |
| 5483 | char *cmd; |
| 5484 | int beep_cmd; |
| 5485 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5486 | if (!beep_handle) |
| 5487 | return -ENODEV; |
| 5488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5489 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5490 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 5491 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | /* beep_cmd set */ |
| 5493 | } else |
| 5494 | return -EINVAL; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5495 | if (tp_features.beep_needs_two_args) { |
| 5496 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", |
| 5497 | beep_cmd, 0)) |
| 5498 | return -EIO; |
| 5499 | } else { |
| 5500 | if (!acpi_evalf(beep_handle, NULL, NULL, "vd", |
| 5501 | beep_cmd)) |
| 5502 | return -EIO; |
| 5503 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5504 | } |
| 5505 | |
| 5506 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5507 | } |
| 5508 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5509 | static struct ibm_struct beep_driver_data = { |
| 5510 | .name = "beep", |
| 5511 | .read = beep_read, |
| 5512 | .write = beep_write, |
| 5513 | }; |
| 5514 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5515 | /************************************************************************* |
| 5516 | * Thermal subdriver |
| 5517 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5518 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5519 | enum thermal_access_mode { |
| 5520 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 5521 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 5522 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 5523 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 5524 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 5525 | }; |
| 5526 | |
| 5527 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 5528 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 5529 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 5530 | 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] | 5531 | |
| 5532 | TPACPI_THERMAL_SENSOR_NA = -128000, /* Sensor not available */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5533 | }; |
| 5534 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5535 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5536 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 5537 | struct ibm_thermal_sensors_struct { |
| 5538 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 5539 | }; |
| 5540 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5541 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5542 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5543 | /* idx is zero-based */ |
| 5544 | static int thermal_get_sensor(int idx, s32 *value) |
| 5545 | { |
| 5546 | int t; |
| 5547 | s8 tmp; |
| 5548 | char tmpi[5]; |
| 5549 | |
| 5550 | t = TP_EC_THERMAL_TMP0; |
| 5551 | |
| 5552 | switch (thermal_read_mode) { |
| 5553 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 5554 | case TPACPI_THERMAL_TPEC_16: |
| 5555 | if (idx >= 8 && idx <= 15) { |
| 5556 | t = TP_EC_THERMAL_TMP8; |
| 5557 | idx -= 8; |
| 5558 | } |
| 5559 | /* fallthrough */ |
| 5560 | #endif |
| 5561 | case TPACPI_THERMAL_TPEC_8: |
| 5562 | if (idx <= 7) { |
| 5563 | if (!acpi_ec_read(t + idx, &tmp)) |
| 5564 | return -EIO; |
| 5565 | *value = tmp * 1000; |
| 5566 | return 0; |
| 5567 | } |
| 5568 | break; |
| 5569 | |
| 5570 | case TPACPI_THERMAL_ACPI_UPDT: |
| 5571 | if (idx <= 7) { |
| 5572 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5573 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 5574 | return -EIO; |
| 5575 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5576 | return -EIO; |
| 5577 | *value = (t - 2732) * 100; |
| 5578 | return 0; |
| 5579 | } |
| 5580 | break; |
| 5581 | |
| 5582 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5583 | if (idx <= 7) { |
| 5584 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5585 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5586 | return -EIO; |
| 5587 | if (t > 127 || t < -127) |
| 5588 | t = TP_EC_THERMAL_TMP_NA; |
| 5589 | *value = t * 1000; |
| 5590 | return 0; |
| 5591 | } |
| 5592 | break; |
| 5593 | |
| 5594 | case TPACPI_THERMAL_NONE: |
| 5595 | default: |
| 5596 | return -ENOSYS; |
| 5597 | } |
| 5598 | |
| 5599 | return -EINVAL; |
| 5600 | } |
| 5601 | |
| 5602 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 5603 | { |
| 5604 | int res, i; |
| 5605 | int n; |
| 5606 | |
| 5607 | n = 8; |
| 5608 | i = 0; |
| 5609 | |
| 5610 | if (!s) |
| 5611 | return -EINVAL; |
| 5612 | |
| 5613 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 5614 | n = 16; |
| 5615 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5616 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5617 | res = thermal_get_sensor(i, &s->temp[i]); |
| 5618 | if (res) |
| 5619 | return res; |
| 5620 | } |
| 5621 | |
| 5622 | return n; |
| 5623 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5624 | |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5625 | static void thermal_dump_all_sensors(void) |
| 5626 | { |
| 5627 | int n, i; |
| 5628 | struct ibm_thermal_sensors_struct t; |
| 5629 | |
| 5630 | n = thermal_get_sensors(&t); |
| 5631 | if (n <= 0) |
| 5632 | return; |
| 5633 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5634 | pr_notice("temperatures (Celsius):"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5635 | |
| 5636 | for (i = 0; i < n; i++) { |
| 5637 | if (t.temp[i] != TPACPI_THERMAL_SENSOR_NA) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5638 | pr_cont(" %d", (int)(t.temp[i] / 1000)); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5639 | else |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5640 | pr_cont(" N/A"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5641 | } |
| 5642 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5643 | pr_cont("\n"); |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5644 | } |
| 5645 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5646 | /* sysfs temp##_input -------------------------------------------------- */ |
| 5647 | |
| 5648 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 5649 | struct device_attribute *attr, |
| 5650 | char *buf) |
| 5651 | { |
| 5652 | struct sensor_device_attribute *sensor_attr = |
| 5653 | to_sensor_dev_attr(attr); |
| 5654 | int idx = sensor_attr->index; |
| 5655 | s32 value; |
| 5656 | int res; |
| 5657 | |
| 5658 | res = thermal_get_sensor(idx, &value); |
| 5659 | if (res) |
| 5660 | return res; |
Henrique de Moraes Holschuh | 9ebd9e8 | 2009-12-09 01:36:28 +0000 | [diff] [blame] | 5661 | if (value == TPACPI_THERMAL_SENSOR_NA) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5662 | return -ENXIO; |
| 5663 | |
| 5664 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 5665 | } |
| 5666 | |
| 5667 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5668 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 5669 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5670 | |
| 5671 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 5672 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 5673 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 5674 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 5675 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 5676 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 5677 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 5678 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 5679 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 5680 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 5681 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 5682 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 5683 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 5684 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 5685 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 5686 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 5687 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 5688 | }; |
| 5689 | |
| 5690 | #define THERMAL_ATTRS(X) \ |
| 5691 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 5692 | |
| 5693 | static struct attribute *thermal_temp_input_attr[] = { |
| 5694 | THERMAL_ATTRS(8), |
| 5695 | THERMAL_ATTRS(9), |
| 5696 | THERMAL_ATTRS(10), |
| 5697 | THERMAL_ATTRS(11), |
| 5698 | THERMAL_ATTRS(12), |
| 5699 | THERMAL_ATTRS(13), |
| 5700 | THERMAL_ATTRS(14), |
| 5701 | THERMAL_ATTRS(15), |
| 5702 | THERMAL_ATTRS(0), |
| 5703 | THERMAL_ATTRS(1), |
| 5704 | THERMAL_ATTRS(2), |
| 5705 | THERMAL_ATTRS(3), |
| 5706 | THERMAL_ATTRS(4), |
| 5707 | THERMAL_ATTRS(5), |
| 5708 | THERMAL_ATTRS(6), |
| 5709 | THERMAL_ATTRS(7), |
| 5710 | NULL |
| 5711 | }; |
| 5712 | |
| 5713 | static const struct attribute_group thermal_temp_input16_group = { |
| 5714 | .attrs = thermal_temp_input_attr |
| 5715 | }; |
| 5716 | |
| 5717 | static const struct attribute_group thermal_temp_input8_group = { |
| 5718 | .attrs = &thermal_temp_input_attr[8] |
| 5719 | }; |
| 5720 | |
| 5721 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 5722 | #undef THERMAL_ATTRS |
| 5723 | |
| 5724 | /* --------------------------------------------------------------------- */ |
| 5725 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5726 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5727 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5728 | u8 t, ta1, ta2; |
| 5729 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5730 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5731 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5732 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5733 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 5734 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5735 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5736 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 5737 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5738 | /* |
| 5739 | * Direct EC access mode: sensors at registers |
| 5740 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 5741 | * non-implemented, thermal sensors return 0x80 when |
| 5742 | * not available |
| 5743 | */ |
| 5744 | |
| 5745 | ta1 = ta2 = 0; |
| 5746 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5747 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5748 | ta1 |= t; |
| 5749 | } else { |
| 5750 | ta1 = 0; |
| 5751 | break; |
| 5752 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5753 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5754 | ta2 |= t; |
| 5755 | } else { |
| 5756 | ta1 = 0; |
| 5757 | break; |
| 5758 | } |
| 5759 | } |
| 5760 | if (ta1 == 0) { |
| 5761 | /* This is sheer paranoia, but we handle it anyway */ |
| 5762 | if (acpi_tmp7) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5763 | pr_err("ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5764 | "falling back to ACPI TMPx access " |
| 5765 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5766 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5767 | } else { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 5768 | pr_err("ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5769 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5770 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5771 | } |
| 5772 | } else { |
| 5773 | thermal_read_mode = |
| 5774 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5775 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5776 | } |
| 5777 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 5778 | if (tpacpi_is_ibm() && |
| 5779 | acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5780 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5781 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5782 | } else { |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 5783 | /* IBM/LENOVO DSDT EC.TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5784 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5785 | } |
| 5786 | } else { |
| 5787 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5788 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5789 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5790 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5791 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 5792 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 5793 | thermal_read_mode); |
| 5794 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5795 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5796 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5797 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5798 | &thermal_temp_input16_group); |
| 5799 | if (res) |
| 5800 | return res; |
| 5801 | break; |
| 5802 | case TPACPI_THERMAL_TPEC_8: |
| 5803 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5804 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5805 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5806 | &thermal_temp_input8_group); |
| 5807 | if (res) |
| 5808 | return res; |
| 5809 | break; |
| 5810 | case TPACPI_THERMAL_NONE: |
| 5811 | default: |
| 5812 | return 1; |
| 5813 | } |
| 5814 | |
| 5815 | return 0; |
| 5816 | } |
| 5817 | |
| 5818 | static void thermal_exit(void) |
| 5819 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5820 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5821 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5822 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5823 | &thermal_temp_input16_group); |
| 5824 | break; |
| 5825 | case TPACPI_THERMAL_TPEC_8: |
| 5826 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5827 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5828 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Roel Kluin | f04d5e0 | 2010-02-02 14:37:58 -0800 | [diff] [blame] | 5829 | &thermal_temp_input8_group); |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5830 | break; |
| 5831 | case TPACPI_THERMAL_NONE: |
| 5832 | default: |
| 5833 | break; |
| 5834 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5835 | } |
| 5836 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5837 | static int thermal_read(struct seq_file *m) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5838 | { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5839 | int n, i; |
| 5840 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5841 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5842 | n = thermal_get_sensors(&t); |
| 5843 | if (unlikely(n < 0)) |
| 5844 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5845 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5846 | seq_printf(m, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5847 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5848 | if (n > 0) { |
| 5849 | for (i = 0; i < (n - 1); i++) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5850 | seq_printf(m, "%d ", t.temp[i] / 1000); |
| 5851 | seq_printf(m, "%d\n", t.temp[i] / 1000); |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5852 | } else |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5853 | seq_printf(m, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5854 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 5855 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5856 | } |
| 5857 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5858 | static struct ibm_struct thermal_driver_data = { |
| 5859 | .name = "thermal", |
| 5860 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5861 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5862 | }; |
| 5863 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5864 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5865 | * Backlight/brightness subdriver |
| 5866 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 5867 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5868 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 5869 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5870 | /* |
| 5871 | * ThinkPads can read brightness from two places: EC HBRV (0x31), or |
| 5872 | * CMOS NVRAM byte 0x5E, bits 0-3. |
| 5873 | * |
| 5874 | * EC HBRV (0x31) has the following layout |
| 5875 | * Bit 7: unknown function |
| 5876 | * Bit 6: unknown function |
| 5877 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 5878 | * Bit 4: must be set to zero to avoid problems |
| 5879 | * Bit 3-0: backlight brightness level |
| 5880 | * |
| 5881 | * brightness_get_raw returns status data in the HBRV layout |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 5882 | * |
| 5883 | * WARNING: The X61 has been verified to use HBRV for something else, so |
| 5884 | * this should be used _only_ on IBM ThinkPads, and maybe with some careful |
| 5885 | * testing on the very early *60 Lenovo models... |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5886 | */ |
| 5887 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5888 | enum { |
| 5889 | TP_EC_BACKLIGHT = 0x31, |
| 5890 | |
| 5891 | /* TP_EC_BACKLIGHT bitmasks */ |
| 5892 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 5893 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 5894 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 5895 | }; |
| 5896 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5897 | enum tpacpi_brightness_access_mode { |
| 5898 | TPACPI_BRGHT_MODE_AUTO = 0, /* Not implemented yet */ |
| 5899 | TPACPI_BRGHT_MODE_EC, /* EC control */ |
| 5900 | TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */ |
| 5901 | TPACPI_BRGHT_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 5902 | TPACPI_BRGHT_MODE_MAX |
| 5903 | }; |
| 5904 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5905 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5906 | |
| 5907 | static enum tpacpi_brightness_access_mode brightness_mode = |
| 5908 | TPACPI_BRGHT_MODE_MAX; |
| 5909 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5910 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 5911 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5912 | static struct mutex brightness_mutex; |
| 5913 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5914 | /* NVRAM brightness access, |
| 5915 | * call with brightness_mutex held! */ |
| 5916 | static unsigned int tpacpi_brightness_nvram_get(void) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5917 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5918 | u8 lnvram; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5919 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5920 | lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 5921 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5922 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 5923 | lnvram &= bright_maxlvl; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5924 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5925 | return lnvram; |
| 5926 | } |
| 5927 | |
| 5928 | static void tpacpi_brightness_checkpoint_nvram(void) |
| 5929 | { |
| 5930 | u8 lec = 0; |
| 5931 | u8 b_nvram; |
| 5932 | |
| 5933 | if (brightness_mode != TPACPI_BRGHT_MODE_ECNVRAM) |
| 5934 | return; |
| 5935 | |
| 5936 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5937 | "trying to checkpoint backlight level to NVRAM...\n"); |
| 5938 | |
| 5939 | if (mutex_lock_killable(&brightness_mutex) < 0) |
| 5940 | return; |
| 5941 | |
| 5942 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5943 | goto unlock; |
| 5944 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
| 5945 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 5946 | |
| 5947 | if (lec != ((b_nvram & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5948 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS)) { |
| 5949 | /* NVRAM needs update */ |
| 5950 | b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS << |
| 5951 | TP_NVRAM_POS_LEVEL_BRIGHTNESS); |
| 5952 | b_nvram |= lec; |
| 5953 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_BRIGHTNESS); |
| 5954 | dbg_printk(TPACPI_DBG_BRGHT, |
| 5955 | "updated NVRAM backlight level to %u (0x%02x)\n", |
| 5956 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5957 | } else |
| 5958 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5959 | "NVRAM backlight level already is %u (0x%02x)\n", |
| 5960 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5961 | |
| 5962 | unlock: |
| 5963 | mutex_unlock(&brightness_mutex); |
| 5964 | } |
| 5965 | |
| 5966 | |
| 5967 | /* call with brightness_mutex held! */ |
| 5968 | static int tpacpi_brightness_get_raw(int *status) |
| 5969 | { |
| 5970 | u8 lec = 0; |
| 5971 | |
| 5972 | switch (brightness_mode) { |
| 5973 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 5974 | *status = tpacpi_brightness_nvram_get(); |
| 5975 | return 0; |
| 5976 | case TPACPI_BRGHT_MODE_EC: |
| 5977 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 5978 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 5979 | return -EIO; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5980 | *status = lec; |
| 5981 | return 0; |
| 5982 | default: |
| 5983 | return -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5984 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5985 | } |
| 5986 | |
| 5987 | /* call with brightness_mutex held! */ |
| 5988 | /* do NOT call with illegal backlight level value */ |
| 5989 | static int tpacpi_brightness_set_ec(unsigned int value) |
| 5990 | { |
| 5991 | u8 lec = 0; |
| 5992 | |
| 5993 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5994 | return -EIO; |
| 5995 | |
| 5996 | if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT, |
| 5997 | (lec & TP_EC_BACKLIGHT_CMDMSK) | |
| 5998 | (value & TP_EC_BACKLIGHT_LVLMSK)))) |
| 5999 | return -EIO; |
| 6000 | |
| 6001 | return 0; |
| 6002 | } |
| 6003 | |
| 6004 | /* call with brightness_mutex held! */ |
| 6005 | static int tpacpi_brightness_set_ucmsstep(unsigned int value) |
| 6006 | { |
| 6007 | int cmos_cmd, inc; |
| 6008 | unsigned int current_value, i; |
| 6009 | |
| 6010 | current_value = tpacpi_brightness_nvram_get(); |
| 6011 | |
| 6012 | if (value == current_value) |
| 6013 | return 0; |
| 6014 | |
| 6015 | cmos_cmd = (value > current_value) ? |
| 6016 | TP_CMOS_BRIGHTNESS_UP : |
| 6017 | TP_CMOS_BRIGHTNESS_DOWN; |
| 6018 | inc = (value > current_value) ? 1 : -1; |
| 6019 | |
| 6020 | for (i = current_value; i != value; i += inc) |
| 6021 | if (issue_thinkpad_cmos_command(cmos_cmd)) |
| 6022 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6023 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6024 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6028 | static int brightness_set(unsigned int value) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6029 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6030 | int res; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6031 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6032 | if (value > bright_maxlvl || value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6033 | return -EINVAL; |
| 6034 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6035 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 6036 | "set backlight level to %d\n", value); |
| 6037 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6038 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6039 | if (res < 0) |
| 6040 | return res; |
| 6041 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6042 | switch (brightness_mode) { |
| 6043 | case TPACPI_BRGHT_MODE_EC: |
| 6044 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 6045 | res = tpacpi_brightness_set_ec(value); |
| 6046 | break; |
| 6047 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 6048 | res = tpacpi_brightness_set_ucmsstep(value); |
| 6049 | break; |
| 6050 | default: |
| 6051 | res = -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6052 | } |
| 6053 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6054 | mutex_unlock(&brightness_mutex); |
| 6055 | return res; |
| 6056 | } |
| 6057 | |
| 6058 | /* sysfs backlight class ----------------------------------------------- */ |
| 6059 | |
| 6060 | static int brightness_update_status(struct backlight_device *bd) |
| 6061 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6062 | unsigned int level = |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6063 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 6064 | bd->props.power == FB_BLANK_UNBLANK) ? |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6065 | bd->props.brightness : 0; |
| 6066 | |
| 6067 | dbg_printk(TPACPI_DBG_BRGHT, |
| 6068 | "backlight: attempt to set level to %d\n", |
| 6069 | level); |
| 6070 | |
| 6071 | /* it is the backlight class's job (caller) to handle |
| 6072 | * EINTR and other errors properly */ |
| 6073 | return brightness_set(level); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6074 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 6075 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6076 | static int brightness_get(struct backlight_device *bd) |
| 6077 | { |
| 6078 | int status, res; |
| 6079 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6080 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6081 | if (res < 0) |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6082 | return 0; |
| 6083 | |
| 6084 | res = tpacpi_brightness_get_raw(&status); |
| 6085 | |
| 6086 | mutex_unlock(&brightness_mutex); |
| 6087 | |
| 6088 | if (res < 0) |
| 6089 | return 0; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6090 | |
| 6091 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 6092 | } |
| 6093 | |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6094 | static void tpacpi_brightness_notify_change(void) |
| 6095 | { |
| 6096 | backlight_force_update(ibm_backlight_device, |
| 6097 | BACKLIGHT_UPDATE_HOTKEY); |
| 6098 | } |
| 6099 | |
Lionel Debroux | acc2472 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 6100 | static const struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6101 | .get_brightness = brightness_get, |
| 6102 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6103 | }; |
| 6104 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6105 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6106 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6107 | /* |
| 6108 | * Call _BCL method of video device. On some ThinkPads this will |
| 6109 | * switch the firmware to the ACPI brightness control mode. |
| 6110 | */ |
| 6111 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6112 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 6113 | { |
| 6114 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 6115 | union acpi_object *obj; |
| 6116 | int rc; |
| 6117 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6118 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, "_BCL", NULL, &buffer))) { |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6119 | obj = (union acpi_object *)buffer.pointer; |
| 6120 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6121 | pr_err("Unknown _BCL data, please report this to %s\n", |
| 6122 | TPACPI_MAIL); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6123 | rc = 0; |
| 6124 | } else { |
| 6125 | rc = obj->package.count; |
| 6126 | } |
| 6127 | } else { |
| 6128 | return 0; |
| 6129 | } |
| 6130 | |
| 6131 | kfree(buffer.pointer); |
| 6132 | return rc; |
| 6133 | } |
| 6134 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6135 | |
| 6136 | /* |
| 6137 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 6138 | */ |
| 6139 | static unsigned int __init tpacpi_check_std_acpi_brightness_support(void) |
| 6140 | { |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6141 | acpi_handle video_device; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6142 | int bcl_levels = 0; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6143 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6144 | tpacpi_acpi_handle_locate("video", ACPI_VIDEO_HID, &video_device); |
| 6145 | if (video_device) |
| 6146 | bcl_levels = tpacpi_query_bcl_levels(video_device); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6147 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6148 | tp_features.bright_acpimode = (bcl_levels > 0); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6149 | |
Henrique de Moraes Holschuh | 122f267 | 2010-08-09 23:48:18 -0300 | [diff] [blame] | 6150 | return (bcl_levels > 2) ? (bcl_levels - 2) : 0; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6151 | } |
| 6152 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6153 | /* |
| 6154 | * These are only useful for models that have only one possibility |
| 6155 | * of GPU. If the BIOS model handles both ATI and Intel, don't use |
| 6156 | * these quirks. |
| 6157 | */ |
| 6158 | #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */ |
| 6159 | #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */ |
| 6160 | #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */ |
| 6161 | |
| 6162 | static const struct tpacpi_quirk brightness_quirk_table[] __initconst = { |
| 6163 | /* Models with ATI GPUs known to require ECNVRAM mode */ |
| 6164 | TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */ |
| 6165 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6166 | /* Models with ATI GPUs that can use ECNVRAM */ |
Henrique de Moraes Holschuh | 7d1894d | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 6167 | TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), /* R50,51 T40-42 */ |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6168 | TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
Henrique de Moraes Holschuh | 7d1894d | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 6169 | TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC), /* R52 */ |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6170 | TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6171 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 6172 | /* Models with Intel Extreme Graphics 2 */ |
Henrique de Moraes Holschuh | 7d1894d | 2010-02-25 21:28:56 -0300 | [diff] [blame] | 6173 | TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), /* X40 */ |
Henrique de Moraes Holschuh | a9f8eac | 2009-12-09 01:36:21 +0000 | [diff] [blame] | 6174 | TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 6175 | 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] | 6176 | |
| 6177 | /* Models with Intel GMA900 */ |
| 6178 | TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC), /* T43, R52 */ |
| 6179 | TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC), /* X41 */ |
| 6180 | TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC), /* X41 Tablet */ |
| 6181 | }; |
| 6182 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6183 | /* |
| 6184 | * Returns < 0 for error, otherwise sets tp_features.bright_* |
| 6185 | * and bright_maxlvl. |
| 6186 | */ |
| 6187 | static void __init tpacpi_detect_brightness_capabilities(void) |
| 6188 | { |
| 6189 | unsigned int b; |
| 6190 | |
| 6191 | vdbg_printk(TPACPI_DBG_INIT, |
| 6192 | "detecting firmware brightness interface capabilities\n"); |
| 6193 | |
| 6194 | /* we could run a quirks check here (same table used by |
| 6195 | * brightness_init) if needed */ |
| 6196 | |
| 6197 | /* |
| 6198 | * We always attempt to detect acpi support, so as to switch |
| 6199 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 6200 | * going to publish a backlight interface |
| 6201 | */ |
| 6202 | b = tpacpi_check_std_acpi_brightness_support(); |
| 6203 | switch (b) { |
| 6204 | case 16: |
| 6205 | bright_maxlvl = 15; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6206 | pr_info("detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6207 | break; |
| 6208 | case 8: |
| 6209 | case 0: |
| 6210 | bright_maxlvl = 7; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6211 | pr_info("detected a 8-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6212 | break; |
| 6213 | default: |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6214 | pr_err("Unsupported brightness interface, " |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6215 | "please contact %s\n", TPACPI_MAIL); |
| 6216 | tp_features.bright_unkfw = 1; |
| 6217 | bright_maxlvl = b - 1; |
| 6218 | } |
| 6219 | } |
| 6220 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6221 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6222 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 6223 | struct backlight_properties props; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6224 | int b; |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6225 | unsigned long quirks; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6226 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6227 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 6228 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 6229 | mutex_init(&brightness_mutex); |
| 6230 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6231 | quirks = tpacpi_check_quirks(brightness_quirk_table, |
| 6232 | ARRAY_SIZE(brightness_quirk_table)); |
| 6233 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6234 | /* tpacpi_detect_brightness_capabilities() must have run already */ |
Thomas Renninger | 2dba1b5 | 2008-08-01 17:38:03 +0200 | [diff] [blame] | 6235 | |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6236 | /* if it is unknown, we don't handle it: it wouldn't be safe */ |
| 6237 | if (tp_features.bright_unkfw) |
| 6238 | return 1; |
| 6239 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6240 | if (!brightness_enable) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6241 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 6242 | "brightness support disabled by " |
| 6243 | "module parameter\n"); |
| 6244 | return 1; |
| 6245 | } |
| 6246 | |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6247 | if (acpi_video_backlight_support()) { |
| 6248 | if (brightness_enable > 1) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6249 | pr_info("Standard ACPI backlight interface " |
| 6250 | "available, not loading native one\n"); |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6251 | return 1; |
| 6252 | } else if (brightness_enable == 1) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6253 | pr_warn("Cannot enable backlight brightness support, " |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6254 | "ACPI is already handling it. Refer to the " |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6255 | "acpi_backlight kernel parameter.\n"); |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6256 | return 1; |
| 6257 | } |
| 6258 | } else if (tp_features.bright_acpimode && brightness_enable > 1) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6259 | pr_notice("Standard ACPI backlight interface not " |
| 6260 | "available, thinkpad_acpi native " |
| 6261 | "brightness control enabled\n"); |
Henrique de Moraes Holschuh | 217f096 | 2010-08-09 23:48:19 -0300 | [diff] [blame] | 6262 | } |
| 6263 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6264 | /* |
| 6265 | * Check for module parameter bogosity, note that we |
| 6266 | * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be |
| 6267 | * able to detect "unspecified" |
| 6268 | */ |
| 6269 | if (brightness_mode > TPACPI_BRGHT_MODE_MAX) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6270 | return -EINVAL; |
| 6271 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6272 | /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */ |
| 6273 | if (brightness_mode == TPACPI_BRGHT_MODE_AUTO || |
| 6274 | brightness_mode == TPACPI_BRGHT_MODE_MAX) { |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6275 | if (quirks & TPACPI_BRGHT_Q_EC) |
| 6276 | brightness_mode = TPACPI_BRGHT_MODE_ECNVRAM; |
| 6277 | else |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6278 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
| 6279 | |
| 6280 | dbg_printk(TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6281 | "driver auto-selected brightness_mode=%d\n", |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6282 | brightness_mode); |
| 6283 | } |
| 6284 | |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 6285 | /* Safety */ |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 6286 | if (!tpacpi_is_ibm() && |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 6287 | (brightness_mode == TPACPI_BRGHT_MODE_ECNVRAM || |
| 6288 | brightness_mode == TPACPI_BRGHT_MODE_EC)) |
| 6289 | return -EINVAL; |
| 6290 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6291 | if (tpacpi_brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6292 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6293 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 6294 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 6295 | props.type = BACKLIGHT_PLATFORM; |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6296 | props.max_brightness = bright_maxlvl; |
| 6297 | props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 6298 | ibm_backlight_device = backlight_device_register(TPACPI_BACKLIGHT_DEV_NAME, |
| 6299 | NULL, NULL, |
| 6300 | &ibm_backlight_data, |
| 6301 | &props); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6302 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6303 | int rc = PTR_ERR(ibm_backlight_device); |
| 6304 | ibm_backlight_device = NULL; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6305 | pr_err("Could not register backlight device\n"); |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame] | 6306 | return rc; |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6307 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6308 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6309 | "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6310 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6311 | if (quirks & TPACPI_BRGHT_Q_ASK) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6312 | pr_notice("brightness: will use unverified default: " |
| 6313 | "brightness_mode=%d\n", brightness_mode); |
| 6314 | pr_notice("brightness: please report to %s whether it works well " |
| 6315 | "or not on your ThinkPad\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6316 | } |
| 6317 | |
Henrique de Moraes Holschuh | 7d9745c | 2010-05-16 19:45:57 -0300 | [diff] [blame] | 6318 | /* Added by mistake in early 2007. Probably useless, but it could |
| 6319 | * be working around some unknown firmware problem where the value |
| 6320 | * read at startup doesn't match the real hardware state... so leave |
| 6321 | * it in place just in case */ |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6322 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6323 | |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6324 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6325 | "brightness: registering brightness hotkeys " |
| 6326 | "as change notification\n"); |
| 6327 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
| 6328 | | TP_ACPI_HKEY_BRGHTUP_MASK |
Joe Perches | 3098064 | 2010-11-14 19:04:38 -0800 | [diff] [blame] | 6329 | | TP_ACPI_HKEY_BRGHTDWN_MASK); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6330 | return 0; |
| 6331 | } |
| 6332 | |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 6333 | static void brightness_suspend(void) |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6334 | { |
| 6335 | tpacpi_brightness_checkpoint_nvram(); |
| 6336 | } |
| 6337 | |
| 6338 | static void brightness_shutdown(void) |
| 6339 | { |
| 6340 | tpacpi_brightness_checkpoint_nvram(); |
| 6341 | } |
| 6342 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6343 | static void brightness_exit(void) |
| 6344 | { |
| 6345 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6346 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6347 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6348 | backlight_device_unregister(ibm_backlight_device); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6349 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6350 | |
| 6351 | tpacpi_brightness_checkpoint_nvram(); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6352 | } |
| 6353 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6354 | static int brightness_read(struct seq_file *m) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6355 | { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6356 | int level; |
| 6357 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6358 | level = brightness_get(NULL); |
| 6359 | if (level < 0) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6360 | seq_printf(m, "level:\t\tunreadable\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6361 | } else { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6362 | seq_printf(m, "level:\t\t%d\n", level); |
| 6363 | seq_printf(m, "commands:\tup, down\n"); |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6364 | seq_printf(m, "commands:\tlevel <level> (<level> is 0-%d)\n", |
| 6365 | bright_maxlvl); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6366 | } |
| 6367 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6368 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | static int brightness_write(char *buf) |
| 6372 | { |
| 6373 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6374 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6375 | char *cmd; |
| 6376 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6377 | level = brightness_get(NULL); |
| 6378 | if (level < 0) |
| 6379 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6380 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6381 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6382 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6383 | if (level < bright_maxlvl) |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6384 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6385 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6386 | if (level > 0) |
| 6387 | level--; |
| 6388 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 6389 | level >= 0 && level <= bright_maxlvl) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6390 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6391 | } else |
| 6392 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6393 | } |
| 6394 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6395 | tpacpi_disclose_usertask("procfs brightness", |
| 6396 | "set level to %d\n", level); |
| 6397 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6398 | /* |
| 6399 | * Now we know what the final level should be, so we try to set it. |
| 6400 | * Doing it this way makes the syscall restartable in case of EINTR |
| 6401 | */ |
| 6402 | rc = brightness_set(level); |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 6403 | if (!rc && ibm_backlight_device) |
| 6404 | backlight_force_update(ibm_backlight_device, |
| 6405 | BACKLIGHT_UPDATE_SYSFS); |
Roel Kluin | 80a8d12 | 2009-11-20 19:48:23 +0100 | [diff] [blame] | 6406 | return (rc == -EINTR)? -ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6407 | } |
| 6408 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6409 | static struct ibm_struct brightness_driver_data = { |
| 6410 | .name = "brightness", |
| 6411 | .read = brightness_read, |
| 6412 | .write = brightness_write, |
| 6413 | .exit = brightness_exit, |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6414 | .suspend = brightness_suspend, |
| 6415 | .shutdown = brightness_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6416 | }; |
| 6417 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6418 | /************************************************************************* |
| 6419 | * Volume subdriver |
| 6420 | */ |
| 6421 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6422 | /* |
| 6423 | * IBM ThinkPads have a simple volume controller with MUTE gating. |
| 6424 | * Very early Lenovo ThinkPads follow the IBM ThinkPad spec. |
| 6425 | * |
| 6426 | * Since the *61 series (and probably also the later *60 series), Lenovo |
| 6427 | * ThinkPads only implement the MUTE gate. |
| 6428 | * |
| 6429 | * EC register 0x30 |
| 6430 | * Bit 6: MUTE (1 mutes sound) |
| 6431 | * Bit 3-0: Volume |
| 6432 | * Other bits should be zero as far as we know. |
| 6433 | * |
| 6434 | * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and |
| 6435 | * bits 3-0 (volume). Other bits in NVRAM may have other functions, |
| 6436 | * such as bit 7 which is used to detect repeated presses of MUTE, |
| 6437 | * and we leave them unchanged. |
| 6438 | */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6439 | |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 6440 | #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT |
| 6441 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6442 | #define TPACPI_ALSA_DRVNAME "ThinkPad EC" |
| 6443 | #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control" |
| 6444 | #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME |
| 6445 | |
Henrique de Moraes Holschuh | ead510c | 2009-12-26 22:52:13 -0200 | [diff] [blame] | 6446 | static int alsa_index = ~((1 << (SNDRV_CARDS - 3)) - 1); /* last three slots */ |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6447 | static char *alsa_id = "ThinkPadEC"; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 6448 | static bool alsa_enable = SNDRV_DEFAULT_ENABLE1; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6449 | |
| 6450 | struct tpacpi_alsa_data { |
| 6451 | struct snd_card *card; |
| 6452 | struct snd_ctl_elem_id *ctl_mute_id; |
| 6453 | struct snd_ctl_elem_id *ctl_vol_id; |
| 6454 | }; |
| 6455 | |
| 6456 | static struct snd_card *alsa_card; |
| 6457 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6458 | enum { |
| 6459 | TP_EC_AUDIO = 0x30, |
| 6460 | |
| 6461 | /* TP_EC_AUDIO bits */ |
| 6462 | TP_EC_AUDIO_MUTESW = 6, |
| 6463 | |
| 6464 | /* TP_EC_AUDIO bitmasks */ |
| 6465 | TP_EC_AUDIO_LVL_MSK = 0x0F, |
| 6466 | TP_EC_AUDIO_MUTESW_MSK = (1 << TP_EC_AUDIO_MUTESW), |
| 6467 | |
| 6468 | /* Maximum volume */ |
| 6469 | TP_EC_VOLUME_MAX = 14, |
| 6470 | }; |
| 6471 | |
| 6472 | enum tpacpi_volume_access_mode { |
| 6473 | TPACPI_VOL_MODE_AUTO = 0, /* Not implemented yet */ |
| 6474 | TPACPI_VOL_MODE_EC, /* Pure EC control */ |
| 6475 | TPACPI_VOL_MODE_UCMS_STEP, /* UCMS step-based control: N/A */ |
| 6476 | TPACPI_VOL_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 6477 | TPACPI_VOL_MODE_MAX |
| 6478 | }; |
| 6479 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6480 | enum tpacpi_volume_capabilities { |
| 6481 | TPACPI_VOL_CAP_AUTO = 0, /* Use white/blacklist */ |
| 6482 | TPACPI_VOL_CAP_VOLMUTE, /* Output vol and mute */ |
| 6483 | TPACPI_VOL_CAP_MUTEONLY, /* Output mute only */ |
| 6484 | TPACPI_VOL_CAP_MAX |
| 6485 | }; |
| 6486 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6487 | static enum tpacpi_volume_access_mode volume_mode = |
| 6488 | TPACPI_VOL_MODE_MAX; |
| 6489 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6490 | static enum tpacpi_volume_capabilities volume_capabilities; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 6491 | static bool volume_control_allowed; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6492 | |
| 6493 | /* |
| 6494 | * Used to syncronize writers to TP_EC_AUDIO and |
| 6495 | * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write |
| 6496 | */ |
| 6497 | static struct mutex volume_mutex; |
| 6498 | |
| 6499 | static void tpacpi_volume_checkpoint_nvram(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6500 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6501 | u8 lec = 0; |
| 6502 | u8 b_nvram; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6503 | u8 ec_mask; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6504 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6505 | if (volume_mode != TPACPI_VOL_MODE_ECNVRAM) |
| 6506 | return; |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 6507 | if (!volume_control_allowed) |
| 6508 | return; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6509 | |
| 6510 | vdbg_printk(TPACPI_DBG_MIXER, |
| 6511 | "trying to checkpoint mixer state to NVRAM...\n"); |
| 6512 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6513 | if (tp_features.mixer_no_level_control) |
| 6514 | ec_mask = TP_EC_AUDIO_MUTESW_MSK; |
| 6515 | else |
| 6516 | ec_mask = TP_EC_AUDIO_MUTESW_MSK | TP_EC_AUDIO_LVL_MSK; |
| 6517 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6518 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6519 | return; |
| 6520 | |
| 6521 | if (unlikely(!acpi_ec_read(TP_EC_AUDIO, &lec))) |
| 6522 | goto unlock; |
| 6523 | lec &= ec_mask; |
| 6524 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 6525 | |
| 6526 | if (lec != (b_nvram & ec_mask)) { |
| 6527 | /* NVRAM needs update */ |
| 6528 | b_nvram &= ~ec_mask; |
| 6529 | b_nvram |= lec; |
| 6530 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_MIXER); |
| 6531 | dbg_printk(TPACPI_DBG_MIXER, |
| 6532 | "updated NVRAM mixer status to 0x%02x (0x%02x)\n", |
| 6533 | (unsigned int) lec, (unsigned int) b_nvram); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6534 | } else { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6535 | vdbg_printk(TPACPI_DBG_MIXER, |
| 6536 | "NVRAM mixer status already is 0x%02x (0x%02x)\n", |
| 6537 | (unsigned int) lec, (unsigned int) b_nvram); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6538 | } |
| 6539 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6540 | unlock: |
| 6541 | mutex_unlock(&volume_mutex); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6542 | } |
| 6543 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6544 | static int volume_get_status_ec(u8 *status) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6545 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6546 | u8 s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6547 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6548 | if (!acpi_ec_read(TP_EC_AUDIO, &s)) |
| 6549 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6550 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6551 | *status = s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6552 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6553 | dbg_printk(TPACPI_DBG_MIXER, "status 0x%02x\n", s); |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6554 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6555 | return 0; |
| 6556 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6557 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6558 | static int volume_get_status(u8 *status) |
| 6559 | { |
| 6560 | return volume_get_status_ec(status); |
| 6561 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6562 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6563 | static int volume_set_status_ec(const u8 status) |
| 6564 | { |
| 6565 | if (!acpi_ec_write(TP_EC_AUDIO, status)) |
| 6566 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6567 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6568 | dbg_printk(TPACPI_DBG_MIXER, "set EC mixer to 0x%02x\n", status); |
| 6569 | |
| 6570 | return 0; |
| 6571 | } |
| 6572 | |
| 6573 | static int volume_set_status(const u8 status) |
| 6574 | { |
| 6575 | return volume_set_status_ec(status); |
| 6576 | } |
| 6577 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6578 | /* returns < 0 on error, 0 on no change, 1 on change */ |
| 6579 | static int __volume_set_mute_ec(const bool mute) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6580 | { |
| 6581 | int rc; |
| 6582 | u8 s, n; |
| 6583 | |
| 6584 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6585 | return -EINTR; |
| 6586 | |
| 6587 | rc = volume_get_status_ec(&s); |
| 6588 | if (rc) |
| 6589 | goto unlock; |
| 6590 | |
| 6591 | n = (mute) ? s | TP_EC_AUDIO_MUTESW_MSK : |
| 6592 | s & ~TP_EC_AUDIO_MUTESW_MSK; |
| 6593 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6594 | if (n != s) { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6595 | rc = volume_set_status_ec(n); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6596 | if (!rc) |
| 6597 | rc = 1; |
| 6598 | } |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6599 | |
| 6600 | unlock: |
| 6601 | mutex_unlock(&volume_mutex); |
| 6602 | return rc; |
| 6603 | } |
| 6604 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6605 | static int volume_alsa_set_mute(const bool mute) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6606 | { |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6607 | dbg_printk(TPACPI_DBG_MIXER, "ALSA: trying to %smute\n", |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6608 | (mute) ? "" : "un"); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6609 | return __volume_set_mute_ec(mute); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6610 | } |
| 6611 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6612 | static int volume_set_mute(const bool mute) |
| 6613 | { |
| 6614 | int rc; |
| 6615 | |
| 6616 | dbg_printk(TPACPI_DBG_MIXER, "trying to %smute\n", |
| 6617 | (mute) ? "" : "un"); |
| 6618 | |
| 6619 | rc = __volume_set_mute_ec(mute); |
| 6620 | return (rc < 0) ? rc : 0; |
| 6621 | } |
| 6622 | |
| 6623 | /* returns < 0 on error, 0 on no change, 1 on change */ |
| 6624 | static int __volume_set_volume_ec(const u8 vol) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6625 | { |
| 6626 | int rc; |
| 6627 | u8 s, n; |
| 6628 | |
| 6629 | if (vol > TP_EC_VOLUME_MAX) |
| 6630 | return -EINVAL; |
| 6631 | |
| 6632 | if (mutex_lock_killable(&volume_mutex) < 0) |
| 6633 | return -EINTR; |
| 6634 | |
| 6635 | rc = volume_get_status_ec(&s); |
| 6636 | if (rc) |
| 6637 | goto unlock; |
| 6638 | |
| 6639 | n = (s & ~TP_EC_AUDIO_LVL_MSK) | vol; |
| 6640 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6641 | if (n != s) { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6642 | rc = volume_set_status_ec(n); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6643 | if (!rc) |
| 6644 | rc = 1; |
| 6645 | } |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6646 | |
| 6647 | unlock: |
| 6648 | mutex_unlock(&volume_mutex); |
| 6649 | return rc; |
| 6650 | } |
| 6651 | |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6652 | static int volume_alsa_set_volume(const u8 vol) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6653 | { |
| 6654 | dbg_printk(TPACPI_DBG_MIXER, |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6655 | "ALSA: trying to set volume level to %hu\n", vol); |
| 6656 | return __volume_set_volume_ec(vol); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6657 | } |
| 6658 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6659 | static void volume_alsa_notify_change(void) |
| 6660 | { |
| 6661 | struct tpacpi_alsa_data *d; |
| 6662 | |
| 6663 | if (alsa_card && alsa_card->private_data) { |
| 6664 | d = alsa_card->private_data; |
| 6665 | if (d->ctl_mute_id) |
| 6666 | snd_ctl_notify(alsa_card, |
| 6667 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 6668 | d->ctl_mute_id); |
| 6669 | if (d->ctl_vol_id) |
| 6670 | snd_ctl_notify(alsa_card, |
| 6671 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 6672 | d->ctl_vol_id); |
| 6673 | } |
| 6674 | } |
| 6675 | |
| 6676 | static int volume_alsa_vol_info(struct snd_kcontrol *kcontrol, |
| 6677 | struct snd_ctl_elem_info *uinfo) |
| 6678 | { |
| 6679 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 6680 | uinfo->count = 1; |
| 6681 | uinfo->value.integer.min = 0; |
| 6682 | uinfo->value.integer.max = TP_EC_VOLUME_MAX; |
| 6683 | return 0; |
| 6684 | } |
| 6685 | |
| 6686 | static int volume_alsa_vol_get(struct snd_kcontrol *kcontrol, |
| 6687 | struct snd_ctl_elem_value *ucontrol) |
| 6688 | { |
| 6689 | u8 s; |
| 6690 | int rc; |
| 6691 | |
| 6692 | rc = volume_get_status(&s); |
| 6693 | if (rc < 0) |
| 6694 | return rc; |
| 6695 | |
| 6696 | ucontrol->value.integer.value[0] = s & TP_EC_AUDIO_LVL_MSK; |
| 6697 | return 0; |
| 6698 | } |
| 6699 | |
| 6700 | static int volume_alsa_vol_put(struct snd_kcontrol *kcontrol, |
| 6701 | struct snd_ctl_elem_value *ucontrol) |
| 6702 | { |
Henrique de Moraes Holschuh | 38e11cd | 2010-05-16 19:45:40 -0300 | [diff] [blame] | 6703 | tpacpi_disclose_usertask("ALSA", "set volume to %ld\n", |
| 6704 | ucontrol->value.integer.value[0]); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6705 | return volume_alsa_set_volume(ucontrol->value.integer.value[0]); |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6706 | } |
| 6707 | |
| 6708 | #define volume_alsa_mute_info snd_ctl_boolean_mono_info |
| 6709 | |
| 6710 | static int volume_alsa_mute_get(struct snd_kcontrol *kcontrol, |
| 6711 | struct snd_ctl_elem_value *ucontrol) |
| 6712 | { |
| 6713 | u8 s; |
| 6714 | int rc; |
| 6715 | |
| 6716 | rc = volume_get_status(&s); |
| 6717 | if (rc < 0) |
| 6718 | return rc; |
| 6719 | |
| 6720 | ucontrol->value.integer.value[0] = |
| 6721 | (s & TP_EC_AUDIO_MUTESW_MSK) ? 0 : 1; |
| 6722 | return 0; |
| 6723 | } |
| 6724 | |
| 6725 | static int volume_alsa_mute_put(struct snd_kcontrol *kcontrol, |
| 6726 | struct snd_ctl_elem_value *ucontrol) |
| 6727 | { |
Henrique de Moraes Holschuh | 38e11cd | 2010-05-16 19:45:40 -0300 | [diff] [blame] | 6728 | tpacpi_disclose_usertask("ALSA", "%smute\n", |
| 6729 | ucontrol->value.integer.value[0] ? |
| 6730 | "un" : ""); |
Henrique de Moraes Holschuh | 88cc837 | 2010-02-27 18:45:29 -0300 | [diff] [blame] | 6731 | return volume_alsa_set_mute(!ucontrol->value.integer.value[0]); |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6732 | } |
| 6733 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 6734 | static struct snd_kcontrol_new volume_alsa_control_vol = { |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6735 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 6736 | .name = "Console Playback Volume", |
| 6737 | .index = 0, |
| 6738 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 6739 | .info = volume_alsa_vol_info, |
| 6740 | .get = volume_alsa_vol_get, |
| 6741 | }; |
| 6742 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 6743 | static struct snd_kcontrol_new volume_alsa_control_mute = { |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6744 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 6745 | .name = "Console Playback Switch", |
| 6746 | .index = 0, |
| 6747 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 6748 | .info = volume_alsa_mute_info, |
| 6749 | .get = volume_alsa_mute_get, |
| 6750 | }; |
| 6751 | |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 6752 | static void volume_suspend(void) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6753 | { |
| 6754 | tpacpi_volume_checkpoint_nvram(); |
| 6755 | } |
| 6756 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6757 | static void volume_resume(void) |
| 6758 | { |
| 6759 | volume_alsa_notify_change(); |
| 6760 | } |
| 6761 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6762 | static void volume_shutdown(void) |
| 6763 | { |
| 6764 | tpacpi_volume_checkpoint_nvram(); |
| 6765 | } |
| 6766 | |
| 6767 | static void volume_exit(void) |
| 6768 | { |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6769 | if (alsa_card) { |
| 6770 | snd_card_free(alsa_card); |
| 6771 | alsa_card = NULL; |
| 6772 | } |
| 6773 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6774 | tpacpi_volume_checkpoint_nvram(); |
| 6775 | } |
| 6776 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6777 | static int __init volume_create_alsa_mixer(void) |
| 6778 | { |
| 6779 | struct snd_card *card; |
| 6780 | struct tpacpi_alsa_data *data; |
| 6781 | struct snd_kcontrol *ctl_vol; |
| 6782 | struct snd_kcontrol *ctl_mute; |
| 6783 | int rc; |
| 6784 | |
| 6785 | rc = snd_card_create(alsa_index, alsa_id, THIS_MODULE, |
| 6786 | sizeof(struct tpacpi_alsa_data), &card); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6787 | if (rc < 0 || !card) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6788 | pr_err("Failed to create ALSA card structures: %d\n", rc); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6789 | return 1; |
| 6790 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6791 | |
| 6792 | BUG_ON(!card->private_data); |
| 6793 | data = card->private_data; |
| 6794 | data->card = card; |
| 6795 | |
| 6796 | strlcpy(card->driver, TPACPI_ALSA_DRVNAME, |
| 6797 | sizeof(card->driver)); |
| 6798 | strlcpy(card->shortname, TPACPI_ALSA_SHRTNAME, |
| 6799 | sizeof(card->shortname)); |
| 6800 | snprintf(card->mixername, sizeof(card->mixername), "ThinkPad EC %s", |
| 6801 | (thinkpad_id.ec_version_str) ? |
| 6802 | thinkpad_id.ec_version_str : "(unknown)"); |
| 6803 | snprintf(card->longname, sizeof(card->longname), |
| 6804 | "%s at EC reg 0x%02x, fw %s", card->shortname, TP_EC_AUDIO, |
| 6805 | (thinkpad_id.ec_version_str) ? |
| 6806 | thinkpad_id.ec_version_str : "unknown"); |
| 6807 | |
| 6808 | if (volume_control_allowed) { |
| 6809 | volume_alsa_control_vol.put = volume_alsa_vol_put; |
| 6810 | volume_alsa_control_vol.access = |
| 6811 | SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 6812 | |
| 6813 | volume_alsa_control_mute.put = volume_alsa_mute_put; |
| 6814 | volume_alsa_control_mute.access = |
| 6815 | SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 6816 | } |
| 6817 | |
| 6818 | if (!tp_features.mixer_no_level_control) { |
| 6819 | ctl_vol = snd_ctl_new1(&volume_alsa_control_vol, NULL); |
| 6820 | rc = snd_ctl_add(card, ctl_vol); |
| 6821 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6822 | pr_err("Failed to create ALSA volume control: %d\n", |
| 6823 | rc); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6824 | goto err_exit; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6825 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6826 | data->ctl_vol_id = &ctl_vol->id; |
| 6827 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6828 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6829 | ctl_mute = snd_ctl_new1(&volume_alsa_control_mute, NULL); |
| 6830 | rc = snd_ctl_add(card, ctl_mute); |
| 6831 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6832 | pr_err("Failed to create ALSA mute control: %d\n", rc); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6833 | goto err_exit; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6834 | } |
| 6835 | data->ctl_mute_id = &ctl_mute->id; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6836 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6837 | snd_card_set_dev(card, &tpacpi_pdev->dev); |
| 6838 | rc = snd_card_register(card); |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6839 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6840 | pr_err("Failed to register ALSA card: %d\n", rc); |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6841 | goto err_exit; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | alsa_card = card; |
Henrique de Moraes Holschuh | 74c75c1 | 2009-12-26 22:52:14 -0200 | [diff] [blame] | 6845 | return 0; |
| 6846 | |
| 6847 | err_exit: |
| 6848 | snd_card_free(card); |
| 6849 | return 1; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6850 | } |
| 6851 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6852 | #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */ |
| 6853 | #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */ |
| 6854 | |
| 6855 | static const struct tpacpi_quirk volume_quirk_table[] __initconst = { |
| 6856 | /* Whitelist volume level on all IBM by default */ |
| 6857 | { .vendor = PCI_VENDOR_ID_IBM, |
| 6858 | .bios = TPACPI_MATCH_ANY, |
| 6859 | .ec = TPACPI_MATCH_ANY, |
| 6860 | .quirks = TPACPI_VOL_Q_LEVEL }, |
| 6861 | |
| 6862 | /* Lenovo models with volume control (needs confirmation) */ |
| 6863 | TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL), /* R60/i */ |
| 6864 | TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL), /* R60e/i */ |
| 6865 | TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL), /* T60/p */ |
| 6866 | TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL), /* X60/s */ |
| 6867 | TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL), /* X60t */ |
| 6868 | TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL), /* Z60 */ |
| 6869 | TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL), /* Z61 */ |
| 6870 | |
| 6871 | /* Whitelist mute-only on all Lenovo by default */ |
| 6872 | { .vendor = PCI_VENDOR_ID_LENOVO, |
| 6873 | .bios = TPACPI_MATCH_ANY, |
| 6874 | .ec = TPACPI_MATCH_ANY, |
| 6875 | .quirks = TPACPI_VOL_Q_MUTEONLY } |
| 6876 | }; |
| 6877 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6878 | static int __init volume_init(struct ibm_init_struct *iibm) |
| 6879 | { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6880 | unsigned long quirks; |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6881 | int rc; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6882 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6883 | vdbg_printk(TPACPI_DBG_INIT, "initializing volume subdriver\n"); |
| 6884 | |
| 6885 | mutex_init(&volume_mutex); |
| 6886 | |
| 6887 | /* |
| 6888 | * Check for module parameter bogosity, note that we |
| 6889 | * init volume_mode to TPACPI_VOL_MODE_MAX in order to be |
| 6890 | * able to detect "unspecified" |
| 6891 | */ |
| 6892 | if (volume_mode > TPACPI_VOL_MODE_MAX) |
| 6893 | return -EINVAL; |
| 6894 | |
| 6895 | if (volume_mode == TPACPI_VOL_MODE_UCMS_STEP) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6896 | pr_err("UCMS step volume mode not implemented, " |
| 6897 | "please contact %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6898 | return 1; |
| 6899 | } |
| 6900 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6901 | if (volume_capabilities >= TPACPI_VOL_CAP_MAX) |
| 6902 | return -EINVAL; |
| 6903 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6904 | /* |
| 6905 | * The ALSA mixer is our primary interface. |
| 6906 | * When disabled, don't install the subdriver at all |
| 6907 | */ |
| 6908 | if (!alsa_enable) { |
| 6909 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6910 | "ALSA mixer disabled by parameter, " |
| 6911 | "not loading volume subdriver...\n"); |
| 6912 | return 1; |
| 6913 | } |
| 6914 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6915 | quirks = tpacpi_check_quirks(volume_quirk_table, |
| 6916 | ARRAY_SIZE(volume_quirk_table)); |
| 6917 | |
| 6918 | switch (volume_capabilities) { |
| 6919 | case TPACPI_VOL_CAP_AUTO: |
| 6920 | if (quirks & TPACPI_VOL_Q_MUTEONLY) |
| 6921 | tp_features.mixer_no_level_control = 1; |
| 6922 | else if (quirks & TPACPI_VOL_Q_LEVEL) |
| 6923 | tp_features.mixer_no_level_control = 0; |
| 6924 | else |
| 6925 | return 1; /* no mixer */ |
| 6926 | break; |
| 6927 | case TPACPI_VOL_CAP_VOLMUTE: |
| 6928 | tp_features.mixer_no_level_control = 0; |
| 6929 | break; |
| 6930 | case TPACPI_VOL_CAP_MUTEONLY: |
| 6931 | tp_features.mixer_no_level_control = 1; |
| 6932 | break; |
| 6933 | default: |
| 6934 | return 1; |
| 6935 | } |
| 6936 | |
| 6937 | if (volume_capabilities != TPACPI_VOL_CAP_AUTO) |
| 6938 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6939 | "using user-supplied volume_capabilities=%d\n", |
| 6940 | volume_capabilities); |
| 6941 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6942 | if (volume_mode == TPACPI_VOL_MODE_AUTO || |
| 6943 | volume_mode == TPACPI_VOL_MODE_MAX) { |
| 6944 | volume_mode = TPACPI_VOL_MODE_ECNVRAM; |
| 6945 | |
| 6946 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6947 | "driver auto-selected volume_mode=%d\n", |
| 6948 | volume_mode); |
| 6949 | } else { |
| 6950 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6951 | "using user-supplied volume_mode=%d\n", |
| 6952 | volume_mode); |
| 6953 | } |
| 6954 | |
| 6955 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6956 | "mute is supported, volume control is %s\n", |
| 6957 | str_supported(!tp_features.mixer_no_level_control)); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6958 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6959 | rc = volume_create_alsa_mixer(); |
| 6960 | if (rc) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6961 | pr_err("Could not create the ALSA mixer interface\n"); |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6962 | return rc; |
| 6963 | } |
| 6964 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 6965 | pr_info("Console audio control enabled, mode: %s\n", |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 6966 | (volume_control_allowed) ? |
| 6967 | "override (read/write)" : |
| 6968 | "monitor (read only)"); |
| 6969 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 6970 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
| 6971 | "registering volume hotkeys as change notification\n"); |
| 6972 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask |
| 6973 | | TP_ACPI_HKEY_VOLUP_MASK |
| 6974 | | TP_ACPI_HKEY_VOLDWN_MASK |
| 6975 | | TP_ACPI_HKEY_MUTE_MASK); |
| 6976 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6977 | return 0; |
| 6978 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6979 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6980 | static int volume_read(struct seq_file *m) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6981 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6982 | u8 status; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6983 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6984 | if (volume_get_status(&status) < 0) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6985 | seq_printf(m, "level:\t\tunreadable\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6986 | } else { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6987 | if (tp_features.mixer_no_level_control) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6988 | seq_printf(m, "level:\t\tunsupported\n"); |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6989 | else |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6990 | seq_printf(m, "level:\t\t%d\n", |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6991 | status & TP_EC_AUDIO_LVL_MSK); |
| 6992 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6993 | seq_printf(m, "mute:\t\t%s\n", |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 6994 | onoff(status, TP_EC_AUDIO_MUTESW)); |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 6995 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 6996 | if (volume_control_allowed) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6997 | seq_printf(m, "commands:\tunmute, mute\n"); |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 6998 | if (!tp_features.mixer_no_level_control) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 6999 | seq_printf(m, |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7000 | "commands:\tup, down\n"); |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 7001 | seq_printf(m, |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7002 | "commands:\tlevel <level>" |
| 7003 | " (<level> is 0-%d)\n", |
| 7004 | TP_EC_VOLUME_MAX); |
| 7005 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7006 | } |
| 7007 | } |
| 7008 | |
| 7009 | return 0; |
| 7010 | } |
| 7011 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7012 | static int volume_write(char *buf) |
| 7013 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7014 | u8 s; |
| 7015 | u8 new_level, new_mute; |
| 7016 | int l; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7017 | char *cmd; |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7018 | int rc; |
| 7019 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7020 | /* |
| 7021 | * We do allow volume control at driver startup, so that the |
| 7022 | * user can set initial state through the volume=... parameter hack. |
| 7023 | */ |
| 7024 | if (!volume_control_allowed && tpacpi_lifecycle != TPACPI_LIFE_INIT) { |
| 7025 | if (unlikely(!tp_warned.volume_ctrl_forbidden)) { |
| 7026 | tp_warned.volume_ctrl_forbidden = 1; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7027 | pr_notice("Console audio control in monitor mode, " |
| 7028 | "changes are not allowed\n"); |
| 7029 | pr_notice("Use the volume_control=1 module parameter " |
| 7030 | "to enable volume control\n"); |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 7031 | } |
| 7032 | return -EPERM; |
| 7033 | } |
| 7034 | |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7035 | rc = volume_get_status(&s); |
| 7036 | if (rc < 0) |
| 7037 | return rc; |
| 7038 | |
| 7039 | new_level = s & TP_EC_AUDIO_LVL_MSK; |
| 7040 | new_mute = s & TP_EC_AUDIO_MUTESW_MSK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7041 | |
| 7042 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7043 | if (!tp_features.mixer_no_level_control) { |
| 7044 | if (strlencmp(cmd, "up") == 0) { |
| 7045 | if (new_mute) |
| 7046 | new_mute = 0; |
| 7047 | else if (new_level < TP_EC_VOLUME_MAX) |
| 7048 | new_level++; |
| 7049 | continue; |
| 7050 | } else if (strlencmp(cmd, "down") == 0) { |
| 7051 | if (new_mute) |
| 7052 | new_mute = 0; |
| 7053 | else if (new_level > 0) |
| 7054 | new_level--; |
| 7055 | continue; |
| 7056 | } else if (sscanf(cmd, "level %u", &l) == 1 && |
| 7057 | l >= 0 && l <= TP_EC_VOLUME_MAX) { |
| 7058 | new_level = l; |
| 7059 | continue; |
| 7060 | } |
| 7061 | } |
| 7062 | if (strlencmp(cmd, "mute") == 0) |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7063 | new_mute = TP_EC_AUDIO_MUTESW_MSK; |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7064 | else if (strlencmp(cmd, "unmute") == 0) |
| 7065 | new_mute = 0; |
| 7066 | else |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7067 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7068 | } |
| 7069 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 7070 | if (tp_features.mixer_no_level_control) { |
| 7071 | tpacpi_disclose_usertask("procfs volume", "%smute\n", |
| 7072 | new_mute ? "" : "un"); |
| 7073 | rc = volume_set_mute(!!new_mute); |
| 7074 | } else { |
| 7075 | tpacpi_disclose_usertask("procfs volume", |
| 7076 | "%smute and set level to %d\n", |
| 7077 | new_mute ? "" : "un", new_level); |
| 7078 | rc = volume_set_status(new_mute | new_level); |
| 7079 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7080 | volume_alsa_notify_change(); |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7081 | |
| 7082 | return (rc == -EINTR) ? -ERESTARTSYS : rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7083 | } |
| 7084 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7085 | static struct ibm_struct volume_driver_data = { |
| 7086 | .name = "volume", |
| 7087 | .read = volume_read, |
| 7088 | .write = volume_write, |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7089 | .exit = volume_exit, |
| 7090 | .suspend = volume_suspend, |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 7091 | .resume = volume_resume, |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 7092 | .shutdown = volume_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7093 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7094 | |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 7095 | #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
| 7096 | |
| 7097 | #define alsa_card NULL |
| 7098 | |
| 7099 | static void inline volume_alsa_notify_change(void) |
| 7100 | { |
| 7101 | } |
| 7102 | |
| 7103 | static int __init volume_init(struct ibm_init_struct *iibm) |
| 7104 | { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7105 | pr_info("volume: disabled as there is no ALSA support in this kernel\n"); |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 7106 | |
| 7107 | return 1; |
| 7108 | } |
| 7109 | |
| 7110 | static struct ibm_struct volume_driver_data = { |
| 7111 | .name = "volume", |
| 7112 | }; |
| 7113 | |
| 7114 | #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
| 7115 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7116 | /************************************************************************* |
| 7117 | * Fan subdriver |
| 7118 | */ |
| 7119 | |
| 7120 | /* |
| 7121 | * FAN ACCESS MODES |
| 7122 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7123 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7124 | * ACPI GFAN method: returns fan level |
| 7125 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7126 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7127 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7128 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7129 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7130 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 7131 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7132 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 7133 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7134 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7135 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7136 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 7137 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7138 | * |
| 7139 | * Fan speed changes of any sort (including those caused by the |
| 7140 | * disengaged mode) are usually done slowly by the firmware as the |
Uwe Kleine-König | 9ddc5b6 | 2010-01-20 17:02:24 +0100 | [diff] [blame] | 7141 | * maximum amount of fan duty cycle change per second seems to be |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7142 | * limited. |
| 7143 | * |
| 7144 | * Reading is not available if GFAN exists. |
| 7145 | * Writing is not available if SFAN exists. |
| 7146 | * |
| 7147 | * Bits |
| 7148 | * 7 automatic mode engaged; |
| 7149 | * (default operation mode of the ThinkPad) |
| 7150 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7151 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7152 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7153 | * the tachometer while the fan controller ramps up |
| 7154 | * the speed (which can take up to a few *minutes*). |
| 7155 | * Speeds up fan to 100% duty-cycle, which is far above |
| 7156 | * the standard RPM levels. It is not impossible that |
| 7157 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7158 | * 5-3 unused in some models. Extra bits for fan level |
| 7159 | * in others, but still useless as all values above |
| 7160 | * 7 map to the same speed as level 7 in these models. |
| 7161 | * 2-0 fan level (0..7 usually) |
| 7162 | * 0x00 = stop |
| 7163 | * 0x07 = max (set when temperatures critical) |
| 7164 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7165 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7166 | * |
| 7167 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 7168 | * boot. Apparently the EC does not initialize it, so unless ACPI DSDT |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7169 | * does so, its initial value is meaningless (0x07). |
| 7170 | * |
| 7171 | * For firmware bugs, refer to: |
| 7172 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 7173 | * |
| 7174 | * ---- |
| 7175 | * |
| 7176 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 7177 | * Main fan tachometer reading (in RPM) |
| 7178 | * |
| 7179 | * This register is present on all ThinkPads with a new-style EC, and |
| 7180 | * it is known not to be present on the A21m/e, and T22, as there is |
| 7181 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 7182 | * ThinkPads from this same time period (and earlier) probably lack the |
| 7183 | * tachometer as well. |
| 7184 | * |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 7185 | * 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] | 7186 | * was never fixed by IBM to report the EC firmware version string |
| 7187 | * probably support the tachometer (like the early X models), so |
| 7188 | * detecting it is quite hard. We need more data to know for sure. |
| 7189 | * |
| 7190 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 7191 | * might result. |
| 7192 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 7193 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 7194 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7195 | * |
| 7196 | * For firmware bugs, refer to: |
| 7197 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 7198 | * |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7199 | * ---- |
| 7200 | * |
| 7201 | * ThinkPad EC register 0x31 bit 0 (only on select models) |
| 7202 | * |
| 7203 | * When bit 0 of EC register 0x31 is zero, the tachometer registers |
| 7204 | * show the speed of the main fan. When bit 0 of EC register 0x31 |
| 7205 | * is one, the tachometer registers show the speed of the auxiliary |
| 7206 | * fan. |
| 7207 | * |
| 7208 | * Fan control seems to affect both fans, regardless of the state |
| 7209 | * of this bit. |
| 7210 | * |
| 7211 | * So far, only the firmware for the X60/X61 non-tablet versions |
| 7212 | * seem to support this (firmware TP-7M). |
| 7213 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7214 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7215 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 7216 | * |
| 7217 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 7218 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 7219 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 7220 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 7221 | * |
| 7222 | * The speeds are stored on handles |
| 7223 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 7224 | * |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7225 | * There are three default speed sets, accessible as handles: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7226 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 7227 | * |
| 7228 | * ACPI DSDT switches which set is in use depending on various |
| 7229 | * factors. |
| 7230 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7231 | * 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] | 7232 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 7233 | * but the ACPI tables just mention level 7. |
| 7234 | */ |
| 7235 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7236 | enum { /* Fan control constants */ |
| 7237 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 7238 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 7239 | * 0x84 must be read before 0x85 */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7240 | fan_select_offset = 0x31, /* EC register 0x31 (Firmware 7M) |
| 7241 | bit 0 selects which fan is active */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7242 | |
| 7243 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 7244 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 7245 | |
| 7246 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 7247 | }; |
| 7248 | |
| 7249 | enum fan_status_access_mode { |
| 7250 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 7251 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 7252 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 7253 | }; |
| 7254 | |
| 7255 | enum fan_control_access_mode { |
| 7256 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 7257 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 7258 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 7259 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 7260 | }; |
| 7261 | |
| 7262 | enum fan_control_commands { |
| 7263 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 7264 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 7265 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 7266 | * and also watchdog cmd */ |
| 7267 | }; |
| 7268 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 7269 | static bool fan_control_allowed; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7270 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7271 | static enum fan_status_access_mode fan_status_access_mode; |
| 7272 | static enum fan_control_access_mode fan_control_access_mode; |
| 7273 | static enum fan_control_commands fan_control_commands; |
| 7274 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7275 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7276 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7277 | static u8 fan_control_resume_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7278 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7279 | |
| 7280 | static struct mutex fan_mutex; |
| 7281 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7282 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 7283 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7284 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7285 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 7286 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7287 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 7288 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7289 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7290 | "JFNS", /* 770x-JL */ |
| 7291 | ); /* all others */ |
| 7292 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7293 | /* |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7294 | * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the |
| 7295 | * HFSP register at boot, so it contains 0x07 but the Thinkpad could |
| 7296 | * be in auto mode (0x80). |
| 7297 | * |
| 7298 | * This is corrected by any write to HFSP either by the driver, or |
| 7299 | * by the firmware. |
| 7300 | * |
| 7301 | * We assume 0x07 really means auto mode while this quirk is active, |
| 7302 | * as this is far more likely than the ThinkPad being in level 7, |
| 7303 | * which is only used by the firmware during thermal emergencies. |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7304 | * |
| 7305 | * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52), |
| 7306 | * TP-70 (T43, R52), which are known to be buggy. |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7307 | */ |
| 7308 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7309 | static void fan_quirk1_setup(void) |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7310 | { |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7311 | if (fan_control_initial_status == 0x07) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7312 | pr_notice("fan_init: initial fan status is unknown, " |
| 7313 | "assuming it is in auto mode\n"); |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7314 | tp_features.fan_ctrl_status_undef = 1; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7315 | } |
| 7316 | } |
| 7317 | |
| 7318 | static void fan_quirk1_handle(u8 *fan_status) |
| 7319 | { |
| 7320 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 7321 | if (*fan_status != fan_control_initial_status) { |
| 7322 | /* something changed the HFSP regisnter since |
| 7323 | * driver init time, so it is not undefined |
| 7324 | * anymore */ |
| 7325 | tp_features.fan_ctrl_status_undef = 0; |
| 7326 | } else { |
| 7327 | /* Return most likely status. In fact, it |
| 7328 | * might be the only possible status */ |
| 7329 | *fan_status = TP_EC_FAN_AUTO; |
| 7330 | } |
| 7331 | } |
| 7332 | } |
| 7333 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7334 | /* Select main fan on X60/X61, NOOP on others */ |
| 7335 | static bool fan_select_fan1(void) |
| 7336 | { |
| 7337 | if (tp_features.second_fan) { |
| 7338 | u8 val; |
| 7339 | |
| 7340 | if (ec_read(fan_select_offset, &val) < 0) |
| 7341 | return false; |
| 7342 | val &= 0xFEU; |
| 7343 | if (ec_write(fan_select_offset, val) < 0) |
| 7344 | return false; |
| 7345 | } |
| 7346 | return true; |
| 7347 | } |
| 7348 | |
| 7349 | /* Select secondary fan on X60/X61 */ |
| 7350 | static bool fan_select_fan2(void) |
| 7351 | { |
| 7352 | u8 val; |
| 7353 | |
| 7354 | if (!tp_features.second_fan) |
| 7355 | return false; |
| 7356 | |
| 7357 | if (ec_read(fan_select_offset, &val) < 0) |
| 7358 | return false; |
| 7359 | val |= 0x01U; |
| 7360 | if (ec_write(fan_select_offset, val) < 0) |
| 7361 | return false; |
| 7362 | |
| 7363 | return true; |
| 7364 | } |
| 7365 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7366 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7367 | * Call with fan_mutex held |
| 7368 | */ |
| 7369 | static void fan_update_desired_level(u8 status) |
| 7370 | { |
| 7371 | if ((status & |
| 7372 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 7373 | if (status > 7) |
| 7374 | fan_control_desired_level = 7; |
| 7375 | else |
| 7376 | fan_control_desired_level = status; |
| 7377 | } |
| 7378 | } |
| 7379 | |
| 7380 | static int fan_get_status(u8 *status) |
| 7381 | { |
| 7382 | u8 s; |
| 7383 | |
| 7384 | /* TODO: |
| 7385 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 7386 | |
| 7387 | switch (fan_status_access_mode) { |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 7388 | case TPACPI_FAN_RD_ACPI_GFAN: { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7389 | /* 570, 600e/x, 770e, 770x */ |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 7390 | int res; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7391 | |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 7392 | if (unlikely(!acpi_evalf(gfan_handle, &res, NULL, "d"))) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7393 | return -EIO; |
| 7394 | |
| 7395 | if (likely(status)) |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 7396 | *status = res & 0x07; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7397 | |
| 7398 | break; |
Dan Carpenter | eceeb43 | 2012-09-01 12:54:07 -0700 | [diff] [blame] | 7399 | } |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7400 | case TPACPI_FAN_RD_TPEC: |
| 7401 | /* all except 570, 600e/x, 770e, 770x */ |
| 7402 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 7403 | return -EIO; |
| 7404 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7405 | if (likely(status)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7406 | *status = s; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 7407 | fan_quirk1_handle(status); |
| 7408 | } |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7409 | |
| 7410 | break; |
| 7411 | |
| 7412 | default: |
| 7413 | return -ENXIO; |
| 7414 | } |
| 7415 | |
| 7416 | return 0; |
| 7417 | } |
| 7418 | |
| 7419 | static int fan_get_status_safe(u8 *status) |
| 7420 | { |
| 7421 | int rc; |
| 7422 | u8 s; |
| 7423 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7424 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7425 | return -ERESTARTSYS; |
| 7426 | rc = fan_get_status(&s); |
| 7427 | if (!rc) |
| 7428 | fan_update_desired_level(s); |
| 7429 | mutex_unlock(&fan_mutex); |
| 7430 | |
| 7431 | if (status) |
| 7432 | *status = s; |
| 7433 | |
| 7434 | return rc; |
| 7435 | } |
| 7436 | |
| 7437 | static int fan_get_speed(unsigned int *speed) |
| 7438 | { |
| 7439 | u8 hi, lo; |
| 7440 | |
| 7441 | switch (fan_status_access_mode) { |
| 7442 | case TPACPI_FAN_RD_TPEC: |
| 7443 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7444 | if (unlikely(!fan_select_fan1())) |
| 7445 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7446 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 7447 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 7448 | return -EIO; |
| 7449 | |
| 7450 | if (likely(speed)) |
| 7451 | *speed = (hi << 8) | lo; |
| 7452 | |
| 7453 | break; |
| 7454 | |
| 7455 | default: |
| 7456 | return -ENXIO; |
| 7457 | } |
| 7458 | |
| 7459 | return 0; |
| 7460 | } |
| 7461 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7462 | static int fan2_get_speed(unsigned int *speed) |
| 7463 | { |
| 7464 | u8 hi, lo; |
| 7465 | bool rc; |
| 7466 | |
| 7467 | switch (fan_status_access_mode) { |
| 7468 | case TPACPI_FAN_RD_TPEC: |
| 7469 | /* all except 570, 600e/x, 770e, 770x */ |
| 7470 | if (unlikely(!fan_select_fan2())) |
| 7471 | return -EIO; |
| 7472 | rc = !acpi_ec_read(fan_rpm_offset, &lo) || |
| 7473 | !acpi_ec_read(fan_rpm_offset + 1, &hi); |
| 7474 | fan_select_fan1(); /* play it safe */ |
| 7475 | if (rc) |
| 7476 | return -EIO; |
| 7477 | |
| 7478 | if (likely(speed)) |
| 7479 | *speed = (hi << 8) | lo; |
| 7480 | |
| 7481 | break; |
| 7482 | |
| 7483 | default: |
| 7484 | return -ENXIO; |
| 7485 | } |
| 7486 | |
| 7487 | return 0; |
| 7488 | } |
| 7489 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7490 | static int fan_set_level(int level) |
| 7491 | { |
| 7492 | if (!fan_control_allowed) |
| 7493 | return -EPERM; |
| 7494 | |
| 7495 | switch (fan_control_access_mode) { |
| 7496 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7497 | if (level >= 0 && level <= 7) { |
| 7498 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 7499 | return -EIO; |
| 7500 | } else |
| 7501 | return -EINVAL; |
| 7502 | break; |
| 7503 | |
| 7504 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7505 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7506 | if (!(level & TP_EC_FAN_AUTO) && |
| 7507 | !(level & TP_EC_FAN_FULLSPEED) && |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7508 | ((level < 0) || (level > 7))) |
| 7509 | return -EINVAL; |
| 7510 | |
| 7511 | /* safety net should the EC not support AUTO |
| 7512 | * or FULLSPEED mode bits and just ignore them */ |
| 7513 | if (level & TP_EC_FAN_FULLSPEED) |
| 7514 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 7515 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7516 | level |= 4; /* safety min speed 4 */ |
| 7517 | |
| 7518 | if (!acpi_ec_write(fan_status_offset, level)) |
| 7519 | return -EIO; |
| 7520 | else |
| 7521 | tp_features.fan_ctrl_status_undef = 0; |
| 7522 | break; |
| 7523 | |
| 7524 | default: |
| 7525 | return -ENXIO; |
| 7526 | } |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7527 | |
| 7528 | vdbg_printk(TPACPI_DBG_FAN, |
| 7529 | "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] | 7530 | return 0; |
| 7531 | } |
| 7532 | |
| 7533 | static int fan_set_level_safe(int level) |
| 7534 | { |
| 7535 | int rc; |
| 7536 | |
| 7537 | if (!fan_control_allowed) |
| 7538 | return -EPERM; |
| 7539 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7540 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7541 | return -ERESTARTSYS; |
| 7542 | |
| 7543 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 7544 | level = fan_control_desired_level; |
| 7545 | |
| 7546 | rc = fan_set_level(level); |
| 7547 | if (!rc) |
| 7548 | fan_update_desired_level(level); |
| 7549 | |
| 7550 | mutex_unlock(&fan_mutex); |
| 7551 | return rc; |
| 7552 | } |
| 7553 | |
| 7554 | static int fan_set_enable(void) |
| 7555 | { |
| 7556 | u8 s; |
| 7557 | int rc; |
| 7558 | |
| 7559 | if (!fan_control_allowed) |
| 7560 | return -EPERM; |
| 7561 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7562 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7563 | return -ERESTARTSYS; |
| 7564 | |
| 7565 | switch (fan_control_access_mode) { |
| 7566 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7567 | case TPACPI_FAN_WR_TPEC: |
| 7568 | rc = fan_get_status(&s); |
| 7569 | if (rc < 0) |
| 7570 | break; |
| 7571 | |
| 7572 | /* Don't go out of emergency fan mode */ |
| 7573 | if (s != 7) { |
| 7574 | s &= 0x07; |
| 7575 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 7576 | } |
| 7577 | |
| 7578 | if (!acpi_ec_write(fan_status_offset, s)) |
| 7579 | rc = -EIO; |
| 7580 | else { |
| 7581 | tp_features.fan_ctrl_status_undef = 0; |
| 7582 | rc = 0; |
| 7583 | } |
| 7584 | break; |
| 7585 | |
| 7586 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7587 | rc = fan_get_status(&s); |
| 7588 | if (rc < 0) |
| 7589 | break; |
| 7590 | |
| 7591 | s &= 0x07; |
| 7592 | |
| 7593 | /* Set fan to at least level 4 */ |
| 7594 | s |= 4; |
| 7595 | |
| 7596 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7597 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7598 | else |
| 7599 | rc = 0; |
| 7600 | break; |
| 7601 | |
| 7602 | default: |
| 7603 | rc = -ENXIO; |
| 7604 | } |
| 7605 | |
| 7606 | mutex_unlock(&fan_mutex); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7607 | |
| 7608 | if (!rc) |
| 7609 | vdbg_printk(TPACPI_DBG_FAN, |
| 7610 | "fan control: set fan control register to 0x%02x\n", |
| 7611 | s); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7612 | return rc; |
| 7613 | } |
| 7614 | |
| 7615 | static int fan_set_disable(void) |
| 7616 | { |
| 7617 | int rc; |
| 7618 | |
| 7619 | if (!fan_control_allowed) |
| 7620 | return -EPERM; |
| 7621 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7622 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7623 | return -ERESTARTSYS; |
| 7624 | |
| 7625 | rc = 0; |
| 7626 | switch (fan_control_access_mode) { |
| 7627 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7628 | case TPACPI_FAN_WR_TPEC: |
| 7629 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 7630 | rc = -EIO; |
| 7631 | else { |
| 7632 | fan_control_desired_level = 0; |
| 7633 | tp_features.fan_ctrl_status_undef = 0; |
| 7634 | } |
| 7635 | break; |
| 7636 | |
| 7637 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 7638 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 7639 | rc = -EIO; |
| 7640 | else |
| 7641 | fan_control_desired_level = 0; |
| 7642 | break; |
| 7643 | |
| 7644 | default: |
| 7645 | rc = -ENXIO; |
| 7646 | } |
| 7647 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7648 | if (!rc) |
| 7649 | vdbg_printk(TPACPI_DBG_FAN, |
| 7650 | "fan control: set fan control register to 0\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7651 | |
| 7652 | mutex_unlock(&fan_mutex); |
| 7653 | return rc; |
| 7654 | } |
| 7655 | |
| 7656 | static int fan_set_speed(int speed) |
| 7657 | { |
| 7658 | int rc; |
| 7659 | |
| 7660 | if (!fan_control_allowed) |
| 7661 | return -EPERM; |
| 7662 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7663 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7664 | return -ERESTARTSYS; |
| 7665 | |
| 7666 | rc = 0; |
| 7667 | switch (fan_control_access_mode) { |
| 7668 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7669 | if (speed >= 0 && speed <= 65535) { |
| 7670 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 7671 | speed, speed, speed)) |
| 7672 | rc = -EIO; |
| 7673 | } else |
| 7674 | rc = -EINVAL; |
| 7675 | break; |
| 7676 | |
| 7677 | default: |
| 7678 | rc = -ENXIO; |
| 7679 | } |
| 7680 | |
| 7681 | mutex_unlock(&fan_mutex); |
| 7682 | return rc; |
| 7683 | } |
| 7684 | |
| 7685 | static void fan_watchdog_reset(void) |
| 7686 | { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7687 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 7688 | return; |
| 7689 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7690 | if (fan_watchdog_maxinterval > 0 && |
Tejun Heo | 41f63c5 | 2012-08-03 10:30:47 -0700 | [diff] [blame] | 7691 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) |
| 7692 | mod_delayed_work(tpacpi_wq, &fan_watchdog_task, |
| 7693 | msecs_to_jiffies(fan_watchdog_maxinterval * 1000)); |
| 7694 | else |
| 7695 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7696 | } |
| 7697 | |
| 7698 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 7699 | { |
| 7700 | int rc; |
| 7701 | |
| 7702 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 7703 | return; |
| 7704 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7705 | pr_notice("fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7706 | rc = fan_set_enable(); |
| 7707 | if (rc < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 7708 | pr_err("fan watchdog: error %d while enabling fan, " |
| 7709 | "will try again later...\n", -rc); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7710 | /* reschedule for later */ |
| 7711 | fan_watchdog_reset(); |
| 7712 | } |
| 7713 | } |
| 7714 | |
| 7715 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7716 | * SYSFS fan layout: hwmon compatible (device) |
| 7717 | * |
| 7718 | * pwm*_enable: |
| 7719 | * 0: "disengaged" mode |
| 7720 | * 1: manual mode |
| 7721 | * 2: native EC "auto" mode (recommended, hardware default) |
| 7722 | * |
| 7723 | * pwm*: set speed in manual mode, ignored otherwise. |
| 7724 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 7725 | * interpolation. |
| 7726 | * |
| 7727 | * fan*_input: tachometer reading, RPM |
| 7728 | * |
| 7729 | * |
| 7730 | * SYSFS fan layout: extensions |
| 7731 | * |
| 7732 | * fan_watchdog (driver): |
| 7733 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 7734 | */ |
| 7735 | |
| 7736 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 7737 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 7738 | struct device_attribute *attr, |
| 7739 | char *buf) |
| 7740 | { |
| 7741 | int res, mode; |
| 7742 | u8 status; |
| 7743 | |
| 7744 | res = fan_get_status_safe(&status); |
| 7745 | if (res) |
| 7746 | return res; |
| 7747 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7748 | if (status & TP_EC_FAN_FULLSPEED) { |
| 7749 | mode = 0; |
| 7750 | } else if (status & TP_EC_FAN_AUTO) { |
| 7751 | mode = 2; |
| 7752 | } else |
| 7753 | mode = 1; |
| 7754 | |
| 7755 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 7756 | } |
| 7757 | |
| 7758 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 7759 | struct device_attribute *attr, |
| 7760 | const char *buf, size_t count) |
| 7761 | { |
| 7762 | unsigned long t; |
| 7763 | int res, level; |
| 7764 | |
| 7765 | if (parse_strtoul(buf, 2, &t)) |
| 7766 | return -EINVAL; |
| 7767 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7768 | tpacpi_disclose_usertask("hwmon pwm1_enable", |
| 7769 | "set fan mode to %lu\n", t); |
| 7770 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7771 | switch (t) { |
| 7772 | case 0: |
| 7773 | level = TP_EC_FAN_FULLSPEED; |
| 7774 | break; |
| 7775 | case 1: |
| 7776 | level = TPACPI_FAN_LAST_LEVEL; |
| 7777 | break; |
| 7778 | case 2: |
| 7779 | level = TP_EC_FAN_AUTO; |
| 7780 | break; |
| 7781 | case 3: |
| 7782 | /* reserved for software-controlled auto mode */ |
| 7783 | return -ENOSYS; |
| 7784 | default: |
| 7785 | return -EINVAL; |
| 7786 | } |
| 7787 | |
| 7788 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 7789 | if (res == -ENXIO) |
| 7790 | return -EINVAL; |
| 7791 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7792 | return res; |
| 7793 | |
| 7794 | fan_watchdog_reset(); |
| 7795 | |
| 7796 | return count; |
| 7797 | } |
| 7798 | |
| 7799 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 7800 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 7801 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 7802 | |
| 7803 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 7804 | static ssize_t fan_pwm1_show(struct device *dev, |
| 7805 | struct device_attribute *attr, |
| 7806 | char *buf) |
| 7807 | { |
| 7808 | int res; |
| 7809 | u8 status; |
| 7810 | |
| 7811 | res = fan_get_status_safe(&status); |
| 7812 | if (res) |
| 7813 | return res; |
| 7814 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7815 | if ((status & |
| 7816 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 7817 | status = fan_control_desired_level; |
| 7818 | |
| 7819 | if (status > 7) |
| 7820 | status = 7; |
| 7821 | |
| 7822 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 7823 | } |
| 7824 | |
| 7825 | static ssize_t fan_pwm1_store(struct device *dev, |
| 7826 | struct device_attribute *attr, |
| 7827 | const char *buf, size_t count) |
| 7828 | { |
| 7829 | unsigned long s; |
| 7830 | int rc; |
| 7831 | u8 status, newlevel; |
| 7832 | |
| 7833 | if (parse_strtoul(buf, 255, &s)) |
| 7834 | return -EINVAL; |
| 7835 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7836 | tpacpi_disclose_usertask("hwmon pwm1", |
| 7837 | "set fan speed to %lu\n", s); |
| 7838 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7839 | /* scale down from 0-255 to 0-7 */ |
| 7840 | newlevel = (s >> 5) & 0x07; |
| 7841 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 7842 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 7843 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7844 | |
| 7845 | rc = fan_get_status(&status); |
| 7846 | if (!rc && (status & |
| 7847 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 7848 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 7849 | if (rc == -ENXIO) |
| 7850 | rc = -EINVAL; |
| 7851 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7852 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 7853 | fan_watchdog_reset(); |
| 7854 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7855 | } |
| 7856 | |
| 7857 | mutex_unlock(&fan_mutex); |
| 7858 | return (rc)? rc : count; |
| 7859 | } |
| 7860 | |
| 7861 | static struct device_attribute dev_attr_fan_pwm1 = |
| 7862 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 7863 | fan_pwm1_show, fan_pwm1_store); |
| 7864 | |
| 7865 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 7866 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 7867 | struct device_attribute *attr, |
| 7868 | char *buf) |
| 7869 | { |
| 7870 | int res; |
| 7871 | unsigned int speed; |
| 7872 | |
| 7873 | res = fan_get_speed(&speed); |
| 7874 | if (res < 0) |
| 7875 | return res; |
| 7876 | |
| 7877 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7878 | } |
| 7879 | |
| 7880 | static struct device_attribute dev_attr_fan_fan1_input = |
| 7881 | __ATTR(fan1_input, S_IRUGO, |
| 7882 | fan_fan1_input_show, NULL); |
| 7883 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7884 | /* sysfs fan fan2_input ------------------------------------------------ */ |
| 7885 | static ssize_t fan_fan2_input_show(struct device *dev, |
| 7886 | struct device_attribute *attr, |
| 7887 | char *buf) |
| 7888 | { |
| 7889 | int res; |
| 7890 | unsigned int speed; |
| 7891 | |
| 7892 | res = fan2_get_speed(&speed); |
| 7893 | if (res < 0) |
| 7894 | return res; |
| 7895 | |
| 7896 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7897 | } |
| 7898 | |
| 7899 | static struct device_attribute dev_attr_fan_fan2_input = |
| 7900 | __ATTR(fan2_input, S_IRUGO, |
| 7901 | fan_fan2_input_show, NULL); |
| 7902 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7903 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7904 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 7905 | char *buf) |
| 7906 | { |
| 7907 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 7908 | } |
| 7909 | |
| 7910 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 7911 | const char *buf, size_t count) |
| 7912 | { |
| 7913 | unsigned long t; |
| 7914 | |
| 7915 | if (parse_strtoul(buf, 120, &t)) |
| 7916 | return -EINVAL; |
| 7917 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7918 | if (!fan_control_allowed) |
| 7919 | return -EPERM; |
| 7920 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7921 | fan_watchdog_maxinterval = t; |
| 7922 | fan_watchdog_reset(); |
| 7923 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7924 | tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t); |
| 7925 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7926 | return count; |
| 7927 | } |
| 7928 | |
| 7929 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 7930 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 7931 | |
| 7932 | /* --------------------------------------------------------------------- */ |
| 7933 | static struct attribute *fan_attributes[] = { |
| 7934 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 7935 | &dev_attr_fan_fan1_input.attr, |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7936 | NULL, /* for fan2_input */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7937 | NULL |
| 7938 | }; |
| 7939 | |
| 7940 | static const struct attribute_group fan_attr_group = { |
| 7941 | .attrs = fan_attributes, |
| 7942 | }; |
| 7943 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7944 | #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */ |
| 7945 | #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] | 7946 | |
| 7947 | #define TPACPI_FAN_QI(__id1, __id2, __quirks) \ |
| 7948 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 7949 | .bios = TPACPI_MATCH_ANY, \ |
| 7950 | .ec = TPID(__id1, __id2), \ |
| 7951 | .quirks = __quirks } |
| 7952 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7953 | #define TPACPI_FAN_QL(__id1, __id2, __quirks) \ |
| 7954 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 7955 | .bios = TPACPI_MATCH_ANY, \ |
| 7956 | .ec = TPID(__id1, __id2), \ |
| 7957 | .quirks = __quirks } |
| 7958 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7959 | static const struct tpacpi_quirk fan_quirk_table[] __initconst = { |
| 7960 | TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1), |
| 7961 | TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1), |
| 7962 | TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1), |
| 7963 | TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1), |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7964 | TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN), |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7965 | }; |
| 7966 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7967 | #undef TPACPI_FAN_QL |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7968 | #undef TPACPI_FAN_QI |
| 7969 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7970 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7971 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7972 | int rc; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7973 | unsigned long quirks; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7974 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7975 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7976 | "initializing fan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7977 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 7978 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7979 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 7980 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7981 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7982 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 7983 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7984 | tp_features.second_fan = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7985 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7986 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 7987 | if (tpacpi_is_ibm()) { |
| 7988 | TPACPI_ACPIHANDLE_INIT(fans); |
| 7989 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 7990 | TPACPI_ACPIHANDLE_INIT(sfan); |
| 7991 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7992 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7993 | quirks = tpacpi_check_quirks(fan_quirk_table, |
| 7994 | ARRAY_SIZE(fan_quirk_table)); |
| 7995 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7996 | if (gfan_handle) { |
| 7997 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7998 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7999 | } else { |
| 8000 | /* all other ThinkPads: note that even old-style |
| 8001 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8002 | if (likely(acpi_ec_read(fan_status_offset, |
| 8003 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8004 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 8005 | if (quirks & TPACPI_FAN_Q1) |
| 8006 | fan_quirk1_setup(); |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8007 | if (quirks & TPACPI_FAN_2FAN) { |
| 8008 | tp_features.second_fan = 1; |
| 8009 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 8010 | "secondary fan support enabled\n"); |
| 8011 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8012 | } else { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8013 | pr_err("ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8014 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8015 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8016 | } |
| 8017 | } |
| 8018 | |
| 8019 | if (sfan_handle) { |
| 8020 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8021 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 8022 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8023 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8024 | } else { |
| 8025 | if (!gfan_handle) { |
| 8026 | /* gfan without sfan means no fan control */ |
| 8027 | /* all other models implement TP EC 0x2f control */ |
| 8028 | |
| 8029 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8030 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8031 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8032 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8033 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8034 | TPACPI_FAN_CMD_SPEED | |
| 8035 | TPACPI_FAN_CMD_LEVEL | |
| 8036 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8037 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8038 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8039 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8040 | TPACPI_FAN_CMD_LEVEL | |
| 8041 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 8042 | } |
| 8043 | } |
| 8044 | } |
| 8045 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8046 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 8047 | "fan is %s, modes %d, %d\n", |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8048 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 8049 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 8050 | fan_status_access_mode, fan_control_access_mode); |
| 8051 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8052 | /* fan control master switch */ |
| 8053 | if (!fan_control_allowed) { |
| 8054 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 8055 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8056 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8057 | "fan control features disabled by parameter\n"); |
| 8058 | } |
| 8059 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8060 | /* update fan_control_desired_level */ |
| 8061 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 8062 | fan_get_status_safe(NULL); |
| 8063 | |
| 8064 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 8065 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 8066 | if (tp_features.second_fan) { |
| 8067 | /* attach second fan tachometer */ |
| 8068 | fan_attributes[ARRAY_SIZE(fan_attributes)-2] = |
| 8069 | &dev_attr_fan_fan2_input.attr; |
| 8070 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8071 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8072 | &fan_attr_group); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8073 | if (rc < 0) |
| 8074 | return rc; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 8075 | |
| 8076 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
| 8077 | &driver_attr_fan_watchdog); |
| 8078 | if (rc < 0) { |
| 8079 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
| 8080 | &fan_attr_group); |
| 8081 | return rc; |
| 8082 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8083 | return 0; |
| 8084 | } else |
| 8085 | return 1; |
| 8086 | } |
| 8087 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8088 | static void fan_exit(void) |
| 8089 | { |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8090 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8091 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8092 | |
| 8093 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8094 | 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] | 8095 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 8096 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8097 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8098 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8099 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8100 | } |
| 8101 | |
Rafael J. Wysocki | fd3c3a4 | 2012-06-27 23:18:44 +0200 | [diff] [blame] | 8102 | static void fan_suspend(void) |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8103 | { |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8104 | int rc; |
| 8105 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8106 | if (!fan_control_allowed) |
| 8107 | return; |
| 8108 | |
| 8109 | /* Store fan status in cache */ |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8110 | fan_control_resume_level = 0; |
| 8111 | rc = fan_get_status_safe(&fan_control_resume_level); |
| 8112 | if (rc < 0) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8113 | pr_notice("failed to read fan level for later " |
| 8114 | "restore during resume: %d\n", rc); |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8115 | |
| 8116 | /* if it is undefined, don't attempt to restore it. |
| 8117 | * KEEP THIS LAST */ |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8118 | if (tp_features.fan_ctrl_status_undef) |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8119 | fan_control_resume_level = 0; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8120 | } |
| 8121 | |
| 8122 | static void fan_resume(void) |
| 8123 | { |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8124 | u8 current_level = 7; |
| 8125 | bool do_set = false; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8126 | int rc; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8127 | |
| 8128 | /* DSDT *always* updates status on resume */ |
| 8129 | tp_features.fan_ctrl_status_undef = 0; |
| 8130 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8131 | if (!fan_control_allowed || |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8132 | !fan_control_resume_level || |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8133 | (fan_get_status_safe(¤t_level) < 0)) |
| 8134 | return; |
| 8135 | |
| 8136 | switch (fan_control_access_mode) { |
| 8137 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8138 | /* never decrease fan level */ |
| 8139 | do_set = (fan_control_resume_level > current_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8140 | break; |
| 8141 | case TPACPI_FAN_WR_ACPI_FANS: |
| 8142 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8143 | /* never decrease fan level, scale is: |
| 8144 | * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO |
| 8145 | * |
| 8146 | * We expect the firmware to set either 7 or AUTO, but we |
| 8147 | * handle FULLSPEED out of paranoia. |
| 8148 | * |
| 8149 | * So, we can safely only restore FULLSPEED or 7, anything |
| 8150 | * else could slow the fan. Restoring AUTO is useless, at |
| 8151 | * best that's exactly what the DSDT already set (it is the |
| 8152 | * slower it uses). |
| 8153 | * |
| 8154 | * Always keep in mind that the DSDT *will* have set the |
| 8155 | * fans to what the vendor supposes is the best level. We |
| 8156 | * muck with it only to speed the fan up. |
| 8157 | */ |
| 8158 | if (fan_control_resume_level != 7 && |
| 8159 | !(fan_control_resume_level & TP_EC_FAN_FULLSPEED)) |
| 8160 | return; |
| 8161 | else |
| 8162 | do_set = !(current_level & TP_EC_FAN_FULLSPEED) && |
| 8163 | (current_level != fan_control_resume_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8164 | break; |
| 8165 | default: |
| 8166 | return; |
| 8167 | } |
| 8168 | if (do_set) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8169 | pr_notice("restoring fan level to 0x%02x\n", |
| 8170 | fan_control_resume_level); |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 8171 | rc = fan_set_level_safe(fan_control_resume_level); |
| 8172 | if (rc < 0) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8173 | pr_notice("failed to restore fan level: %d\n", rc); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8174 | } |
| 8175 | } |
| 8176 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8177 | static int fan_read(struct seq_file *m) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8178 | { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8179 | int rc; |
| 8180 | u8 status; |
| 8181 | unsigned int speed = 0; |
| 8182 | |
| 8183 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8184 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8185 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8186 | rc = fan_get_status_safe(&status); |
| 8187 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8188 | return rc; |
| 8189 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8190 | seq_printf(m, "status:\t\t%s\n" |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8191 | "level:\t\t%d\n", |
| 8192 | (status != 0) ? "enabled" : "disabled", status); |
| 8193 | break; |
| 8194 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8195 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8196 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8197 | rc = fan_get_status_safe(&status); |
| 8198 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8199 | return rc; |
| 8200 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8201 | seq_printf(m, "status:\t\t%s\n", |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8202 | (status != 0) ? "enabled" : "disabled"); |
| 8203 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8204 | rc = fan_get_speed(&speed); |
| 8205 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8206 | return rc; |
| 8207 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8208 | seq_printf(m, "speed:\t\t%d\n", speed); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8209 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8210 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8211 | /* Disengaged mode takes precedence */ |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8212 | seq_printf(m, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8213 | else if (status & TP_EC_FAN_AUTO) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8214 | seq_printf(m, "level:\t\tauto\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8215 | else |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8216 | seq_printf(m, "level:\t\t%d\n", status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8217 | break; |
| 8218 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8219 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8220 | default: |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8221 | seq_printf(m, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8222 | } |
| 8223 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8224 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8225 | seq_printf(m, "commands:\tlevel <level>"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8226 | |
| 8227 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8228 | case TPACPI_FAN_WR_ACPI_SFAN: |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8229 | seq_printf(m, " (<level> is 0-7)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8230 | break; |
| 8231 | |
| 8232 | default: |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8233 | seq_printf(m, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8234 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8235 | break; |
| 8236 | } |
| 8237 | } |
| 8238 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8239 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8240 | seq_printf(m, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8241 | "commands:\twatchdog <timeout> (<timeout> " |
| 8242 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8243 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8244 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8245 | seq_printf(m, "commands:\tspeed <speed>" |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8246 | " (<speed> is 0-65535)\n"); |
| 8247 | |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8248 | return 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8249 | } |
| 8250 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8251 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 8252 | { |
| 8253 | int level; |
| 8254 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8255 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8256 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 8257 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8258 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8259 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8260 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8261 | return 0; |
| 8262 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8263 | *rc = fan_set_level_safe(level); |
| 8264 | if (*rc == -ENXIO) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8265 | pr_err("level command accepted for unsupported access mode %d\n", |
| 8266 | fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8267 | else if (!*rc) |
| 8268 | tpacpi_disclose_usertask("procfs fan", |
| 8269 | "set level to %d\n", level); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8270 | |
| 8271 | return 1; |
| 8272 | } |
| 8273 | |
| 8274 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 8275 | { |
| 8276 | if (strlencmp(cmd, "enable") != 0) |
| 8277 | return 0; |
| 8278 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8279 | *rc = fan_set_enable(); |
| 8280 | if (*rc == -ENXIO) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8281 | pr_err("enable command accepted for unsupported access mode %d\n", |
| 8282 | fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8283 | else if (!*rc) |
| 8284 | tpacpi_disclose_usertask("procfs fan", "enable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8285 | |
| 8286 | return 1; |
| 8287 | } |
| 8288 | |
| 8289 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 8290 | { |
| 8291 | if (strlencmp(cmd, "disable") != 0) |
| 8292 | return 0; |
| 8293 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8294 | *rc = fan_set_disable(); |
| 8295 | if (*rc == -ENXIO) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8296 | pr_err("disable command accepted for unsupported access mode %d\n", |
| 8297 | fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8298 | else if (!*rc) |
| 8299 | tpacpi_disclose_usertask("procfs fan", "disable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8300 | |
| 8301 | return 1; |
| 8302 | } |
| 8303 | |
| 8304 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 8305 | { |
| 8306 | int speed; |
| 8307 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8308 | /* TODO: |
| 8309 | * Support speed <low> <medium> <high> ? */ |
| 8310 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8311 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 8312 | return 0; |
| 8313 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8314 | *rc = fan_set_speed(speed); |
| 8315 | if (*rc == -ENXIO) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8316 | pr_err("speed command accepted for unsupported access mode %d\n", |
| 8317 | fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8318 | else if (!*rc) |
| 8319 | tpacpi_disclose_usertask("procfs fan", |
| 8320 | "set speed to %d\n", speed); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8321 | |
| 8322 | return 1; |
| 8323 | } |
| 8324 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8325 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 8326 | { |
| 8327 | int interval; |
| 8328 | |
| 8329 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 8330 | return 0; |
| 8331 | |
| 8332 | if (interval < 0 || interval > 120) |
| 8333 | *rc = -EINVAL; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8334 | else { |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8335 | fan_watchdog_maxinterval = interval; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 8336 | tpacpi_disclose_usertask("procfs fan", |
| 8337 | "set watchdog timer to %d\n", |
| 8338 | interval); |
| 8339 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8340 | |
| 8341 | return 1; |
| 8342 | } |
| 8343 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8344 | static int fan_write(char *buf) |
| 8345 | { |
| 8346 | char *cmd; |
| 8347 | int rc = 0; |
| 8348 | |
| 8349 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8350 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8351 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8352 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8353 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8354 | fan_write_cmd_disable(cmd, &rc) || |
| 8355 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 8356 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8357 | fan_write_cmd_speed(cmd, &rc)) |
| 8358 | ) |
| 8359 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 8360 | else if (!rc) |
| 8361 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8362 | } |
| 8363 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 8364 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8365 | } |
| 8366 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8367 | static struct ibm_struct fan_driver_data = { |
| 8368 | .name = "fan", |
| 8369 | .read = fan_read, |
| 8370 | .write = fan_write, |
| 8371 | .exit = fan_exit, |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 8372 | .suspend = fan_suspend, |
| 8373 | .resume = fan_resume, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8374 | }; |
| 8375 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8376 | /**************************************************************************** |
| 8377 | **************************************************************************** |
| 8378 | * |
| 8379 | * Infrastructure |
| 8380 | * |
| 8381 | **************************************************************************** |
| 8382 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8383 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8384 | /* |
| 8385 | * HKEY event callout for other subdrivers go here |
| 8386 | * (yes, it is ugly, but it is quick, safe, and gets the job done |
| 8387 | */ |
| 8388 | static void tpacpi_driver_event(const unsigned int hkey_event) |
| 8389 | { |
Henrique de Moraes Holschuh | 347a268 | 2009-12-09 01:36:24 +0000 | [diff] [blame] | 8390 | if (ibm_backlight_device) { |
| 8391 | switch (hkey_event) { |
| 8392 | case TP_HKEY_EV_BRGHT_UP: |
| 8393 | case TP_HKEY_EV_BRGHT_DOWN: |
| 8394 | tpacpi_brightness_notify_change(); |
| 8395 | } |
| 8396 | } |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 8397 | if (alsa_card) { |
| 8398 | switch (hkey_event) { |
| 8399 | case TP_HKEY_EV_VOL_UP: |
| 8400 | case TP_HKEY_EV_VOL_DOWN: |
| 8401 | case TP_HKEY_EV_VOL_MUTE: |
| 8402 | volume_alsa_notify_change(); |
| 8403 | } |
| 8404 | } |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8405 | } |
| 8406 | |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8407 | static void hotkey_driver_event(const unsigned int scancode) |
| 8408 | { |
Henrique de Moraes Holschuh | 67bcae6 | 2009-09-20 14:09:27 -0300 | [diff] [blame] | 8409 | tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE + scancode); |
Henrique de Moraes Holschuh | 8b468c0 | 2009-09-20 14:09:26 -0300 | [diff] [blame] | 8410 | } |
| 8411 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8412 | /* sysfs name ---------------------------------------------------------- */ |
| 8413 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 8414 | struct device_attribute *attr, |
| 8415 | char *buf) |
| 8416 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8417 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8418 | } |
| 8419 | |
| 8420 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 8421 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 8422 | |
| 8423 | /* --------------------------------------------------------------------- */ |
| 8424 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8425 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 8426 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8427 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8428 | /* |
| 8429 | * Module and infrastructure proble, init and exit handling |
| 8430 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8431 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 8432 | static bool force_load; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8433 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8434 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8435 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8436 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8437 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8438 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8439 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8440 | } |
| 8441 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 8442 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8443 | static void ibm_exit(struct ibm_struct *ibm) |
| 8444 | { |
| 8445 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 8446 | |
| 8447 | list_del_init(&ibm->all_drivers); |
| 8448 | |
| 8449 | if (ibm->flags.acpi_notify_installed) { |
| 8450 | dbg_printk(TPACPI_DBG_EXIT, |
| 8451 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 8452 | BUG_ON(!ibm->acpi); |
| 8453 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 8454 | ibm->acpi->type, |
| 8455 | dispatch_acpi_notify); |
| 8456 | ibm->flags.acpi_notify_installed = 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8457 | } |
| 8458 | |
| 8459 | if (ibm->flags.proc_created) { |
| 8460 | dbg_printk(TPACPI_DBG_EXIT, |
| 8461 | "%s: remove_proc_entry\n", ibm->name); |
| 8462 | remove_proc_entry(ibm->name, proc_dir); |
| 8463 | ibm->flags.proc_created = 0; |
| 8464 | } |
| 8465 | |
| 8466 | if (ibm->flags.acpi_driver_registered) { |
| 8467 | dbg_printk(TPACPI_DBG_EXIT, |
| 8468 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 8469 | BUG_ON(!ibm->acpi); |
| 8470 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 8471 | kfree(ibm->acpi->driver); |
| 8472 | ibm->acpi->driver = NULL; |
| 8473 | ibm->flags.acpi_driver_registered = 0; |
| 8474 | } |
| 8475 | |
| 8476 | if (ibm->flags.init_called && ibm->exit) { |
| 8477 | ibm->exit(); |
| 8478 | ibm->flags.init_called = 0; |
| 8479 | } |
| 8480 | |
| 8481 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 8482 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 8483 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8484 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8485 | { |
| 8486 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8487 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8488 | struct proc_dir_entry *entry; |
| 8489 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8490 | BUG_ON(ibm == NULL); |
| 8491 | |
| 8492 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 8493 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8494 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8495 | return 0; |
| 8496 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8497 | dbg_printk(TPACPI_DBG_INIT, |
| 8498 | "probing for %s\n", ibm->name); |
| 8499 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8500 | if (iibm->init) { |
| 8501 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8502 | if (ret > 0) |
| 8503 | return 0; /* probe failed */ |
| 8504 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8505 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8506 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8507 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8508 | } |
| 8509 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8510 | if (ibm->acpi) { |
| 8511 | if (ibm->acpi->hid) { |
| 8512 | ret = register_tpacpi_subdriver(ibm); |
| 8513 | if (ret) |
| 8514 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8515 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8516 | |
| 8517 | if (ibm->acpi->notify) { |
| 8518 | ret = setup_acpi_notify(ibm); |
| 8519 | if (ret == -ENODEV) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8520 | pr_notice("disabling subdriver %s\n", |
| 8521 | ibm->name); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 8522 | ret = 0; |
| 8523 | goto err_out; |
| 8524 | } |
| 8525 | if (ret < 0) |
| 8526 | goto err_out; |
| 8527 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8528 | } |
| 8529 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8530 | dbg_printk(TPACPI_DBG_INIT, |
| 8531 | "%s installed\n", ibm->name); |
| 8532 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8533 | if (ibm->read) { |
Al Viro | d161a13 | 2011-07-24 03:36:29 -0400 | [diff] [blame] | 8534 | umode_t mode = iibm->base_procfs_mode; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8535 | |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 8536 | if (!mode) |
| 8537 | mode = S_IRUGO; |
Alexey Dobriyan | 887965e | 2009-12-15 21:51:12 -0200 | [diff] [blame] | 8538 | if (ibm->write) |
| 8539 | mode |= S_IWUSR; |
| 8540 | entry = proc_create_data(ibm->name, mode, proc_dir, |
| 8541 | &dispatch_proc_fops, ibm); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8542 | if (!entry) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8543 | pr_err("unable to create proc entry %s\n", ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8544 | ret = -ENODEV; |
| 8545 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8546 | } |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 8547 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8548 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8549 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8550 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 8551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8552 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8553 | |
| 8554 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 8555 | dbg_printk(TPACPI_DBG_INIT, |
| 8556 | "%s: at error exit path with result %d\n", |
| 8557 | ibm->name, ret); |
| 8558 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8559 | ibm_exit(ibm); |
| 8560 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8561 | } |
| 8562 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8563 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8564 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8565 | static bool __pure __init tpacpi_is_fw_digit(const char c) |
| 8566 | { |
| 8567 | return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); |
| 8568 | } |
| 8569 | |
| 8570 | /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */ |
| 8571 | static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, |
| 8572 | const char t) |
| 8573 | { |
| 8574 | return s && strlen(s) >= 8 && |
| 8575 | tpacpi_is_fw_digit(s[0]) && |
| 8576 | tpacpi_is_fw_digit(s[1]) && |
Manoj Iyer | 16a3d9f | 2012-09-24 11:57:40 -0500 | [diff] [blame^] | 8577 | s[2] == t && |
| 8578 | (s[3] == 'T' || s[3] == 'N') && |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8579 | tpacpi_is_fw_digit(s[4]) && |
Keith Packard | b569ab3 | 2011-03-31 15:22:33 -0700 | [diff] [blame] | 8580 | tpacpi_is_fw_digit(s[5]); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8581 | } |
| 8582 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8583 | /* returns 0 - probe ok, or < 0 - probe error. |
| 8584 | * Probe ok doesn't mean thinkpad found. |
| 8585 | * On error, kfree() cleanup on tp->* is not performed, caller must do it */ |
| 8586 | static int __must_check __init get_thinkpad_model_data( |
| 8587 | struct thinkpad_id_data *tp) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8588 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 8589 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8590 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8591 | char const *s; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8592 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8593 | if (!tp) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8594 | return -EINVAL; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8595 | |
| 8596 | memset(tp, 0, sizeof(*tp)); |
| 8597 | |
| 8598 | if (dmi_name_in_vendors("IBM")) |
| 8599 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 8600 | else if (dmi_name_in_vendors("LENOVO")) |
| 8601 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 8602 | else |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8603 | return 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8604 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8605 | s = dmi_get_system_info(DMI_BIOS_VERSION); |
| 8606 | tp->bios_version_str = kstrdup(s, GFP_KERNEL); |
| 8607 | if (s && !tp->bios_version_str) |
| 8608 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8609 | |
| 8610 | /* Really ancient ThinkPad 240X will fail this, which is fine */ |
Manoj Iyer | 16a3d9f | 2012-09-24 11:57:40 -0500 | [diff] [blame^] | 8611 | if (!(tpacpi_is_valid_fw_id(tp->bios_version_str, 'E') || |
| 8612 | tpacpi_is_valid_fw_id(tp->bios_version_str, 'C'))) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8613 | return 0; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8614 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8615 | tp->bios_model = tp->bios_version_str[0] |
| 8616 | | (tp->bios_version_str[1] << 8); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8617 | tp->bios_release = (tp->bios_version_str[4] << 8) |
| 8618 | | tp->bios_version_str[5]; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8619 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8620 | /* |
| 8621 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 8622 | * X32 or newer, all Z series; Some models must have an |
| 8623 | * up-to-date BIOS or they will not be detected. |
| 8624 | * |
| 8625 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 8626 | */ |
| 8627 | 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] | 8628 | if (sscanf(dev->name, |
| 8629 | "IBM ThinkPad Embedded Controller -[%17c", |
| 8630 | ec_fw_string) == 1) { |
| 8631 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 8632 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8633 | |
| 8634 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8635 | if (!tp->ec_version_str) |
| 8636 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8637 | |
| 8638 | if (tpacpi_is_valid_fw_id(ec_fw_string, 'H')) { |
| 8639 | tp->ec_model = ec_fw_string[0] |
| 8640 | | (ec_fw_string[1] << 8); |
| 8641 | tp->ec_release = (ec_fw_string[4] << 8) |
| 8642 | | ec_fw_string[5]; |
| 8643 | } else { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8644 | pr_notice("ThinkPad firmware release %s " |
| 8645 | "doesn't match the known patterns\n", |
| 8646 | ec_fw_string); |
| 8647 | pr_notice("please report this to %s\n", |
| 8648 | TPACPI_MAIL); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 8649 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8650 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 8651 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 8652 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8653 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8654 | s = dmi_get_system_info(DMI_PRODUCT_VERSION); |
Manoj Iyer | 23b0531 | 2012-03-09 17:32:24 -0600 | [diff] [blame] | 8655 | if (s && !(strnicmp(s, "ThinkPad", 8) && strnicmp(s, "Lenovo", 6))) { |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8656 | tp->model_str = kstrdup(s, GFP_KERNEL); |
| 8657 | if (!tp->model_str) |
| 8658 | return -ENOMEM; |
Manoj Iyer | a4f46bb | 2012-08-06 18:15:37 -0500 | [diff] [blame] | 8659 | } else { |
| 8660 | s = dmi_get_system_info(DMI_BIOS_VENDOR); |
| 8661 | if (s && !(strnicmp(s, "Lenovo", 6))) { |
| 8662 | tp->model_str = kstrdup(s, GFP_KERNEL); |
| 8663 | if (!tp->model_str) |
| 8664 | return -ENOMEM; |
| 8665 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8666 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 8667 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8668 | s = dmi_get_system_info(DMI_PRODUCT_NAME); |
| 8669 | tp->nummodel_str = kstrdup(s, GFP_KERNEL); |
| 8670 | if (s && !tp->nummodel_str) |
| 8671 | return -ENOMEM; |
| 8672 | |
| 8673 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8674 | } |
| 8675 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8676 | static int __init probe_for_thinkpad(void) |
| 8677 | { |
| 8678 | int is_thinkpad; |
| 8679 | |
| 8680 | if (acpi_disabled) |
| 8681 | return -ENODEV; |
| 8682 | |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 8683 | /* It would be dangerous to run the driver in this case */ |
| 8684 | if (!tpacpi_is_ibm() && !tpacpi_is_lenovo()) |
| 8685 | return -ENODEV; |
| 8686 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8687 | /* |
| 8688 | * 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] | 8689 | * 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] | 8690 | */ |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 8691 | is_thinkpad = (thinkpad_id.model_str != NULL) || |
| 8692 | (thinkpad_id.ec_model != 0) || |
| 8693 | tpacpi_is_fw_known(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8694 | |
Henrique de Moraes Holschuh | 437e470 | 2010-05-16 19:45:43 -0300 | [diff] [blame] | 8695 | /* The EC handler is required */ |
| 8696 | tpacpi_acpi_handle_locate("ec", TPACPI_ACPI_EC_HID, &ec_handle); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8697 | if (!ec_handle) { |
| 8698 | if (is_thinkpad) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8699 | pr_err("Not yet supported ThinkPad detected!\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8700 | return -ENODEV; |
| 8701 | } |
| 8702 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 8703 | if (!is_thinkpad && !force_load) |
| 8704 | return -ENODEV; |
| 8705 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8706 | return 0; |
| 8707 | } |
| 8708 | |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 8709 | static void __init thinkpad_acpi_init_banner(void) |
| 8710 | { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8711 | pr_info("%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 8712 | pr_info("%s\n", TPACPI_URL); |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 8713 | |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8714 | pr_info("ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 8715 | (thinkpad_id.bios_version_str) ? |
| 8716 | thinkpad_id.bios_version_str : "unknown", |
| 8717 | (thinkpad_id.ec_version_str) ? |
| 8718 | thinkpad_id.ec_version_str : "unknown"); |
| 8719 | |
| 8720 | BUG_ON(!thinkpad_id.vendor); |
| 8721 | |
| 8722 | if (thinkpad_id.model_str) |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8723 | pr_info("%s %s, model %s\n", |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 8724 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 8725 | "IBM" : ((thinkpad_id.vendor == |
| 8726 | PCI_VENDOR_ID_LENOVO) ? |
| 8727 | "Lenovo" : "Unknown vendor"), |
| 8728 | thinkpad_id.model_str, |
| 8729 | (thinkpad_id.nummodel_str) ? |
| 8730 | thinkpad_id.nummodel_str : "unknown"); |
| 8731 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8732 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8733 | /* Module init, exit, parameters */ |
| 8734 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8735 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 8736 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8737 | .data = &thinkpad_acpi_driver_data, |
| 8738 | }, |
| 8739 | { |
| 8740 | .init = hotkey_init, |
| 8741 | .data = &hotkey_driver_data, |
| 8742 | }, |
| 8743 | { |
| 8744 | .init = bluetooth_init, |
| 8745 | .data = &bluetooth_driver_data, |
| 8746 | }, |
| 8747 | { |
| 8748 | .init = wan_init, |
| 8749 | .data = &wan_driver_data, |
| 8750 | }, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8751 | { |
| 8752 | .init = uwb_init, |
| 8753 | .data = &uwb_driver_data, |
| 8754 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 8755 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8756 | { |
| 8757 | .init = video_init, |
Henrique de Moraes Holschuh | b525c06 | 2010-02-25 22:22:22 -0300 | [diff] [blame] | 8758 | .base_procfs_mode = S_IRUSR, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8759 | .data = &video_driver_data, |
| 8760 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 8761 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8762 | { |
| 8763 | .init = light_init, |
| 8764 | .data = &light_driver_data, |
| 8765 | }, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8766 | { |
| 8767 | .init = cmos_init, |
| 8768 | .data = &cmos_driver_data, |
| 8769 | }, |
| 8770 | { |
| 8771 | .init = led_init, |
| 8772 | .data = &led_driver_data, |
| 8773 | }, |
| 8774 | { |
| 8775 | .init = beep_init, |
| 8776 | .data = &beep_driver_data, |
| 8777 | }, |
| 8778 | { |
| 8779 | .init = thermal_init, |
| 8780 | .data = &thermal_driver_data, |
| 8781 | }, |
| 8782 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8783 | .init = brightness_init, |
| 8784 | .data = &brightness_driver_data, |
| 8785 | }, |
| 8786 | { |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 8787 | .init = volume_init, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8788 | .data = &volume_driver_data, |
| 8789 | }, |
| 8790 | { |
| 8791 | .init = fan_init, |
| 8792 | .data = &fan_driver_data, |
| 8793 | }, |
| 8794 | }; |
| 8795 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8796 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 8797 | { |
| 8798 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8799 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8800 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 8801 | if (!kp || !kp->name || !val) |
| 8802 | return -EINVAL; |
| 8803 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8804 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 8805 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 8806 | WARN_ON(ibm == NULL); |
| 8807 | |
| 8808 | if (!ibm || !ibm->name) |
| 8809 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8810 | |
| 8811 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 8812 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8813 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8814 | strcpy(ibms_init[i].param, val); |
| 8815 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8816 | return 0; |
| 8817 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8818 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8819 | |
| 8820 | return -EINVAL; |
| 8821 | } |
| 8822 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8823 | module_param(experimental, int, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8824 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8825 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8826 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 8827 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8828 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 8829 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8830 | module_param(force_load, bool, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8831 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8832 | "Attempts to load the driver even on a " |
| 8833 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 8834 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8835 | module_param_named(fan_control, fan_control_allowed, bool, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8836 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8837 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 8838 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8839 | module_param_named(brightness_mode, brightness_mode, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8840 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8841 | "Selects brightness control strategy: " |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 8842 | "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 8843 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8844 | module_param(brightness_enable, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8845 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8846 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 8847 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8848 | module_param(hotkey_report_mode, uint, 0444); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8849 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8850 | "used for backwards compatibility with userspace, " |
| 8851 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8852 | |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 8853 | #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT |
Henrique de Moraes Holschuh | 329e4e1 | 2009-12-15 21:51:08 -0200 | [diff] [blame] | 8854 | module_param_named(volume_mode, volume_mode, uint, 0444); |
| 8855 | MODULE_PARM_DESC(volume_mode, |
| 8856 | "Selects volume control strategy: " |
| 8857 | "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM"); |
| 8858 | |
Henrique de Moraes Holschuh | a112cee | 2009-12-15 21:51:09 -0200 | [diff] [blame] | 8859 | module_param_named(volume_capabilities, volume_capabilities, uint, 0444); |
| 8860 | MODULE_PARM_DESC(volume_capabilities, |
| 8861 | "Selects the mixer capabilites: " |
| 8862 | "0=auto, 1=volume and mute, 2=mute only"); |
| 8863 | |
Henrique de Moraes Holschuh | c7ac629 | 2009-12-15 21:51:10 -0200 | [diff] [blame] | 8864 | module_param_named(volume_control, volume_control_allowed, bool, 0444); |
| 8865 | MODULE_PARM_DESC(volume_control, |
| 8866 | "Enables software override for the console audio " |
| 8867 | "control when true"); |
| 8868 | |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 8869 | /* ALSA module API parameters */ |
| 8870 | module_param_named(index, alsa_index, int, 0444); |
| 8871 | MODULE_PARM_DESC(index, "ALSA index for the ACPI EC Mixer"); |
| 8872 | module_param_named(id, alsa_id, charp, 0444); |
| 8873 | MODULE_PARM_DESC(id, "ALSA id for the ACPI EC Mixer"); |
| 8874 | module_param_named(enable, alsa_enable, bool, 0444); |
| 8875 | MODULE_PARM_DESC(enable, "Enable the ALSA interface for the ACPI EC Mixer"); |
Henrique de Moraes Holschuh | ff850c3 | 2009-12-26 22:52:15 -0200 | [diff] [blame] | 8876 | #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
Henrique de Moraes Holschuh | 0d204c3 | 2009-12-15 21:51:11 -0200 | [diff] [blame] | 8877 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8878 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8879 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 8880 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8881 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8882 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8883 | TPACPI_PARAM(hotkey); |
| 8884 | TPACPI_PARAM(bluetooth); |
| 8885 | TPACPI_PARAM(video); |
| 8886 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8887 | TPACPI_PARAM(cmos); |
| 8888 | TPACPI_PARAM(led); |
| 8889 | TPACPI_PARAM(beep); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8890 | TPACPI_PARAM(brightness); |
| 8891 | TPACPI_PARAM(volume); |
| 8892 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 8893 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8894 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8895 | module_param(dbg_wlswemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8896 | MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation"); |
| 8897 | module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0); |
| 8898 | MODULE_PARM_DESC(wlsw_state, |
| 8899 | "Initial state of the emulated WLSW switch"); |
| 8900 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8901 | module_param(dbg_bluetoothemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8902 | MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation"); |
| 8903 | module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0); |
| 8904 | MODULE_PARM_DESC(bluetooth_state, |
| 8905 | "Initial state of the emulated bluetooth switch"); |
| 8906 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8907 | module_param(dbg_wwanemul, uint, 0444); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8908 | MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation"); |
| 8909 | module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0); |
| 8910 | MODULE_PARM_DESC(wwan_state, |
| 8911 | "Initial state of the emulated WWAN switch"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8912 | |
Henrique de Moraes Holschuh | b09c722 | 2009-12-09 01:36:27 +0000 | [diff] [blame] | 8913 | module_param(dbg_uwbemul, uint, 0444); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 8914 | MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation"); |
| 8915 | module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0); |
| 8916 | MODULE_PARM_DESC(uwb_state, |
| 8917 | "Initial state of the emulated UWB switch"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 8918 | #endif |
| 8919 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8920 | static void thinkpad_acpi_module_exit(void) |
| 8921 | { |
| 8922 | struct ibm_struct *ibm, *itmp; |
| 8923 | |
| 8924 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 8925 | |
| 8926 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 8927 | &tpacpi_all_drivers, |
| 8928 | all_drivers) { |
| 8929 | ibm_exit(ibm); |
| 8930 | } |
| 8931 | |
| 8932 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 8933 | |
| 8934 | if (tpacpi_inputdev) { |
| 8935 | if (tp_features.input_device_registered) |
| 8936 | input_unregister_device(tpacpi_inputdev); |
| 8937 | else |
| 8938 | input_free_device(tpacpi_inputdev); |
Li Dongyang | 00d3959 | 2012-07-25 10:45:09 +1000 | [diff] [blame] | 8939 | kfree(hotkey_keycode_map); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8940 | } |
| 8941 | |
| 8942 | if (tpacpi_hwmon) |
| 8943 | hwmon_device_unregister(tpacpi_hwmon); |
| 8944 | |
| 8945 | if (tp_features.sensors_pdev_attrs_registered) |
| 8946 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 8947 | &dev_attr_thinkpad_acpi_pdev_name); |
| 8948 | if (tpacpi_sensors_pdev) |
| 8949 | platform_device_unregister(tpacpi_sensors_pdev); |
| 8950 | if (tpacpi_pdev) |
| 8951 | platform_device_unregister(tpacpi_pdev); |
| 8952 | |
| 8953 | if (tp_features.sensors_pdrv_attrs_registered) |
| 8954 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 8955 | if (tp_features.platform_drv_attrs_registered) |
| 8956 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 8957 | |
| 8958 | if (tp_features.sensors_pdrv_registered) |
| 8959 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 8960 | |
| 8961 | if (tp_features.platform_drv_registered) |
| 8962 | platform_driver_unregister(&tpacpi_pdriver); |
| 8963 | |
| 8964 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8965 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8966 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8967 | if (tpacpi_wq) |
| 8968 | destroy_workqueue(tpacpi_wq); |
| 8969 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8970 | kfree(thinkpad_id.bios_version_str); |
| 8971 | kfree(thinkpad_id.ec_version_str); |
| 8972 | kfree(thinkpad_id.model_str); |
Li Dongyang | d2be15b | 2012-07-25 10:45:08 +1000 | [diff] [blame] | 8973 | kfree(thinkpad_id.nummodel_str); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8974 | } |
| 8975 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 8976 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8977 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8978 | { |
| 8979 | int ret, i; |
| 8980 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 8981 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 8982 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8983 | /* Parameter checking */ |
| 8984 | if (hotkey_report_mode > 2) |
| 8985 | return -EINVAL; |
| 8986 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8987 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8988 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8989 | ret = get_thinkpad_model_data(&thinkpad_id); |
| 8990 | if (ret) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 8991 | pr_err("unable to get DMI data: %d\n", ret); |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8992 | thinkpad_acpi_module_exit(); |
| 8993 | return ret; |
| 8994 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8995 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8996 | if (ret) { |
| 8997 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8998 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8999 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9000 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9001 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 9002 | |
Henrique de Moraes Holschuh | 7a43f78 | 2010-05-16 19:45:31 -0300 | [diff] [blame] | 9003 | thinkpad_acpi_init_banner(); |
| 9004 | tpacpi_check_outdated_fw(); |
| 9005 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9006 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 9007 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9008 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 9009 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
| 9010 | if (!tpacpi_wq) { |
| 9011 | thinkpad_acpi_module_exit(); |
| 9012 | return -ENOMEM; |
| 9013 | } |
| 9014 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9015 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9016 | if (!proc_dir) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9017 | pr_err("unable to create proc dir " TPACPI_PROC_DIR "\n"); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9018 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9019 | return -ENODEV; |
| 9020 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 9021 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9022 | ret = platform_driver_register(&tpacpi_pdriver); |
| 9023 | if (ret) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9024 | pr_err("unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9025 | thinkpad_acpi_module_exit(); |
| 9026 | return ret; |
| 9027 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 9028 | tp_features.platform_drv_registered = 1; |
| 9029 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9030 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 9031 | if (ret) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9032 | pr_err("unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9033 | thinkpad_acpi_module_exit(); |
| 9034 | return ret; |
| 9035 | } |
| 9036 | tp_features.sensors_pdrv_registered = 1; |
| 9037 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9038 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 9039 | if (!ret) { |
| 9040 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9041 | ret = tpacpi_create_driver_attributes( |
| 9042 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 9043 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9044 | if (ret) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9045 | pr_err("unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9046 | thinkpad_acpi_module_exit(); |
| 9047 | return ret; |
| 9048 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 9049 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 9050 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9051 | |
| 9052 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9053 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9054 | NULL, 0); |
| 9055 | if (IS_ERR(tpacpi_pdev)) { |
| 9056 | ret = PTR_ERR(tpacpi_pdev); |
| 9057 | tpacpi_pdev = NULL; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9058 | pr_err("unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9059 | thinkpad_acpi_module_exit(); |
| 9060 | return ret; |
| 9061 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9062 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 9063 | TPACPI_HWMON_DRVR_NAME, |
| 9064 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9065 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 9066 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 9067 | tpacpi_sensors_pdev = NULL; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9068 | pr_err("unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9069 | thinkpad_acpi_module_exit(); |
| 9070 | return ret; |
| 9071 | } |
| 9072 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 9073 | &dev_attr_thinkpad_acpi_pdev_name); |
| 9074 | if (ret) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9075 | pr_err("unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 9076 | thinkpad_acpi_module_exit(); |
| 9077 | return ret; |
| 9078 | } |
| 9079 | tp_features.sensors_pdev_attrs_registered = 1; |
| 9080 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9081 | if (IS_ERR(tpacpi_hwmon)) { |
| 9082 | ret = PTR_ERR(tpacpi_hwmon); |
| 9083 | tpacpi_hwmon = NULL; |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9084 | pr_err("unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 9085 | thinkpad_acpi_module_exit(); |
| 9086 | return ret; |
| 9087 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 9088 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9089 | tpacpi_inputdev = input_allocate_device(); |
| 9090 | if (!tpacpi_inputdev) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9091 | pr_err("unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9092 | thinkpad_acpi_module_exit(); |
| 9093 | return -ENOMEM; |
| 9094 | } else { |
| 9095 | /* Prepare input device, but don't register */ |
| 9096 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9097 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9098 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | e28393c | 2010-05-16 19:45:23 -0300 | [diff] [blame] | 9099 | tpacpi_inputdev->id.vendor = thinkpad_id.vendor; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9100 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 9101 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
Henrique de Moraes Holschuh | d112ef9 | 2009-12-09 01:36:26 +0000 | [diff] [blame] | 9102 | tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9103 | } |
Henrique de Moraes Holschuh | 7777583 | 2010-05-16 19:45:33 -0300 | [diff] [blame] | 9104 | |
| 9105 | /* Init subdriver dependencies */ |
| 9106 | tpacpi_detect_brightness_capabilities(); |
| 9107 | |
| 9108 | /* Init subdrivers */ |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 9109 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 9110 | ret = ibm_init(&ibms_init[i]); |
| 9111 | if (ret >= 0 && *ibms_init[i].param) |
| 9112 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9113 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9114 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9115 | return ret; |
| 9116 | } |
| 9117 | } |
Henrique de Moraes Holschuh | b589ea4 | 2010-02-25 21:28:58 -0300 | [diff] [blame] | 9118 | |
| 9119 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
| 9120 | |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9121 | ret = input_register_device(tpacpi_inputdev); |
| 9122 | if (ret < 0) { |
Joe Perches | 0978e01 | 2011-04-04 10:06:25 -0700 | [diff] [blame] | 9123 | pr_err("unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 9124 | thinkpad_acpi_module_exit(); |
| 9125 | return ret; |
| 9126 | } else { |
| 9127 | tp_features.input_device_registered = 1; |
| 9128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9129 | |
| 9130 | return 0; |
| 9131 | } |
| 9132 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 9133 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 9134 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9135 | /* |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 9136 | * This will autoload the driver in almost every ThinkPad |
| 9137 | * in widespread use. |
| 9138 | * |
| 9139 | * Only _VERY_ old models, like the 240, 240x and 570 lack |
| 9140 | * the HKEY event interface. |
| 9141 | */ |
| 9142 | MODULE_DEVICE_TABLE(acpi, ibm_htk_device_ids); |
| 9143 | |
| 9144 | /* |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9145 | * DMI matching for module autoloading |
| 9146 | * |
| 9147 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 9148 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 9149 | * |
| 9150 | * Only models listed in thinkwiki will be supported, so add yours |
| 9151 | * if it is not there yet. |
| 9152 | */ |
| 9153 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
Mathieu Chouquet-Stringer | b36a50f | 2009-03-14 16:35:26 +0100 | [diff] [blame] | 9154 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*") |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9155 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9156 | /* Ancient thinkpad BIOSes have to be identified by |
| 9157 | * BIOS type or model number, and there are far less |
| 9158 | * BIOS types than model numbers... */ |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 9159 | IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9160 | |
Henrique de Moraes Holschuh | f68f53a | 2009-04-14 02:44:12 +0000 | [diff] [blame] | 9161 | MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>"); |
| 9162 | MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 9163 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 9164 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 9165 | MODULE_LICENSE("GPL"); |
| 9166 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 9167 | module_init(thinkpad_acpi_module_init); |
| 9168 | module_exit(thinkpad_acpi_module_exit); |