Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 2 | * thinkpad_acpi.c - ThinkPad ACPI Extras |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> |
Henrique de Moraes Holschuh | 1c762ca | 2009-04-04 04:25:42 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
Henrique de Moraes Holschuh | a62bc91 | 2007-03-23 17:33:58 -0300 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 21 | * 02110-1301, USA. |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 22 | */ |
| 23 | |
Henrique de Moraes Holschuh | b57f7e7 | 2009-04-14 02:44:14 +0000 | [diff] [blame] | 24 | #define TPACPI_VERSION "0.23" |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 25 | #define TPACPI_SYSFS_VERSION 0x020400 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 26 | |
| 27 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * Changelog: |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 29 | * 2007-10-20 changelog trimmed down |
| 30 | * |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 31 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
| 32 | * drivers/misc. |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 33 | * |
| 34 | * 2006-11-22 0.13 new maintainer |
| 35 | * changelog now lives in git commit history, and will |
| 36 | * not be updated further in-file. |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 37 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 38 | * 2005-03-17 0.11 support for 600e, 770x |
| 39 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 40 | * |
| 41 | * 2005-01-16 0.9 use MODULE_VERSION |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 42 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
| 43 | * fix parameter passing on module loading |
| 44 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
| 45 | * thanks to Jim Radford <radford@blackbean.org> |
| 46 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
| 47 | * thanks to Chris Wright <chrisw@osdl.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | */ |
| 49 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 50 | #include <linux/kernel.h> |
| 51 | #include <linux/module.h> |
| 52 | #include <linux/init.h> |
| 53 | #include <linux/types.h> |
| 54 | #include <linux/string.h> |
| 55 | #include <linux/list.h> |
| 56 | #include <linux/mutex.h> |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 57 | #include <linux/sched.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 58 | #include <linux/kthread.h> |
| 59 | #include <linux/freezer.h> |
| 60 | #include <linux/delay.h> |
| 61 | |
| 62 | #include <linux/nvram.h> |
| 63 | #include <linux/proc_fs.h> |
| 64 | #include <linux/sysfs.h> |
| 65 | #include <linux/backlight.h> |
| 66 | #include <linux/fb.h> |
| 67 | #include <linux/platform_device.h> |
| 68 | #include <linux/hwmon.h> |
| 69 | #include <linux/hwmon-sysfs.h> |
| 70 | #include <linux/input.h> |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 71 | #include <linux/leds.h> |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 72 | #include <linux/rfkill.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 73 | #include <asm/uaccess.h> |
| 74 | |
| 75 | #include <linux/dmi.h> |
| 76 | #include <linux/jiffies.h> |
| 77 | #include <linux/workqueue.h> |
| 78 | |
| 79 | #include <acpi/acpi_drivers.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 80 | |
| 81 | #include <linux/pci_ids.h> |
| 82 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 83 | |
| 84 | /* ThinkPad CMOS commands */ |
| 85 | #define TP_CMOS_VOLUME_DOWN 0 |
| 86 | #define TP_CMOS_VOLUME_UP 1 |
| 87 | #define TP_CMOS_VOLUME_MUTE 2 |
| 88 | #define TP_CMOS_BRIGHTNESS_UP 4 |
| 89 | #define TP_CMOS_BRIGHTNESS_DOWN 5 |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 90 | #define TP_CMOS_THINKLIGHT_ON 12 |
| 91 | #define TP_CMOS_THINKLIGHT_OFF 13 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 92 | |
| 93 | /* NVRAM Addresses */ |
| 94 | enum tp_nvram_addr { |
| 95 | TP_NVRAM_ADDR_HK2 = 0x57, |
| 96 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, |
| 97 | TP_NVRAM_ADDR_VIDEO = 0x59, |
| 98 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, |
| 99 | TP_NVRAM_ADDR_MIXER = 0x60, |
| 100 | }; |
| 101 | |
| 102 | /* NVRAM bit masks */ |
| 103 | enum { |
| 104 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, |
| 105 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, |
| 106 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, |
| 107 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, |
| 108 | TP_NVRAM_MASK_THINKLIGHT = 0x10, |
| 109 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, |
| 110 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, |
| 111 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, |
| 112 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, |
| 113 | TP_NVRAM_MASK_MUTE = 0x40, |
| 114 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, |
| 115 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, |
| 116 | TP_NVRAM_POS_LEVEL_VOLUME = 0, |
| 117 | }; |
| 118 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 119 | /* ACPI HIDs */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 120 | #define TPACPI_ACPI_HKEY_HID "IBM0068" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 121 | |
| 122 | /* Input IDs */ |
| 123 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ |
| 124 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 |
| 125 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 126 | /* ACPI \WGSV commands */ |
| 127 | enum { |
| 128 | TP_ACPI_WGSV_GET_STATE = 0x01, /* Get state information */ |
| 129 | TP_ACPI_WGSV_PWR_ON_ON_RESUME = 0x02, /* Resume WWAN powered on */ |
| 130 | TP_ACPI_WGSV_PWR_OFF_ON_RESUME = 0x03, /* Resume WWAN powered off */ |
| 131 | TP_ACPI_WGSV_SAVE_STATE = 0x04, /* Save state for S4/S5 */ |
| 132 | }; |
| 133 | |
| 134 | /* TP_ACPI_WGSV_GET_STATE bits */ |
| 135 | enum { |
| 136 | TP_ACPI_WGSV_STATE_WWANEXIST = 0x0001, /* WWAN hw available */ |
| 137 | TP_ACPI_WGSV_STATE_WWANPWR = 0x0002, /* WWAN radio enabled */ |
| 138 | TP_ACPI_WGSV_STATE_WWANPWRRES = 0x0004, /* WWAN state at resume */ |
| 139 | TP_ACPI_WGSV_STATE_WWANBIOSOFF = 0x0008, /* WWAN disabled in BIOS */ |
| 140 | TP_ACPI_WGSV_STATE_BLTHEXIST = 0x0001, /* BLTH hw available */ |
| 141 | TP_ACPI_WGSV_STATE_BLTHPWR = 0x0002, /* BLTH radio enabled */ |
| 142 | TP_ACPI_WGSV_STATE_BLTHPWRRES = 0x0004, /* BLTH state at resume */ |
| 143 | TP_ACPI_WGSV_STATE_BLTHBIOSOFF = 0x0008, /* BLTH disabled in BIOS */ |
| 144 | TP_ACPI_WGSV_STATE_UWBEXIST = 0x0010, /* UWB hw available */ |
| 145 | TP_ACPI_WGSV_STATE_UWBPWR = 0x0020, /* UWB radio enabled */ |
| 146 | }; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 147 | |
| 148 | /**************************************************************************** |
| 149 | * Main driver |
| 150 | */ |
| 151 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 152 | #define TPACPI_NAME "thinkpad" |
| 153 | #define TPACPI_DESC "ThinkPad ACPI Extras" |
| 154 | #define TPACPI_FILE TPACPI_NAME "_acpi" |
| 155 | #define TPACPI_URL "http://ibm-acpi.sf.net/" |
| 156 | #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 157 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 158 | #define TPACPI_PROC_DIR "ibm" |
| 159 | #define TPACPI_ACPI_EVENT_PREFIX "ibm" |
| 160 | #define TPACPI_DRVR_NAME TPACPI_FILE |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 161 | #define TPACPI_DRVR_SHORTNAME "tpacpi" |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 162 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 163 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 164 | #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd" |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 165 | #define TPACPI_WORKQUEUE_NAME "ktpacpid" |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 166 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 167 | #define TPACPI_MAX_ACPI_ARGS 3 |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 168 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 169 | /* rfkill switches */ |
| 170 | enum { |
| 171 | TPACPI_RFK_BLUETOOTH_SW_ID = 0, |
| 172 | TPACPI_RFK_WWAN_SW_ID, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 173 | TPACPI_RFK_UWB_SW_ID, |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 174 | }; |
| 175 | |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 176 | /* printk headers */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 177 | #define TPACPI_LOG TPACPI_FILE ": " |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 178 | #define TPACPI_EMERG KERN_EMERG TPACPI_LOG |
| 179 | #define TPACPI_ALERT KERN_ALERT TPACPI_LOG |
| 180 | #define TPACPI_CRIT KERN_CRIT TPACPI_LOG |
| 181 | #define TPACPI_ERR KERN_ERR TPACPI_LOG |
| 182 | #define TPACPI_WARN KERN_WARNING TPACPI_LOG |
| 183 | #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG |
| 184 | #define TPACPI_INFO KERN_INFO TPACPI_LOG |
| 185 | #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 186 | |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 187 | /* Debugging printk groups */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 188 | #define TPACPI_DBG_ALL 0xffff |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 189 | #define TPACPI_DBG_DISCLOSETASK 0x8000 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 190 | #define TPACPI_DBG_INIT 0x0001 |
| 191 | #define TPACPI_DBG_EXIT 0x0002 |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 192 | #define TPACPI_DBG_RFKILL 0x0004 |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 193 | #define TPACPI_DBG_HKEY 0x0008 |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 194 | #define TPACPI_DBG_FAN 0x0010 |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 195 | #define TPACPI_DBG_BRGHT 0x0020 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 196 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 197 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 198 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 199 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 200 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 201 | |
| 202 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 203 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 204 | */ |
| 205 | |
| 206 | struct ibm_struct; |
| 207 | |
| 208 | struct tp_acpi_drv_struct { |
| 209 | const struct acpi_device_id *hid; |
| 210 | struct acpi_driver *driver; |
| 211 | |
| 212 | void (*notify) (struct ibm_struct *, u32); |
| 213 | acpi_handle *handle; |
| 214 | u32 type; |
| 215 | struct acpi_device *device; |
| 216 | }; |
| 217 | |
| 218 | struct ibm_struct { |
| 219 | char *name; |
| 220 | |
| 221 | int (*read) (char *); |
| 222 | int (*write) (char *); |
| 223 | void (*exit) (void); |
| 224 | void (*resume) (void); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 225 | void (*suspend) (pm_message_t state); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 226 | void (*shutdown) (void); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 227 | |
| 228 | struct list_head all_drivers; |
| 229 | |
| 230 | struct tp_acpi_drv_struct *acpi; |
| 231 | |
| 232 | struct { |
| 233 | u8 acpi_driver_registered:1; |
| 234 | u8 acpi_notify_installed:1; |
| 235 | u8 proc_created:1; |
| 236 | u8 init_called:1; |
| 237 | u8 experimental:1; |
| 238 | } flags; |
| 239 | }; |
| 240 | |
| 241 | struct ibm_init_struct { |
| 242 | char param[32]; |
| 243 | |
| 244 | int (*init) (struct ibm_init_struct *); |
| 245 | struct ibm_struct *data; |
| 246 | }; |
| 247 | |
| 248 | static struct { |
| 249 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 250 | u32 bay_status:1; |
| 251 | u32 bay_eject:1; |
| 252 | u32 bay_status2:1; |
| 253 | u32 bay_eject2:1; |
| 254 | #endif |
| 255 | u32 bluetooth:1; |
| 256 | u32 hotkey:1; |
| 257 | u32 hotkey_mask:1; |
| 258 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 259 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 260 | u32 light:1; |
| 261 | u32 light_status:1; |
| 262 | u32 bright_16levels:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 263 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 264 | u32 wan:1; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 265 | u32 uwb:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 266 | u32 fan_ctrl_status_undef:1; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 267 | u32 beep_needs_two_args:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 268 | u32 input_device_registered:1; |
| 269 | u32 platform_drv_registered:1; |
| 270 | u32 platform_drv_attrs_registered:1; |
| 271 | u32 sensors_pdrv_registered:1; |
| 272 | u32 sensors_pdrv_attrs_registered:1; |
| 273 | u32 sensors_pdev_attrs_registered:1; |
| 274 | u32 hotkey_poll_active:1; |
| 275 | } tp_features; |
| 276 | |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 277 | static struct { |
| 278 | u16 hotkey_mask_ff:1; |
| 279 | } tp_warned; |
| 280 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 281 | struct thinkpad_id_data { |
| 282 | unsigned int vendor; /* ThinkPad vendor: |
| 283 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 284 | |
| 285 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 286 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 287 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 288 | u16 bios_model; /* 1Y = 0x5931, 0 = unknown */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 289 | u16 ec_model; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 290 | u16 bios_release; /* 1ZETK1WW = 0x314b, 0 = unknown */ |
| 291 | u16 ec_release; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 292 | |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 293 | char *model_str; /* ThinkPad T43 */ |
| 294 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 295 | }; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 296 | static struct thinkpad_id_data thinkpad_id; |
| 297 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 298 | static enum { |
| 299 | TPACPI_LIFE_INIT = 0, |
| 300 | TPACPI_LIFE_RUNNING, |
| 301 | TPACPI_LIFE_EXITING, |
| 302 | } tpacpi_lifecycle; |
| 303 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 304 | static int experimental; |
| 305 | static u32 dbg_level; |
| 306 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 307 | static struct workqueue_struct *tpacpi_wq; |
| 308 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 309 | enum led_status_t { |
| 310 | TPACPI_LED_OFF = 0, |
| 311 | TPACPI_LED_ON, |
| 312 | TPACPI_LED_BLINK, |
| 313 | }; |
| 314 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 315 | /* Special LED class that can defer work */ |
| 316 | struct tpacpi_led_classdev { |
| 317 | struct led_classdev led_classdev; |
| 318 | struct work_struct work; |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 319 | enum led_status_t new_state; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 320 | unsigned int led; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 321 | }; |
| 322 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 323 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 324 | static int dbg_wlswemul; |
| 325 | static int tpacpi_wlsw_emulstate; |
| 326 | static int dbg_bluetoothemul; |
| 327 | static int tpacpi_bluetooth_emulstate; |
| 328 | static int dbg_wwanemul; |
| 329 | static int tpacpi_wwan_emulstate; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 330 | static int dbg_uwbemul; |
| 331 | static int tpacpi_uwb_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 332 | #endif |
| 333 | |
| 334 | |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 335 | /************************************************************************* |
| 336 | * Debugging helpers |
| 337 | */ |
| 338 | |
| 339 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 340 | do { if (dbg_level & (a_dbg_level)) \ |
| 341 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ |
| 342 | } while (0) |
| 343 | |
| 344 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 345 | #define vdbg_printk dbg_printk |
| 346 | static const char *str_supported(int is_supported); |
| 347 | #else |
| 348 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 349 | do { } while (0) |
| 350 | #endif |
| 351 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 352 | static void tpacpi_log_usertask(const char * const what) |
| 353 | { |
| 354 | printk(TPACPI_DEBUG "%s: access by process with PID %d\n", |
| 355 | what, task_tgid_vnr(current)); |
| 356 | } |
| 357 | |
| 358 | #define tpacpi_disclose_usertask(what, format, arg...) \ |
| 359 | do { \ |
| 360 | if (unlikely( \ |
| 361 | (dbg_level & TPACPI_DBG_DISCLOSETASK) && \ |
| 362 | (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \ |
| 363 | printk(TPACPI_DEBUG "%s: PID %d: " format, \ |
| 364 | what, task_tgid_vnr(current), ## arg); \ |
| 365 | } \ |
| 366 | } while (0) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 367 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 368 | /* |
| 369 | * Quirk handling helpers |
| 370 | * |
| 371 | * ThinkPad IDs and versions seen in the field so far |
| 372 | * are two-characters from the set [0-9A-Z], i.e. base 36. |
| 373 | * |
| 374 | * We use values well outside that range as specials. |
| 375 | */ |
| 376 | |
| 377 | #define TPACPI_MATCH_ANY 0xffffU |
| 378 | #define TPACPI_MATCH_UNKNOWN 0U |
| 379 | |
| 380 | /* TPID('1', 'Y') == 0x5931 */ |
| 381 | #define TPID(__c1, __c2) (((__c2) << 8) | (__c1)) |
| 382 | |
| 383 | #define TPACPI_Q_IBM(__id1, __id2, __quirk) \ |
| 384 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 385 | .bios = TPID(__id1, __id2), \ |
| 386 | .ec = TPACPI_MATCH_ANY, \ |
| 387 | .quirks = (__quirk) } |
| 388 | |
| 389 | #define TPACPI_Q_LNV(__id1, __id2, __quirk) \ |
| 390 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 391 | .bios = TPID(__id1, __id2), \ |
| 392 | .ec = TPACPI_MATCH_ANY, \ |
| 393 | .quirks = (__quirk) } |
| 394 | |
| 395 | struct tpacpi_quirk { |
| 396 | unsigned int vendor; |
| 397 | u16 bios; |
| 398 | u16 ec; |
| 399 | unsigned long quirks; |
| 400 | }; |
| 401 | |
| 402 | /** |
| 403 | * tpacpi_check_quirks() - search BIOS/EC version on a list |
| 404 | * @qlist: array of &struct tpacpi_quirk |
| 405 | * @qlist_size: number of elements in @qlist |
| 406 | * |
| 407 | * Iterates over a quirks list until one is found that matches the |
| 408 | * ThinkPad's vendor, BIOS and EC model. |
| 409 | * |
| 410 | * Returns 0 if nothing matches, otherwise returns the quirks field of |
| 411 | * the matching &struct tpacpi_quirk entry. |
| 412 | * |
| 413 | * The match criteria is: vendor, ec and bios much match. |
| 414 | */ |
| 415 | static unsigned long __init tpacpi_check_quirks( |
| 416 | const struct tpacpi_quirk *qlist, |
| 417 | unsigned int qlist_size) |
| 418 | { |
| 419 | while (qlist_size) { |
| 420 | if ((qlist->vendor == thinkpad_id.vendor || |
| 421 | qlist->vendor == TPACPI_MATCH_ANY) && |
| 422 | (qlist->bios == thinkpad_id.bios_model || |
| 423 | qlist->bios == TPACPI_MATCH_ANY) && |
| 424 | (qlist->ec == thinkpad_id.ec_model || |
| 425 | qlist->ec == TPACPI_MATCH_ANY)) |
| 426 | return qlist->quirks; |
| 427 | |
| 428 | qlist_size--; |
| 429 | qlist++; |
| 430 | } |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 435 | /**************************************************************************** |
| 436 | **************************************************************************** |
| 437 | * |
| 438 | * ACPI Helpers and device model |
| 439 | * |
| 440 | **************************************************************************** |
| 441 | ****************************************************************************/ |
| 442 | |
| 443 | /************************************************************************* |
| 444 | * ACPI basic handles |
| 445 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 447 | static acpi_handle root_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 449 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | static acpi_handle object##_handle; \ |
| 451 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 452 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | static char *object##_paths[] = { paths } |
| 454 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 455 | TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 456 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 457 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 458 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 459 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 460 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 461 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 462 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 464 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 465 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 467 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 468 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 469 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 470 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 471 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 472 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 473 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 474 | "^HKEY", /* R30, R31 */ |
| 475 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 476 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 477 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 478 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 479 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 480 | "\\_SB.PCI0.VID0", /* 770e */ |
| 481 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 482 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 483 | ); /* R30, R31 */ |
| 484 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 485 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 486 | /************************************************************************* |
| 487 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 488 | */ |
| 489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | static int acpi_evalf(acpi_handle handle, |
| 491 | void *res, char *method, char *fmt, ...) |
| 492 | { |
| 493 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 494 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 495 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 496 | struct acpi_buffer result, *resultp; |
| 497 | union acpi_object out_obj; |
| 498 | acpi_status status; |
| 499 | va_list ap; |
| 500 | char res_type; |
| 501 | int success; |
| 502 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | if (!*fmt) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 505 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | if (*fmt == 'q') { |
| 510 | quiet = 1; |
| 511 | fmt++; |
| 512 | } else |
| 513 | quiet = 0; |
| 514 | |
| 515 | res_type = *(fmt++); |
| 516 | |
| 517 | params.count = 0; |
| 518 | params.pointer = &in_objs[0]; |
| 519 | |
| 520 | va_start(ap, fmt); |
| 521 | while (*fmt) { |
| 522 | char c = *(fmt++); |
| 523 | switch (c) { |
| 524 | case 'd': /* int */ |
| 525 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 526 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 527 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 528 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 530 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | "with invalid format character '%c'\n", c); |
| 532 | return 0; |
| 533 | } |
| 534 | } |
| 535 | va_end(ap); |
| 536 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 537 | if (res_type != 'v') { |
| 538 | result.length = sizeof(out_obj); |
| 539 | result.pointer = &out_obj; |
| 540 | resultp = &result; |
| 541 | } else |
| 542 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 544 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
| 546 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 547 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | if (res) |
| 549 | *(int *)res = out_obj.integer.value; |
| 550 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 551 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 552 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | success = status == AE_OK; |
| 554 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 555 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 557 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | "with invalid format character '%c'\n", res_type); |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | if (!success && !quiet) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 563 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | method, fmt0, status); |
| 565 | |
| 566 | return success; |
| 567 | } |
| 568 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 569 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 570 | { |
| 571 | int v; |
| 572 | |
| 573 | if (ecrd_handle) { |
| 574 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 575 | return 0; |
| 576 | *p = v; |
| 577 | } else { |
| 578 | if (ec_read(i, p) < 0) |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | return 1; |
| 583 | } |
| 584 | |
| 585 | static int acpi_ec_write(int i, u8 v) |
| 586 | { |
| 587 | if (ecwr_handle) { |
| 588 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 589 | return 0; |
| 590 | } else { |
| 591 | if (ec_write(i, v) < 0) |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | return 1; |
| 596 | } |
| 597 | |
Henrique de Moraes Holschuh | 013c40e | 2008-01-08 13:02:54 -0200 | [diff] [blame] | 598 | #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 599 | static int _sta(acpi_handle handle) |
| 600 | { |
| 601 | int status; |
| 602 | |
| 603 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) |
| 604 | status = 0; |
| 605 | |
| 606 | return status; |
| 607 | } |
Henrique de Moraes Holschuh | 013c40e | 2008-01-08 13:02:54 -0200 | [diff] [blame] | 608 | #endif |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 609 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 610 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 611 | { |
| 612 | if (!cmos_handle) |
| 613 | return -ENXIO; |
| 614 | |
| 615 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 616 | return -EIO; |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 621 | /************************************************************************* |
| 622 | * ACPI device model |
| 623 | */ |
| 624 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 625 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 626 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 627 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
| 628 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 629 | static void drv_acpi_handle_init(char *name, |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 630 | acpi_handle *handle, acpi_handle parent, |
| 631 | char **paths, int num_paths, char **path) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 632 | { |
| 633 | int i; |
| 634 | acpi_status status; |
| 635 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 636 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 637 | name); |
| 638 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 639 | for (i = 0; i < num_paths; i++) { |
| 640 | status = acpi_get_handle(parent, paths[i], handle); |
| 641 | if (ACPI_SUCCESS(status)) { |
| 642 | *path = paths[i]; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 643 | dbg_printk(TPACPI_DBG_INIT, |
| 644 | "Found ACPI handle %s for %s\n", |
| 645 | *path, name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 646 | return; |
| 647 | } |
| 648 | } |
| 649 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 650 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 651 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 652 | *handle = NULL; |
| 653 | } |
| 654 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 655 | 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] | 656 | { |
| 657 | struct ibm_struct *ibm = data; |
| 658 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 659 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 660 | return; |
| 661 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 662 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 663 | return; |
| 664 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 665 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 666 | } |
| 667 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 668 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 669 | { |
| 670 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 671 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 672 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 673 | BUG_ON(!ibm->acpi); |
| 674 | |
| 675 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 676 | return 0; |
| 677 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 678 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 679 | "setting up ACPI notify for %s\n", ibm->name); |
| 680 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 681 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 682 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 683 | printk(TPACPI_ERR "acpi_bus_get_device(%s) failed: %d\n", |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 684 | ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 685 | return -ENODEV; |
| 686 | } |
| 687 | |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 688 | ibm->acpi->device->driver_data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 689 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 690 | TPACPI_ACPI_EVENT_PREFIX, |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 691 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 692 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 693 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 694 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 695 | if (ACPI_FAILURE(status)) { |
| 696 | if (status == AE_ALREADY_EXISTS) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 697 | printk(TPACPI_NOTICE |
| 698 | "another device driver is already " |
| 699 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 700 | } else { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 701 | printk(TPACPI_ERR |
| 702 | "acpi_install_notify_handler(%s) failed: %d\n", |
| 703 | ibm->name, status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 704 | } |
| 705 | return -ENODEV; |
| 706 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 707 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 708 | return 0; |
| 709 | } |
| 710 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 711 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 712 | { |
| 713 | return 0; |
| 714 | } |
| 715 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 716 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 717 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 718 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 719 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 720 | dbg_printk(TPACPI_DBG_INIT, |
| 721 | "registering %s as an ACPI driver\n", ibm->name); |
| 722 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 723 | BUG_ON(!ibm->acpi); |
| 724 | |
| 725 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 726 | if (!ibm->acpi->driver) { |
Mariusz Kozlowski | 4f778b9 | 2008-10-18 14:23:53 -0300 | [diff] [blame] | 727 | printk(TPACPI_ERR |
| 728 | "failed to allocate memory for ibm->acpi->driver\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 729 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 730 | } |
| 731 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 732 | 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] | 733 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 734 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 735 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 736 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 737 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 738 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 739 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 740 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 741 | kfree(ibm->acpi->driver); |
| 742 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 743 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 744 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 745 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 746 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | |
| 750 | /**************************************************************************** |
| 751 | **************************************************************************** |
| 752 | * |
| 753 | * Procfs Helpers |
| 754 | * |
| 755 | **************************************************************************** |
| 756 | ****************************************************************************/ |
| 757 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 758 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 759 | int count, int *eof, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 760 | { |
| 761 | struct ibm_struct *ibm = data; |
| 762 | int len; |
| 763 | |
| 764 | if (!ibm || !ibm->read) |
| 765 | return -EINVAL; |
| 766 | |
| 767 | len = ibm->read(page); |
| 768 | if (len < 0) |
| 769 | return len; |
| 770 | |
| 771 | if (len <= off + count) |
| 772 | *eof = 1; |
| 773 | *start = page + off; |
| 774 | len -= off; |
| 775 | if (len > count) |
| 776 | len = count; |
| 777 | if (len < 0) |
| 778 | len = 0; |
| 779 | |
| 780 | return len; |
| 781 | } |
| 782 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 783 | static int dispatch_procfs_write(struct file *file, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 784 | const char __user *userbuf, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 785 | unsigned long count, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 786 | { |
| 787 | struct ibm_struct *ibm = data; |
| 788 | char *kernbuf; |
| 789 | int ret; |
| 790 | |
| 791 | if (!ibm || !ibm->write) |
| 792 | return -EINVAL; |
| 793 | |
| 794 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 795 | if (!kernbuf) |
| 796 | return -ENOMEM; |
| 797 | |
| 798 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 799 | kfree(kernbuf); |
| 800 | return -EFAULT; |
| 801 | } |
| 802 | |
| 803 | kernbuf[count] = 0; |
| 804 | strcat(kernbuf, ","); |
| 805 | ret = ibm->write(kernbuf); |
| 806 | if (ret == 0) |
| 807 | ret = count; |
| 808 | |
| 809 | kfree(kernbuf); |
| 810 | |
| 811 | return ret; |
| 812 | } |
| 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | static char *next_cmd(char **cmds) |
| 815 | { |
| 816 | char *start = *cmds; |
| 817 | char *end; |
| 818 | |
| 819 | while ((end = strchr(start, ',')) && end == start) |
| 820 | start = end + 1; |
| 821 | |
| 822 | if (!end) |
| 823 | return NULL; |
| 824 | |
| 825 | *end = 0; |
| 826 | *cmds = end + 1; |
| 827 | return start; |
| 828 | } |
| 829 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 830 | |
| 831 | /**************************************************************************** |
| 832 | **************************************************************************** |
| 833 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 834 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 835 | * |
| 836 | **************************************************************************** |
| 837 | ****************************************************************************/ |
| 838 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 839 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 840 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 841 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 842 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 843 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 844 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 845 | |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 846 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
| 847 | pm_message_t state) |
| 848 | { |
| 849 | struct ibm_struct *ibm, *itmp; |
| 850 | |
| 851 | list_for_each_entry_safe(ibm, itmp, |
| 852 | &tpacpi_all_drivers, |
| 853 | all_drivers) { |
| 854 | if (ibm->suspend) |
| 855 | (ibm->suspend)(state); |
| 856 | } |
| 857 | |
| 858 | return 0; |
| 859 | } |
| 860 | |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 861 | static int tpacpi_resume_handler(struct platform_device *pdev) |
| 862 | { |
| 863 | struct ibm_struct *ibm, *itmp; |
| 864 | |
| 865 | list_for_each_entry_safe(ibm, itmp, |
| 866 | &tpacpi_all_drivers, |
| 867 | all_drivers) { |
| 868 | if (ibm->resume) |
| 869 | (ibm->resume)(); |
| 870 | } |
| 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 875 | static void tpacpi_shutdown_handler(struct platform_device *pdev) |
| 876 | { |
| 877 | struct ibm_struct *ibm, *itmp; |
| 878 | |
| 879 | list_for_each_entry_safe(ibm, itmp, |
| 880 | &tpacpi_all_drivers, |
| 881 | all_drivers) { |
| 882 | if (ibm->shutdown) |
| 883 | (ibm->shutdown)(); |
| 884 | } |
| 885 | } |
| 886 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 887 | static struct platform_driver tpacpi_pdriver = { |
| 888 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 889 | .name = TPACPI_DRVR_NAME, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 890 | .owner = THIS_MODULE, |
| 891 | }, |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 892 | .suspend = tpacpi_suspend_handler, |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 893 | .resume = tpacpi_resume_handler, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 894 | .shutdown = tpacpi_shutdown_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 895 | }; |
| 896 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 897 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 898 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 899 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 900 | .owner = THIS_MODULE, |
| 901 | }, |
| 902 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 903 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 904 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 905 | * sysfs support helpers |
| 906 | */ |
| 907 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 908 | struct attribute_set { |
| 909 | unsigned int members, max_members; |
| 910 | struct attribute_group group; |
| 911 | }; |
| 912 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 913 | struct attribute_set_obj { |
| 914 | struct attribute_set s; |
| 915 | struct attribute *a; |
| 916 | } __attribute__((packed)); |
| 917 | |
| 918 | 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] | 919 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 920 | { |
| 921 | struct attribute_set_obj *sobj; |
| 922 | |
| 923 | if (max_members == 0) |
| 924 | return NULL; |
| 925 | |
| 926 | /* Allocates space for implicit NULL at the end too */ |
| 927 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 928 | max_members * sizeof(struct attribute *), |
| 929 | GFP_KERNEL); |
| 930 | if (!sobj) |
| 931 | return NULL; |
| 932 | sobj->s.max_members = max_members; |
| 933 | sobj->s.group.attrs = &sobj->a; |
| 934 | sobj->s.group.name = name; |
| 935 | |
| 936 | return &sobj->s; |
| 937 | } |
| 938 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 939 | #define destroy_attr_set(_set) \ |
| 940 | kfree(_set); |
| 941 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 942 | /* 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] | 943 | 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] | 944 | { |
| 945 | if (!s || !attr) |
| 946 | return -EINVAL; |
| 947 | |
| 948 | if (s->members >= s->max_members) |
| 949 | return -ENOMEM; |
| 950 | |
| 951 | s->group.attrs[s->members] = attr; |
| 952 | s->members++; |
| 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 957 | 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] | 958 | struct attribute **attr, |
| 959 | unsigned int count) |
| 960 | { |
| 961 | int i, res; |
| 962 | |
| 963 | for (i = 0; i < count; i++) { |
| 964 | res = add_to_attr_set(s, attr[i]); |
| 965 | if (res) |
| 966 | return res; |
| 967 | } |
| 968 | |
| 969 | return 0; |
| 970 | } |
| 971 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 972 | 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] | 973 | { |
| 974 | sysfs_remove_group(kobj, &s->group); |
| 975 | destroy_attr_set(s); |
| 976 | } |
| 977 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 978 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 979 | sysfs_create_group(_kobj, &_attr_set->group) |
| 980 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 981 | static int parse_strtoul(const char *buf, |
| 982 | unsigned long max, unsigned long *value) |
| 983 | { |
| 984 | char *endp; |
| 985 | |
Henrique de Moraes Holschuh | 32afbf0 | 2007-10-08 10:12:56 -0300 | [diff] [blame] | 986 | while (*buf && isspace(*buf)) |
| 987 | buf++; |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 988 | *value = simple_strtoul(buf, &endp, 0); |
| 989 | while (*endp && isspace(*endp)) |
| 990 | endp++; |
| 991 | if (*endp || *value > max) |
| 992 | return -EINVAL; |
| 993 | |
| 994 | return 0; |
| 995 | } |
| 996 | |
Henrique de Moraes Holschuh | d64c81c4 | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 997 | static void tpacpi_disable_brightness_delay(void) |
| 998 | { |
| 999 | if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0)) |
| 1000 | printk(TPACPI_NOTICE |
| 1001 | "ACPI backlight control delay disabled\n"); |
| 1002 | } |
| 1003 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 1004 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 1005 | { |
| 1006 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 1007 | union acpi_object *obj; |
| 1008 | int rc; |
| 1009 | |
| 1010 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { |
| 1011 | obj = (union acpi_object *)buffer.pointer; |
| 1012 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
| 1013 | printk(TPACPI_ERR "Unknown _BCL data, " |
| 1014 | "please report this to %s\n", TPACPI_MAIL); |
| 1015 | rc = 0; |
| 1016 | } else { |
| 1017 | rc = obj->package.count; |
| 1018 | } |
| 1019 | } else { |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | kfree(buffer.pointer); |
| 1024 | return rc; |
| 1025 | } |
| 1026 | |
| 1027 | static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle, |
| 1028 | u32 lvl, void *context, void **rv) |
| 1029 | { |
| 1030 | char name[ACPI_PATH_SEGMENT_LENGTH]; |
| 1031 | struct acpi_buffer buffer = { sizeof(name), &name }; |
| 1032 | |
| 1033 | if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && |
| 1034 | !strncmp("_BCL", name, sizeof(name) - 1)) { |
| 1035 | BUG_ON(!rv || !*rv); |
| 1036 | **(int **)rv = tpacpi_query_bcl_levels(handle); |
| 1037 | return AE_CTRL_TERMINATE; |
| 1038 | } else { |
| 1039 | return AE_OK; |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | /* |
| 1044 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 1045 | */ |
| 1046 | static int __init tpacpi_check_std_acpi_brightness_support(void) |
| 1047 | { |
| 1048 | int status; |
| 1049 | int bcl_levels = 0; |
| 1050 | void *bcl_ptr = &bcl_levels; |
| 1051 | |
| 1052 | if (!vid_handle) { |
| 1053 | TPACPI_ACPIHANDLE_INIT(vid); |
| 1054 | } |
| 1055 | if (!vid_handle) |
| 1056 | return 0; |
| 1057 | |
| 1058 | /* |
| 1059 | * Search for a _BCL method, and execute it. This is safe on all |
| 1060 | * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista |
| 1061 | * BIOS in ACPI backlight control mode. We do NOT have to care |
| 1062 | * about calling the _BCL method in an enabled video device, any |
| 1063 | * will do for our purposes. |
| 1064 | */ |
| 1065 | |
| 1066 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, |
| 1067 | tpacpi_acpi_walk_find_bcl, NULL, |
| 1068 | &bcl_ptr); |
| 1069 | |
| 1070 | if (ACPI_SUCCESS(status) && bcl_levels > 2) { |
| 1071 | tp_features.bright_acpimode = 1; |
| 1072 | return (bcl_levels - 2); |
| 1073 | } |
| 1074 | |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 1078 | static int __init tpacpi_new_rfkill(const unsigned int id, |
| 1079 | struct rfkill **rfk, |
| 1080 | const enum rfkill_type rfktype, |
| 1081 | const char *name, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1082 | const bool set_default, |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 1083 | int (*toggle_radio)(void *, enum rfkill_state), |
| 1084 | int (*get_state)(void *, enum rfkill_state *)) |
| 1085 | { |
| 1086 | int res; |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 1087 | enum rfkill_state initial_state = RFKILL_STATE_SOFT_BLOCKED; |
| 1088 | |
| 1089 | res = get_state(NULL, &initial_state); |
| 1090 | if (res < 0) { |
| 1091 | printk(TPACPI_ERR |
| 1092 | "failed to read initial state for %s, error %d; " |
| 1093 | "will turn radio off\n", name, res); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1094 | } else if (set_default) { |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 1095 | /* try to set the initial state as the default for the rfkill |
| 1096 | * type, since we ask the firmware to preserve it across S5 in |
| 1097 | * NVRAM */ |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 1098 | if (rfkill_set_default(rfktype, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 1099 | (initial_state == RFKILL_STATE_UNBLOCKED) ? |
| 1100 | RFKILL_STATE_UNBLOCKED : |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 1101 | RFKILL_STATE_SOFT_BLOCKED) == -EPERM) |
| 1102 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 1103 | "Default state for %s cannot be changed\n", |
| 1104 | name); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 1105 | } |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 1106 | |
| 1107 | *rfk = rfkill_allocate(&tpacpi_pdev->dev, rfktype); |
| 1108 | if (!*rfk) { |
| 1109 | printk(TPACPI_ERR |
| 1110 | "failed to allocate memory for rfkill class\n"); |
| 1111 | return -ENOMEM; |
| 1112 | } |
| 1113 | |
| 1114 | (*rfk)->name = name; |
| 1115 | (*rfk)->get_state = get_state; |
| 1116 | (*rfk)->toggle_radio = toggle_radio; |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 1117 | (*rfk)->state = initial_state; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 1118 | |
| 1119 | res = rfkill_register(*rfk); |
| 1120 | if (res < 0) { |
| 1121 | printk(TPACPI_ERR |
| 1122 | "failed to register %s rfkill switch: %d\n", |
| 1123 | name, res); |
| 1124 | rfkill_free(*rfk); |
| 1125 | *rfk = NULL; |
| 1126 | return res; |
| 1127 | } |
| 1128 | |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1132 | static void printk_deprecated_attribute(const char * const what, |
| 1133 | const char * const details) |
| 1134 | { |
| 1135 | tpacpi_log_usertask("deprecated sysfs attribute"); |
| 1136 | printk(TPACPI_WARN "WARNING: sysfs attribute %s is deprecated and " |
| 1137 | "will be removed. %s\n", |
| 1138 | what, details); |
| 1139 | } |
| 1140 | |
| 1141 | static void printk_deprecated_rfkill_attribute(const char * const what) |
| 1142 | { |
| 1143 | printk_deprecated_attribute(what, |
| 1144 | "Please switch to generic rfkill before year 2010"); |
| 1145 | } |
| 1146 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1147 | /************************************************************************* |
| 1148 | * thinkpad-acpi driver attributes |
| 1149 | */ |
| 1150 | |
| 1151 | /* interface_version --------------------------------------------------- */ |
| 1152 | static ssize_t tpacpi_driver_interface_version_show( |
| 1153 | struct device_driver *drv, |
| 1154 | char *buf) |
| 1155 | { |
| 1156 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 1157 | } |
| 1158 | |
| 1159 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 1160 | tpacpi_driver_interface_version_show, NULL); |
| 1161 | |
| 1162 | /* debug_level --------------------------------------------------------- */ |
| 1163 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 1164 | char *buf) |
| 1165 | { |
| 1166 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 1167 | } |
| 1168 | |
| 1169 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 1170 | const char *buf, size_t count) |
| 1171 | { |
| 1172 | unsigned long t; |
| 1173 | |
| 1174 | if (parse_strtoul(buf, 0xffff, &t)) |
| 1175 | return -EINVAL; |
| 1176 | |
| 1177 | dbg_level = t; |
| 1178 | |
| 1179 | return count; |
| 1180 | } |
| 1181 | |
| 1182 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1183 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 1184 | |
| 1185 | /* version ------------------------------------------------------------- */ |
| 1186 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 1187 | char *buf) |
| 1188 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1189 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 1190 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | static DRIVER_ATTR(version, S_IRUGO, |
| 1194 | tpacpi_driver_version_show, NULL); |
| 1195 | |
| 1196 | /* --------------------------------------------------------------------- */ |
| 1197 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1198 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1199 | |
| 1200 | static void tpacpi_send_radiosw_update(void); |
| 1201 | |
| 1202 | /* wlsw_emulstate ------------------------------------------------------ */ |
| 1203 | static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv, |
| 1204 | char *buf) |
| 1205 | { |
| 1206 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate); |
| 1207 | } |
| 1208 | |
| 1209 | static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv, |
| 1210 | const char *buf, size_t count) |
| 1211 | { |
| 1212 | unsigned long t; |
| 1213 | |
| 1214 | if (parse_strtoul(buf, 1, &t)) |
| 1215 | return -EINVAL; |
| 1216 | |
| 1217 | if (tpacpi_wlsw_emulstate != t) { |
| 1218 | tpacpi_wlsw_emulstate = !!t; |
| 1219 | tpacpi_send_radiosw_update(); |
| 1220 | } else |
| 1221 | tpacpi_wlsw_emulstate = !!t; |
| 1222 | |
| 1223 | return count; |
| 1224 | } |
| 1225 | |
| 1226 | static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO, |
| 1227 | tpacpi_driver_wlsw_emulstate_show, |
| 1228 | tpacpi_driver_wlsw_emulstate_store); |
| 1229 | |
| 1230 | /* bluetooth_emulstate ------------------------------------------------- */ |
| 1231 | static ssize_t tpacpi_driver_bluetooth_emulstate_show( |
| 1232 | struct device_driver *drv, |
| 1233 | char *buf) |
| 1234 | { |
| 1235 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate); |
| 1236 | } |
| 1237 | |
| 1238 | static ssize_t tpacpi_driver_bluetooth_emulstate_store( |
| 1239 | struct device_driver *drv, |
| 1240 | const char *buf, size_t count) |
| 1241 | { |
| 1242 | unsigned long t; |
| 1243 | |
| 1244 | if (parse_strtoul(buf, 1, &t)) |
| 1245 | return -EINVAL; |
| 1246 | |
| 1247 | tpacpi_bluetooth_emulstate = !!t; |
| 1248 | |
| 1249 | return count; |
| 1250 | } |
| 1251 | |
| 1252 | static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO, |
| 1253 | tpacpi_driver_bluetooth_emulstate_show, |
| 1254 | tpacpi_driver_bluetooth_emulstate_store); |
| 1255 | |
| 1256 | /* wwan_emulstate ------------------------------------------------- */ |
| 1257 | static ssize_t tpacpi_driver_wwan_emulstate_show( |
| 1258 | struct device_driver *drv, |
| 1259 | char *buf) |
| 1260 | { |
| 1261 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate); |
| 1262 | } |
| 1263 | |
| 1264 | static ssize_t tpacpi_driver_wwan_emulstate_store( |
| 1265 | struct device_driver *drv, |
| 1266 | const char *buf, size_t count) |
| 1267 | { |
| 1268 | unsigned long t; |
| 1269 | |
| 1270 | if (parse_strtoul(buf, 1, &t)) |
| 1271 | return -EINVAL; |
| 1272 | |
| 1273 | tpacpi_wwan_emulstate = !!t; |
| 1274 | |
| 1275 | return count; |
| 1276 | } |
| 1277 | |
| 1278 | static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO, |
| 1279 | tpacpi_driver_wwan_emulstate_show, |
| 1280 | tpacpi_driver_wwan_emulstate_store); |
| 1281 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1282 | /* uwb_emulstate ------------------------------------------------- */ |
| 1283 | static ssize_t tpacpi_driver_uwb_emulstate_show( |
| 1284 | struct device_driver *drv, |
| 1285 | char *buf) |
| 1286 | { |
| 1287 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate); |
| 1288 | } |
| 1289 | |
| 1290 | static ssize_t tpacpi_driver_uwb_emulstate_store( |
| 1291 | struct device_driver *drv, |
| 1292 | const char *buf, size_t count) |
| 1293 | { |
| 1294 | unsigned long t; |
| 1295 | |
| 1296 | if (parse_strtoul(buf, 1, &t)) |
| 1297 | return -EINVAL; |
| 1298 | |
| 1299 | tpacpi_uwb_emulstate = !!t; |
| 1300 | |
| 1301 | return count; |
| 1302 | } |
| 1303 | |
| 1304 | static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO, |
| 1305 | tpacpi_driver_uwb_emulstate_show, |
| 1306 | tpacpi_driver_uwb_emulstate_store); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1307 | #endif |
| 1308 | |
| 1309 | /* --------------------------------------------------------------------- */ |
| 1310 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1311 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1312 | &driver_attr_debug_level, &driver_attr_version, |
| 1313 | &driver_attr_interface_version, |
| 1314 | }; |
| 1315 | |
| 1316 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 1317 | { |
| 1318 | int i, res; |
| 1319 | |
| 1320 | i = 0; |
| 1321 | res = 0; |
| 1322 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 1323 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 1324 | i++; |
| 1325 | } |
| 1326 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1327 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1328 | if (!res && dbg_wlswemul) |
| 1329 | res = driver_create_file(drv, &driver_attr_wlsw_emulstate); |
| 1330 | if (!res && dbg_bluetoothemul) |
| 1331 | res = driver_create_file(drv, &driver_attr_bluetooth_emulstate); |
| 1332 | if (!res && dbg_wwanemul) |
| 1333 | res = driver_create_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1334 | if (!res && dbg_uwbemul) |
| 1335 | res = driver_create_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1336 | #endif |
| 1337 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1338 | return res; |
| 1339 | } |
| 1340 | |
| 1341 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 1342 | { |
| 1343 | int i; |
| 1344 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1345 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1346 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1347 | |
| 1348 | #ifdef THINKPAD_ACPI_DEBUGFACILITIES |
| 1349 | driver_remove_file(drv, &driver_attr_wlsw_emulstate); |
| 1350 | driver_remove_file(drv, &driver_attr_bluetooth_emulstate); |
| 1351 | driver_remove_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1352 | driver_remove_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1353 | #endif |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1354 | } |
| 1355 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1356 | /**************************************************************************** |
| 1357 | **************************************************************************** |
| 1358 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1359 | * Subdrivers |
| 1360 | * |
| 1361 | **************************************************************************** |
| 1362 | ****************************************************************************/ |
| 1363 | |
| 1364 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 1365 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1366 | */ |
| 1367 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1368 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1370 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 1371 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1373 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1374 | (thinkpad_id.bios_version_str) ? |
| 1375 | thinkpad_id.bios_version_str : "unknown", |
| 1376 | (thinkpad_id.ec_version_str) ? |
| 1377 | thinkpad_id.ec_version_str : "unknown"); |
| 1378 | |
| 1379 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1380 | printk(TPACPI_INFO "%s %s, model %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1381 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 1382 | "IBM" : ((thinkpad_id.vendor == |
| 1383 | PCI_VENDOR_ID_LENOVO) ? |
| 1384 | "Lenovo" : "Unknown vendor"), |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1385 | thinkpad_id.model_str, |
| 1386 | (thinkpad_id.nummodel_str) ? |
| 1387 | thinkpad_id.nummodel_str : "unknown"); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 1388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | return 0; |
| 1390 | } |
| 1391 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1392 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | { |
| 1394 | int len = 0; |
| 1395 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1396 | len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); |
| 1397 | len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | |
| 1399 | return len; |
| 1400 | } |
| 1401 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1402 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1403 | .name = "driver", |
| 1404 | .read = thinkpad_acpi_driver_read, |
| 1405 | }; |
| 1406 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1407 | /************************************************************************* |
| 1408 | * Hotkey subdriver |
| 1409 | */ |
| 1410 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1411 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1412 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1413 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1414 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1415 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1416 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1417 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1418 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1419 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1420 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1421 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1422 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1423 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1424 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1425 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1426 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1427 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1428 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1429 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1430 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1431 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1432 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1433 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1434 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1435 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1436 | }; |
| 1437 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1438 | enum { /* Keys available through NVRAM polling */ |
| 1439 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1440 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1441 | }; |
| 1442 | |
| 1443 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1444 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1445 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1446 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1447 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1448 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1449 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1450 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1451 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1452 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1453 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1454 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1455 | }; |
| 1456 | |
| 1457 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1458 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1459 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1460 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1461 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1462 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1463 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1464 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1465 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1466 | TP_ACPI_HKEY_MUTE_MASK, |
| 1467 | }; |
| 1468 | |
| 1469 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1470 | struct tp_nvram_state { |
| 1471 | u16 thinkpad_toggle:1; |
| 1472 | u16 zoom_toggle:1; |
| 1473 | u16 display_toggle:1; |
| 1474 | u16 thinklight_toggle:1; |
| 1475 | u16 hibernate_toggle:1; |
| 1476 | u16 displayexp_toggle:1; |
| 1477 | u16 display_state:1; |
| 1478 | u16 brightness_toggle:1; |
| 1479 | u16 volume_toggle:1; |
| 1480 | u16 mute:1; |
| 1481 | |
| 1482 | u8 brightness_level; |
| 1483 | u8 volume_level; |
| 1484 | }; |
| 1485 | |
| 1486 | static struct task_struct *tpacpi_hotkey_task; |
| 1487 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 1488 | static int hotkey_poll_freq = 10; /* Hz */ |
| 1489 | static struct mutex hotkey_thread_mutex; |
| 1490 | static struct mutex hotkey_thread_data_mutex; |
| 1491 | static unsigned int hotkey_config_change; |
| 1492 | |
| 1493 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1494 | |
| 1495 | #define hotkey_source_mask 0U |
| 1496 | |
| 1497 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1498 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1499 | static struct mutex hotkey_mutex; |
| 1500 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1501 | static enum { /* Reasons for waking up */ |
| 1502 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 1503 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 1504 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 1505 | } hotkey_wakeup_reason; |
| 1506 | |
| 1507 | static int hotkey_autosleep_ack; |
| 1508 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1509 | static u32 hotkey_orig_mask; |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1510 | static u32 hotkey_all_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1511 | static u32 hotkey_reserved_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1512 | static u32 hotkey_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1513 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1514 | static unsigned int hotkey_report_mode; |
| 1515 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1516 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1517 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 1518 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1519 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1520 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1521 | #define HOTKEY_CONFIG_CRITICAL_START \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1522 | do { \ |
| 1523 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 1524 | hotkey_config_change++; \ |
| 1525 | } while (0); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1526 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 1527 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1528 | #else |
| 1529 | #define HOTKEY_CONFIG_CRITICAL_START |
| 1530 | #define HOTKEY_CONFIG_CRITICAL_END |
| 1531 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1532 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1533 | /* HKEY.MHKG() return bits */ |
| 1534 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 1535 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1536 | static int hotkey_get_wlsw(int *status) |
| 1537 | { |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1538 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1539 | if (dbg_wlswemul) { |
| 1540 | *status = !!tpacpi_wlsw_emulstate; |
| 1541 | return 0; |
| 1542 | } |
| 1543 | #endif |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1544 | if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) |
| 1545 | return -EIO; |
| 1546 | return 0; |
| 1547 | } |
| 1548 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1549 | static int hotkey_get_tablet_mode(int *status) |
| 1550 | { |
| 1551 | int s; |
| 1552 | |
| 1553 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 1554 | return -EIO; |
| 1555 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 1556 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 1557 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1558 | } |
| 1559 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1560 | /* |
| 1561 | * Call with hotkey_mutex held |
| 1562 | */ |
| 1563 | static int hotkey_mask_get(void) |
| 1564 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1565 | u32 m = 0; |
| 1566 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1567 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1568 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1569 | return -EIO; |
| 1570 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1571 | hotkey_mask = m | (hotkey_source_mask & hotkey_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1572 | |
| 1573 | return 0; |
| 1574 | } |
| 1575 | |
| 1576 | /* |
| 1577 | * Call with hotkey_mutex held |
| 1578 | */ |
| 1579 | static int hotkey_mask_set(u32 mask) |
| 1580 | { |
| 1581 | int i; |
| 1582 | int rc = 0; |
| 1583 | |
| 1584 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 1585 | if (!tp_warned.hotkey_mask_ff && |
| 1586 | (mask == 0xffff || mask == 0xffffff || |
| 1587 | mask == 0xffffffff)) { |
| 1588 | tp_warned.hotkey_mask_ff = 1; |
| 1589 | printk(TPACPI_NOTICE |
| 1590 | "setting the hotkey mask to 0x%08x is likely " |
| 1591 | "not the best way to go about it\n", mask); |
| 1592 | printk(TPACPI_NOTICE |
| 1593 | "please consider using the driver defaults, " |
| 1594 | "and refer to up-to-date thinkpad-acpi " |
| 1595 | "documentation\n"); |
| 1596 | } |
| 1597 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1598 | HOTKEY_CONFIG_CRITICAL_START |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1599 | for (i = 0; i < 32; i++) { |
| 1600 | u32 m = 1 << i; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1601 | /* enable in firmware mask only keys not in NVRAM |
| 1602 | * mode, but enable the key in the cached hotkey_mask |
| 1603 | * regardless of mode, or the key will end up |
| 1604 | * disabled by hotkey_mask_get() */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1605 | if (!acpi_evalf(hkey_handle, |
| 1606 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1607 | !!((mask & ~hotkey_source_mask) & m))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1608 | rc = -EIO; |
| 1609 | break; |
| 1610 | } else { |
| 1611 | hotkey_mask = (hotkey_mask & ~m) | (mask & m); |
| 1612 | } |
| 1613 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1614 | HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1615 | |
| 1616 | /* hotkey_mask_get must be called unconditionally below */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1617 | if (!hotkey_mask_get() && !rc && |
| 1618 | (hotkey_mask & ~hotkey_source_mask) != |
| 1619 | (mask & ~hotkey_source_mask)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1620 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1621 | "requested hot key mask 0x%08x, but " |
| 1622 | "firmware forced it to 0x%08x\n", |
| 1623 | mask, hotkey_mask); |
| 1624 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1625 | } else { |
| 1626 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1627 | HOTKEY_CONFIG_CRITICAL_START |
| 1628 | hotkey_mask = mask & hotkey_source_mask; |
| 1629 | HOTKEY_CONFIG_CRITICAL_END |
| 1630 | hotkey_mask_get(); |
| 1631 | if (hotkey_mask != mask) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1632 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1633 | "requested hot key mask 0x%08x, " |
| 1634 | "forced to 0x%08x (NVRAM poll mask is " |
| 1635 | "0x%08x): no firmware mask support\n", |
| 1636 | mask, hotkey_mask, hotkey_source_mask); |
| 1637 | } |
| 1638 | #else |
| 1639 | hotkey_mask_get(); |
| 1640 | rc = -ENXIO; |
| 1641 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | return rc; |
| 1645 | } |
| 1646 | |
| 1647 | static int hotkey_status_get(int *status) |
| 1648 | { |
| 1649 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 1650 | return -EIO; |
| 1651 | |
| 1652 | return 0; |
| 1653 | } |
| 1654 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 1655 | static int hotkey_status_set(bool enable) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1656 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 1657 | 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] | 1658 | return -EIO; |
| 1659 | |
| 1660 | return 0; |
| 1661 | } |
| 1662 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1663 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1664 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1665 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1666 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1667 | if (tp_features.hotkey_tablet && |
| 1668 | !hotkey_get_tablet_mode(&state)) { |
| 1669 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1670 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1671 | input_report_switch(tpacpi_inputdev, |
| 1672 | SW_TABLET_MODE, !!state); |
| 1673 | input_sync(tpacpi_inputdev); |
| 1674 | |
| 1675 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1676 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1677 | } |
| 1678 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1679 | static void tpacpi_input_send_key(unsigned int scancode) |
| 1680 | { |
| 1681 | unsigned int keycode; |
| 1682 | |
| 1683 | keycode = hotkey_keycode_map[scancode]; |
| 1684 | |
| 1685 | if (keycode != KEY_RESERVED) { |
| 1686 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1687 | |
| 1688 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 1689 | if (keycode == KEY_UNKNOWN) |
| 1690 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1691 | scancode); |
| 1692 | input_sync(tpacpi_inputdev); |
| 1693 | |
| 1694 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 1695 | if (keycode == KEY_UNKNOWN) |
| 1696 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1697 | scancode); |
| 1698 | input_sync(tpacpi_inputdev); |
| 1699 | |
| 1700 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1701 | } |
| 1702 | } |
| 1703 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1704 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1705 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 1706 | |
| 1707 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 1708 | { |
| 1709 | tpacpi_input_send_key(scancode); |
| 1710 | if (hotkey_report_mode < 2) { |
| 1711 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
| 1712 | 0x80, 0x1001 + scancode); |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m) |
| 1717 | { |
| 1718 | u8 d; |
| 1719 | |
| 1720 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 1721 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 1722 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 1723 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 1724 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 1725 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 1726 | } |
| 1727 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 1728 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 1729 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 1730 | } |
| 1731 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 1732 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 1733 | n->displayexp_toggle = |
| 1734 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 1735 | } |
| 1736 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 1737 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 1738 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 1739 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 1740 | n->brightness_toggle = |
| 1741 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 1742 | } |
| 1743 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 1744 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 1745 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 1746 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 1747 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 1748 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1753 | do { \ |
| 1754 | if ((mask & (1 << __scancode)) && \ |
| 1755 | oldn->__member != newn->__member) \ |
| 1756 | tpacpi_hotkey_send_key(__scancode); \ |
| 1757 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1758 | |
| 1759 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
| 1760 | do { if (mask & (1 << __scancode)) \ |
| 1761 | tpacpi_hotkey_send_key(__scancode); } while (0) |
| 1762 | |
| 1763 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1764 | struct tp_nvram_state *newn, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1765 | u32 mask) |
| 1766 | { |
| 1767 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 1768 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 1769 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 1770 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 1771 | |
| 1772 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 1773 | |
| 1774 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 1775 | |
| 1776 | /* handle volume */ |
| 1777 | if (oldn->volume_toggle != newn->volume_toggle) { |
| 1778 | if (oldn->mute != newn->mute) { |
| 1779 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1780 | } |
| 1781 | if (oldn->volume_level > newn->volume_level) { |
| 1782 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1783 | } else if (oldn->volume_level < newn->volume_level) { |
| 1784 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1785 | } else if (oldn->mute == newn->mute) { |
| 1786 | /* repeated key presses that didn't change state */ |
| 1787 | if (newn->mute) { |
| 1788 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1789 | } else if (newn->volume_level != 0) { |
| 1790 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1791 | } else { |
| 1792 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1793 | } |
| 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | /* handle brightness */ |
| 1798 | if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 1799 | if (oldn->brightness_level < newn->brightness_level) { |
| 1800 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1801 | } else if (oldn->brightness_level > newn->brightness_level) { |
| 1802 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1803 | } else { |
| 1804 | /* repeated key presses that didn't change state */ |
| 1805 | if (newn->brightness_level != 0) { |
| 1806 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1807 | } else { |
| 1808 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1809 | } |
| 1810 | } |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | #undef TPACPI_COMPARE_KEY |
| 1815 | #undef TPACPI_MAY_SEND_KEY |
| 1816 | |
| 1817 | static int hotkey_kthread(void *data) |
| 1818 | { |
| 1819 | struct tp_nvram_state s[2]; |
| 1820 | u32 mask; |
| 1821 | unsigned int si, so; |
| 1822 | unsigned long t; |
| 1823 | unsigned int change_detector, must_reset; |
| 1824 | |
| 1825 | mutex_lock(&hotkey_thread_mutex); |
| 1826 | |
| 1827 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 1828 | goto exit; |
| 1829 | |
| 1830 | set_freezable(); |
| 1831 | |
| 1832 | so = 0; |
| 1833 | si = 1; |
| 1834 | t = 0; |
| 1835 | |
| 1836 | /* Initial state for compares */ |
| 1837 | mutex_lock(&hotkey_thread_data_mutex); |
| 1838 | change_detector = hotkey_config_change; |
| 1839 | mask = hotkey_source_mask & hotkey_mask; |
| 1840 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1841 | hotkey_read_nvram(&s[so], mask); |
| 1842 | |
| 1843 | while (!kthread_should_stop() && hotkey_poll_freq) { |
| 1844 | if (t == 0) |
| 1845 | t = 1000/hotkey_poll_freq; |
| 1846 | t = msleep_interruptible(t); |
| 1847 | if (unlikely(kthread_should_stop())) |
| 1848 | break; |
| 1849 | must_reset = try_to_freeze(); |
| 1850 | if (t > 0 && !must_reset) |
| 1851 | continue; |
| 1852 | |
| 1853 | mutex_lock(&hotkey_thread_data_mutex); |
| 1854 | if (must_reset || hotkey_config_change != change_detector) { |
| 1855 | /* forget old state on thaw or config change */ |
| 1856 | si = so; |
| 1857 | t = 0; |
| 1858 | change_detector = hotkey_config_change; |
| 1859 | } |
| 1860 | mask = hotkey_source_mask & hotkey_mask; |
| 1861 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1862 | |
| 1863 | if (likely(mask)) { |
| 1864 | hotkey_read_nvram(&s[si], mask); |
| 1865 | if (likely(si != so)) { |
| 1866 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1867 | mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | so = si; |
| 1872 | si ^= 1; |
| 1873 | } |
| 1874 | |
| 1875 | exit: |
| 1876 | mutex_unlock(&hotkey_thread_mutex); |
| 1877 | return 0; |
| 1878 | } |
| 1879 | |
| 1880 | static void hotkey_poll_stop_sync(void) |
| 1881 | { |
| 1882 | if (tpacpi_hotkey_task) { |
| 1883 | if (frozen(tpacpi_hotkey_task) || |
| 1884 | freezing(tpacpi_hotkey_task)) |
| 1885 | thaw_process(tpacpi_hotkey_task); |
| 1886 | |
| 1887 | kthread_stop(tpacpi_hotkey_task); |
| 1888 | tpacpi_hotkey_task = NULL; |
| 1889 | mutex_lock(&hotkey_thread_mutex); |
| 1890 | /* at this point, the thread did exit */ |
| 1891 | mutex_unlock(&hotkey_thread_mutex); |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | /* call with hotkey_mutex held */ |
| 1896 | static void hotkey_poll_setup(int may_warn) |
| 1897 | { |
| 1898 | if ((hotkey_source_mask & hotkey_mask) != 0 && |
| 1899 | hotkey_poll_freq > 0 && |
| 1900 | (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { |
| 1901 | if (!tpacpi_hotkey_task) { |
| 1902 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 1903 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1904 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 1905 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1906 | printk(TPACPI_ERR |
| 1907 | "could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1908 | "for hotkey polling\n"); |
| 1909 | } |
| 1910 | } |
| 1911 | } else { |
| 1912 | hotkey_poll_stop_sync(); |
| 1913 | if (may_warn && |
| 1914 | hotkey_source_mask != 0 && hotkey_poll_freq == 0) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1915 | printk(TPACPI_NOTICE |
| 1916 | "hot keys 0x%08x require polling, " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1917 | "which is currently disabled\n", |
| 1918 | hotkey_source_mask); |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | static void hotkey_poll_setup_safe(int may_warn) |
| 1924 | { |
| 1925 | mutex_lock(&hotkey_mutex); |
| 1926 | hotkey_poll_setup(may_warn); |
| 1927 | mutex_unlock(&hotkey_mutex); |
| 1928 | } |
| 1929 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 1930 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1931 | |
| 1932 | static void hotkey_poll_setup_safe(int __unused) |
| 1933 | { |
| 1934 | } |
| 1935 | |
| 1936 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1937 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1938 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 1939 | { |
| 1940 | switch (tpacpi_lifecycle) { |
| 1941 | case TPACPI_LIFE_INIT: |
| 1942 | /* |
| 1943 | * hotkey_init will call hotkey_poll_setup_safe |
| 1944 | * at the appropriate moment |
| 1945 | */ |
| 1946 | return 0; |
| 1947 | case TPACPI_LIFE_EXITING: |
| 1948 | return -EBUSY; |
| 1949 | case TPACPI_LIFE_RUNNING: |
| 1950 | hotkey_poll_setup_safe(0); |
| 1951 | return 0; |
| 1952 | } |
| 1953 | |
| 1954 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 1955 | BUG(); |
| 1956 | return -EBUSY; |
| 1957 | } |
| 1958 | |
| 1959 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 1960 | { |
| 1961 | /* disable hotkey polling when possible */ |
| 1962 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING) |
| 1963 | hotkey_poll_setup_safe(0); |
| 1964 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1965 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1966 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 1967 | static ssize_t hotkey_enable_show(struct device *dev, |
| 1968 | struct device_attribute *attr, |
| 1969 | char *buf) |
| 1970 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1971 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1972 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 1973 | printk_deprecated_attribute("hotkey_enable", |
| 1974 | "Hotkey reporting is always enabled"); |
| 1975 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1976 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1977 | if (res) |
| 1978 | return res; |
| 1979 | |
| 1980 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 1981 | } |
| 1982 | |
| 1983 | static ssize_t hotkey_enable_store(struct device *dev, |
| 1984 | struct device_attribute *attr, |
| 1985 | const char *buf, size_t count) |
| 1986 | { |
| 1987 | unsigned long t; |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 1988 | |
| 1989 | printk_deprecated_attribute("hotkey_enable", |
| 1990 | "Hotkeys can be disabled through hotkey_mask"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1991 | |
| 1992 | if (parse_strtoul(buf, 1, &t)) |
| 1993 | return -EINVAL; |
| 1994 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 1995 | if (t == 0) |
| 1996 | return -EPERM; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1997 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 1998 | return count; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2002 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2003 | hotkey_enable_show, hotkey_enable_store); |
| 2004 | |
| 2005 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 2006 | static ssize_t hotkey_mask_show(struct device *dev, |
| 2007 | struct device_attribute *attr, |
| 2008 | char *buf) |
| 2009 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2010 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2011 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2012 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2013 | return -ERESTARTSYS; |
| 2014 | res = hotkey_mask_get(); |
| 2015 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2016 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2017 | return (res)? |
| 2018 | res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | static ssize_t hotkey_mask_store(struct device *dev, |
| 2022 | struct device_attribute *attr, |
| 2023 | const char *buf, size_t count) |
| 2024 | { |
| 2025 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2026 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2027 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2028 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2029 | return -EINVAL; |
| 2030 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2031 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2032 | return -ERESTARTSYS; |
| 2033 | |
| 2034 | res = hotkey_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2035 | |
| 2036 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2037 | hotkey_poll_setup(1); |
| 2038 | #endif |
| 2039 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2040 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2041 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2042 | tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t); |
| 2043 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2044 | return (res) ? res : count; |
| 2045 | } |
| 2046 | |
| 2047 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2048 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2049 | hotkey_mask_show, hotkey_mask_store); |
| 2050 | |
| 2051 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 2052 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 2053 | struct device_attribute *attr, |
| 2054 | char *buf) |
| 2055 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2056 | return sprintf(buf, "0\n"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2060 | __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] | 2061 | |
| 2062 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 2063 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 2064 | struct device_attribute *attr, |
| 2065 | char *buf) |
| 2066 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2067 | 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] | 2068 | } |
| 2069 | |
| 2070 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2071 | __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] | 2072 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2073 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 2074 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 2075 | struct device_attribute *attr, |
| 2076 | char *buf) |
| 2077 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2078 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 2079 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 2083 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 2084 | |
| 2085 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 2086 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 2087 | struct device_attribute *attr, |
| 2088 | char *buf) |
| 2089 | { |
| 2090 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2091 | (hotkey_all_mask | hotkey_source_mask) |
| 2092 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 2096 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 2097 | hotkey_recommended_mask_show, NULL); |
| 2098 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2099 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2100 | |
| 2101 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 2102 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 2103 | struct device_attribute *attr, |
| 2104 | char *buf) |
| 2105 | { |
| 2106 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 2107 | } |
| 2108 | |
| 2109 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 2110 | struct device_attribute *attr, |
| 2111 | const char *buf, size_t count) |
| 2112 | { |
| 2113 | unsigned long t; |
| 2114 | |
| 2115 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 2116 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 2117 | return -EINVAL; |
| 2118 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2119 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2120 | return -ERESTARTSYS; |
| 2121 | |
| 2122 | HOTKEY_CONFIG_CRITICAL_START |
| 2123 | hotkey_source_mask = t; |
| 2124 | HOTKEY_CONFIG_CRITICAL_END |
| 2125 | |
| 2126 | hotkey_poll_setup(1); |
| 2127 | |
| 2128 | mutex_unlock(&hotkey_mutex); |
| 2129 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2130 | tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); |
| 2131 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2132 | return count; |
| 2133 | } |
| 2134 | |
| 2135 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 2136 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 2137 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 2138 | |
| 2139 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 2140 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 2141 | struct device_attribute *attr, |
| 2142 | char *buf) |
| 2143 | { |
| 2144 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 2145 | } |
| 2146 | |
| 2147 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 2148 | struct device_attribute *attr, |
| 2149 | const char *buf, size_t count) |
| 2150 | { |
| 2151 | unsigned long t; |
| 2152 | |
| 2153 | if (parse_strtoul(buf, 25, &t)) |
| 2154 | return -EINVAL; |
| 2155 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2156 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2157 | return -ERESTARTSYS; |
| 2158 | |
| 2159 | hotkey_poll_freq = t; |
| 2160 | |
| 2161 | hotkey_poll_setup(1); |
| 2162 | mutex_unlock(&hotkey_mutex); |
| 2163 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2164 | tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t); |
| 2165 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2166 | return count; |
| 2167 | } |
| 2168 | |
| 2169 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 2170 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 2171 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 2172 | |
| 2173 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2174 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2175 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2176 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 2177 | struct device_attribute *attr, |
| 2178 | char *buf) |
| 2179 | { |
| 2180 | int res, s; |
| 2181 | res = hotkey_get_wlsw(&s); |
| 2182 | if (res < 0) |
| 2183 | return res; |
| 2184 | |
| 2185 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 2186 | } |
| 2187 | |
| 2188 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 2189 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 2190 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2191 | static void hotkey_radio_sw_notify_change(void) |
| 2192 | { |
| 2193 | if (tp_features.hotkey_wlsw) |
| 2194 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2195 | "hotkey_radio_sw"); |
| 2196 | } |
| 2197 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2198 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 2199 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 2200 | struct device_attribute *attr, |
| 2201 | char *buf) |
| 2202 | { |
| 2203 | int res, s; |
| 2204 | res = hotkey_get_tablet_mode(&s); |
| 2205 | if (res < 0) |
| 2206 | return res; |
| 2207 | |
| 2208 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 2209 | } |
| 2210 | |
| 2211 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 2212 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 2213 | |
| 2214 | static void hotkey_tablet_mode_notify_change(void) |
| 2215 | { |
| 2216 | if (tp_features.hotkey_tablet) |
| 2217 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2218 | "hotkey_tablet_mode"); |
| 2219 | } |
| 2220 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2221 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 2222 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 2223 | struct device_attribute *attr, |
| 2224 | char *buf) |
| 2225 | { |
| 2226 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2227 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 2228 | } |
| 2229 | |
| 2230 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 2231 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 2232 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2233 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2234 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 2235 | struct device_attribute *attr, |
| 2236 | char *buf) |
| 2237 | { |
| 2238 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 2239 | } |
| 2240 | |
| 2241 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 2242 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 2243 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2244 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2245 | { |
| 2246 | if (tp_features.hotkey_mask) |
| 2247 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2248 | "wakeup_reason"); |
| 2249 | } |
| 2250 | |
| 2251 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2252 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 2253 | struct device_attribute *attr, |
| 2254 | char *buf) |
| 2255 | { |
| 2256 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 2257 | } |
| 2258 | |
| 2259 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 2260 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 2261 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 2262 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2263 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2264 | { |
| 2265 | if (tp_features.hotkey_mask) |
| 2266 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2267 | "wakeup_hotunplug_complete"); |
| 2268 | } |
| 2269 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2270 | /* --------------------------------------------------------------------- */ |
| 2271 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2272 | static struct attribute *hotkey_attributes[] __initdata = { |
| 2273 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2274 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2275 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2276 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2277 | &dev_attr_hotkey_mask.attr, |
| 2278 | &dev_attr_hotkey_all_mask.attr, |
| 2279 | &dev_attr_hotkey_recommended_mask.attr, |
| 2280 | &dev_attr_hotkey_source_mask.attr, |
| 2281 | &dev_attr_hotkey_poll_freq.attr, |
| 2282 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2283 | }; |
| 2284 | |
| 2285 | static struct attribute *hotkey_mask_attributes[] __initdata = { |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2286 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2287 | #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2288 | &dev_attr_hotkey_mask.attr, |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2289 | &dev_attr_hotkey_all_mask.attr, |
| 2290 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2291 | #endif |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2292 | &dev_attr_hotkey_wakeup_reason.attr, |
| 2293 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2294 | }; |
| 2295 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 2296 | static void bluetooth_update_rfk(void); |
| 2297 | static void wan_update_rfk(void); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 2298 | static void uwb_update_rfk(void); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2299 | static void tpacpi_send_radiosw_update(void) |
| 2300 | { |
| 2301 | int wlsw; |
| 2302 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 2303 | /* Sync these BEFORE sending any rfkill events */ |
| 2304 | if (tp_features.bluetooth) |
| 2305 | bluetooth_update_rfk(); |
| 2306 | if (tp_features.wan) |
| 2307 | wan_update_rfk(); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 2308 | if (tp_features.uwb) |
| 2309 | uwb_update_rfk(); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 2310 | |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2311 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { |
| 2312 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2313 | |
| 2314 | input_report_switch(tpacpi_inputdev, |
| 2315 | SW_RFKILL_ALL, !!wlsw); |
| 2316 | input_sync(tpacpi_inputdev); |
| 2317 | |
| 2318 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2319 | } |
| 2320 | hotkey_radio_sw_notify_change(); |
| 2321 | } |
| 2322 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2323 | static void hotkey_exit(void) |
| 2324 | { |
| 2325 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2326 | hotkey_poll_stop_sync(); |
| 2327 | #endif |
| 2328 | |
| 2329 | if (hotkey_dev_attributes) |
| 2330 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 2331 | |
| 2332 | kfree(hotkey_keycode_map); |
| 2333 | |
| 2334 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2335 | dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2336 | "restoring original hot key mask\n"); |
| 2337 | /* no short-circuit boolean operator below! */ |
| 2338 | if ((hotkey_mask_set(hotkey_orig_mask) | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2339 | hotkey_status_set(false)) != 0) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2340 | printk(TPACPI_ERR |
| 2341 | "failed to restore hot key mask " |
| 2342 | "to BIOS defaults\n"); |
| 2343 | } |
| 2344 | } |
| 2345 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2346 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2347 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2348 | /* Requirements for changing the default keymaps: |
| 2349 | * |
| 2350 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 2351 | * good reasons. Do not change them unless you have deep |
| 2352 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 2353 | * the various ThinkPad models. The driver behaves |
| 2354 | * differently for KEY_RESERVED: such keys have their |
| 2355 | * hot key mask *unset* in mask_recommended, and also |
| 2356 | * in the initial hot key mask programmed into the |
| 2357 | * firmware at driver load time, which means the firm- |
| 2358 | * ware may react very differently if you change them to |
| 2359 | * something else; |
| 2360 | * |
| 2361 | * 2. You must be subscribed to the linux-thinkpad and |
| 2362 | * ibm-acpi-devel mailing lists, and you should read the |
| 2363 | * list archives since 2007 if you want to change the |
| 2364 | * keymaps. This requirement exists so that you will |
| 2365 | * know the past history of problems with the thinkpad- |
| 2366 | * acpi driver keymaps, and also that you will be |
| 2367 | * listening to any bug reports; |
| 2368 | * |
| 2369 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 2370 | * for merging, *ever*. Send them to the linux-acpi |
| 2371 | * mailinglist for comments. Merging is to be done only |
| 2372 | * through acpi-test and the ACPI maintainer. |
| 2373 | * |
| 2374 | * If the above is too much to ask, don't change the keymap. |
| 2375 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 2376 | */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2377 | static u16 ibm_keycode_map[] __initdata = { |
| 2378 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 2379 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
| 2380 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 2381 | 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] | 2382 | |
| 2383 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2384 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 2385 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 2386 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2387 | |
| 2388 | /* brightness: firmware always reacts to them, unless |
| 2389 | * X.org did some tricks in the radeon BIOS scratch |
| 2390 | * registers of *some* models */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2391 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2392 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2393 | |
| 2394 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2395 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2396 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2397 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 2398 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2399 | |
| 2400 | /* Volume: firmware always react to it and reprograms |
| 2401 | * the built-in *extra* mixer. Never map it to control |
| 2402 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2403 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2404 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2405 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2406 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2407 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2408 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2409 | /* (assignments unknown, please report if found) */ |
| 2410 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2411 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2412 | }; |
| 2413 | static u16 lenovo_keycode_map[] __initdata = { |
| 2414 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 2415 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
| 2416 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 2417 | 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] | 2418 | |
| 2419 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2420 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 2421 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 2422 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2423 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 2424 | /* These either have to go through ACPI video, or |
| 2425 | * act like in the IBM ThinkPads, so don't ever |
| 2426 | * enable them by default */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 2427 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 2428 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2429 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2430 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2431 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2432 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 2433 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2434 | |
| 2435 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 2436 | * react to it and reprograms the built-in *extra* mixer. |
| 2437 | * Never map it to control another mixer by default. |
| 2438 | * |
| 2439 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 2440 | * these over the regular keyboard, so these are no-ops, |
| 2441 | * but there are still weird bugs re. MUTE, so do not |
| 2442 | * change unless you get test reports from all Lenovo |
| 2443 | * models. May cause the BIOS to interfere with the |
| 2444 | * HDA mixer. |
| 2445 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2446 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2447 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2448 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2449 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2450 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2451 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2452 | /* (assignments unknown, please report if found) */ |
| 2453 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2454 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2455 | }; |
| 2456 | |
| 2457 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) |
| 2458 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) |
| 2459 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) |
| 2460 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2461 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2462 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2463 | int hkeyv; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2464 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2465 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 2466 | "initializing hotkey subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2467 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2468 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2469 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 2470 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2471 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2472 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2473 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2474 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2475 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2476 | mutex_init(&hotkey_thread_mutex); |
| 2477 | mutex_init(&hotkey_thread_data_mutex); |
| 2478 | #endif |
| 2479 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2480 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2481 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2482 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2483 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 2484 | "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2485 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2486 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2487 | if (!tp_features.hotkey) |
| 2488 | return 1; |
| 2489 | |
Henrique de Moraes Holschuh | d64c81c4 | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 2490 | tpacpi_disable_brightness_delay(); |
| 2491 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2492 | hotkey_dev_attributes = create_attr_set(13, NULL); |
| 2493 | if (!hotkey_dev_attributes) |
| 2494 | return -ENOMEM; |
| 2495 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 2496 | hotkey_attributes, |
| 2497 | ARRAY_SIZE(hotkey_attributes)); |
| 2498 | if (res) |
| 2499 | goto err_exit; |
| 2500 | |
| 2501 | /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 2502 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 2503 | for HKEY interface version 0x100 */ |
| 2504 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 2505 | if ((hkeyv >> 8) != 1) { |
| 2506 | printk(TPACPI_ERR "unknown version of the " |
| 2507 | "HKEY interface: 0x%x\n", hkeyv); |
| 2508 | printk(TPACPI_ERR "please report this to %s\n", |
| 2509 | TPACPI_MAIL); |
| 2510 | } else { |
| 2511 | /* |
| 2512 | * MHKV 0x100 in A31, R40, R40e, |
| 2513 | * T4x, X31, and later |
| 2514 | */ |
| 2515 | tp_features.hotkey_mask = 1; |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2516 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 2517 | "firmware HKEY interface version: 0x%x\n", |
| 2518 | hkeyv); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2522 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 2523 | "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2524 | str_supported(tp_features.hotkey_mask)); |
| 2525 | |
| 2526 | if (tp_features.hotkey_mask) { |
| 2527 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
| 2528 | "MHKA", "qd")) { |
| 2529 | printk(TPACPI_ERR |
| 2530 | "missing MHKA handler, " |
| 2531 | "please report this to %s\n", |
| 2532 | TPACPI_MAIL); |
| 2533 | /* FN+F12, FN+F4, FN+F3 */ |
| 2534 | hotkey_all_mask = 0x080cU; |
| 2535 | } |
| 2536 | } |
| 2537 | |
| 2538 | /* hotkey_source_mask *must* be zero for |
| 2539 | * the first hotkey_mask_get */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2540 | if (tp_features.hotkey_mask) { |
| 2541 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2542 | if (res) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2543 | goto err_exit; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2544 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2545 | hotkey_orig_mask = hotkey_mask; |
| 2546 | res = add_many_to_attr_set( |
| 2547 | hotkey_dev_attributes, |
| 2548 | hotkey_mask_attributes, |
| 2549 | ARRAY_SIZE(hotkey_mask_attributes)); |
| 2550 | if (res) |
| 2551 | goto err_exit; |
| 2552 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2553 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2554 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2555 | if (tp_features.hotkey_mask) { |
| 2556 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 2557 | & ~hotkey_all_mask; |
| 2558 | } else { |
| 2559 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK; |
| 2560 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2561 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2562 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2563 | "hotkey source mask 0x%08x, polling freq %d\n", |
| 2564 | hotkey_source_mask, hotkey_poll_freq); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2565 | #endif |
| 2566 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2567 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 2568 | if (dbg_wlswemul) { |
| 2569 | tp_features.hotkey_wlsw = 1; |
| 2570 | printk(TPACPI_INFO |
| 2571 | "radio switch emulation enabled\n"); |
| 2572 | } else |
| 2573 | #endif |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2574 | /* Not all thinkpads have a hardware radio switch */ |
| 2575 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 2576 | tp_features.hotkey_wlsw = 1; |
| 2577 | printk(TPACPI_INFO |
| 2578 | "radio switch found; radios are %s\n", |
| 2579 | enabled(status, 0)); |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2580 | } |
| 2581 | if (tp_features.hotkey_wlsw) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2582 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2583 | &dev_attr_hotkey_radio_sw.attr); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2584 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2585 | /* For X41t, X60t, X61t Tablets... */ |
| 2586 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 2587 | tp_features.hotkey_tablet = 1; |
| 2588 | printk(TPACPI_INFO |
| 2589 | "possible tablet mode switch found; " |
| 2590 | "ThinkPad in %s mode\n", |
| 2591 | (status & TP_HOTKEY_TABLET_MASK)? |
| 2592 | "tablet" : "laptop"); |
| 2593 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2594 | &dev_attr_hotkey_tablet_mode.attr); |
| 2595 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2596 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2597 | if (!res) |
| 2598 | res = register_attr_set_with_sysfs( |
| 2599 | hotkey_dev_attributes, |
| 2600 | &tpacpi_pdev->dev.kobj); |
| 2601 | if (res) |
| 2602 | goto err_exit; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2603 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2604 | /* Set up key map */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2605 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2606 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 2607 | GFP_KERNEL); |
| 2608 | if (!hotkey_keycode_map) { |
| 2609 | printk(TPACPI_ERR |
| 2610 | "failed to allocate memory for key map\n"); |
| 2611 | res = -ENOMEM; |
| 2612 | goto err_exit; |
| 2613 | } |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2614 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2615 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2616 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2617 | "using Lenovo default hot key map\n"); |
| 2618 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, |
| 2619 | TPACPI_HOTKEY_MAP_SIZE); |
| 2620 | } else { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2621 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2622 | "using IBM default hot key map\n"); |
| 2623 | memcpy(hotkey_keycode_map, &ibm_keycode_map, |
| 2624 | TPACPI_HOTKEY_MAP_SIZE); |
| 2625 | } |
| 2626 | |
| 2627 | set_bit(EV_KEY, tpacpi_inputdev->evbit); |
| 2628 | set_bit(EV_MSC, tpacpi_inputdev->evbit); |
| 2629 | set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); |
| 2630 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 2631 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 2632 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 2633 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
| 2634 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
| 2635 | set_bit(hotkey_keycode_map[i], |
| 2636 | tpacpi_inputdev->keybit); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2637 | } else { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2638 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 2639 | hotkey_reserved_mask |= 1 << i; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2640 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2641 | } |
| 2642 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2643 | if (tp_features.hotkey_wlsw) { |
| 2644 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2645 | set_bit(SW_RFKILL_ALL, tpacpi_inputdev->swbit); |
| 2646 | } |
| 2647 | if (tp_features.hotkey_tablet) { |
| 2648 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2649 | set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2650 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2651 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2652 | /* Do not issue duplicate brightness change events to |
| 2653 | * userspace */ |
| 2654 | if (!tp_features.bright_acpimode) |
| 2655 | /* update bright_acpimode... */ |
| 2656 | tpacpi_check_std_acpi_brightness_support(); |
| 2657 | |
Henrique de Moraes Holschuh | 8bf3d4c | 2009-05-30 13:25:09 -0300 | [diff] [blame^] | 2658 | if (tp_features.bright_acpimode && acpi_video_backlight_support()) { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2659 | printk(TPACPI_INFO |
| 2660 | "This ThinkPad has standard ACPI backlight " |
| 2661 | "brightness control, supported by the ACPI " |
| 2662 | "video driver\n"); |
| 2663 | printk(TPACPI_NOTICE |
| 2664 | "Disabling thinkpad-acpi brightness events " |
| 2665 | "by default...\n"); |
| 2666 | |
| 2667 | /* The hotkey_reserved_mask change below is not |
| 2668 | * necessary while the keys are at KEY_RESERVED in the |
| 2669 | * default map, but better safe than sorry, leave it |
| 2670 | * here as a marker of what we have to do, especially |
| 2671 | * when we finally become able to set this at runtime |
| 2672 | * on response to X.org requests */ |
| 2673 | hotkey_reserved_mask |= |
| 2674 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 2675 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2676 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2677 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2678 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 2679 | "enabling firmware HKEY event interface...\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2680 | res = hotkey_status_set(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2681 | if (res) { |
| 2682 | hotkey_exit(); |
| 2683 | return res; |
| 2684 | } |
| 2685 | res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask) |
| 2686 | & ~hotkey_reserved_mask) |
| 2687 | | hotkey_orig_mask); |
| 2688 | if (res < 0 && res != -ENXIO) { |
| 2689 | hotkey_exit(); |
| 2690 | return res; |
| 2691 | } |
| 2692 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2693 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 2694 | "legacy ibm/hotkey event reporting over procfs %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2695 | (hotkey_report_mode < 2) ? |
| 2696 | "enabled" : "disabled"); |
| 2697 | |
| 2698 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 2699 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 2700 | |
| 2701 | hotkey_poll_setup_safe(1); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2702 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2703 | tpacpi_input_send_tabletsw(); |
| 2704 | |
| 2705 | return 0; |
| 2706 | |
| 2707 | err_exit: |
| 2708 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 2709 | hotkey_dev_attributes = NULL; |
| 2710 | |
| 2711 | return (res < 0)? res : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2712 | } |
| 2713 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2714 | static bool hotkey_notify_hotkey(const u32 hkey, |
| 2715 | bool *send_acpi_ev, |
| 2716 | bool *ignore_acpi_ev) |
| 2717 | { |
| 2718 | /* 0x1000-0x1FFF: key presses */ |
| 2719 | unsigned int scancode = hkey & 0xfff; |
| 2720 | *send_acpi_ev = true; |
| 2721 | *ignore_acpi_ev = false; |
| 2722 | |
| 2723 | if (scancode > 0 && scancode < 0x21) { |
| 2724 | scancode--; |
| 2725 | if (!(hotkey_source_mask & (1 << scancode))) { |
| 2726 | tpacpi_input_send_key(scancode); |
| 2727 | *send_acpi_ev = false; |
| 2728 | } else { |
| 2729 | *ignore_acpi_ev = true; |
| 2730 | } |
| 2731 | return true; |
| 2732 | } |
| 2733 | return false; |
| 2734 | } |
| 2735 | |
| 2736 | static bool hotkey_notify_wakeup(const u32 hkey, |
| 2737 | bool *send_acpi_ev, |
| 2738 | bool *ignore_acpi_ev) |
| 2739 | { |
| 2740 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 2741 | *send_acpi_ev = true; |
| 2742 | *ignore_acpi_ev = false; |
| 2743 | |
| 2744 | switch (hkey) { |
| 2745 | case 0x2304: /* suspend, undock */ |
| 2746 | case 0x2404: /* hibernation, undock */ |
| 2747 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 2748 | *ignore_acpi_ev = true; |
| 2749 | break; |
| 2750 | |
| 2751 | case 0x2305: /* suspend, bay eject */ |
| 2752 | case 0x2405: /* hibernation, bay eject */ |
| 2753 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 2754 | *ignore_acpi_ev = true; |
| 2755 | break; |
| 2756 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 2757 | case 0x2313: /* Battery on critical low level (S3) */ |
| 2758 | case 0x2413: /* Battery on critical low level (S4) */ |
| 2759 | printk(TPACPI_ALERT |
| 2760 | "EMERGENCY WAKEUP: battery almost empty\n"); |
| 2761 | /* how to auto-heal: */ |
| 2762 | /* 2313: woke up from S3, go to S4/S5 */ |
| 2763 | /* 2413: woke up from S4, go to S5 */ |
| 2764 | break; |
| 2765 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2766 | default: |
| 2767 | return false; |
| 2768 | } |
| 2769 | |
| 2770 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
| 2771 | printk(TPACPI_INFO |
| 2772 | "woke up due to a hot-unplug " |
| 2773 | "request...\n"); |
| 2774 | hotkey_wakeup_reason_notify_change(); |
| 2775 | } |
| 2776 | return true; |
| 2777 | } |
| 2778 | |
| 2779 | static bool hotkey_notify_usrevent(const u32 hkey, |
| 2780 | bool *send_acpi_ev, |
| 2781 | bool *ignore_acpi_ev) |
| 2782 | { |
| 2783 | /* 0x5000-0x5FFF: human interface helpers */ |
| 2784 | *send_acpi_ev = true; |
| 2785 | *ignore_acpi_ev = false; |
| 2786 | |
| 2787 | switch (hkey) { |
| 2788 | case 0x5010: /* Lenovo new BIOS: brightness changed */ |
| 2789 | case 0x500b: /* X61t: tablet pen inserted into bay */ |
| 2790 | case 0x500c: /* X61t: tablet pen removed from bay */ |
| 2791 | return true; |
| 2792 | |
| 2793 | case 0x5009: /* X41t-X61t: swivel up (tablet mode) */ |
| 2794 | case 0x500a: /* X41t-X61t: swivel down (normal mode) */ |
| 2795 | tpacpi_input_send_tabletsw(); |
| 2796 | hotkey_tablet_mode_notify_change(); |
| 2797 | *send_acpi_ev = false; |
| 2798 | return true; |
| 2799 | |
| 2800 | case 0x5001: |
| 2801 | case 0x5002: |
| 2802 | /* LID switch events. Do not propagate */ |
| 2803 | *ignore_acpi_ev = true; |
| 2804 | return true; |
| 2805 | |
| 2806 | default: |
| 2807 | return false; |
| 2808 | } |
| 2809 | } |
| 2810 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 2811 | static bool hotkey_notify_thermal(const u32 hkey, |
| 2812 | bool *send_acpi_ev, |
| 2813 | bool *ignore_acpi_ev) |
| 2814 | { |
| 2815 | /* 0x6000-0x6FFF: thermal alarms */ |
| 2816 | *send_acpi_ev = true; |
| 2817 | *ignore_acpi_ev = false; |
| 2818 | |
| 2819 | switch (hkey) { |
| 2820 | case 0x6011: |
| 2821 | printk(TPACPI_CRIT |
| 2822 | "THERMAL ALARM: battery is too hot!\n"); |
| 2823 | /* recommended action: warn user through gui */ |
| 2824 | return true; |
| 2825 | case 0x6012: |
| 2826 | printk(TPACPI_ALERT |
| 2827 | "THERMAL EMERGENCY: battery is extremely hot!\n"); |
| 2828 | /* recommended action: immediate sleep/hibernate */ |
| 2829 | return true; |
| 2830 | case 0x6021: |
| 2831 | printk(TPACPI_CRIT |
| 2832 | "THERMAL ALARM: " |
| 2833 | "a sensor reports something is too hot!\n"); |
| 2834 | /* recommended action: warn user through gui, that */ |
| 2835 | /* some internal component is too hot */ |
| 2836 | return true; |
| 2837 | case 0x6022: |
| 2838 | printk(TPACPI_ALERT |
| 2839 | "THERMAL EMERGENCY: " |
| 2840 | "a sensor reports something is extremely hot!\n"); |
| 2841 | /* recommended action: immediate sleep/hibernate */ |
| 2842 | return true; |
Henrique de Moraes Holschuh | 54926ce | 2009-01-11 03:01:09 -0200 | [diff] [blame] | 2843 | case 0x6030: |
| 2844 | printk(TPACPI_INFO |
| 2845 | "EC reports that Thermal Table has changed\n"); |
| 2846 | /* recommended action: do nothing, we don't have |
| 2847 | * Lenovo ATM information */ |
| 2848 | return true; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 2849 | default: |
| 2850 | printk(TPACPI_ALERT |
| 2851 | "THERMAL ALERT: unknown thermal alarm received\n"); |
| 2852 | return false; |
| 2853 | } |
| 2854 | } |
| 2855 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2856 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 2857 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2858 | u32 hkey; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2859 | bool send_acpi_ev; |
| 2860 | bool ignore_acpi_ev; |
| 2861 | bool known_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2862 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2863 | if (event != 0x80) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2864 | printk(TPACPI_ERR |
| 2865 | "unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2866 | /* 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] | 2867 | acpi_bus_generate_netlink_event( |
| 2868 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 2869 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2870 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2871 | return; |
| 2872 | } |
| 2873 | |
| 2874 | while (1) { |
| 2875 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2876 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2877 | return; |
| 2878 | } |
| 2879 | |
| 2880 | if (hkey == 0) { |
| 2881 | /* queue empty */ |
| 2882 | return; |
| 2883 | } |
| 2884 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2885 | send_acpi_ev = true; |
| 2886 | ignore_acpi_ev = false; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2887 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2888 | switch (hkey >> 12) { |
| 2889 | case 1: |
| 2890 | /* 0x1000-0x1FFF: key presses */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2891 | known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev, |
| 2892 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2893 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2894 | case 2: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2895 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 2896 | known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev, |
| 2897 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2898 | break; |
| 2899 | case 3: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2900 | /* 0x3000-0x3FFF: bay-related wakeups */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2901 | if (hkey == 0x3003) { |
| 2902 | hotkey_autosleep_ack = 1; |
| 2903 | printk(TPACPI_INFO |
| 2904 | "bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2905 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2906 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2907 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2908 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2909 | } |
| 2910 | break; |
| 2911 | case 4: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2912 | /* 0x4000-0x4FFF: dock-related wakeups */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2913 | if (hkey == 0x4003) { |
| 2914 | hotkey_autosleep_ack = 1; |
| 2915 | printk(TPACPI_INFO |
| 2916 | "undocked\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2917 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2918 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2919 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2920 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2921 | } |
| 2922 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2923 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2924 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2925 | known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev, |
| 2926 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2927 | break; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 2928 | case 6: |
| 2929 | /* 0x6000-0x6FFF: thermal alarms */ |
| 2930 | known_ev = hotkey_notify_thermal(hkey, &send_acpi_ev, |
| 2931 | &ignore_acpi_ev); |
| 2932 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2933 | case 7: |
| 2934 | /* 0x7000-0x7FFF: misc */ |
| 2935 | if (tp_features.hotkey_wlsw && hkey == 0x7000) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2936 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2937 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2938 | known_ev = true; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2939 | break; |
| 2940 | } |
| 2941 | /* fallthrough to default */ |
| 2942 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2943 | known_ev = false; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2944 | } |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 2945 | if (!known_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2946 | printk(TPACPI_NOTICE |
| 2947 | "unhandled HKEY event 0x%04x\n", hkey); |
Henrique de Moraes Holschuh | cb42935 | 2009-01-11 03:01:07 -0200 | [diff] [blame] | 2948 | printk(TPACPI_NOTICE |
| 2949 | "please report the conditions when this " |
| 2950 | "event happened to %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2951 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2952 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2953 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2954 | if (!ignore_acpi_ev && |
| 2955 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 2956 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 2957 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2958 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2959 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2960 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2961 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2962 | acpi_bus_generate_netlink_event( |
| 2963 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 2964 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2965 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2966 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2967 | } |
| 2968 | } |
| 2969 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2970 | static void hotkey_suspend(pm_message_t state) |
| 2971 | { |
| 2972 | /* Do these on suspend, we get the events on early resume! */ |
| 2973 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 2974 | hotkey_autosleep_ack = 0; |
| 2975 | } |
| 2976 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2977 | static void hotkey_resume(void) |
| 2978 | { |
Henrique de Moraes Holschuh | d64c81c4 | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 2979 | tpacpi_disable_brightness_delay(); |
| 2980 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2981 | if (hotkey_mask_get()) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2982 | printk(TPACPI_ERR |
| 2983 | "error while trying to read hot key mask " |
| 2984 | "from firmware\n"); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2985 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2986 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2987 | hotkey_wakeup_reason_notify_change(); |
| 2988 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2989 | hotkey_poll_setup_safe(0); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2990 | } |
| 2991 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2992 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2993 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2995 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | int len = 0; |
| 2997 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2998 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2999 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3000 | return len; |
| 3001 | } |
| 3002 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3003 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3004 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3005 | res = hotkey_status_get(&status); |
| 3006 | if (!res) |
| 3007 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3008 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3009 | if (res) |
| 3010 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | |
| 3012 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3013 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3014 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | len += sprintf(p + len, |
| 3016 | "commands:\tenable, disable, reset, <mask>\n"); |
| 3017 | } else { |
| 3018 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 3019 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 3020 | } |
| 3021 | |
| 3022 | return len; |
| 3023 | } |
| 3024 | |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3025 | static void hotkey_enabledisable_warn(bool enable) |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3026 | { |
| 3027 | tpacpi_log_usertask("procfs hotkey enable/disable"); |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3028 | if (!WARN((tpacpi_lifecycle == TPACPI_LIFE_RUNNING || !enable), |
| 3029 | TPACPI_WARN |
| 3030 | "hotkey enable/disable functionality has been " |
| 3031 | "removed from the driver. Hotkeys are always " |
| 3032 | "enabled\n")) |
| 3033 | printk(TPACPI_ERR |
| 3034 | "Please remove the hotkey=enable module " |
| 3035 | "parameter, it is deprecated. Hotkeys are always " |
| 3036 | "enabled\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3039 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3041 | int res; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3042 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3045 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | return -ENODEV; |
| 3047 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3048 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3049 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3050 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3051 | mask = hotkey_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3052 | |
| 3053 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | while ((cmd = next_cmd(&buf))) { |
| 3055 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3056 | hotkey_enabledisable_warn(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3058 | hotkey_enabledisable_warn(0); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3059 | res = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | } else if (strlencmp(cmd, "reset") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3061 | mask = hotkey_orig_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 3063 | /* mask set */ |
| 3064 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 3065 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3066 | } else { |
| 3067 | res = -EINVAL; |
| 3068 | goto errexit; |
| 3069 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | } |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3071 | |
| 3072 | if (!res) |
| 3073 | tpacpi_disclose_usertask("procfs hotkey", |
| 3074 | "set mask to 0x%08x\n", mask); |
| 3075 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3076 | if (!res && mask != hotkey_mask) |
| 3077 | res = hotkey_mask_set(mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3079 | errexit: |
| 3080 | mutex_unlock(&hotkey_mutex); |
| 3081 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3082 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3084 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3085 | {TPACPI_ACPI_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3086 | {"", 0}, |
| 3087 | }; |
| 3088 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3089 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3090 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3091 | .notify = hotkey_notify, |
| 3092 | .handle = &hkey_handle, |
| 3093 | .type = ACPI_DEVICE_NOTIFY, |
| 3094 | }; |
| 3095 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3096 | static struct ibm_struct hotkey_driver_data = { |
| 3097 | .name = "hotkey", |
| 3098 | .read = hotkey_read, |
| 3099 | .write = hotkey_write, |
| 3100 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3101 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3102 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3103 | .acpi = &ibm_hotkey_acpidriver, |
| 3104 | }; |
| 3105 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3106 | /************************************************************************* |
| 3107 | * Bluetooth subdriver |
| 3108 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3110 | enum { |
| 3111 | /* ACPI GBDC/SBDC bits */ |
| 3112 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 3113 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3114 | TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: |
| 3115 | off / last state */ |
| 3116 | }; |
| 3117 | |
| 3118 | enum { |
| 3119 | /* ACPI \BLTH commands */ |
| 3120 | TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */ |
| 3121 | TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */ |
| 3122 | TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */ |
| 3123 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */ |
| 3124 | 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] | 3125 | }; |
| 3126 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3127 | #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" |
| 3128 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3129 | static struct rfkill *tpacpi_bluetooth_rfkill; |
| 3130 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3131 | static void bluetooth_suspend(pm_message_t state) |
| 3132 | { |
| 3133 | /* Try to make sure radio will resume powered off */ |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3134 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 3135 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME)) |
| 3136 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3137 | "bluetooth power down on resume request failed\n"); |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3138 | } |
| 3139 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3140 | static int bluetooth_get_radiosw(void) |
| 3141 | { |
| 3142 | int status; |
| 3143 | |
| 3144 | if (!tp_features.bluetooth) |
| 3145 | return -ENODEV; |
| 3146 | |
Henrique de Moraes Holschuh | 133ec3b | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3147 | /* WLSW overrides bluetooth in firmware/hardware, reflect that */ |
| 3148 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3149 | return RFKILL_STATE_HARD_BLOCKED; |
Henrique de Moraes Holschuh | 133ec3b | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3150 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3151 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3152 | if (dbg_bluetoothemul) |
| 3153 | return (tpacpi_bluetooth_emulstate) ? |
| 3154 | RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; |
| 3155 | #endif |
| 3156 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3157 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 3158 | return -EIO; |
| 3159 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3160 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? |
| 3161 | RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3162 | } |
| 3163 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3164 | static void bluetooth_update_rfk(void) |
| 3165 | { |
| 3166 | int status; |
| 3167 | |
| 3168 | if (!tpacpi_bluetooth_rfkill) |
| 3169 | return; |
| 3170 | |
| 3171 | status = bluetooth_get_radiosw(); |
| 3172 | if (status < 0) |
| 3173 | return; |
| 3174 | rfkill_force_state(tpacpi_bluetooth_rfkill, status); |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3175 | |
| 3176 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3177 | "forced rfkill state to %d\n", |
| 3178 | status); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | static int bluetooth_set_radiosw(int radio_on, int update_rfk) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3182 | { |
| 3183 | int status; |
| 3184 | |
| 3185 | if (!tp_features.bluetooth) |
| 3186 | return -ENODEV; |
| 3187 | |
Henrique de Moraes Holschuh | 133ec3b | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3188 | /* WLSW overrides bluetooth in firmware/hardware, but there is no |
| 3189 | * reason to risk weird behaviour. */ |
| 3190 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status |
| 3191 | && radio_on) |
| 3192 | return -EPERM; |
| 3193 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3194 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3195 | "will %s bluetooth\n", radio_on ? "enable" : "disable"); |
| 3196 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3197 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3198 | if (dbg_bluetoothemul) { |
| 3199 | tpacpi_bluetooth_emulstate = !!radio_on; |
| 3200 | if (update_rfk) |
| 3201 | bluetooth_update_rfk(); |
| 3202 | return 0; |
| 3203 | } |
| 3204 | #endif |
| 3205 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3206 | /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */ |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3207 | if (radio_on) |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3208 | status = TP_ACPI_BLUETOOTH_RADIOSSW; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3209 | else |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3210 | status = 0; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3211 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 3212 | return -EIO; |
| 3213 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3214 | if (update_rfk) |
| 3215 | bluetooth_update_rfk(); |
| 3216 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3217 | return 0; |
| 3218 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3219 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3220 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 3221 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 3222 | struct device_attribute *attr, |
| 3223 | char *buf) |
| 3224 | { |
| 3225 | int status; |
| 3226 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 3227 | printk_deprecated_rfkill_attribute("bluetooth_enable"); |
| 3228 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3229 | status = bluetooth_get_radiosw(); |
| 3230 | if (status < 0) |
| 3231 | return status; |
| 3232 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3233 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 3234 | (status == RFKILL_STATE_UNBLOCKED) ? 1 : 0); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3235 | } |
| 3236 | |
| 3237 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 3238 | struct device_attribute *attr, |
| 3239 | const char *buf, size_t count) |
| 3240 | { |
| 3241 | unsigned long t; |
| 3242 | int res; |
| 3243 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 3244 | printk_deprecated_rfkill_attribute("bluetooth_enable"); |
| 3245 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3246 | if (parse_strtoul(buf, 1, &t)) |
| 3247 | return -EINVAL; |
| 3248 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3249 | tpacpi_disclose_usertask("bluetooth_enable", "set to %ld\n", t); |
| 3250 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3251 | res = bluetooth_set_radiosw(t, 1); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3252 | |
| 3253 | return (res) ? res : count; |
| 3254 | } |
| 3255 | |
| 3256 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 3257 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3258 | bluetooth_enable_show, bluetooth_enable_store); |
| 3259 | |
| 3260 | /* --------------------------------------------------------------------- */ |
| 3261 | |
| 3262 | static struct attribute *bluetooth_attributes[] = { |
| 3263 | &dev_attr_bluetooth_enable.attr, |
| 3264 | NULL |
| 3265 | }; |
| 3266 | |
| 3267 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3268 | .attrs = bluetooth_attributes, |
| 3269 | }; |
| 3270 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3271 | static int tpacpi_bluetooth_rfk_get(void *data, enum rfkill_state *state) |
| 3272 | { |
| 3273 | int bts = bluetooth_get_radiosw(); |
| 3274 | |
| 3275 | if (bts < 0) |
| 3276 | return bts; |
| 3277 | |
| 3278 | *state = bts; |
| 3279 | return 0; |
| 3280 | } |
| 3281 | |
| 3282 | static int tpacpi_bluetooth_rfk_set(void *data, enum rfkill_state state) |
| 3283 | { |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3284 | dbg_printk(TPACPI_DBG_RFKILL, |
| 3285 | "request to change radio state to %d\n", state); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3286 | return bluetooth_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0); |
| 3287 | } |
| 3288 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3289 | static void bluetooth_shutdown(void) |
| 3290 | { |
| 3291 | /* Order firmware to save current state to NVRAM */ |
| 3292 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 3293 | TP_ACPI_BLTH_SAVE_STATE)) |
| 3294 | printk(TPACPI_NOTICE |
| 3295 | "failed to save bluetooth state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3296 | else |
| 3297 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3298 | "bluestooth state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3299 | } |
| 3300 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3301 | static void bluetooth_exit(void) |
| 3302 | { |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3303 | bluetooth_shutdown(); |
| 3304 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3305 | if (tpacpi_bluetooth_rfkill) |
| 3306 | rfkill_unregister(tpacpi_bluetooth_rfkill); |
| 3307 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3308 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 3309 | &bluetooth_attr_group); |
| 3310 | } |
| 3311 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3312 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3314 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3315 | int status = 0; |
| 3316 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3317 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3318 | "initializing bluetooth subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3319 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3320 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3321 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3322 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 3323 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3324 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3325 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3327 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3328 | "bluetooth is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3329 | str_supported(tp_features.bluetooth), |
| 3330 | status); |
| 3331 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3332 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3333 | if (dbg_bluetoothemul) { |
| 3334 | tp_features.bluetooth = 1; |
| 3335 | printk(TPACPI_INFO |
| 3336 | "bluetooth switch emulation enabled\n"); |
| 3337 | } else |
| 3338 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3339 | if (tp_features.bluetooth && |
| 3340 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 3341 | /* no bluetooth hardware present in system */ |
| 3342 | tp_features.bluetooth = 0; |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3343 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3344 | "bluetooth hardware not installed\n"); |
| 3345 | } |
| 3346 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3347 | if (!tp_features.bluetooth) |
| 3348 | return 1; |
| 3349 | |
| 3350 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3351 | &bluetooth_attr_group); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3352 | if (res) |
| 3353 | return res; |
| 3354 | |
| 3355 | res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3356 | &tpacpi_bluetooth_rfkill, |
| 3357 | RFKILL_TYPE_BLUETOOTH, |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3358 | TPACPI_RFK_BLUETOOTH_SW_NAME, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 3359 | true, |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3360 | tpacpi_bluetooth_rfk_set, |
| 3361 | tpacpi_bluetooth_rfk_get); |
| 3362 | if (res) { |
| 3363 | bluetooth_exit(); |
| 3364 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3365 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3366 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3367 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3370 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3371 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | { |
| 3373 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3374 | int status = bluetooth_get_radiosw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3376 | if (!tp_features.bluetooth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3379 | len += sprintf(p + len, "status:\t\t%s\n", |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3380 | (status == RFKILL_STATE_UNBLOCKED) ? |
| 3381 | "enabled" : "disabled"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 3383 | } |
| 3384 | |
| 3385 | return len; |
| 3386 | } |
| 3387 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3388 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | char *cmd; |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3391 | int state = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3393 | if (!tp_features.bluetooth) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3394 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | |
| 3396 | while ((cmd = next_cmd(&buf))) { |
| 3397 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3398 | state = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3400 | state = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | } else |
| 3402 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3405 | if (state != -1) { |
| 3406 | tpacpi_disclose_usertask("procfs bluetooth", |
| 3407 | "attempt to %s\n", |
| 3408 | state ? "enable" : "disable"); |
| 3409 | bluetooth_set_radiosw(state, 1); |
| 3410 | } |
| 3411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | return 0; |
| 3413 | } |
| 3414 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3415 | static struct ibm_struct bluetooth_driver_data = { |
| 3416 | .name = "bluetooth", |
| 3417 | .read = bluetooth_read, |
| 3418 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3419 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3420 | .suspend = bluetooth_suspend, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3421 | .shutdown = bluetooth_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3422 | }; |
| 3423 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3424 | /************************************************************************* |
| 3425 | * Wan subdriver |
| 3426 | */ |
| 3427 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3428 | enum { |
| 3429 | /* ACPI GWAN/SWAN bits */ |
| 3430 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 3431 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3432 | TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: |
| 3433 | off / last state */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3434 | }; |
| 3435 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3436 | #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" |
| 3437 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3438 | static struct rfkill *tpacpi_wan_rfkill; |
| 3439 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3440 | static void wan_suspend(pm_message_t state) |
| 3441 | { |
| 3442 | /* Try to make sure radio will resume powered off */ |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3443 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "qvd", |
| 3444 | TP_ACPI_WGSV_PWR_OFF_ON_RESUME)) |
| 3445 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3446 | "WWAN power down on resume request failed\n"); |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3447 | } |
| 3448 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3449 | static int wan_get_radiosw(void) |
| 3450 | { |
| 3451 | int status; |
| 3452 | |
| 3453 | if (!tp_features.wan) |
| 3454 | return -ENODEV; |
| 3455 | |
Henrique de Moraes Holschuh | 133ec3b | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3456 | /* WLSW overrides WWAN in firmware/hardware, reflect that */ |
| 3457 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3458 | return RFKILL_STATE_HARD_BLOCKED; |
Henrique de Moraes Holschuh | 133ec3b | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3459 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3460 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3461 | if (dbg_wwanemul) |
| 3462 | return (tpacpi_wwan_emulstate) ? |
| 3463 | RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; |
| 3464 | #endif |
| 3465 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3466 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 3467 | return -EIO; |
| 3468 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3469 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? |
| 3470 | RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3471 | } |
| 3472 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3473 | static void wan_update_rfk(void) |
| 3474 | { |
| 3475 | int status; |
| 3476 | |
| 3477 | if (!tpacpi_wan_rfkill) |
| 3478 | return; |
| 3479 | |
| 3480 | status = wan_get_radiosw(); |
| 3481 | if (status < 0) |
| 3482 | return; |
| 3483 | rfkill_force_state(tpacpi_wan_rfkill, status); |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3484 | |
| 3485 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3486 | "forced rfkill state to %d\n", |
| 3487 | status); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | static int wan_set_radiosw(int radio_on, int update_rfk) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3491 | { |
| 3492 | int status; |
| 3493 | |
| 3494 | if (!tp_features.wan) |
| 3495 | return -ENODEV; |
| 3496 | |
Henrique de Moraes Holschuh | 133ec3b | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3497 | /* WLSW overrides bluetooth in firmware/hardware, but there is no |
| 3498 | * reason to risk weird behaviour. */ |
| 3499 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status |
| 3500 | && radio_on) |
| 3501 | return -EPERM; |
| 3502 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3503 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3504 | "will %s WWAN\n", radio_on ? "enable" : "disable"); |
| 3505 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3506 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3507 | if (dbg_wwanemul) { |
| 3508 | tpacpi_wwan_emulstate = !!radio_on; |
| 3509 | if (update_rfk) |
| 3510 | wan_update_rfk(); |
| 3511 | return 0; |
| 3512 | } |
| 3513 | #endif |
| 3514 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3515 | /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */ |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3516 | if (radio_on) |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3517 | status = TP_ACPI_WANCARD_RADIOSSW; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3518 | else |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3519 | status = 0; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3520 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 3521 | return -EIO; |
| 3522 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3523 | if (update_rfk) |
| 3524 | wan_update_rfk(); |
| 3525 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3526 | return 0; |
| 3527 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3528 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3529 | /* sysfs wan enable ---------------------------------------------------- */ |
| 3530 | static ssize_t wan_enable_show(struct device *dev, |
| 3531 | struct device_attribute *attr, |
| 3532 | char *buf) |
| 3533 | { |
| 3534 | int status; |
| 3535 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 3536 | printk_deprecated_rfkill_attribute("wwan_enable"); |
| 3537 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3538 | status = wan_get_radiosw(); |
| 3539 | if (status < 0) |
| 3540 | return status; |
| 3541 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3542 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 3543 | (status == RFKILL_STATE_UNBLOCKED) ? 1 : 0); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3544 | } |
| 3545 | |
| 3546 | static ssize_t wan_enable_store(struct device *dev, |
| 3547 | struct device_attribute *attr, |
| 3548 | const char *buf, size_t count) |
| 3549 | { |
| 3550 | unsigned long t; |
| 3551 | int res; |
| 3552 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 3553 | printk_deprecated_rfkill_attribute("wwan_enable"); |
| 3554 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3555 | if (parse_strtoul(buf, 1, &t)) |
| 3556 | return -EINVAL; |
| 3557 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3558 | tpacpi_disclose_usertask("wwan_enable", "set to %ld\n", t); |
| 3559 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3560 | res = wan_set_radiosw(t, 1); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3561 | |
| 3562 | return (res) ? res : count; |
| 3563 | } |
| 3564 | |
| 3565 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 3566 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3567 | wan_enable_show, wan_enable_store); |
| 3568 | |
| 3569 | /* --------------------------------------------------------------------- */ |
| 3570 | |
| 3571 | static struct attribute *wan_attributes[] = { |
| 3572 | &dev_attr_wan_enable.attr, |
| 3573 | NULL |
| 3574 | }; |
| 3575 | |
| 3576 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3577 | .attrs = wan_attributes, |
| 3578 | }; |
| 3579 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3580 | static int tpacpi_wan_rfk_get(void *data, enum rfkill_state *state) |
| 3581 | { |
| 3582 | int wans = wan_get_radiosw(); |
| 3583 | |
| 3584 | if (wans < 0) |
| 3585 | return wans; |
| 3586 | |
| 3587 | *state = wans; |
| 3588 | return 0; |
| 3589 | } |
| 3590 | |
| 3591 | static int tpacpi_wan_rfk_set(void *data, enum rfkill_state state) |
| 3592 | { |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3593 | dbg_printk(TPACPI_DBG_RFKILL, |
| 3594 | "request to change radio state to %d\n", state); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3595 | return wan_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0); |
| 3596 | } |
| 3597 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3598 | static void wan_shutdown(void) |
| 3599 | { |
| 3600 | /* Order firmware to save current state to NVRAM */ |
| 3601 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd", |
| 3602 | TP_ACPI_WGSV_SAVE_STATE)) |
| 3603 | printk(TPACPI_NOTICE |
| 3604 | "failed to save WWAN state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3605 | else |
| 3606 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3607 | "WWAN state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3608 | } |
| 3609 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3610 | static void wan_exit(void) |
| 3611 | { |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3612 | wan_shutdown(); |
| 3613 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3614 | if (tpacpi_wan_rfkill) |
| 3615 | rfkill_unregister(tpacpi_wan_rfkill); |
| 3616 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3617 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 3618 | &wan_attr_group); |
| 3619 | } |
| 3620 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3621 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3622 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3623 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3624 | int status = 0; |
| 3625 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3626 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3627 | "initializing wan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3628 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3629 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3630 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3631 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3632 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3633 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3634 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3635 | "wan is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3636 | str_supported(tp_features.wan), |
| 3637 | status); |
| 3638 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3639 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3640 | if (dbg_wwanemul) { |
| 3641 | tp_features.wan = 1; |
| 3642 | printk(TPACPI_INFO |
| 3643 | "wwan switch emulation enabled\n"); |
| 3644 | } else |
| 3645 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3646 | if (tp_features.wan && |
| 3647 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 3648 | /* no wan hardware present in system */ |
| 3649 | tp_features.wan = 0; |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3650 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3651 | "wan hardware not installed\n"); |
| 3652 | } |
| 3653 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3654 | if (!tp_features.wan) |
| 3655 | return 1; |
| 3656 | |
| 3657 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3658 | &wan_attr_group); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3659 | if (res) |
| 3660 | return res; |
| 3661 | |
| 3662 | res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, |
| 3663 | &tpacpi_wan_rfkill, |
| 3664 | RFKILL_TYPE_WWAN, |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3665 | TPACPI_RFK_WWAN_SW_NAME, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 3666 | true, |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3667 | tpacpi_wan_rfk_set, |
| 3668 | tpacpi_wan_rfk_get); |
| 3669 | if (res) { |
| 3670 | wan_exit(); |
| 3671 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3672 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3673 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3674 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3675 | } |
| 3676 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3677 | /* procfs -------------------------------------------------------------- */ |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3678 | static int wan_read(char *p) |
| 3679 | { |
| 3680 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3681 | int status = wan_get_radiosw(); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3682 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3683 | tpacpi_disclose_usertask("procfs wan", "read"); |
| 3684 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3685 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3686 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3687 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3688 | len += sprintf(p + len, "status:\t\t%s\n", |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3689 | (status == RFKILL_STATE_UNBLOCKED) ? |
| 3690 | "enabled" : "disabled"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3691 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 3692 | } |
| 3693 | |
| 3694 | return len; |
| 3695 | } |
| 3696 | |
| 3697 | static int wan_write(char *buf) |
| 3698 | { |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3699 | char *cmd; |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3700 | int state = -1; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3701 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3702 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3703 | return -ENODEV; |
| 3704 | |
| 3705 | while ((cmd = next_cmd(&buf))) { |
| 3706 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3707 | state = 1; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3708 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3709 | state = 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3710 | } else |
| 3711 | return -EINVAL; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3712 | } |
| 3713 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3714 | if (state != -1) { |
| 3715 | tpacpi_disclose_usertask("procfs wan", |
| 3716 | "attempt to %s\n", |
| 3717 | state ? "enable" : "disable"); |
| 3718 | wan_set_radiosw(state, 1); |
| 3719 | } |
| 3720 | |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3721 | return 0; |
| 3722 | } |
| 3723 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3724 | static struct ibm_struct wan_driver_data = { |
| 3725 | .name = "wan", |
| 3726 | .read = wan_read, |
| 3727 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3728 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3729 | .suspend = wan_suspend, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3730 | .shutdown = wan_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3731 | }; |
| 3732 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3733 | /************************************************************************* |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 3734 | * UWB subdriver |
| 3735 | */ |
| 3736 | |
| 3737 | enum { |
| 3738 | /* ACPI GUWB/SUWB bits */ |
| 3739 | TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */ |
| 3740 | TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */ |
| 3741 | }; |
| 3742 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3743 | #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" |
| 3744 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 3745 | static struct rfkill *tpacpi_uwb_rfkill; |
| 3746 | |
| 3747 | static int uwb_get_radiosw(void) |
| 3748 | { |
| 3749 | int status; |
| 3750 | |
| 3751 | if (!tp_features.uwb) |
| 3752 | return -ENODEV; |
| 3753 | |
| 3754 | /* WLSW overrides UWB in firmware/hardware, reflect that */ |
| 3755 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status) |
| 3756 | return RFKILL_STATE_HARD_BLOCKED; |
| 3757 | |
| 3758 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3759 | if (dbg_uwbemul) |
| 3760 | return (tpacpi_uwb_emulstate) ? |
| 3761 | RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; |
| 3762 | #endif |
| 3763 | |
| 3764 | if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) |
| 3765 | return -EIO; |
| 3766 | |
| 3767 | return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? |
| 3768 | RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; |
| 3769 | } |
| 3770 | |
| 3771 | static void uwb_update_rfk(void) |
| 3772 | { |
| 3773 | int status; |
| 3774 | |
| 3775 | if (!tpacpi_uwb_rfkill) |
| 3776 | return; |
| 3777 | |
| 3778 | status = uwb_get_radiosw(); |
| 3779 | if (status < 0) |
| 3780 | return; |
| 3781 | rfkill_force_state(tpacpi_uwb_rfkill, status); |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3782 | |
| 3783 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3784 | "forced rfkill state to %d\n", |
| 3785 | status); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | static int uwb_set_radiosw(int radio_on, int update_rfk) |
| 3789 | { |
| 3790 | int status; |
| 3791 | |
| 3792 | if (!tp_features.uwb) |
| 3793 | return -ENODEV; |
| 3794 | |
| 3795 | /* WLSW overrides UWB in firmware/hardware, but there is no |
| 3796 | * reason to risk weird behaviour. */ |
| 3797 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status |
| 3798 | && radio_on) |
| 3799 | return -EPERM; |
| 3800 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3801 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3802 | "will %s UWB\n", radio_on ? "enable" : "disable"); |
| 3803 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 3804 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3805 | if (dbg_uwbemul) { |
| 3806 | tpacpi_uwb_emulstate = !!radio_on; |
| 3807 | if (update_rfk) |
| 3808 | uwb_update_rfk(); |
| 3809 | return 0; |
| 3810 | } |
| 3811 | #endif |
| 3812 | |
| 3813 | status = (radio_on) ? TP_ACPI_UWB_RADIOSSW : 0; |
| 3814 | if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) |
| 3815 | return -EIO; |
| 3816 | |
| 3817 | if (update_rfk) |
| 3818 | uwb_update_rfk(); |
| 3819 | |
| 3820 | return 0; |
| 3821 | } |
| 3822 | |
| 3823 | /* --------------------------------------------------------------------- */ |
| 3824 | |
| 3825 | static int tpacpi_uwb_rfk_get(void *data, enum rfkill_state *state) |
| 3826 | { |
| 3827 | int uwbs = uwb_get_radiosw(); |
| 3828 | |
| 3829 | if (uwbs < 0) |
| 3830 | return uwbs; |
| 3831 | |
| 3832 | *state = uwbs; |
| 3833 | return 0; |
| 3834 | } |
| 3835 | |
| 3836 | static int tpacpi_uwb_rfk_set(void *data, enum rfkill_state state) |
| 3837 | { |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3838 | dbg_printk(TPACPI_DBG_RFKILL, |
| 3839 | "request to change radio state to %d\n", state); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 3840 | return uwb_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0); |
| 3841 | } |
| 3842 | |
| 3843 | static void uwb_exit(void) |
| 3844 | { |
| 3845 | if (tpacpi_uwb_rfkill) |
| 3846 | rfkill_unregister(tpacpi_uwb_rfkill); |
| 3847 | } |
| 3848 | |
| 3849 | static int __init uwb_init(struct ibm_init_struct *iibm) |
| 3850 | { |
| 3851 | int res; |
| 3852 | int status = 0; |
| 3853 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3854 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3855 | "initializing uwb subdriver\n"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 3856 | |
| 3857 | TPACPI_ACPIHANDLE_INIT(hkey); |
| 3858 | |
| 3859 | tp_features.uwb = hkey_handle && |
| 3860 | acpi_evalf(hkey_handle, &status, "GUWB", "qd"); |
| 3861 | |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3862 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3863 | "uwb is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 3864 | str_supported(tp_features.uwb), |
| 3865 | status); |
| 3866 | |
| 3867 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3868 | if (dbg_uwbemul) { |
| 3869 | tp_features.uwb = 1; |
| 3870 | printk(TPACPI_INFO |
| 3871 | "uwb switch emulation enabled\n"); |
| 3872 | } else |
| 3873 | #endif |
| 3874 | if (tp_features.uwb && |
| 3875 | !(status & TP_ACPI_UWB_HWPRESENT)) { |
| 3876 | /* no uwb hardware present in system */ |
| 3877 | tp_features.uwb = 0; |
| 3878 | dbg_printk(TPACPI_DBG_INIT, |
| 3879 | "uwb hardware not installed\n"); |
| 3880 | } |
| 3881 | |
| 3882 | if (!tp_features.uwb) |
| 3883 | return 1; |
| 3884 | |
| 3885 | res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, |
| 3886 | &tpacpi_uwb_rfkill, |
| 3887 | RFKILL_TYPE_UWB, |
Henrique de Moraes Holschuh | bee4cd9b | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3888 | TPACPI_RFK_UWB_SW_NAME, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 3889 | false, |
| 3890 | tpacpi_uwb_rfk_set, |
| 3891 | tpacpi_uwb_rfk_get); |
| 3892 | |
| 3893 | return res; |
| 3894 | } |
| 3895 | |
| 3896 | static struct ibm_struct uwb_driver_data = { |
| 3897 | .name = "uwb", |
| 3898 | .exit = uwb_exit, |
| 3899 | .flags.experimental = 1, |
| 3900 | }; |
| 3901 | |
| 3902 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3903 | * Video subdriver |
| 3904 | */ |
| 3905 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 3906 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 3907 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3908 | enum video_access_mode { |
| 3909 | TPACPI_VIDEO_NONE = 0, |
| 3910 | TPACPI_VIDEO_570, /* 570 */ |
| 3911 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 3912 | TPACPI_VIDEO_NEW, /* all others */ |
| 3913 | }; |
| 3914 | |
| 3915 | enum { /* video status flags, based on VIDEO_570 */ |
| 3916 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 3917 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 3918 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 3919 | }; |
| 3920 | |
| 3921 | enum { /* TPACPI_VIDEO_570 constants */ |
| 3922 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 3923 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 3924 | * video_status_flags */ |
| 3925 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 3926 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 3927 | }; |
| 3928 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 3929 | static enum video_access_mode video_supported; |
| 3930 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3931 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3932 | static int video_autosw_get(void); |
| 3933 | static int video_autosw_set(int enable); |
| 3934 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3935 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3936 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3937 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3939 | int ivga; |
| 3940 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3941 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 3942 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3943 | TPACPI_ACPIHANDLE_INIT(vid); |
| 3944 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3945 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3946 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 3947 | /* G41, assume IVGA doesn't change */ |
| 3948 | vid_handle = vid2_handle; |
| 3949 | |
| 3950 | if (!vid_handle) |
| 3951 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3952 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3953 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 3954 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3955 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3956 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 3957 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3958 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3959 | else |
| 3960 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3961 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3963 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 3964 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 3965 | video_supported); |
| 3966 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3967 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | } |
| 3969 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3970 | static void video_exit(void) |
| 3971 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3972 | dbg_printk(TPACPI_DBG_EXIT, |
| 3973 | "restoring original video autoswitch mode\n"); |
| 3974 | if (video_autosw_set(video_orig_autosw)) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3975 | printk(TPACPI_ERR "error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3976 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3977 | } |
| 3978 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3979 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | { |
| 3981 | int status = 0; |
| 3982 | int i; |
| 3983 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3984 | switch (video_supported) { |
| 3985 | case TPACPI_VIDEO_570: |
| 3986 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 3987 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 3988 | return -EIO; |
| 3989 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 3990 | break; |
| 3991 | case TPACPI_VIDEO_770: |
| 3992 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 3993 | return -EIO; |
| 3994 | if (i) |
| 3995 | status |= TP_ACPI_VIDEO_S_LCD; |
| 3996 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 3997 | return -EIO; |
| 3998 | if (i) |
| 3999 | status |= TP_ACPI_VIDEO_S_CRT; |
| 4000 | break; |
| 4001 | case TPACPI_VIDEO_NEW: |
| 4002 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 4003 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4004 | return -EIO; |
| 4005 | if (i) |
| 4006 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4008 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 4009 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4010 | return -EIO; |
| 4011 | if (i) |
| 4012 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4013 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 4014 | return -EIO; |
| 4015 | if (i) |
| 4016 | status |= TP_ACPI_VIDEO_S_DVI; |
| 4017 | break; |
| 4018 | default: |
| 4019 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | |
| 4022 | return status; |
| 4023 | } |
| 4024 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4025 | static int video_outputsw_set(int status) |
| 4026 | { |
| 4027 | int autosw; |
| 4028 | int res = 0; |
| 4029 | |
| 4030 | switch (video_supported) { |
| 4031 | case TPACPI_VIDEO_570: |
| 4032 | res = acpi_evalf(NULL, NULL, |
| 4033 | "\\_SB.PHS2", "vdd", |
| 4034 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 4035 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 4036 | break; |
| 4037 | case TPACPI_VIDEO_770: |
| 4038 | autosw = video_autosw_get(); |
| 4039 | if (autosw < 0) |
| 4040 | return autosw; |
| 4041 | |
| 4042 | res = video_autosw_set(1); |
| 4043 | if (res) |
| 4044 | return res; |
| 4045 | res = acpi_evalf(vid_handle, NULL, |
| 4046 | "ASWT", "vdd", status * 0x100, 0); |
| 4047 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4048 | printk(TPACPI_ERR |
| 4049 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4050 | return -EIO; |
| 4051 | } |
| 4052 | break; |
| 4053 | case TPACPI_VIDEO_NEW: |
| 4054 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4055 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4056 | break; |
| 4057 | default: |
| 4058 | return -ENOSYS; |
| 4059 | } |
| 4060 | |
| 4061 | return (res)? 0 : -EIO; |
| 4062 | } |
| 4063 | |
| 4064 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4066 | int autosw = 0; |
| 4067 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4068 | switch (video_supported) { |
| 4069 | case TPACPI_VIDEO_570: |
| 4070 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 4071 | return -EIO; |
| 4072 | break; |
| 4073 | case TPACPI_VIDEO_770: |
| 4074 | case TPACPI_VIDEO_NEW: |
| 4075 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 4076 | return -EIO; |
| 4077 | break; |
| 4078 | default: |
| 4079 | return -ENOSYS; |
| 4080 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4081 | |
| 4082 | return autosw & 1; |
| 4083 | } |
| 4084 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4085 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4086 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4087 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4088 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4089 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4090 | } |
| 4091 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4092 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4093 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4094 | int autosw = video_autosw_get(); |
| 4095 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4096 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4097 | if (autosw < 0) |
| 4098 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4099 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4100 | switch (video_supported) { |
| 4101 | case TPACPI_VIDEO_570: |
| 4102 | res = video_autosw_set(1); |
| 4103 | if (res) |
| 4104 | return res; |
| 4105 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 4106 | break; |
| 4107 | case TPACPI_VIDEO_770: |
| 4108 | case TPACPI_VIDEO_NEW: |
| 4109 | res = video_autosw_set(1); |
| 4110 | if (res) |
| 4111 | return res; |
| 4112 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 4113 | break; |
| 4114 | default: |
| 4115 | return -ENOSYS; |
| 4116 | } |
| 4117 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4118 | printk(TPACPI_ERR |
| 4119 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4120 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4121 | } |
| 4122 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4123 | return (res)? 0 : -EIO; |
| 4124 | } |
| 4125 | |
| 4126 | static int video_expand_toggle(void) |
| 4127 | { |
| 4128 | switch (video_supported) { |
| 4129 | case TPACPI_VIDEO_570: |
| 4130 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 4131 | 0 : -EIO; |
| 4132 | case TPACPI_VIDEO_770: |
| 4133 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 4134 | 0 : -EIO; |
| 4135 | case TPACPI_VIDEO_NEW: |
| 4136 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 4137 | 0 : -EIO; |
| 4138 | default: |
| 4139 | return -ENOSYS; |
| 4140 | } |
| 4141 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4142 | } |
| 4143 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4144 | static int video_read(char *p) |
| 4145 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4146 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4147 | int len = 0; |
| 4148 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4149 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4150 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4151 | return len; |
| 4152 | } |
| 4153 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4154 | status = video_outputsw_get(); |
| 4155 | if (status < 0) |
| 4156 | return status; |
| 4157 | |
| 4158 | autosw = video_autosw_get(); |
| 4159 | if (autosw < 0) |
| 4160 | return autosw; |
| 4161 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4162 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 4163 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 4164 | len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1)); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4165 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4166 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 4167 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 4168 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 4169 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4170 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4171 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 4172 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 4173 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 4174 | |
| 4175 | return len; |
| 4176 | } |
| 4177 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4178 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | { |
| 4180 | char *cmd; |
| 4181 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4182 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4184 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4185 | return -ENODEV; |
| 4186 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4187 | enable = 0; |
| 4188 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | |
| 4190 | while ((cmd = next_cmd(&buf))) { |
| 4191 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4192 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4194 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4196 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4198 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4199 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4200 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4201 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4202 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4203 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4204 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4206 | res = video_autosw_set(1); |
| 4207 | if (res) |
| 4208 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4210 | res = video_autosw_set(0); |
| 4211 | if (res) |
| 4212 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4214 | res = video_outputsw_cycle(); |
| 4215 | if (res) |
| 4216 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4218 | res = video_expand_toggle(); |
| 4219 | if (res) |
| 4220 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | } else |
| 4222 | return -EINVAL; |
| 4223 | } |
| 4224 | |
| 4225 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4226 | status = video_outputsw_get(); |
| 4227 | if (status < 0) |
| 4228 | return status; |
| 4229 | res = video_outputsw_set((status & ~disable) | enable); |
| 4230 | if (res) |
| 4231 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | return 0; |
| 4235 | } |
| 4236 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4237 | static struct ibm_struct video_driver_data = { |
| 4238 | .name = "video", |
| 4239 | .read = video_read, |
| 4240 | .write = video_write, |
| 4241 | .exit = video_exit, |
| 4242 | }; |
| 4243 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4244 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 4245 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4246 | /************************************************************************* |
| 4247 | * Light (thinklight) subdriver |
| 4248 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4250 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 4251 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4252 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4253 | static int light_get_status(void) |
| 4254 | { |
| 4255 | int status = 0; |
| 4256 | |
| 4257 | if (tp_features.light_status) { |
| 4258 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 4259 | return -EIO; |
| 4260 | return (!!status); |
| 4261 | } |
| 4262 | |
| 4263 | return -ENXIO; |
| 4264 | } |
| 4265 | |
| 4266 | static int light_set_status(int status) |
| 4267 | { |
| 4268 | int rc; |
| 4269 | |
| 4270 | if (tp_features.light) { |
| 4271 | if (cmos_handle) { |
| 4272 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", |
| 4273 | (status)? |
| 4274 | TP_CMOS_THINKLIGHT_ON : |
| 4275 | TP_CMOS_THINKLIGHT_OFF); |
| 4276 | } else { |
| 4277 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", |
| 4278 | (status)? 1 : 0); |
| 4279 | } |
| 4280 | return (rc)? 0 : -EIO; |
| 4281 | } |
| 4282 | |
| 4283 | return -ENXIO; |
| 4284 | } |
| 4285 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4286 | static void light_set_status_worker(struct work_struct *work) |
| 4287 | { |
| 4288 | struct tpacpi_led_classdev *data = |
| 4289 | container_of(work, struct tpacpi_led_classdev, work); |
| 4290 | |
| 4291 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4292 | light_set_status((data->new_state != TPACPI_LED_OFF)); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4293 | } |
| 4294 | |
| 4295 | static void light_sysfs_set(struct led_classdev *led_cdev, |
| 4296 | enum led_brightness brightness) |
| 4297 | { |
| 4298 | struct tpacpi_led_classdev *data = |
| 4299 | container_of(led_cdev, |
| 4300 | struct tpacpi_led_classdev, |
| 4301 | led_classdev); |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4302 | data->new_state = (brightness != LED_OFF) ? |
| 4303 | TPACPI_LED_ON : TPACPI_LED_OFF; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4304 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) |
| 4308 | { |
| 4309 | return (light_get_status() == 1)? LED_FULL : LED_OFF; |
| 4310 | } |
| 4311 | |
| 4312 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { |
| 4313 | .led_classdev = { |
| 4314 | .name = "tpacpi::thinklight", |
| 4315 | .brightness_set = &light_sysfs_set, |
| 4316 | .brightness_get = &light_sysfs_get, |
| 4317 | } |
| 4318 | }; |
| 4319 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4320 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4322 | int rc; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4323 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4324 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 4325 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4326 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 4327 | TPACPI_ACPIHANDLE_INIT(lght); |
| 4328 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4329 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4330 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4331 | /* 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] | 4332 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4333 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4334 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4335 | /* light status not supported on |
| 4336 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4337 | tp_features.light_status = |
| 4338 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4340 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
| 4341 | str_supported(tp_features.light), |
| 4342 | str_supported(tp_features.light_status)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4343 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4344 | if (!tp_features.light) |
| 4345 | return 1; |
| 4346 | |
| 4347 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 4348 | &tpacpi_led_thinklight.led_classdev); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4349 | |
| 4350 | if (rc < 0) { |
| 4351 | tp_features.light = 0; |
| 4352 | tp_features.light_status = 0; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4353 | } else { |
| 4354 | rc = 0; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4355 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4356 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4357 | return rc; |
| 4358 | } |
| 4359 | |
| 4360 | static void light_exit(void) |
| 4361 | { |
| 4362 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); |
| 4363 | if (work_pending(&tpacpi_led_thinklight.work)) |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4364 | flush_workqueue(tpacpi_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | } |
| 4366 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4367 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | { |
| 4369 | int len = 0; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4370 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4372 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4373 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4374 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4375 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 4376 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 4377 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4378 | status = light_get_status(); |
| 4379 | if (status < 0) |
| 4380 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4382 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 4383 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | |
| 4385 | return len; |
| 4386 | } |
| 4387 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4388 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4391 | int newstatus = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4392 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4393 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4394 | return -ENODEV; |
| 4395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | while ((cmd = next_cmd(&buf))) { |
| 4397 | if (strlencmp(cmd, "on") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4398 | newstatus = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | } else if (strlencmp(cmd, "off") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4400 | newstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | } else |
| 4402 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | } |
| 4404 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4405 | return light_set_status(newstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | } |
| 4407 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4408 | static struct ibm_struct light_driver_data = { |
| 4409 | .name = "light", |
| 4410 | .read = light_read, |
| 4411 | .write = light_write, |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4412 | .exit = light_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4413 | }; |
| 4414 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4415 | /************************************************************************* |
| 4416 | * Dock subdriver |
| 4417 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 4419 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4420 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4421 | static void dock_notify(struct ibm_struct *ibm, u32 event); |
| 4422 | static int dock_read(char *p); |
| 4423 | static int dock_write(char *buf); |
| 4424 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4425 | TPACPI_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4426 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ |
| 4427 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ |
| 4428 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
| 4429 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
| 4430 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4431 | /* don't list other alternatives as we install a notify handler on the 570 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4432 | TPACPI_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4433 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 4434 | static const struct acpi_device_id ibm_pci_device_ids[] = { |
| 4435 | {PCI_ROOT_HID_STRING, 0}, |
| 4436 | {"", 0}, |
| 4437 | }; |
| 4438 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 4439 | static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = { |
| 4440 | { |
| 4441 | .notify = dock_notify, |
| 4442 | .handle = &dock_handle, |
| 4443 | .type = ACPI_SYSTEM_NOTIFY, |
| 4444 | }, |
| 4445 | { |
Henrique de Moraes Holschuh | 996fba0 | 2007-07-18 23:45:40 -0300 | [diff] [blame] | 4446 | /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING. |
| 4447 | * We just use it to get notifications of dock hotplug |
| 4448 | * in very old thinkpads */ |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 4449 | .hid = ibm_pci_device_ids, |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 4450 | .notify = dock_notify, |
| 4451 | .handle = &pci_handle, |
| 4452 | .type = ACPI_SYSTEM_NOTIFY, |
| 4453 | }, |
| 4454 | }; |
| 4455 | |
| 4456 | static struct ibm_struct dock_driver_data[2] = { |
| 4457 | { |
| 4458 | .name = "dock", |
| 4459 | .read = dock_read, |
| 4460 | .write = dock_write, |
| 4461 | .acpi = &ibm_dock_acpidriver[0], |
| 4462 | }, |
| 4463 | { |
| 4464 | .name = "dock", |
| 4465 | .acpi = &ibm_dock_acpidriver[1], |
| 4466 | }, |
| 4467 | }; |
| 4468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | #define dock_docked() (_sta(dock_handle) & 1) |
| 4470 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4471 | static int __init dock_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4472 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4473 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n"); |
| 4474 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4475 | TPACPI_ACPIHANDLE_INIT(dock); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4476 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4477 | vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n", |
| 4478 | str_supported(dock_handle != NULL)); |
| 4479 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4480 | return (dock_handle)? 0 : 1; |
| 4481 | } |
| 4482 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 4483 | static int __init dock_init2(struct ibm_init_struct *iibm) |
| 4484 | { |
| 4485 | int dock2_needed; |
| 4486 | |
| 4487 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n"); |
| 4488 | |
| 4489 | if (dock_driver_data[0].flags.acpi_driver_registered && |
| 4490 | dock_driver_data[0].flags.acpi_notify_installed) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4491 | TPACPI_ACPIHANDLE_INIT(pci); |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 4492 | dock2_needed = (pci_handle != NULL); |
| 4493 | vdbg_printk(TPACPI_DBG_INIT, |
| 4494 | "dock PCI handler for the TP 570 is %s\n", |
| 4495 | str_supported(dock2_needed)); |
| 4496 | } else { |
| 4497 | vdbg_printk(TPACPI_DBG_INIT, |
| 4498 | "dock subdriver part 2 not required\n"); |
| 4499 | dock2_needed = 0; |
| 4500 | } |
| 4501 | |
| 4502 | return (dock2_needed)? 0 : 1; |
| 4503 | } |
| 4504 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4505 | static void dock_notify(struct ibm_struct *ibm, u32 event) |
| 4506 | { |
| 4507 | int docked = dock_docked(); |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 4508 | int pci = ibm->acpi->hid && ibm->acpi->device && |
| 4509 | acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4510 | int data; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4511 | |
| 4512 | if (event == 1 && !pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4513 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4514 | else if (event == 1 && pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4515 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4516 | else if (event == 3 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4517 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4518 | else if (event == 3 && !docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4519 | data = 2; /* undock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4520 | else if (event == 0 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4521 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4522 | else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4523 | printk(TPACPI_ERR "unknown dock event %d, status %d\n", |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4524 | event, _sta(dock_handle)); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4525 | data = 0; /* unknown */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4526 | } |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 4527 | acpi_bus_generate_proc_event(ibm->acpi->device, event, data); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4528 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 4529 | dev_name(&ibm->acpi->device->dev), |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4530 | event, data); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4531 | } |
| 4532 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4533 | static int dock_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | { |
| 4535 | int len = 0; |
| 4536 | int docked = dock_docked(); |
| 4537 | |
| 4538 | if (!dock_handle) |
| 4539 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4540 | else if (!docked) |
| 4541 | len += sprintf(p + len, "status:\t\tundocked\n"); |
| 4542 | else { |
| 4543 | len += sprintf(p + len, "status:\t\tdocked\n"); |
| 4544 | len += sprintf(p + len, "commands:\tdock, undock\n"); |
| 4545 | } |
| 4546 | |
| 4547 | return len; |
| 4548 | } |
| 4549 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4550 | static int dock_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | { |
| 4552 | char *cmd; |
| 4553 | |
| 4554 | if (!dock_docked()) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4555 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | |
| 4557 | while ((cmd = next_cmd(&buf))) { |
| 4558 | if (strlencmp(cmd, "undock") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4559 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || |
| 4560 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | return -EIO; |
| 4562 | } else if (strlencmp(cmd, "dock") == 0) { |
| 4563 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) |
| 4564 | return -EIO; |
| 4565 | } else |
| 4566 | return -EINVAL; |
| 4567 | } |
| 4568 | |
| 4569 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 4572 | #endif /* CONFIG_THINKPAD_ACPI_DOCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4574 | /************************************************************************* |
| 4575 | * Bay subdriver |
| 4576 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 4578 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4579 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4580 | TPACPI_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4581 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
| 4582 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ |
| 4583 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
| 4584 | ); /* A21e, R30, R31 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4585 | TPACPI_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4586 | "_EJ0", /* all others */ |
| 4587 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4588 | TPACPI_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4589 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ |
| 4590 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4591 | TPACPI_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4592 | "_EJ0", /* 770x */ |
| 4593 | ); /* all others */ |
| 4594 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4595 | static int __init bay_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4597 | vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n"); |
| 4598 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4599 | TPACPI_ACPIHANDLE_INIT(bay); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4600 | if (bay_handle) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4601 | TPACPI_ACPIHANDLE_INIT(bay_ej); |
| 4602 | TPACPI_ACPIHANDLE_INIT(bay2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4603 | if (bay2_handle) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4604 | TPACPI_ACPIHANDLE_INIT(bay2_ej); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4605 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4606 | tp_features.bay_status = bay_handle && |
| 4607 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); |
| 4608 | tp_features.bay_status2 = bay2_handle && |
| 4609 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4610 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4611 | tp_features.bay_eject = bay_handle && bay_ej_handle && |
| 4612 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); |
| 4613 | tp_features.bay_eject2 = bay2_handle && bay2_ej_handle && |
| 4614 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4616 | vdbg_printk(TPACPI_DBG_INIT, |
| 4617 | "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4618 | str_supported(tp_features.bay_status), |
| 4619 | str_supported(tp_features.bay_eject), |
| 4620 | str_supported(tp_features.bay_status2), |
| 4621 | str_supported(tp_features.bay_eject2)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4622 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4623 | return (tp_features.bay_status || tp_features.bay_eject || |
| 4624 | tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | } |
| 4626 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4627 | static void bay_notify(struct ibm_struct *ibm, u32 event) |
| 4628 | { |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 4629 | acpi_bus_generate_proc_event(ibm->acpi->device, event, 0); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4630 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 4631 | dev_name(&ibm->acpi->device->dev), |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 4632 | event, 0); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4633 | } |
| 4634 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4635 | #define bay_occupied(b) (_sta(b##_handle) & 1) |
| 4636 | |
| 4637 | static int bay_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | { |
| 4639 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4640 | int occupied = bay_occupied(bay); |
| 4641 | int occupied2 = bay_occupied(bay2); |
| 4642 | int eject, eject2; |
| 4643 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4644 | len += sprintf(p + len, "status:\t\t%s\n", |
| 4645 | tp_features.bay_status ? |
| 4646 | (occupied ? "occupied" : "unoccupied") : |
| 4647 | "not supported"); |
| 4648 | if (tp_features.bay_status2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4649 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? |
| 4650 | "occupied" : "unoccupied"); |
| 4651 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4652 | eject = tp_features.bay_eject && occupied; |
| 4653 | eject2 = tp_features.bay_eject2 && occupied2; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4654 | |
| 4655 | if (eject && eject2) |
| 4656 | len += sprintf(p + len, "commands:\teject, eject2\n"); |
| 4657 | else if (eject) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | len += sprintf(p + len, "commands:\teject\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4659 | else if (eject2) |
| 4660 | len += sprintf(p + len, "commands:\teject2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | |
| 4662 | return len; |
| 4663 | } |
| 4664 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4665 | static int bay_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | { |
| 4667 | char *cmd; |
| 4668 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4669 | if (!tp_features.bay_eject && !tp_features.bay_eject2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4670 | return -ENODEV; |
| 4671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4673 | if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4674 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) |
| 4675 | return -EIO; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4676 | } else if (tp_features.bay_eject2 && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4677 | strlencmp(cmd, "eject2") == 0) { |
| 4678 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4679 | return -EIO; |
| 4680 | } else |
| 4681 | return -EINVAL; |
| 4682 | } |
| 4683 | |
| 4684 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4685 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4686 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 4687 | static struct tp_acpi_drv_struct ibm_bay_acpidriver = { |
| 4688 | .notify = bay_notify, |
| 4689 | .handle = &bay_handle, |
| 4690 | .type = ACPI_SYSTEM_NOTIFY, |
| 4691 | }; |
| 4692 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4693 | static struct ibm_struct bay_driver_data = { |
| 4694 | .name = "bay", |
| 4695 | .read = bay_read, |
| 4696 | .write = bay_write, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 4697 | .acpi = &ibm_bay_acpidriver, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4698 | }; |
| 4699 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 4700 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4702 | /************************************************************************* |
| 4703 | * CMOS subdriver |
| 4704 | */ |
| 4705 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4706 | /* sysfs cmos_command -------------------------------------------------- */ |
| 4707 | static ssize_t cmos_command_store(struct device *dev, |
| 4708 | struct device_attribute *attr, |
| 4709 | const char *buf, size_t count) |
| 4710 | { |
| 4711 | unsigned long cmos_cmd; |
| 4712 | int res; |
| 4713 | |
| 4714 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 4715 | return -EINVAL; |
| 4716 | |
| 4717 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4718 | return (res)? res : count; |
| 4719 | } |
| 4720 | |
| 4721 | static struct device_attribute dev_attr_cmos_command = |
| 4722 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 4723 | |
| 4724 | /* --------------------------------------------------------------------- */ |
| 4725 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4726 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4727 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4728 | int res; |
| 4729 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4730 | vdbg_printk(TPACPI_DBG_INIT, |
| 4731 | "initializing cmos commands subdriver\n"); |
| 4732 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4733 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4734 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4735 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 4736 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4737 | |
| 4738 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4739 | if (res) |
| 4740 | return res; |
| 4741 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4742 | return (cmos_handle)? 0 : 1; |
| 4743 | } |
| 4744 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4745 | static void cmos_exit(void) |
| 4746 | { |
| 4747 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4748 | } |
| 4749 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4750 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | { |
| 4752 | int len = 0; |
| 4753 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4754 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4755 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | if (!cmos_handle) |
| 4757 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4758 | else { |
| 4759 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4760 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4761 | } |
| 4762 | |
| 4763 | return len; |
| 4764 | } |
| 4765 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4766 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | { |
| 4768 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4769 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | |
| 4771 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4772 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 4773 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | /* cmos_cmd set */ |
| 4775 | } else |
| 4776 | return -EINVAL; |
| 4777 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4778 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4779 | if (res) |
| 4780 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4784 | } |
| 4785 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4786 | static struct ibm_struct cmos_driver_data = { |
| 4787 | .name = "cmos", |
| 4788 | .read = cmos_read, |
| 4789 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4790 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4791 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4792 | |
| 4793 | /************************************************************************* |
| 4794 | * LED subdriver |
| 4795 | */ |
| 4796 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4797 | enum led_access_mode { |
| 4798 | TPACPI_LED_NONE = 0, |
| 4799 | TPACPI_LED_570, /* 570 */ |
| 4800 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 4801 | TPACPI_LED_NEW, /* all others */ |
| 4802 | }; |
| 4803 | |
| 4804 | enum { /* For TPACPI_LED_OLD */ |
| 4805 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 4806 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 4807 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 4808 | }; |
| 4809 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4810 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4811 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4812 | TPACPI_HANDLE(led, ec, "SLED", /* 570 */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4813 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */ |
| 4814 | /* T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4815 | "LED", /* all others */ |
| 4816 | ); /* R30, R31 */ |
| 4817 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4818 | #define TPACPI_LED_NUMLEDS 16 |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4819 | static struct tpacpi_led_classdev *tpacpi_leds; |
| 4820 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; |
Harvey Harrison | e3aa51f | 2008-05-29 17:51:57 -0700 | [diff] [blame] | 4821 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4822 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
| 4823 | "tpacpi::power", |
| 4824 | "tpacpi:orange:batt", |
| 4825 | "tpacpi:green:batt", |
| 4826 | "tpacpi::dock_active", |
| 4827 | "tpacpi::bay_active", |
| 4828 | "tpacpi::dock_batt", |
| 4829 | "tpacpi::unknown_led", |
| 4830 | "tpacpi::standby", |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4831 | "tpacpi::dock_status1", |
| 4832 | "tpacpi::dock_status2", |
| 4833 | "tpacpi::unknown_led2", |
| 4834 | "tpacpi::unknown_led3", |
| 4835 | "tpacpi::thinkvantage", |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4836 | }; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4837 | #define TPACPI_SAFE_LEDS 0x1081U |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4838 | |
| 4839 | static inline bool tpacpi_is_led_restricted(const unsigned int led) |
| 4840 | { |
| 4841 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
| 4842 | return false; |
| 4843 | #else |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4844 | return (1U & (TPACPI_SAFE_LEDS >> led)) == 0; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4845 | #endif |
| 4846 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4847 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4848 | static int led_get_status(const unsigned int led) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4849 | { |
| 4850 | int status; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4851 | enum led_status_t led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4852 | |
| 4853 | switch (led_supported) { |
| 4854 | case TPACPI_LED_570: |
| 4855 | if (!acpi_evalf(ec_handle, |
| 4856 | &status, "GLED", "dd", 1 << led)) |
| 4857 | return -EIO; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4858 | led_s = (status == 0)? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4859 | TPACPI_LED_OFF : |
| 4860 | ((status == 1)? |
| 4861 | TPACPI_LED_ON : |
| 4862 | TPACPI_LED_BLINK); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4863 | tpacpi_led_state_cache[led] = led_s; |
| 4864 | return led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4865 | default: |
| 4866 | return -ENXIO; |
| 4867 | } |
| 4868 | |
| 4869 | /* not reached */ |
| 4870 | } |
| 4871 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4872 | static int led_set_status(const unsigned int led, |
| 4873 | const enum led_status_t ledstatus) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4874 | { |
| 4875 | /* off, on, blink. Index is led_status_t */ |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4876 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
| 4877 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4878 | |
| 4879 | int rc = 0; |
| 4880 | |
| 4881 | switch (led_supported) { |
| 4882 | case TPACPI_LED_570: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4883 | /* 570 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4884 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4885 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4886 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 4887 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4888 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 4889 | (1 << led), led_sled_arg1[ledstatus])) |
| 4890 | rc = -EIO; |
| 4891 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4892 | case TPACPI_LED_OLD: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4893 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4894 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4895 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4896 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 4897 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4898 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
| 4899 | if (rc >= 0) |
| 4900 | rc = ec_write(TPACPI_LED_EC_HLBL, |
| 4901 | (ledstatus == TPACPI_LED_BLINK) << led); |
| 4902 | if (rc >= 0) |
| 4903 | rc = ec_write(TPACPI_LED_EC_HLCL, |
| 4904 | (ledstatus != TPACPI_LED_OFF) << led); |
| 4905 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4906 | case TPACPI_LED_NEW: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4907 | /* all others */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4908 | if (unlikely(led >= TPACPI_LED_NUMLEDS)) |
| 4909 | return -EINVAL; |
| 4910 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 4911 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4912 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 4913 | led, led_led_arg1[ledstatus])) |
| 4914 | rc = -EIO; |
| 4915 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4916 | default: |
| 4917 | rc = -ENXIO; |
| 4918 | } |
| 4919 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4920 | if (!rc) |
| 4921 | tpacpi_led_state_cache[led] = ledstatus; |
| 4922 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4923 | return rc; |
| 4924 | } |
| 4925 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4926 | static void led_set_status_worker(struct work_struct *work) |
| 4927 | { |
| 4928 | struct tpacpi_led_classdev *data = |
| 4929 | container_of(work, struct tpacpi_led_classdev, work); |
| 4930 | |
| 4931 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4932 | led_set_status(data->led, data->new_state); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4933 | } |
| 4934 | |
| 4935 | static void led_sysfs_set(struct led_classdev *led_cdev, |
| 4936 | enum led_brightness brightness) |
| 4937 | { |
| 4938 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 4939 | struct tpacpi_led_classdev, led_classdev); |
| 4940 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4941 | if (brightness == LED_OFF) |
| 4942 | data->new_state = TPACPI_LED_OFF; |
| 4943 | else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) |
| 4944 | data->new_state = TPACPI_LED_ON; |
| 4945 | else |
| 4946 | data->new_state = TPACPI_LED_BLINK; |
| 4947 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4948 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4949 | } |
| 4950 | |
| 4951 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, |
| 4952 | unsigned long *delay_on, unsigned long *delay_off) |
| 4953 | { |
| 4954 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 4955 | struct tpacpi_led_classdev, led_classdev); |
| 4956 | |
| 4957 | /* Can we choose the flash rate? */ |
| 4958 | if (*delay_on == 0 && *delay_off == 0) { |
| 4959 | /* yes. set them to the hardware blink rate (1 Hz) */ |
| 4960 | *delay_on = 500; /* ms */ |
| 4961 | *delay_off = 500; /* ms */ |
| 4962 | } else if ((*delay_on != 500) || (*delay_off != 500)) |
| 4963 | return -EINVAL; |
| 4964 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4965 | data->new_state = TPACPI_LED_BLINK; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4966 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4967 | |
| 4968 | return 0; |
| 4969 | } |
| 4970 | |
| 4971 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) |
| 4972 | { |
| 4973 | int rc; |
| 4974 | |
| 4975 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 4976 | struct tpacpi_led_classdev, led_classdev); |
| 4977 | |
| 4978 | rc = led_get_status(data->led); |
| 4979 | |
| 4980 | if (rc == TPACPI_LED_OFF || rc < 0) |
| 4981 | rc = LED_OFF; /* no error handling in led class :( */ |
| 4982 | else |
| 4983 | rc = LED_FULL; |
| 4984 | |
| 4985 | return rc; |
| 4986 | } |
| 4987 | |
| 4988 | static void led_exit(void) |
| 4989 | { |
| 4990 | unsigned int i; |
| 4991 | |
| 4992 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 4993 | if (tpacpi_leds[i].led_classdev.name) |
| 4994 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); |
| 4995 | } |
| 4996 | |
| 4997 | kfree(tpacpi_leds); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4998 | } |
| 4999 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5000 | static int __init tpacpi_init_led(unsigned int led) |
| 5001 | { |
| 5002 | int rc; |
| 5003 | |
| 5004 | tpacpi_leds[led].led = led; |
| 5005 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5006 | /* LEDs with no name don't get registered */ |
| 5007 | if (!tpacpi_led_names[led]) |
| 5008 | return 0; |
| 5009 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5010 | tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set; |
| 5011 | tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set; |
| 5012 | if (led_supported == TPACPI_LED_570) |
| 5013 | tpacpi_leds[led].led_classdev.brightness_get = |
| 5014 | &led_sysfs_get; |
| 5015 | |
| 5016 | tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led]; |
| 5017 | |
| 5018 | INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker); |
| 5019 | |
| 5020 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 5021 | &tpacpi_leds[led].led_classdev); |
| 5022 | if (rc < 0) |
| 5023 | tpacpi_leds[led].led_classdev.name = NULL; |
| 5024 | |
| 5025 | return rc; |
| 5026 | } |
| 5027 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5028 | static const struct tpacpi_quirk led_useful_qtable[] __initconst = { |
| 5029 | TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */ |
| 5030 | TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */ |
| 5031 | TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */ |
| 5032 | |
| 5033 | TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */ |
| 5034 | TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */ |
| 5035 | TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */ |
| 5036 | TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */ |
| 5037 | TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */ |
| 5038 | TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */ |
| 5039 | TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */ |
| 5040 | TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */ |
| 5041 | |
| 5042 | TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */ |
| 5043 | TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */ |
| 5044 | TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */ |
| 5045 | TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */ |
| 5046 | TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */ |
| 5047 | |
| 5048 | TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */ |
| 5049 | TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */ |
| 5050 | TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */ |
| 5051 | TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */ |
| 5052 | |
| 5053 | /* (1) - may have excess leds enabled on MSB */ |
| 5054 | |
| 5055 | /* Defaults (order matters, keep last, don't reorder!) */ |
| 5056 | { /* Lenovo */ |
| 5057 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 5058 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5059 | .quirks = 0x1fffU, |
| 5060 | }, |
| 5061 | { /* IBM ThinkPads with no EC version string */ |
| 5062 | .vendor = PCI_VENDOR_ID_IBM, |
| 5063 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_UNKNOWN, |
| 5064 | .quirks = 0x00ffU, |
| 5065 | }, |
| 5066 | { /* IBM ThinkPads with EC version string */ |
| 5067 | .vendor = PCI_VENDOR_ID_IBM, |
| 5068 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5069 | .quirks = 0x00bfU, |
| 5070 | }, |
| 5071 | }; |
| 5072 | |
| 5073 | #undef TPACPI_LEDQ_IBM |
| 5074 | #undef TPACPI_LEDQ_LNV |
| 5075 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5076 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5077 | { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5078 | unsigned int i; |
| 5079 | int rc; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5080 | unsigned long useful_leds; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5081 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5082 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 5083 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5084 | TPACPI_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5085 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5086 | if (!led_handle) |
| 5087 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5088 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5089 | else if (strlencmp(led_path, "SLED") == 0) |
| 5090 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5091 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5092 | else if (strlencmp(led_path, "SYSL") == 0) |
| 5093 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5094 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5095 | else |
| 5096 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5097 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5098 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5099 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 5100 | str_supported(led_supported), led_supported); |
| 5101 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5102 | if (led_supported == TPACPI_LED_NONE) |
| 5103 | return 1; |
| 5104 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5105 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
| 5106 | GFP_KERNEL); |
| 5107 | if (!tpacpi_leds) { |
| 5108 | printk(TPACPI_ERR "Out of memory for LED data\n"); |
| 5109 | return -ENOMEM; |
| 5110 | } |
| 5111 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5112 | useful_leds = tpacpi_check_quirks(led_useful_qtable, |
| 5113 | ARRAY_SIZE(led_useful_qtable)); |
| 5114 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5115 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5116 | if (!tpacpi_is_led_restricted(i) && |
| 5117 | test_bit(i, &useful_leds)) { |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5118 | rc = tpacpi_init_led(i); |
| 5119 | if (rc < 0) { |
| 5120 | led_exit(); |
| 5121 | return rc; |
| 5122 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5123 | } |
| 5124 | } |
| 5125 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5126 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5127 | printk(TPACPI_NOTICE |
| 5128 | "warning: userspace override of important " |
| 5129 | "firmware LEDs is enabled\n"); |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5130 | #endif |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5131 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5132 | } |
| 5133 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5134 | #define str_led_status(s) \ |
| 5135 | ((s) == TPACPI_LED_OFF ? "off" : \ |
| 5136 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5137 | |
| 5138 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | { |
| 5140 | int len = 0; |
| 5141 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5142 | if (!led_supported) { |
| 5143 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5144 | return len; |
| 5145 | } |
| 5146 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 5147 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5148 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5149 | /* 570 */ |
| 5150 | int i, status; |
| 5151 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5152 | status = led_get_status(i); |
| 5153 | if (status < 0) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5154 | return -EIO; |
| 5155 | len += sprintf(p + len, "%d:\t\t%s\n", |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5156 | i, str_led_status(status)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5157 | } |
| 5158 | } |
| 5159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5160 | len += sprintf(p + len, "commands:\t" |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5161 | "<led> on, <led> off, <led> blink (<led> is 0-15)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | |
| 5163 | return len; |
| 5164 | } |
| 5165 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5166 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5167 | { |
| 5168 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5169 | int led, rc; |
| 5170 | enum led_status_t s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5171 | |
| 5172 | if (!led_supported) |
| 5173 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | |
| 5175 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5176 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5177 | return -EINVAL; |
| 5178 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5179 | if (strstr(cmd, "off")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5180 | s = TPACPI_LED_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5181 | } else if (strstr(cmd, "on")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5182 | s = TPACPI_LED_ON; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5183 | } else if (strstr(cmd, "blink")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5184 | s = TPACPI_LED_BLINK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5185 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5186 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5187 | } |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5188 | |
| 5189 | rc = led_set_status(led, s); |
| 5190 | if (rc < 0) |
| 5191 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5192 | } |
| 5193 | |
| 5194 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5195 | } |
| 5196 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5197 | static struct ibm_struct led_driver_data = { |
| 5198 | .name = "led", |
| 5199 | .read = led_read, |
| 5200 | .write = led_write, |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5201 | .exit = led_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5202 | }; |
| 5203 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5204 | /************************************************************************* |
| 5205 | * Beep subdriver |
| 5206 | */ |
| 5207 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5208 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5209 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5210 | #define TPACPI_BEEP_Q1 0x0001 |
| 5211 | |
| 5212 | static const struct tpacpi_quirk beep_quirk_table[] __initconst = { |
| 5213 | TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1), /* 570 */ |
| 5214 | TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */ |
| 5215 | }; |
| 5216 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5217 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5218 | { |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5219 | unsigned long quirks; |
| 5220 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5221 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 5222 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5223 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5224 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5225 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 5226 | str_supported(beep_handle != NULL)); |
| 5227 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5228 | quirks = tpacpi_check_quirks(beep_quirk_table, |
| 5229 | ARRAY_SIZE(beep_quirk_table)); |
| 5230 | |
| 5231 | tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); |
| 5232 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5233 | return (beep_handle)? 0 : 1; |
| 5234 | } |
| 5235 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5236 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5237 | { |
| 5238 | int len = 0; |
| 5239 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5240 | if (!beep_handle) |
| 5241 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5242 | else { |
| 5243 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 5244 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 5245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5246 | |
| 5247 | return len; |
| 5248 | } |
| 5249 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5250 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5251 | { |
| 5252 | char *cmd; |
| 5253 | int beep_cmd; |
| 5254 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5255 | if (!beep_handle) |
| 5256 | return -ENODEV; |
| 5257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5258 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5259 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 5260 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5261 | /* beep_cmd set */ |
| 5262 | } else |
| 5263 | return -EINVAL; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5264 | if (tp_features.beep_needs_two_args) { |
| 5265 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", |
| 5266 | beep_cmd, 0)) |
| 5267 | return -EIO; |
| 5268 | } else { |
| 5269 | if (!acpi_evalf(beep_handle, NULL, NULL, "vd", |
| 5270 | beep_cmd)) |
| 5271 | return -EIO; |
| 5272 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5276 | } |
| 5277 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5278 | static struct ibm_struct beep_driver_data = { |
| 5279 | .name = "beep", |
| 5280 | .read = beep_read, |
| 5281 | .write = beep_write, |
| 5282 | }; |
| 5283 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5284 | /************************************************************************* |
| 5285 | * Thermal subdriver |
| 5286 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5287 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5288 | enum thermal_access_mode { |
| 5289 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 5290 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 5291 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 5292 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 5293 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 5294 | }; |
| 5295 | |
| 5296 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 5297 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 5298 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 5299 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
| 5300 | }; |
| 5301 | |
| 5302 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 5303 | struct ibm_thermal_sensors_struct { |
| 5304 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 5305 | }; |
| 5306 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5307 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5308 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5309 | /* idx is zero-based */ |
| 5310 | static int thermal_get_sensor(int idx, s32 *value) |
| 5311 | { |
| 5312 | int t; |
| 5313 | s8 tmp; |
| 5314 | char tmpi[5]; |
| 5315 | |
| 5316 | t = TP_EC_THERMAL_TMP0; |
| 5317 | |
| 5318 | switch (thermal_read_mode) { |
| 5319 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 5320 | case TPACPI_THERMAL_TPEC_16: |
| 5321 | if (idx >= 8 && idx <= 15) { |
| 5322 | t = TP_EC_THERMAL_TMP8; |
| 5323 | idx -= 8; |
| 5324 | } |
| 5325 | /* fallthrough */ |
| 5326 | #endif |
| 5327 | case TPACPI_THERMAL_TPEC_8: |
| 5328 | if (idx <= 7) { |
| 5329 | if (!acpi_ec_read(t + idx, &tmp)) |
| 5330 | return -EIO; |
| 5331 | *value = tmp * 1000; |
| 5332 | return 0; |
| 5333 | } |
| 5334 | break; |
| 5335 | |
| 5336 | case TPACPI_THERMAL_ACPI_UPDT: |
| 5337 | if (idx <= 7) { |
| 5338 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5339 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 5340 | return -EIO; |
| 5341 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5342 | return -EIO; |
| 5343 | *value = (t - 2732) * 100; |
| 5344 | return 0; |
| 5345 | } |
| 5346 | break; |
| 5347 | |
| 5348 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5349 | if (idx <= 7) { |
| 5350 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5351 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5352 | return -EIO; |
| 5353 | if (t > 127 || t < -127) |
| 5354 | t = TP_EC_THERMAL_TMP_NA; |
| 5355 | *value = t * 1000; |
| 5356 | return 0; |
| 5357 | } |
| 5358 | break; |
| 5359 | |
| 5360 | case TPACPI_THERMAL_NONE: |
| 5361 | default: |
| 5362 | return -ENOSYS; |
| 5363 | } |
| 5364 | |
| 5365 | return -EINVAL; |
| 5366 | } |
| 5367 | |
| 5368 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 5369 | { |
| 5370 | int res, i; |
| 5371 | int n; |
| 5372 | |
| 5373 | n = 8; |
| 5374 | i = 0; |
| 5375 | |
| 5376 | if (!s) |
| 5377 | return -EINVAL; |
| 5378 | |
| 5379 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 5380 | n = 16; |
| 5381 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5382 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5383 | res = thermal_get_sensor(i, &s->temp[i]); |
| 5384 | if (res) |
| 5385 | return res; |
| 5386 | } |
| 5387 | |
| 5388 | return n; |
| 5389 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5390 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5391 | /* sysfs temp##_input -------------------------------------------------- */ |
| 5392 | |
| 5393 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 5394 | struct device_attribute *attr, |
| 5395 | char *buf) |
| 5396 | { |
| 5397 | struct sensor_device_attribute *sensor_attr = |
| 5398 | to_sensor_dev_attr(attr); |
| 5399 | int idx = sensor_attr->index; |
| 5400 | s32 value; |
| 5401 | int res; |
| 5402 | |
| 5403 | res = thermal_get_sensor(idx, &value); |
| 5404 | if (res) |
| 5405 | return res; |
| 5406 | if (value == TP_EC_THERMAL_TMP_NA * 1000) |
| 5407 | return -ENXIO; |
| 5408 | |
| 5409 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 5410 | } |
| 5411 | |
| 5412 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5413 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 5414 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5415 | |
| 5416 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 5417 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 5418 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 5419 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 5420 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 5421 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 5422 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 5423 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 5424 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 5425 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 5426 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 5427 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 5428 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 5429 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 5430 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 5431 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 5432 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 5433 | }; |
| 5434 | |
| 5435 | #define THERMAL_ATTRS(X) \ |
| 5436 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 5437 | |
| 5438 | static struct attribute *thermal_temp_input_attr[] = { |
| 5439 | THERMAL_ATTRS(8), |
| 5440 | THERMAL_ATTRS(9), |
| 5441 | THERMAL_ATTRS(10), |
| 5442 | THERMAL_ATTRS(11), |
| 5443 | THERMAL_ATTRS(12), |
| 5444 | THERMAL_ATTRS(13), |
| 5445 | THERMAL_ATTRS(14), |
| 5446 | THERMAL_ATTRS(15), |
| 5447 | THERMAL_ATTRS(0), |
| 5448 | THERMAL_ATTRS(1), |
| 5449 | THERMAL_ATTRS(2), |
| 5450 | THERMAL_ATTRS(3), |
| 5451 | THERMAL_ATTRS(4), |
| 5452 | THERMAL_ATTRS(5), |
| 5453 | THERMAL_ATTRS(6), |
| 5454 | THERMAL_ATTRS(7), |
| 5455 | NULL |
| 5456 | }; |
| 5457 | |
| 5458 | static const struct attribute_group thermal_temp_input16_group = { |
| 5459 | .attrs = thermal_temp_input_attr |
| 5460 | }; |
| 5461 | |
| 5462 | static const struct attribute_group thermal_temp_input8_group = { |
| 5463 | .attrs = &thermal_temp_input_attr[8] |
| 5464 | }; |
| 5465 | |
| 5466 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 5467 | #undef THERMAL_ATTRS |
| 5468 | |
| 5469 | /* --------------------------------------------------------------------- */ |
| 5470 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5471 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5472 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5473 | u8 t, ta1, ta2; |
| 5474 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5475 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5476 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5477 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5478 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 5479 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5480 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5481 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 5482 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5483 | /* |
| 5484 | * Direct EC access mode: sensors at registers |
| 5485 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 5486 | * non-implemented, thermal sensors return 0x80 when |
| 5487 | * not available |
| 5488 | */ |
| 5489 | |
| 5490 | ta1 = ta2 = 0; |
| 5491 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5492 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5493 | ta1 |= t; |
| 5494 | } else { |
| 5495 | ta1 = 0; |
| 5496 | break; |
| 5497 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5498 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5499 | ta2 |= t; |
| 5500 | } else { |
| 5501 | ta1 = 0; |
| 5502 | break; |
| 5503 | } |
| 5504 | } |
| 5505 | if (ta1 == 0) { |
| 5506 | /* This is sheer paranoia, but we handle it anyway */ |
| 5507 | if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5508 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5509 | "ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5510 | "falling back to ACPI TMPx access " |
| 5511 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5512 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5513 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5514 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5515 | "ThinkPad ACPI EC access misbehaving, " |
| 5516 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5517 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5518 | } |
| 5519 | } else { |
| 5520 | thermal_read_mode = |
| 5521 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5522 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5523 | } |
| 5524 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5525 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 5526 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5527 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5528 | } else { |
| 5529 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5530 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5531 | } |
| 5532 | } else { |
| 5533 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5534 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5535 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5536 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5537 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 5538 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 5539 | thermal_read_mode); |
| 5540 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5541 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5542 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5543 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5544 | &thermal_temp_input16_group); |
| 5545 | if (res) |
| 5546 | return res; |
| 5547 | break; |
| 5548 | case TPACPI_THERMAL_TPEC_8: |
| 5549 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5550 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5551 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5552 | &thermal_temp_input8_group); |
| 5553 | if (res) |
| 5554 | return res; |
| 5555 | break; |
| 5556 | case TPACPI_THERMAL_NONE: |
| 5557 | default: |
| 5558 | return 1; |
| 5559 | } |
| 5560 | |
| 5561 | return 0; |
| 5562 | } |
| 5563 | |
| 5564 | static void thermal_exit(void) |
| 5565 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5566 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5567 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5568 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5569 | &thermal_temp_input16_group); |
| 5570 | break; |
| 5571 | case TPACPI_THERMAL_TPEC_8: |
| 5572 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5573 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5574 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5575 | &thermal_temp_input16_group); |
| 5576 | break; |
| 5577 | case TPACPI_THERMAL_NONE: |
| 5578 | default: |
| 5579 | break; |
| 5580 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | static int thermal_read(char *p) |
| 5584 | { |
| 5585 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5586 | int n, i; |
| 5587 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5588 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5589 | n = thermal_get_sensors(&t); |
| 5590 | if (unlikely(n < 0)) |
| 5591 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5592 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5593 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5594 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5595 | if (n > 0) { |
| 5596 | for (i = 0; i < (n - 1); i++) |
| 5597 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 5598 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 5599 | } else |
| 5600 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5601 | |
| 5602 | return len; |
| 5603 | } |
| 5604 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5605 | static struct ibm_struct thermal_driver_data = { |
| 5606 | .name = "thermal", |
| 5607 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5608 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5609 | }; |
| 5610 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5611 | /************************************************************************* |
| 5612 | * EC Dump subdriver |
| 5613 | */ |
| 5614 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5615 | static u8 ecdump_regs[256]; |
| 5616 | |
| 5617 | static int ecdump_read(char *p) |
| 5618 | { |
| 5619 | int len = 0; |
| 5620 | int i, j; |
| 5621 | u8 v; |
| 5622 | |
| 5623 | len += sprintf(p + len, "EC " |
| 5624 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 5625 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 5626 | for (i = 0; i < 256; i += 16) { |
| 5627 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 5628 | for (j = 0; j < 16; j++) { |
| 5629 | if (!acpi_ec_read(i + j, &v)) |
| 5630 | break; |
| 5631 | if (v != ecdump_regs[i + j]) |
| 5632 | len += sprintf(p + len, " *%02x", v); |
| 5633 | else |
| 5634 | len += sprintf(p + len, " %02x", v); |
| 5635 | ecdump_regs[i + j] = v; |
| 5636 | } |
| 5637 | len += sprintf(p + len, "\n"); |
| 5638 | if (j != 16) |
| 5639 | break; |
| 5640 | } |
| 5641 | |
| 5642 | /* These are way too dangerous to advertise openly... */ |
| 5643 | #if 0 |
| 5644 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 5645 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 5646 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 5647 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 5648 | #endif |
| 5649 | return len; |
| 5650 | } |
| 5651 | |
| 5652 | static int ecdump_write(char *buf) |
| 5653 | { |
| 5654 | char *cmd; |
| 5655 | int i, v; |
| 5656 | |
| 5657 | while ((cmd = next_cmd(&buf))) { |
| 5658 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 5659 | /* i and v set */ |
| 5660 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 5661 | /* i and v set */ |
| 5662 | } else |
| 5663 | return -EINVAL; |
| 5664 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 5665 | if (!acpi_ec_write(i, v)) |
| 5666 | return -EIO; |
| 5667 | } else |
| 5668 | return -EINVAL; |
| 5669 | } |
| 5670 | |
| 5671 | return 0; |
| 5672 | } |
| 5673 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5674 | static struct ibm_struct ecdump_driver_data = { |
| 5675 | .name = "ecdump", |
| 5676 | .read = ecdump_read, |
| 5677 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5678 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5679 | }; |
| 5680 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5681 | /************************************************************************* |
| 5682 | * Backlight/brightness subdriver |
| 5683 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 5684 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5685 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 5686 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5687 | /* |
| 5688 | * ThinkPads can read brightness from two places: EC HBRV (0x31), or |
| 5689 | * CMOS NVRAM byte 0x5E, bits 0-3. |
| 5690 | * |
| 5691 | * EC HBRV (0x31) has the following layout |
| 5692 | * Bit 7: unknown function |
| 5693 | * Bit 6: unknown function |
| 5694 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 5695 | * Bit 4: must be set to zero to avoid problems |
| 5696 | * Bit 3-0: backlight brightness level |
| 5697 | * |
| 5698 | * brightness_get_raw returns status data in the HBRV layout |
| 5699 | */ |
| 5700 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5701 | enum { |
| 5702 | TP_EC_BACKLIGHT = 0x31, |
| 5703 | |
| 5704 | /* TP_EC_BACKLIGHT bitmasks */ |
| 5705 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 5706 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 5707 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 5708 | }; |
| 5709 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5710 | enum tpacpi_brightness_access_mode { |
| 5711 | TPACPI_BRGHT_MODE_AUTO = 0, /* Not implemented yet */ |
| 5712 | TPACPI_BRGHT_MODE_EC, /* EC control */ |
| 5713 | TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */ |
| 5714 | TPACPI_BRGHT_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 5715 | TPACPI_BRGHT_MODE_MAX |
| 5716 | }; |
| 5717 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5718 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5719 | |
| 5720 | static enum tpacpi_brightness_access_mode brightness_mode = |
| 5721 | TPACPI_BRGHT_MODE_MAX; |
| 5722 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5723 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 5724 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5725 | static struct mutex brightness_mutex; |
| 5726 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5727 | /* NVRAM brightness access, |
| 5728 | * call with brightness_mutex held! */ |
| 5729 | static unsigned int tpacpi_brightness_nvram_get(void) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5730 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5731 | u8 lnvram; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5732 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5733 | lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 5734 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5735 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 5736 | lnvram &= (tp_features.bright_16levels) ? 0x0f : 0x07; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5737 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5738 | return lnvram; |
| 5739 | } |
| 5740 | |
| 5741 | static void tpacpi_brightness_checkpoint_nvram(void) |
| 5742 | { |
| 5743 | u8 lec = 0; |
| 5744 | u8 b_nvram; |
| 5745 | |
| 5746 | if (brightness_mode != TPACPI_BRGHT_MODE_ECNVRAM) |
| 5747 | return; |
| 5748 | |
| 5749 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5750 | "trying to checkpoint backlight level to NVRAM...\n"); |
| 5751 | |
| 5752 | if (mutex_lock_killable(&brightness_mutex) < 0) |
| 5753 | return; |
| 5754 | |
| 5755 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5756 | goto unlock; |
| 5757 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
| 5758 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 5759 | |
| 5760 | if (lec != ((b_nvram & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5761 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS)) { |
| 5762 | /* NVRAM needs update */ |
| 5763 | b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS << |
| 5764 | TP_NVRAM_POS_LEVEL_BRIGHTNESS); |
| 5765 | b_nvram |= lec; |
| 5766 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_BRIGHTNESS); |
| 5767 | dbg_printk(TPACPI_DBG_BRGHT, |
| 5768 | "updated NVRAM backlight level to %u (0x%02x)\n", |
| 5769 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5770 | } else |
| 5771 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5772 | "NVRAM backlight level already is %u (0x%02x)\n", |
| 5773 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5774 | |
| 5775 | unlock: |
| 5776 | mutex_unlock(&brightness_mutex); |
| 5777 | } |
| 5778 | |
| 5779 | |
| 5780 | /* call with brightness_mutex held! */ |
| 5781 | static int tpacpi_brightness_get_raw(int *status) |
| 5782 | { |
| 5783 | u8 lec = 0; |
| 5784 | |
| 5785 | switch (brightness_mode) { |
| 5786 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 5787 | *status = tpacpi_brightness_nvram_get(); |
| 5788 | return 0; |
| 5789 | case TPACPI_BRGHT_MODE_EC: |
| 5790 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 5791 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 5792 | return -EIO; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5793 | *status = lec; |
| 5794 | return 0; |
| 5795 | default: |
| 5796 | return -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5797 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | /* call with brightness_mutex held! */ |
| 5801 | /* do NOT call with illegal backlight level value */ |
| 5802 | static int tpacpi_brightness_set_ec(unsigned int value) |
| 5803 | { |
| 5804 | u8 lec = 0; |
| 5805 | |
| 5806 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5807 | return -EIO; |
| 5808 | |
| 5809 | if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT, |
| 5810 | (lec & TP_EC_BACKLIGHT_CMDMSK) | |
| 5811 | (value & TP_EC_BACKLIGHT_LVLMSK)))) |
| 5812 | return -EIO; |
| 5813 | |
| 5814 | return 0; |
| 5815 | } |
| 5816 | |
| 5817 | /* call with brightness_mutex held! */ |
| 5818 | static int tpacpi_brightness_set_ucmsstep(unsigned int value) |
| 5819 | { |
| 5820 | int cmos_cmd, inc; |
| 5821 | unsigned int current_value, i; |
| 5822 | |
| 5823 | current_value = tpacpi_brightness_nvram_get(); |
| 5824 | |
| 5825 | if (value == current_value) |
| 5826 | return 0; |
| 5827 | |
| 5828 | cmos_cmd = (value > current_value) ? |
| 5829 | TP_CMOS_BRIGHTNESS_UP : |
| 5830 | TP_CMOS_BRIGHTNESS_DOWN; |
| 5831 | inc = (value > current_value) ? 1 : -1; |
| 5832 | |
| 5833 | for (i = current_value; i != value; i += inc) |
| 5834 | if (issue_thinkpad_cmos_command(cmos_cmd)) |
| 5835 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5836 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5837 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5841 | static int brightness_set(unsigned int value) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5842 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5843 | int res; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5844 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5845 | if (value > ((tp_features.bright_16levels)? 15 : 7) || |
| 5846 | value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5847 | return -EINVAL; |
| 5848 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5849 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5850 | "set backlight level to %d\n", value); |
| 5851 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 5852 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5853 | if (res < 0) |
| 5854 | return res; |
| 5855 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5856 | switch (brightness_mode) { |
| 5857 | case TPACPI_BRGHT_MODE_EC: |
| 5858 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 5859 | res = tpacpi_brightness_set_ec(value); |
| 5860 | break; |
| 5861 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 5862 | res = tpacpi_brightness_set_ucmsstep(value); |
| 5863 | break; |
| 5864 | default: |
| 5865 | res = -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5866 | } |
| 5867 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5868 | mutex_unlock(&brightness_mutex); |
| 5869 | return res; |
| 5870 | } |
| 5871 | |
| 5872 | /* sysfs backlight class ----------------------------------------------- */ |
| 5873 | |
| 5874 | static int brightness_update_status(struct backlight_device *bd) |
| 5875 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5876 | unsigned int level = |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5877 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 5878 | bd->props.power == FB_BLANK_UNBLANK) ? |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5879 | bd->props.brightness : 0; |
| 5880 | |
| 5881 | dbg_printk(TPACPI_DBG_BRGHT, |
| 5882 | "backlight: attempt to set level to %d\n", |
| 5883 | level); |
| 5884 | |
| 5885 | /* it is the backlight class's job (caller) to handle |
| 5886 | * EINTR and other errors properly */ |
| 5887 | return brightness_set(level); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5888 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 5889 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5890 | static int brightness_get(struct backlight_device *bd) |
| 5891 | { |
| 5892 | int status, res; |
| 5893 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5894 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5895 | if (res < 0) |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5896 | return 0; |
| 5897 | |
| 5898 | res = tpacpi_brightness_get_raw(&status); |
| 5899 | |
| 5900 | mutex_unlock(&brightness_mutex); |
| 5901 | |
| 5902 | if (res < 0) |
| 5903 | return 0; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5904 | |
| 5905 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 5906 | } |
| 5907 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 5908 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5909 | .get_brightness = brightness_get, |
| 5910 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 5911 | }; |
| 5912 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5913 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 5914 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5915 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 5916 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 5917 | int b; |
| 5918 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5919 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 5920 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 5921 | mutex_init(&brightness_mutex); |
| 5922 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 5923 | /* |
| 5924 | * We always attempt to detect acpi support, so as to switch |
| 5925 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 5926 | * going to publish a backlight interface |
| 5927 | */ |
| 5928 | b = tpacpi_check_std_acpi_brightness_support(); |
| 5929 | if (b > 0) { |
Thomas Renninger | 2dba1b5 | 2008-08-01 17:38:03 +0200 | [diff] [blame] | 5930 | |
| 5931 | if (acpi_video_backlight_support()) { |
| 5932 | if (brightness_enable > 1) { |
| 5933 | printk(TPACPI_NOTICE |
| 5934 | "Standard ACPI backlight interface " |
| 5935 | "available, not loading native one.\n"); |
| 5936 | return 1; |
| 5937 | } else if (brightness_enable == 1) { |
| 5938 | printk(TPACPI_NOTICE |
| 5939 | "Backlight control force enabled, even if standard " |
| 5940 | "ACPI backlight interface is available\n"); |
| 5941 | } |
| 5942 | } else { |
| 5943 | if (brightness_enable > 1) { |
| 5944 | printk(TPACPI_NOTICE |
| 5945 | "Standard ACPI backlight interface not " |
| 5946 | "available, thinkpad_acpi native " |
| 5947 | "brightness control enabled\n"); |
| 5948 | } |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 5949 | } |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 5950 | } |
| 5951 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 5952 | if (!brightness_enable) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5953 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 5954 | "brightness support disabled by " |
| 5955 | "module parameter\n"); |
| 5956 | return 1; |
| 5957 | } |
| 5958 | |
| 5959 | if (b > 16) { |
| 5960 | printk(TPACPI_ERR |
| 5961 | "Unsupported brightness interface, " |
| 5962 | "please contact %s\n", TPACPI_MAIL); |
| 5963 | return 1; |
| 5964 | } |
| 5965 | if (b == 16) |
| 5966 | tp_features.bright_16levels = 1; |
| 5967 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5968 | /* |
| 5969 | * Check for module parameter bogosity, note that we |
| 5970 | * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be |
| 5971 | * able to detect "unspecified" |
| 5972 | */ |
| 5973 | if (brightness_mode > TPACPI_BRGHT_MODE_MAX) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 5974 | return -EINVAL; |
| 5975 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5976 | /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */ |
| 5977 | if (brightness_mode == TPACPI_BRGHT_MODE_AUTO || |
| 5978 | brightness_mode == TPACPI_BRGHT_MODE_MAX) { |
| 5979 | if (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) { |
| 5980 | /* |
| 5981 | * IBM models that define HBRV probably have |
| 5982 | * EC-based backlight level control |
| 5983 | */ |
| 5984 | if (acpi_evalf(ec_handle, NULL, "HBRV", "qd")) |
| 5985 | /* T40-T43, R50-R52, R50e, R51e, X31-X41 */ |
| 5986 | brightness_mode = TPACPI_BRGHT_MODE_ECNVRAM; |
| 5987 | else |
| 5988 | /* all other IBM ThinkPads */ |
| 5989 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
| 5990 | } else |
| 5991 | /* All Lenovo ThinkPads */ |
| 5992 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
| 5993 | |
| 5994 | dbg_printk(TPACPI_DBG_BRGHT, |
| 5995 | "selected brightness_mode=%d\n", |
| 5996 | brightness_mode); |
| 5997 | } |
| 5998 | |
| 5999 | if (tpacpi_brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6000 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6001 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6002 | if (tp_features.bright_16levels) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6003 | printk(TPACPI_INFO |
| 6004 | "detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6005 | |
Henrique de Moraes Holschuh | 7d5a015 | 2007-04-24 11:48:20 -0300 | [diff] [blame] | 6006 | ibm_backlight_device = backlight_device_register( |
| 6007 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
| 6008 | &ibm_backlight_data); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6009 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6010 | printk(TPACPI_ERR "Could not register backlight device\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6011 | return PTR_ERR(ibm_backlight_device); |
| 6012 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6013 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6014 | "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6015 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6016 | ibm_backlight_device->props.max_brightness = |
| 6017 | (tp_features.bright_16levels)? 15 : 7; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6018 | ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6019 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6020 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6021 | return 0; |
| 6022 | } |
| 6023 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6024 | static void brightness_suspend(pm_message_t state) |
| 6025 | { |
| 6026 | tpacpi_brightness_checkpoint_nvram(); |
| 6027 | } |
| 6028 | |
| 6029 | static void brightness_shutdown(void) |
| 6030 | { |
| 6031 | tpacpi_brightness_checkpoint_nvram(); |
| 6032 | } |
| 6033 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6034 | static void brightness_exit(void) |
| 6035 | { |
| 6036 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6037 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6038 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6039 | backlight_device_unregister(ibm_backlight_device); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6040 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6041 | |
| 6042 | tpacpi_brightness_checkpoint_nvram(); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6043 | } |
| 6044 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6045 | static int brightness_read(char *p) |
| 6046 | { |
| 6047 | int len = 0; |
| 6048 | int level; |
| 6049 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6050 | level = brightness_get(NULL); |
| 6051 | if (level < 0) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6052 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 6053 | } else { |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6054 | len += sprintf(p + len, "level:\t\t%d\n", level); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6055 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 6056 | len += sprintf(p + len, "commands:\tlevel <level>" |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6057 | " (<level> is 0-%d)\n", |
| 6058 | (tp_features.bright_16levels) ? 15 : 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6059 | } |
| 6060 | |
| 6061 | return len; |
| 6062 | } |
| 6063 | |
| 6064 | static int brightness_write(char *buf) |
| 6065 | { |
| 6066 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6067 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6068 | char *cmd; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6069 | int max_level = (tp_features.bright_16levels) ? 15 : 7; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6070 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6071 | level = brightness_get(NULL); |
| 6072 | if (level < 0) |
| 6073 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6074 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6075 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6076 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6077 | if (level < max_level) |
| 6078 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6079 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6080 | if (level > 0) |
| 6081 | level--; |
| 6082 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
| 6083 | level >= 0 && level <= max_level) { |
| 6084 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6085 | } else |
| 6086 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6087 | } |
| 6088 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6089 | tpacpi_disclose_usertask("procfs brightness", |
| 6090 | "set level to %d\n", level); |
| 6091 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6092 | /* |
| 6093 | * Now we know what the final level should be, so we try to set it. |
| 6094 | * Doing it this way makes the syscall restartable in case of EINTR |
| 6095 | */ |
| 6096 | rc = brightness_set(level); |
| 6097 | return (rc == -EINTR)? ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6098 | } |
| 6099 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6100 | static struct ibm_struct brightness_driver_data = { |
| 6101 | .name = "brightness", |
| 6102 | .read = brightness_read, |
| 6103 | .write = brightness_write, |
| 6104 | .exit = brightness_exit, |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6105 | .suspend = brightness_suspend, |
| 6106 | .shutdown = brightness_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6107 | }; |
| 6108 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6109 | /************************************************************************* |
| 6110 | * Volume subdriver |
| 6111 | */ |
| 6112 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6113 | static int volume_offset = 0x30; |
| 6114 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6115 | static int volume_read(char *p) |
| 6116 | { |
| 6117 | int len = 0; |
| 6118 | u8 level; |
| 6119 | |
| 6120 | if (!acpi_ec_read(volume_offset, &level)) { |
| 6121 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 6122 | } else { |
| 6123 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 6124 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 6125 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 6126 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 6127 | " (<level> is 0-15)\n"); |
| 6128 | } |
| 6129 | |
| 6130 | return len; |
| 6131 | } |
| 6132 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6133 | static int volume_write(char *buf) |
| 6134 | { |
| 6135 | int cmos_cmd, inc, i; |
| 6136 | u8 level, mute; |
| 6137 | int new_level, new_mute; |
| 6138 | char *cmd; |
| 6139 | |
| 6140 | while ((cmd = next_cmd(&buf))) { |
| 6141 | if (!acpi_ec_read(volume_offset, &level)) |
| 6142 | return -EIO; |
| 6143 | new_mute = mute = level & 0x40; |
| 6144 | new_level = level = level & 0xf; |
| 6145 | |
| 6146 | if (strlencmp(cmd, "up") == 0) { |
| 6147 | if (mute) |
| 6148 | new_mute = 0; |
| 6149 | else |
| 6150 | new_level = level == 15 ? 15 : level + 1; |
| 6151 | } else if (strlencmp(cmd, "down") == 0) { |
| 6152 | if (mute) |
| 6153 | new_mute = 0; |
| 6154 | else |
| 6155 | new_level = level == 0 ? 0 : level - 1; |
| 6156 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 6157 | new_level >= 0 && new_level <= 15) { |
| 6158 | /* new_level set */ |
| 6159 | } else if (strlencmp(cmd, "mute") == 0) { |
| 6160 | new_mute = 0x40; |
| 6161 | } else |
| 6162 | return -EINVAL; |
| 6163 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6164 | if (new_level != level) { |
| 6165 | /* mute doesn't change */ |
| 6166 | |
| 6167 | cmos_cmd = (new_level > level) ? |
| 6168 | TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6169 | inc = new_level > level ? 1 : -1; |
| 6170 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6171 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6172 | !acpi_ec_write(volume_offset, level))) |
| 6173 | return -EIO; |
| 6174 | |
| 6175 | for (i = level; i != new_level; i += inc) |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6176 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6177 | !acpi_ec_write(volume_offset, i + inc)) |
| 6178 | return -EIO; |
| 6179 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6180 | if (mute && |
| 6181 | (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
| 6182 | !acpi_ec_write(volume_offset, new_level + mute))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6183 | return -EIO; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6184 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6185 | } |
| 6186 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6187 | if (new_mute != mute) { |
| 6188 | /* level doesn't change */ |
| 6189 | |
| 6190 | cmos_cmd = (new_mute) ? |
| 6191 | TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6192 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6193 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6194 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 6195 | return -EIO; |
| 6196 | } |
| 6197 | } |
| 6198 | |
| 6199 | return 0; |
| 6200 | } |
| 6201 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6202 | static struct ibm_struct volume_driver_data = { |
| 6203 | .name = "volume", |
| 6204 | .read = volume_read, |
| 6205 | .write = volume_write, |
| 6206 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6207 | |
| 6208 | /************************************************************************* |
| 6209 | * Fan subdriver |
| 6210 | */ |
| 6211 | |
| 6212 | /* |
| 6213 | * FAN ACCESS MODES |
| 6214 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6215 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6216 | * ACPI GFAN method: returns fan level |
| 6217 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6218 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6219 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6220 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6221 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6222 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 6223 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6224 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 6225 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6226 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6227 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6228 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 6229 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6230 | * |
| 6231 | * Fan speed changes of any sort (including those caused by the |
| 6232 | * disengaged mode) are usually done slowly by the firmware as the |
| 6233 | * maximum ammount of fan duty cycle change per second seems to be |
| 6234 | * limited. |
| 6235 | * |
| 6236 | * Reading is not available if GFAN exists. |
| 6237 | * Writing is not available if SFAN exists. |
| 6238 | * |
| 6239 | * Bits |
| 6240 | * 7 automatic mode engaged; |
| 6241 | * (default operation mode of the ThinkPad) |
| 6242 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6243 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6244 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6245 | * the tachometer while the fan controller ramps up |
| 6246 | * the speed (which can take up to a few *minutes*). |
| 6247 | * Speeds up fan to 100% duty-cycle, which is far above |
| 6248 | * the standard RPM levels. It is not impossible that |
| 6249 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6250 | * 5-3 unused in some models. Extra bits for fan level |
| 6251 | * in others, but still useless as all values above |
| 6252 | * 7 map to the same speed as level 7 in these models. |
| 6253 | * 2-0 fan level (0..7 usually) |
| 6254 | * 0x00 = stop |
| 6255 | * 0x07 = max (set when temperatures critical) |
| 6256 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6257 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6258 | * |
| 6259 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 6260 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 6261 | * does so, its initial value is meaningless (0x07). |
| 6262 | * |
| 6263 | * For firmware bugs, refer to: |
| 6264 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 6265 | * |
| 6266 | * ---- |
| 6267 | * |
| 6268 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 6269 | * Main fan tachometer reading (in RPM) |
| 6270 | * |
| 6271 | * This register is present on all ThinkPads with a new-style EC, and |
| 6272 | * it is known not to be present on the A21m/e, and T22, as there is |
| 6273 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 6274 | * ThinkPads from this same time period (and earlier) probably lack the |
| 6275 | * tachometer as well. |
| 6276 | * |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 6277 | * 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] | 6278 | * was never fixed by IBM to report the EC firmware version string |
| 6279 | * probably support the tachometer (like the early X models), so |
| 6280 | * detecting it is quite hard. We need more data to know for sure. |
| 6281 | * |
| 6282 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 6283 | * might result. |
| 6284 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6285 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 6286 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6287 | * |
| 6288 | * For firmware bugs, refer to: |
| 6289 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 6290 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6291 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6292 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 6293 | * |
| 6294 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 6295 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 6296 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 6297 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 6298 | * |
| 6299 | * The speeds are stored on handles |
| 6300 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 6301 | * |
| 6302 | * There are three default speed sets, acessible as handles: |
| 6303 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 6304 | * |
| 6305 | * ACPI DSDT switches which set is in use depending on various |
| 6306 | * factors. |
| 6307 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6308 | * 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] | 6309 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 6310 | * but the ACPI tables just mention level 7. |
| 6311 | */ |
| 6312 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6313 | enum { /* Fan control constants */ |
| 6314 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 6315 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 6316 | * 0x84 must be read before 0x85 */ |
| 6317 | |
| 6318 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 6319 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 6320 | |
| 6321 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 6322 | }; |
| 6323 | |
| 6324 | enum fan_status_access_mode { |
| 6325 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 6326 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 6327 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 6328 | }; |
| 6329 | |
| 6330 | enum fan_control_access_mode { |
| 6331 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 6332 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 6333 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 6334 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 6335 | }; |
| 6336 | |
| 6337 | enum fan_control_commands { |
| 6338 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 6339 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 6340 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 6341 | * and also watchdog cmd */ |
| 6342 | }; |
| 6343 | |
| 6344 | static int fan_control_allowed; |
| 6345 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6346 | static enum fan_status_access_mode fan_status_access_mode; |
| 6347 | static enum fan_control_access_mode fan_control_access_mode; |
| 6348 | static enum fan_control_commands fan_control_commands; |
| 6349 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6350 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6351 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 6352 | static u8 fan_control_resume_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6353 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6354 | |
| 6355 | static struct mutex fan_mutex; |
| 6356 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6357 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 6358 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6359 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6360 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 6361 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6362 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 6363 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6364 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6365 | "JFNS", /* 770x-JL */ |
| 6366 | ); /* all others */ |
| 6367 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6368 | /* |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6369 | * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the |
| 6370 | * HFSP register at boot, so it contains 0x07 but the Thinkpad could |
| 6371 | * be in auto mode (0x80). |
| 6372 | * |
| 6373 | * This is corrected by any write to HFSP either by the driver, or |
| 6374 | * by the firmware. |
| 6375 | * |
| 6376 | * We assume 0x07 really means auto mode while this quirk is active, |
| 6377 | * as this is far more likely than the ThinkPad being in level 7, |
| 6378 | * which is only used by the firmware during thermal emergencies. |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6379 | * |
| 6380 | * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52), |
| 6381 | * TP-70 (T43, R52), which are known to be buggy. |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6382 | */ |
| 6383 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6384 | static void fan_quirk1_setup(void) |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6385 | { |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6386 | if (fan_control_initial_status == 0x07) { |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6387 | printk(TPACPI_NOTICE |
| 6388 | "fan_init: initial fan status is unknown, " |
| 6389 | "assuming it is in auto mode\n"); |
| 6390 | tp_features.fan_ctrl_status_undef = 1; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6391 | } |
| 6392 | } |
| 6393 | |
| 6394 | static void fan_quirk1_handle(u8 *fan_status) |
| 6395 | { |
| 6396 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 6397 | if (*fan_status != fan_control_initial_status) { |
| 6398 | /* something changed the HFSP regisnter since |
| 6399 | * driver init time, so it is not undefined |
| 6400 | * anymore */ |
| 6401 | tp_features.fan_ctrl_status_undef = 0; |
| 6402 | } else { |
| 6403 | /* Return most likely status. In fact, it |
| 6404 | * might be the only possible status */ |
| 6405 | *fan_status = TP_EC_FAN_AUTO; |
| 6406 | } |
| 6407 | } |
| 6408 | } |
| 6409 | |
| 6410 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6411 | * Call with fan_mutex held |
| 6412 | */ |
| 6413 | static void fan_update_desired_level(u8 status) |
| 6414 | { |
| 6415 | if ((status & |
| 6416 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 6417 | if (status > 7) |
| 6418 | fan_control_desired_level = 7; |
| 6419 | else |
| 6420 | fan_control_desired_level = status; |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | static int fan_get_status(u8 *status) |
| 6425 | { |
| 6426 | u8 s; |
| 6427 | |
| 6428 | /* TODO: |
| 6429 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 6430 | |
| 6431 | switch (fan_status_access_mode) { |
| 6432 | case TPACPI_FAN_RD_ACPI_GFAN: |
| 6433 | /* 570, 600e/x, 770e, 770x */ |
| 6434 | |
| 6435 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
| 6436 | return -EIO; |
| 6437 | |
| 6438 | if (likely(status)) |
| 6439 | *status = s & 0x07; |
| 6440 | |
| 6441 | break; |
| 6442 | |
| 6443 | case TPACPI_FAN_RD_TPEC: |
| 6444 | /* all except 570, 600e/x, 770e, 770x */ |
| 6445 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 6446 | return -EIO; |
| 6447 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6448 | if (likely(status)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6449 | *status = s; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6450 | fan_quirk1_handle(status); |
| 6451 | } |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6452 | |
| 6453 | break; |
| 6454 | |
| 6455 | default: |
| 6456 | return -ENXIO; |
| 6457 | } |
| 6458 | |
| 6459 | return 0; |
| 6460 | } |
| 6461 | |
| 6462 | static int fan_get_status_safe(u8 *status) |
| 6463 | { |
| 6464 | int rc; |
| 6465 | u8 s; |
| 6466 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6467 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6468 | return -ERESTARTSYS; |
| 6469 | rc = fan_get_status(&s); |
| 6470 | if (!rc) |
| 6471 | fan_update_desired_level(s); |
| 6472 | mutex_unlock(&fan_mutex); |
| 6473 | |
| 6474 | if (status) |
| 6475 | *status = s; |
| 6476 | |
| 6477 | return rc; |
| 6478 | } |
| 6479 | |
| 6480 | static int fan_get_speed(unsigned int *speed) |
| 6481 | { |
| 6482 | u8 hi, lo; |
| 6483 | |
| 6484 | switch (fan_status_access_mode) { |
| 6485 | case TPACPI_FAN_RD_TPEC: |
| 6486 | /* all except 570, 600e/x, 770e, 770x */ |
| 6487 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 6488 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 6489 | return -EIO; |
| 6490 | |
| 6491 | if (likely(speed)) |
| 6492 | *speed = (hi << 8) | lo; |
| 6493 | |
| 6494 | break; |
| 6495 | |
| 6496 | default: |
| 6497 | return -ENXIO; |
| 6498 | } |
| 6499 | |
| 6500 | return 0; |
| 6501 | } |
| 6502 | |
| 6503 | static int fan_set_level(int level) |
| 6504 | { |
| 6505 | if (!fan_control_allowed) |
| 6506 | return -EPERM; |
| 6507 | |
| 6508 | switch (fan_control_access_mode) { |
| 6509 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6510 | if (level >= 0 && level <= 7) { |
| 6511 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 6512 | return -EIO; |
| 6513 | } else |
| 6514 | return -EINVAL; |
| 6515 | break; |
| 6516 | |
| 6517 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6518 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 6519 | if (!(level & TP_EC_FAN_AUTO) && |
| 6520 | !(level & TP_EC_FAN_FULLSPEED) && |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6521 | ((level < 0) || (level > 7))) |
| 6522 | return -EINVAL; |
| 6523 | |
| 6524 | /* safety net should the EC not support AUTO |
| 6525 | * or FULLSPEED mode bits and just ignore them */ |
| 6526 | if (level & TP_EC_FAN_FULLSPEED) |
| 6527 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 6528 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6529 | level |= 4; /* safety min speed 4 */ |
| 6530 | |
| 6531 | if (!acpi_ec_write(fan_status_offset, level)) |
| 6532 | return -EIO; |
| 6533 | else |
| 6534 | tp_features.fan_ctrl_status_undef = 0; |
| 6535 | break; |
| 6536 | |
| 6537 | default: |
| 6538 | return -ENXIO; |
| 6539 | } |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6540 | |
| 6541 | vdbg_printk(TPACPI_DBG_FAN, |
| 6542 | "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] | 6543 | return 0; |
| 6544 | } |
| 6545 | |
| 6546 | static int fan_set_level_safe(int level) |
| 6547 | { |
| 6548 | int rc; |
| 6549 | |
| 6550 | if (!fan_control_allowed) |
| 6551 | return -EPERM; |
| 6552 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6553 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6554 | return -ERESTARTSYS; |
| 6555 | |
| 6556 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 6557 | level = fan_control_desired_level; |
| 6558 | |
| 6559 | rc = fan_set_level(level); |
| 6560 | if (!rc) |
| 6561 | fan_update_desired_level(level); |
| 6562 | |
| 6563 | mutex_unlock(&fan_mutex); |
| 6564 | return rc; |
| 6565 | } |
| 6566 | |
| 6567 | static int fan_set_enable(void) |
| 6568 | { |
| 6569 | u8 s; |
| 6570 | int rc; |
| 6571 | |
| 6572 | if (!fan_control_allowed) |
| 6573 | return -EPERM; |
| 6574 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6575 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6576 | return -ERESTARTSYS; |
| 6577 | |
| 6578 | switch (fan_control_access_mode) { |
| 6579 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6580 | case TPACPI_FAN_WR_TPEC: |
| 6581 | rc = fan_get_status(&s); |
| 6582 | if (rc < 0) |
| 6583 | break; |
| 6584 | |
| 6585 | /* Don't go out of emergency fan mode */ |
| 6586 | if (s != 7) { |
| 6587 | s &= 0x07; |
| 6588 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 6589 | } |
| 6590 | |
| 6591 | if (!acpi_ec_write(fan_status_offset, s)) |
| 6592 | rc = -EIO; |
| 6593 | else { |
| 6594 | tp_features.fan_ctrl_status_undef = 0; |
| 6595 | rc = 0; |
| 6596 | } |
| 6597 | break; |
| 6598 | |
| 6599 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6600 | rc = fan_get_status(&s); |
| 6601 | if (rc < 0) |
| 6602 | break; |
| 6603 | |
| 6604 | s &= 0x07; |
| 6605 | |
| 6606 | /* Set fan to at least level 4 */ |
| 6607 | s |= 4; |
| 6608 | |
| 6609 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6610 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6611 | else |
| 6612 | rc = 0; |
| 6613 | break; |
| 6614 | |
| 6615 | default: |
| 6616 | rc = -ENXIO; |
| 6617 | } |
| 6618 | |
| 6619 | mutex_unlock(&fan_mutex); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6620 | |
| 6621 | if (!rc) |
| 6622 | vdbg_printk(TPACPI_DBG_FAN, |
| 6623 | "fan control: set fan control register to 0x%02x\n", |
| 6624 | s); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6625 | return rc; |
| 6626 | } |
| 6627 | |
| 6628 | static int fan_set_disable(void) |
| 6629 | { |
| 6630 | int rc; |
| 6631 | |
| 6632 | if (!fan_control_allowed) |
| 6633 | return -EPERM; |
| 6634 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6635 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6636 | return -ERESTARTSYS; |
| 6637 | |
| 6638 | rc = 0; |
| 6639 | switch (fan_control_access_mode) { |
| 6640 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6641 | case TPACPI_FAN_WR_TPEC: |
| 6642 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 6643 | rc = -EIO; |
| 6644 | else { |
| 6645 | fan_control_desired_level = 0; |
| 6646 | tp_features.fan_ctrl_status_undef = 0; |
| 6647 | } |
| 6648 | break; |
| 6649 | |
| 6650 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6651 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 6652 | rc = -EIO; |
| 6653 | else |
| 6654 | fan_control_desired_level = 0; |
| 6655 | break; |
| 6656 | |
| 6657 | default: |
| 6658 | rc = -ENXIO; |
| 6659 | } |
| 6660 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6661 | if (!rc) |
| 6662 | vdbg_printk(TPACPI_DBG_FAN, |
| 6663 | "fan control: set fan control register to 0\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6664 | |
| 6665 | mutex_unlock(&fan_mutex); |
| 6666 | return rc; |
| 6667 | } |
| 6668 | |
| 6669 | static int fan_set_speed(int speed) |
| 6670 | { |
| 6671 | int rc; |
| 6672 | |
| 6673 | if (!fan_control_allowed) |
| 6674 | return -EPERM; |
| 6675 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6676 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6677 | return -ERESTARTSYS; |
| 6678 | |
| 6679 | rc = 0; |
| 6680 | switch (fan_control_access_mode) { |
| 6681 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6682 | if (speed >= 0 && speed <= 65535) { |
| 6683 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 6684 | speed, speed, speed)) |
| 6685 | rc = -EIO; |
| 6686 | } else |
| 6687 | rc = -EINVAL; |
| 6688 | break; |
| 6689 | |
| 6690 | default: |
| 6691 | rc = -ENXIO; |
| 6692 | } |
| 6693 | |
| 6694 | mutex_unlock(&fan_mutex); |
| 6695 | return rc; |
| 6696 | } |
| 6697 | |
| 6698 | static void fan_watchdog_reset(void) |
| 6699 | { |
| 6700 | static int fan_watchdog_active; |
| 6701 | |
| 6702 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 6703 | return; |
| 6704 | |
| 6705 | if (fan_watchdog_active) |
| 6706 | cancel_delayed_work(&fan_watchdog_task); |
| 6707 | |
| 6708 | if (fan_watchdog_maxinterval > 0 && |
| 6709 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
| 6710 | fan_watchdog_active = 1; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 6711 | if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task, |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6712 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 6713 | * 1000))) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6714 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 6715 | "failed to queue the fan watchdog, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6716 | "watchdog will not trigger\n"); |
| 6717 | } |
| 6718 | } else |
| 6719 | fan_watchdog_active = 0; |
| 6720 | } |
| 6721 | |
| 6722 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 6723 | { |
| 6724 | int rc; |
| 6725 | |
| 6726 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 6727 | return; |
| 6728 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6729 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6730 | rc = fan_set_enable(); |
| 6731 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6732 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6733 | "will try again later...\n", -rc); |
| 6734 | /* reschedule for later */ |
| 6735 | fan_watchdog_reset(); |
| 6736 | } |
| 6737 | } |
| 6738 | |
| 6739 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6740 | * SYSFS fan layout: hwmon compatible (device) |
| 6741 | * |
| 6742 | * pwm*_enable: |
| 6743 | * 0: "disengaged" mode |
| 6744 | * 1: manual mode |
| 6745 | * 2: native EC "auto" mode (recommended, hardware default) |
| 6746 | * |
| 6747 | * pwm*: set speed in manual mode, ignored otherwise. |
| 6748 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 6749 | * interpolation. |
| 6750 | * |
| 6751 | * fan*_input: tachometer reading, RPM |
| 6752 | * |
| 6753 | * |
| 6754 | * SYSFS fan layout: extensions |
| 6755 | * |
| 6756 | * fan_watchdog (driver): |
| 6757 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 6758 | */ |
| 6759 | |
| 6760 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 6761 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 6762 | struct device_attribute *attr, |
| 6763 | char *buf) |
| 6764 | { |
| 6765 | int res, mode; |
| 6766 | u8 status; |
| 6767 | |
| 6768 | res = fan_get_status_safe(&status); |
| 6769 | if (res) |
| 6770 | return res; |
| 6771 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6772 | if (status & TP_EC_FAN_FULLSPEED) { |
| 6773 | mode = 0; |
| 6774 | } else if (status & TP_EC_FAN_AUTO) { |
| 6775 | mode = 2; |
| 6776 | } else |
| 6777 | mode = 1; |
| 6778 | |
| 6779 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 6780 | } |
| 6781 | |
| 6782 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 6783 | struct device_attribute *attr, |
| 6784 | const char *buf, size_t count) |
| 6785 | { |
| 6786 | unsigned long t; |
| 6787 | int res, level; |
| 6788 | |
| 6789 | if (parse_strtoul(buf, 2, &t)) |
| 6790 | return -EINVAL; |
| 6791 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6792 | tpacpi_disclose_usertask("hwmon pwm1_enable", |
| 6793 | "set fan mode to %lu\n", t); |
| 6794 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6795 | switch (t) { |
| 6796 | case 0: |
| 6797 | level = TP_EC_FAN_FULLSPEED; |
| 6798 | break; |
| 6799 | case 1: |
| 6800 | level = TPACPI_FAN_LAST_LEVEL; |
| 6801 | break; |
| 6802 | case 2: |
| 6803 | level = TP_EC_FAN_AUTO; |
| 6804 | break; |
| 6805 | case 3: |
| 6806 | /* reserved for software-controlled auto mode */ |
| 6807 | return -ENOSYS; |
| 6808 | default: |
| 6809 | return -EINVAL; |
| 6810 | } |
| 6811 | |
| 6812 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 6813 | if (res == -ENXIO) |
| 6814 | return -EINVAL; |
| 6815 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6816 | return res; |
| 6817 | |
| 6818 | fan_watchdog_reset(); |
| 6819 | |
| 6820 | return count; |
| 6821 | } |
| 6822 | |
| 6823 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 6824 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 6825 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 6826 | |
| 6827 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 6828 | static ssize_t fan_pwm1_show(struct device *dev, |
| 6829 | struct device_attribute *attr, |
| 6830 | char *buf) |
| 6831 | { |
| 6832 | int res; |
| 6833 | u8 status; |
| 6834 | |
| 6835 | res = fan_get_status_safe(&status); |
| 6836 | if (res) |
| 6837 | return res; |
| 6838 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6839 | if ((status & |
| 6840 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 6841 | status = fan_control_desired_level; |
| 6842 | |
| 6843 | if (status > 7) |
| 6844 | status = 7; |
| 6845 | |
| 6846 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 6847 | } |
| 6848 | |
| 6849 | static ssize_t fan_pwm1_store(struct device *dev, |
| 6850 | struct device_attribute *attr, |
| 6851 | const char *buf, size_t count) |
| 6852 | { |
| 6853 | unsigned long s; |
| 6854 | int rc; |
| 6855 | u8 status, newlevel; |
| 6856 | |
| 6857 | if (parse_strtoul(buf, 255, &s)) |
| 6858 | return -EINVAL; |
| 6859 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6860 | tpacpi_disclose_usertask("hwmon pwm1", |
| 6861 | "set fan speed to %lu\n", s); |
| 6862 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6863 | /* scale down from 0-255 to 0-7 */ |
| 6864 | newlevel = (s >> 5) & 0x07; |
| 6865 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6866 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 6867 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6868 | |
| 6869 | rc = fan_get_status(&status); |
| 6870 | if (!rc && (status & |
| 6871 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 6872 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 6873 | if (rc == -ENXIO) |
| 6874 | rc = -EINVAL; |
| 6875 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6876 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 6877 | fan_watchdog_reset(); |
| 6878 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6879 | } |
| 6880 | |
| 6881 | mutex_unlock(&fan_mutex); |
| 6882 | return (rc)? rc : count; |
| 6883 | } |
| 6884 | |
| 6885 | static struct device_attribute dev_attr_fan_pwm1 = |
| 6886 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 6887 | fan_pwm1_show, fan_pwm1_store); |
| 6888 | |
| 6889 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 6890 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 6891 | struct device_attribute *attr, |
| 6892 | char *buf) |
| 6893 | { |
| 6894 | int res; |
| 6895 | unsigned int speed; |
| 6896 | |
| 6897 | res = fan_get_speed(&speed); |
| 6898 | if (res < 0) |
| 6899 | return res; |
| 6900 | |
| 6901 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 6902 | } |
| 6903 | |
| 6904 | static struct device_attribute dev_attr_fan_fan1_input = |
| 6905 | __ATTR(fan1_input, S_IRUGO, |
| 6906 | fan_fan1_input_show, NULL); |
| 6907 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6908 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6909 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 6910 | char *buf) |
| 6911 | { |
| 6912 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 6913 | } |
| 6914 | |
| 6915 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 6916 | const char *buf, size_t count) |
| 6917 | { |
| 6918 | unsigned long t; |
| 6919 | |
| 6920 | if (parse_strtoul(buf, 120, &t)) |
| 6921 | return -EINVAL; |
| 6922 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 6923 | if (!fan_control_allowed) |
| 6924 | return -EPERM; |
| 6925 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6926 | fan_watchdog_maxinterval = t; |
| 6927 | fan_watchdog_reset(); |
| 6928 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6929 | tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t); |
| 6930 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6931 | return count; |
| 6932 | } |
| 6933 | |
| 6934 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 6935 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 6936 | |
| 6937 | /* --------------------------------------------------------------------- */ |
| 6938 | static struct attribute *fan_attributes[] = { |
| 6939 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 6940 | &dev_attr_fan_fan1_input.attr, |
| 6941 | NULL |
| 6942 | }; |
| 6943 | |
| 6944 | static const struct attribute_group fan_attr_group = { |
| 6945 | .attrs = fan_attributes, |
| 6946 | }; |
| 6947 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6948 | #define TPACPI_FAN_Q1 0x0001 |
| 6949 | |
| 6950 | #define TPACPI_FAN_QI(__id1, __id2, __quirks) \ |
| 6951 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 6952 | .bios = TPACPI_MATCH_ANY, \ |
| 6953 | .ec = TPID(__id1, __id2), \ |
| 6954 | .quirks = __quirks } |
| 6955 | |
| 6956 | static const struct tpacpi_quirk fan_quirk_table[] __initconst = { |
| 6957 | TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1), |
| 6958 | TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1), |
| 6959 | TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1), |
| 6960 | TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1), |
| 6961 | }; |
| 6962 | |
| 6963 | #undef TPACPI_FAN_QI |
| 6964 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6965 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6966 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6967 | int rc; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6968 | unsigned long quirks; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6969 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6970 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 6971 | "initializing fan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6972 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 6973 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6974 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 6975 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6976 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6977 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 6978 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6979 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6980 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6981 | TPACPI_ACPIHANDLE_INIT(fans); |
| 6982 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 6983 | TPACPI_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6984 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6985 | quirks = tpacpi_check_quirks(fan_quirk_table, |
| 6986 | ARRAY_SIZE(fan_quirk_table)); |
| 6987 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6988 | if (gfan_handle) { |
| 6989 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6990 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6991 | } else { |
| 6992 | /* all other ThinkPads: note that even old-style |
| 6993 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6994 | if (likely(acpi_ec_read(fan_status_offset, |
| 6995 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6996 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6997 | if (quirks & TPACPI_FAN_Q1) |
| 6998 | fan_quirk1_setup(); |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6999 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7000 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7001 | "ThinkPad ACPI EC access misbehaving, " |
| 7002 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7003 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7004 | } |
| 7005 | } |
| 7006 | |
| 7007 | if (sfan_handle) { |
| 7008 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7009 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 7010 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7011 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7012 | } else { |
| 7013 | if (!gfan_handle) { |
| 7014 | /* gfan without sfan means no fan control */ |
| 7015 | /* all other models implement TP EC 0x2f control */ |
| 7016 | |
| 7017 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7018 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7019 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7020 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7021 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7022 | TPACPI_FAN_CMD_SPEED | |
| 7023 | TPACPI_FAN_CMD_LEVEL | |
| 7024 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7025 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7026 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7027 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7028 | TPACPI_FAN_CMD_LEVEL | |
| 7029 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7030 | } |
| 7031 | } |
| 7032 | } |
| 7033 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7034 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7035 | "fan is %s, modes %d, %d\n", |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7036 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 7037 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 7038 | fan_status_access_mode, fan_control_access_mode); |
| 7039 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7040 | /* fan control master switch */ |
| 7041 | if (!fan_control_allowed) { |
| 7042 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 7043 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7044 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7045 | "fan control features disabled by parameter\n"); |
| 7046 | } |
| 7047 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7048 | /* update fan_control_desired_level */ |
| 7049 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 7050 | fan_get_status_safe(NULL); |
| 7051 | |
| 7052 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 7053 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7054 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7055 | &fan_attr_group); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7056 | if (rc < 0) |
| 7057 | return rc; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 7058 | |
| 7059 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
| 7060 | &driver_attr_fan_watchdog); |
| 7061 | if (rc < 0) { |
| 7062 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
| 7063 | &fan_attr_group); |
| 7064 | return rc; |
| 7065 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7066 | return 0; |
| 7067 | } else |
| 7068 | return 1; |
| 7069 | } |
| 7070 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7071 | static void fan_exit(void) |
| 7072 | { |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7073 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7074 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7075 | |
| 7076 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7077 | 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] | 7078 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 7079 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7080 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7081 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7082 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7083 | } |
| 7084 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7085 | static void fan_suspend(pm_message_t state) |
| 7086 | { |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7087 | int rc; |
| 7088 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7089 | if (!fan_control_allowed) |
| 7090 | return; |
| 7091 | |
| 7092 | /* Store fan status in cache */ |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7093 | fan_control_resume_level = 0; |
| 7094 | rc = fan_get_status_safe(&fan_control_resume_level); |
| 7095 | if (rc < 0) |
| 7096 | printk(TPACPI_NOTICE |
| 7097 | "failed to read fan level for later " |
| 7098 | "restore during resume: %d\n", rc); |
| 7099 | |
| 7100 | /* if it is undefined, don't attempt to restore it. |
| 7101 | * KEEP THIS LAST */ |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7102 | if (tp_features.fan_ctrl_status_undef) |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7103 | fan_control_resume_level = 0; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | static void fan_resume(void) |
| 7107 | { |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7108 | u8 current_level = 7; |
| 7109 | bool do_set = false; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7110 | int rc; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7111 | |
| 7112 | /* DSDT *always* updates status on resume */ |
| 7113 | tp_features.fan_ctrl_status_undef = 0; |
| 7114 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7115 | if (!fan_control_allowed || |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7116 | !fan_control_resume_level || |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7117 | (fan_get_status_safe(¤t_level) < 0)) |
| 7118 | return; |
| 7119 | |
| 7120 | switch (fan_control_access_mode) { |
| 7121 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7122 | /* never decrease fan level */ |
| 7123 | do_set = (fan_control_resume_level > current_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7124 | break; |
| 7125 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7126 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7127 | /* never decrease fan level, scale is: |
| 7128 | * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO |
| 7129 | * |
| 7130 | * We expect the firmware to set either 7 or AUTO, but we |
| 7131 | * handle FULLSPEED out of paranoia. |
| 7132 | * |
| 7133 | * So, we can safely only restore FULLSPEED or 7, anything |
| 7134 | * else could slow the fan. Restoring AUTO is useless, at |
| 7135 | * best that's exactly what the DSDT already set (it is the |
| 7136 | * slower it uses). |
| 7137 | * |
| 7138 | * Always keep in mind that the DSDT *will* have set the |
| 7139 | * fans to what the vendor supposes is the best level. We |
| 7140 | * muck with it only to speed the fan up. |
| 7141 | */ |
| 7142 | if (fan_control_resume_level != 7 && |
| 7143 | !(fan_control_resume_level & TP_EC_FAN_FULLSPEED)) |
| 7144 | return; |
| 7145 | else |
| 7146 | do_set = !(current_level & TP_EC_FAN_FULLSPEED) && |
| 7147 | (current_level != fan_control_resume_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7148 | break; |
| 7149 | default: |
| 7150 | return; |
| 7151 | } |
| 7152 | if (do_set) { |
| 7153 | printk(TPACPI_NOTICE |
| 7154 | "restoring fan level to 0x%02x\n", |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7155 | fan_control_resume_level); |
| 7156 | rc = fan_set_level_safe(fan_control_resume_level); |
| 7157 | if (rc < 0) |
| 7158 | printk(TPACPI_NOTICE |
| 7159 | "failed to restore fan level: %d\n", rc); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7160 | } |
| 7161 | } |
| 7162 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7163 | static int fan_read(char *p) |
| 7164 | { |
| 7165 | int len = 0; |
| 7166 | int rc; |
| 7167 | u8 status; |
| 7168 | unsigned int speed = 0; |
| 7169 | |
| 7170 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7171 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7172 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7173 | rc = fan_get_status_safe(&status); |
| 7174 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7175 | return rc; |
| 7176 | |
| 7177 | len += sprintf(p + len, "status:\t\t%s\n" |
| 7178 | "level:\t\t%d\n", |
| 7179 | (status != 0) ? "enabled" : "disabled", status); |
| 7180 | break; |
| 7181 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7182 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7183 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7184 | rc = fan_get_status_safe(&status); |
| 7185 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7186 | return rc; |
| 7187 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7188 | len += sprintf(p + len, "status:\t\t%s\n", |
| 7189 | (status != 0) ? "enabled" : "disabled"); |
| 7190 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7191 | rc = fan_get_speed(&speed); |
| 7192 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7193 | return rc; |
| 7194 | |
| 7195 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 7196 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7197 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7198 | /* Disengaged mode takes precedence */ |
| 7199 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7200 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7201 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 7202 | else |
| 7203 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 7204 | break; |
| 7205 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7206 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7207 | default: |
| 7208 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 7209 | } |
| 7210 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7211 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7212 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 7213 | |
| 7214 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7215 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7216 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 7217 | break; |
| 7218 | |
| 7219 | default: |
| 7220 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7221 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7222 | break; |
| 7223 | } |
| 7224 | } |
| 7225 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7226 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7227 | len += sprintf(p + len, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7228 | "commands:\twatchdog <timeout> (<timeout> " |
| 7229 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7230 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7231 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7232 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 7233 | " (<speed> is 0-65535)\n"); |
| 7234 | |
| 7235 | return len; |
| 7236 | } |
| 7237 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7238 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 7239 | { |
| 7240 | int level; |
| 7241 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7242 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7243 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7244 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7245 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7246 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7247 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7248 | return 0; |
| 7249 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7250 | *rc = fan_set_level_safe(level); |
| 7251 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7252 | printk(TPACPI_ERR "level command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7253 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7254 | else if (!*rc) |
| 7255 | tpacpi_disclose_usertask("procfs fan", |
| 7256 | "set level to %d\n", level); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7257 | |
| 7258 | return 1; |
| 7259 | } |
| 7260 | |
| 7261 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 7262 | { |
| 7263 | if (strlencmp(cmd, "enable") != 0) |
| 7264 | return 0; |
| 7265 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7266 | *rc = fan_set_enable(); |
| 7267 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7268 | printk(TPACPI_ERR "enable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7269 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7270 | else if (!*rc) |
| 7271 | tpacpi_disclose_usertask("procfs fan", "enable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7272 | |
| 7273 | return 1; |
| 7274 | } |
| 7275 | |
| 7276 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 7277 | { |
| 7278 | if (strlencmp(cmd, "disable") != 0) |
| 7279 | return 0; |
| 7280 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7281 | *rc = fan_set_disable(); |
| 7282 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7283 | printk(TPACPI_ERR "disable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7284 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7285 | else if (!*rc) |
| 7286 | tpacpi_disclose_usertask("procfs fan", "disable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7287 | |
| 7288 | return 1; |
| 7289 | } |
| 7290 | |
| 7291 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 7292 | { |
| 7293 | int speed; |
| 7294 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7295 | /* TODO: |
| 7296 | * Support speed <low> <medium> <high> ? */ |
| 7297 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7298 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 7299 | return 0; |
| 7300 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7301 | *rc = fan_set_speed(speed); |
| 7302 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7303 | printk(TPACPI_ERR "speed command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7304 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7305 | else if (!*rc) |
| 7306 | tpacpi_disclose_usertask("procfs fan", |
| 7307 | "set speed to %d\n", speed); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7308 | |
| 7309 | return 1; |
| 7310 | } |
| 7311 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7312 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 7313 | { |
| 7314 | int interval; |
| 7315 | |
| 7316 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 7317 | return 0; |
| 7318 | |
| 7319 | if (interval < 0 || interval > 120) |
| 7320 | *rc = -EINVAL; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7321 | else { |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7322 | fan_watchdog_maxinterval = interval; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7323 | tpacpi_disclose_usertask("procfs fan", |
| 7324 | "set watchdog timer to %d\n", |
| 7325 | interval); |
| 7326 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7327 | |
| 7328 | return 1; |
| 7329 | } |
| 7330 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7331 | static int fan_write(char *buf) |
| 7332 | { |
| 7333 | char *cmd; |
| 7334 | int rc = 0; |
| 7335 | |
| 7336 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7337 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7338 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7339 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7340 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7341 | fan_write_cmd_disable(cmd, &rc) || |
| 7342 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7343 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7344 | fan_write_cmd_speed(cmd, &rc)) |
| 7345 | ) |
| 7346 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7347 | else if (!rc) |
| 7348 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7349 | } |
| 7350 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7351 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7352 | } |
| 7353 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7354 | static struct ibm_struct fan_driver_data = { |
| 7355 | .name = "fan", |
| 7356 | .read = fan_read, |
| 7357 | .write = fan_write, |
| 7358 | .exit = fan_exit, |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7359 | .suspend = fan_suspend, |
| 7360 | .resume = fan_resume, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7361 | }; |
| 7362 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7363 | /**************************************************************************** |
| 7364 | **************************************************************************** |
| 7365 | * |
| 7366 | * Infrastructure |
| 7367 | * |
| 7368 | **************************************************************************** |
| 7369 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7370 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7371 | /* sysfs name ---------------------------------------------------------- */ |
| 7372 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 7373 | struct device_attribute *attr, |
| 7374 | char *buf) |
| 7375 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7376 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7377 | } |
| 7378 | |
| 7379 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 7380 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 7381 | |
| 7382 | /* --------------------------------------------------------------------- */ |
| 7383 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7384 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 7385 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7386 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7387 | /* |
| 7388 | * Module and infrastructure proble, init and exit handling |
| 7389 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7390 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7391 | static int force_load; |
| 7392 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7393 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7394 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7395 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7396 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7397 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7398 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7399 | } |
| 7400 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 7401 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7402 | static void ibm_exit(struct ibm_struct *ibm) |
| 7403 | { |
| 7404 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 7405 | |
| 7406 | list_del_init(&ibm->all_drivers); |
| 7407 | |
| 7408 | if (ibm->flags.acpi_notify_installed) { |
| 7409 | dbg_printk(TPACPI_DBG_EXIT, |
| 7410 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 7411 | BUG_ON(!ibm->acpi); |
| 7412 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 7413 | ibm->acpi->type, |
| 7414 | dispatch_acpi_notify); |
| 7415 | ibm->flags.acpi_notify_installed = 0; |
| 7416 | ibm->flags.acpi_notify_installed = 0; |
| 7417 | } |
| 7418 | |
| 7419 | if (ibm->flags.proc_created) { |
| 7420 | dbg_printk(TPACPI_DBG_EXIT, |
| 7421 | "%s: remove_proc_entry\n", ibm->name); |
| 7422 | remove_proc_entry(ibm->name, proc_dir); |
| 7423 | ibm->flags.proc_created = 0; |
| 7424 | } |
| 7425 | |
| 7426 | if (ibm->flags.acpi_driver_registered) { |
| 7427 | dbg_printk(TPACPI_DBG_EXIT, |
| 7428 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 7429 | BUG_ON(!ibm->acpi); |
| 7430 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 7431 | kfree(ibm->acpi->driver); |
| 7432 | ibm->acpi->driver = NULL; |
| 7433 | ibm->flags.acpi_driver_registered = 0; |
| 7434 | } |
| 7435 | |
| 7436 | if (ibm->flags.init_called && ibm->exit) { |
| 7437 | ibm->exit(); |
| 7438 | ibm->flags.init_called = 0; |
| 7439 | } |
| 7440 | |
| 7441 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 7442 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7443 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7444 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7445 | { |
| 7446 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7447 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7448 | struct proc_dir_entry *entry; |
| 7449 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7450 | BUG_ON(ibm == NULL); |
| 7451 | |
| 7452 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 7453 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7454 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7455 | return 0; |
| 7456 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7457 | dbg_printk(TPACPI_DBG_INIT, |
| 7458 | "probing for %s\n", ibm->name); |
| 7459 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7460 | if (iibm->init) { |
| 7461 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7462 | if (ret > 0) |
| 7463 | return 0; /* probe failed */ |
| 7464 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7465 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7466 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7467 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7468 | } |
| 7469 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7470 | if (ibm->acpi) { |
| 7471 | if (ibm->acpi->hid) { |
| 7472 | ret = register_tpacpi_subdriver(ibm); |
| 7473 | if (ret) |
| 7474 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7475 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7476 | |
| 7477 | if (ibm->acpi->notify) { |
| 7478 | ret = setup_acpi_notify(ibm); |
| 7479 | if (ret == -ENODEV) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7480 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7481 | ibm->name); |
| 7482 | ret = 0; |
| 7483 | goto err_out; |
| 7484 | } |
| 7485 | if (ret < 0) |
| 7486 | goto err_out; |
| 7487 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7488 | } |
| 7489 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7490 | dbg_printk(TPACPI_DBG_INIT, |
| 7491 | "%s installed\n", ibm->name); |
| 7492 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7493 | if (ibm->read) { |
| 7494 | entry = create_proc_entry(ibm->name, |
| 7495 | S_IFREG | S_IRUGO | S_IWUSR, |
| 7496 | proc_dir); |
| 7497 | if (!entry) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7498 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7499 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7500 | ret = -ENODEV; |
| 7501 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7502 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7503 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7504 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7505 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7506 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7507 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7508 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7509 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7510 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 7511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7512 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7513 | |
| 7514 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7515 | dbg_printk(TPACPI_DBG_INIT, |
| 7516 | "%s: at error exit path with result %d\n", |
| 7517 | ibm->name, ret); |
| 7518 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7519 | ibm_exit(ibm); |
| 7520 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7521 | } |
| 7522 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7523 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7524 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7525 | static bool __pure __init tpacpi_is_fw_digit(const char c) |
| 7526 | { |
| 7527 | return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); |
| 7528 | } |
| 7529 | |
| 7530 | /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */ |
| 7531 | static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, |
| 7532 | const char t) |
| 7533 | { |
| 7534 | return s && strlen(s) >= 8 && |
| 7535 | tpacpi_is_fw_digit(s[0]) && |
| 7536 | tpacpi_is_fw_digit(s[1]) && |
| 7537 | s[2] == t && s[3] == 'T' && |
| 7538 | tpacpi_is_fw_digit(s[4]) && |
| 7539 | tpacpi_is_fw_digit(s[5]) && |
| 7540 | s[6] == 'W' && s[7] == 'W'; |
| 7541 | } |
| 7542 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7543 | /* returns 0 - probe ok, or < 0 - probe error. |
| 7544 | * Probe ok doesn't mean thinkpad found. |
| 7545 | * On error, kfree() cleanup on tp->* is not performed, caller must do it */ |
| 7546 | static int __must_check __init get_thinkpad_model_data( |
| 7547 | struct thinkpad_id_data *tp) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7548 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 7549 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7550 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7551 | char const *s; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7552 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7553 | if (!tp) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7554 | return -EINVAL; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7555 | |
| 7556 | memset(tp, 0, sizeof(*tp)); |
| 7557 | |
| 7558 | if (dmi_name_in_vendors("IBM")) |
| 7559 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 7560 | else if (dmi_name_in_vendors("LENOVO")) |
| 7561 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 7562 | else |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7563 | return 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7564 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7565 | s = dmi_get_system_info(DMI_BIOS_VERSION); |
| 7566 | tp->bios_version_str = kstrdup(s, GFP_KERNEL); |
| 7567 | if (s && !tp->bios_version_str) |
| 7568 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7569 | |
| 7570 | /* Really ancient ThinkPad 240X will fail this, which is fine */ |
| 7571 | if (!tpacpi_is_valid_fw_id(tp->bios_version_str, 'E')) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7572 | return 0; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7573 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7574 | tp->bios_model = tp->bios_version_str[0] |
| 7575 | | (tp->bios_version_str[1] << 8); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7576 | tp->bios_release = (tp->bios_version_str[4] << 8) |
| 7577 | | tp->bios_version_str[5]; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7578 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7579 | /* |
| 7580 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 7581 | * X32 or newer, all Z series; Some models must have an |
| 7582 | * up-to-date BIOS or they will not be detected. |
| 7583 | * |
| 7584 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 7585 | */ |
| 7586 | 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] | 7587 | if (sscanf(dev->name, |
| 7588 | "IBM ThinkPad Embedded Controller -[%17c", |
| 7589 | ec_fw_string) == 1) { |
| 7590 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 7591 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7592 | |
| 7593 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7594 | if (!tp->ec_version_str) |
| 7595 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7596 | |
| 7597 | if (tpacpi_is_valid_fw_id(ec_fw_string, 'H')) { |
| 7598 | tp->ec_model = ec_fw_string[0] |
| 7599 | | (ec_fw_string[1] << 8); |
| 7600 | tp->ec_release = (ec_fw_string[4] << 8) |
| 7601 | | ec_fw_string[5]; |
| 7602 | } else { |
| 7603 | printk(TPACPI_NOTICE |
| 7604 | "ThinkPad firmware release %s " |
| 7605 | "doesn't match the known patterns\n", |
| 7606 | ec_fw_string); |
| 7607 | printk(TPACPI_NOTICE |
| 7608 | "please report this to %s\n", |
| 7609 | TPACPI_MAIL); |
| 7610 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7611 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7612 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7613 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7614 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7615 | s = dmi_get_system_info(DMI_PRODUCT_VERSION); |
| 7616 | if (s && !strnicmp(s, "ThinkPad", 8)) { |
| 7617 | tp->model_str = kstrdup(s, GFP_KERNEL); |
| 7618 | if (!tp->model_str) |
| 7619 | return -ENOMEM; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7620 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 7621 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7622 | s = dmi_get_system_info(DMI_PRODUCT_NAME); |
| 7623 | tp->nummodel_str = kstrdup(s, GFP_KERNEL); |
| 7624 | if (s && !tp->nummodel_str) |
| 7625 | return -ENOMEM; |
| 7626 | |
| 7627 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7628 | } |
| 7629 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7630 | static int __init probe_for_thinkpad(void) |
| 7631 | { |
| 7632 | int is_thinkpad; |
| 7633 | |
| 7634 | if (acpi_disabled) |
| 7635 | return -ENODEV; |
| 7636 | |
| 7637 | /* |
| 7638 | * Non-ancient models have better DMI tagging, but very old models |
| 7639 | * don't. |
| 7640 | */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7641 | is_thinkpad = (thinkpad_id.model_str != NULL); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7642 | |
| 7643 | /* ec is required because many other handles are relative to it */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7644 | TPACPI_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7645 | if (!ec_handle) { |
| 7646 | if (is_thinkpad) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7647 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7648 | "Not yet supported ThinkPad detected!\n"); |
| 7649 | return -ENODEV; |
| 7650 | } |
| 7651 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 7652 | /* |
| 7653 | * Risks a regression on very old machines, but reduces potential |
| 7654 | * false positives a damn great deal |
| 7655 | */ |
| 7656 | if (!is_thinkpad) |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7657 | is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 7658 | |
| 7659 | if (!is_thinkpad && !force_load) |
| 7660 | return -ENODEV; |
| 7661 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7662 | return 0; |
| 7663 | } |
| 7664 | |
| 7665 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7666 | /* Module init, exit, parameters */ |
| 7667 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7668 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 7669 | { |
| 7670 | .init = thinkpad_acpi_driver_init, |
| 7671 | .data = &thinkpad_acpi_driver_data, |
| 7672 | }, |
| 7673 | { |
| 7674 | .init = hotkey_init, |
| 7675 | .data = &hotkey_driver_data, |
| 7676 | }, |
| 7677 | { |
| 7678 | .init = bluetooth_init, |
| 7679 | .data = &bluetooth_driver_data, |
| 7680 | }, |
| 7681 | { |
| 7682 | .init = wan_init, |
| 7683 | .data = &wan_driver_data, |
| 7684 | }, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 7685 | { |
| 7686 | .init = uwb_init, |
| 7687 | .data = &uwb_driver_data, |
| 7688 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 7689 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7690 | { |
| 7691 | .init = video_init, |
| 7692 | .data = &video_driver_data, |
| 7693 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 7694 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7695 | { |
| 7696 | .init = light_init, |
| 7697 | .data = &light_driver_data, |
| 7698 | }, |
| 7699 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
| 7700 | { |
| 7701 | .init = dock_init, |
| 7702 | .data = &dock_driver_data[0], |
| 7703 | }, |
| 7704 | { |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 7705 | .init = dock_init2, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7706 | .data = &dock_driver_data[1], |
| 7707 | }, |
| 7708 | #endif |
| 7709 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 7710 | { |
| 7711 | .init = bay_init, |
| 7712 | .data = &bay_driver_data, |
| 7713 | }, |
| 7714 | #endif |
| 7715 | { |
| 7716 | .init = cmos_init, |
| 7717 | .data = &cmos_driver_data, |
| 7718 | }, |
| 7719 | { |
| 7720 | .init = led_init, |
| 7721 | .data = &led_driver_data, |
| 7722 | }, |
| 7723 | { |
| 7724 | .init = beep_init, |
| 7725 | .data = &beep_driver_data, |
| 7726 | }, |
| 7727 | { |
| 7728 | .init = thermal_init, |
| 7729 | .data = &thermal_driver_data, |
| 7730 | }, |
| 7731 | { |
| 7732 | .data = &ecdump_driver_data, |
| 7733 | }, |
| 7734 | { |
| 7735 | .init = brightness_init, |
| 7736 | .data = &brightness_driver_data, |
| 7737 | }, |
| 7738 | { |
| 7739 | .data = &volume_driver_data, |
| 7740 | }, |
| 7741 | { |
| 7742 | .init = fan_init, |
| 7743 | .data = &fan_driver_data, |
| 7744 | }, |
| 7745 | }; |
| 7746 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7747 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 7748 | { |
| 7749 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7750 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7751 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 7752 | if (!kp || !kp->name || !val) |
| 7753 | return -EINVAL; |
| 7754 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7755 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 7756 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 7757 | WARN_ON(ibm == NULL); |
| 7758 | |
| 7759 | if (!ibm || !ibm->name) |
| 7760 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7761 | |
| 7762 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 7763 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7764 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7765 | strcpy(ibms_init[i].param, val); |
| 7766 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7767 | return 0; |
| 7768 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7769 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7770 | |
| 7771 | return -EINVAL; |
| 7772 | } |
| 7773 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7774 | module_param(experimental, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7775 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7776 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7777 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 7778 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7779 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 7780 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 7781 | module_param(force_load, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7782 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7783 | "Attempts to load the driver even on a " |
| 7784 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 7785 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 7786 | module_param_named(fan_control, fan_control_allowed, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7787 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7788 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7789 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 7790 | module_param_named(brightness_mode, brightness_mode, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7791 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7792 | "Selects brightness control strategy: " |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 7793 | "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 7794 | |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 7795 | module_param(brightness_enable, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7796 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7797 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 7798 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 7799 | module_param(hotkey_report_mode, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7800 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7801 | "used for backwards compatibility with userspace, " |
| 7802 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 7803 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7804 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7805 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 7806 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7807 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7808 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7809 | TPACPI_PARAM(hotkey); |
| 7810 | TPACPI_PARAM(bluetooth); |
| 7811 | TPACPI_PARAM(video); |
| 7812 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 7813 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7814 | TPACPI_PARAM(dock); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7815 | #endif |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 7816 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7817 | TPACPI_PARAM(bay); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 7818 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7819 | TPACPI_PARAM(cmos); |
| 7820 | TPACPI_PARAM(led); |
| 7821 | TPACPI_PARAM(beep); |
| 7822 | TPACPI_PARAM(ecdump); |
| 7823 | TPACPI_PARAM(brightness); |
| 7824 | TPACPI_PARAM(volume); |
| 7825 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7826 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 7827 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 7828 | module_param(dbg_wlswemul, uint, 0); |
| 7829 | MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation"); |
| 7830 | module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0); |
| 7831 | MODULE_PARM_DESC(wlsw_state, |
| 7832 | "Initial state of the emulated WLSW switch"); |
| 7833 | |
| 7834 | module_param(dbg_bluetoothemul, uint, 0); |
| 7835 | MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation"); |
| 7836 | module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0); |
| 7837 | MODULE_PARM_DESC(bluetooth_state, |
| 7838 | "Initial state of the emulated bluetooth switch"); |
| 7839 | |
| 7840 | module_param(dbg_wwanemul, uint, 0); |
| 7841 | MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation"); |
| 7842 | module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0); |
| 7843 | MODULE_PARM_DESC(wwan_state, |
| 7844 | "Initial state of the emulated WWAN switch"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 7845 | |
| 7846 | module_param(dbg_uwbemul, uint, 0); |
| 7847 | MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation"); |
| 7848 | module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0); |
| 7849 | MODULE_PARM_DESC(uwb_state, |
| 7850 | "Initial state of the emulated UWB switch"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 7851 | #endif |
| 7852 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7853 | static void thinkpad_acpi_module_exit(void) |
| 7854 | { |
| 7855 | struct ibm_struct *ibm, *itmp; |
| 7856 | |
| 7857 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 7858 | |
| 7859 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 7860 | &tpacpi_all_drivers, |
| 7861 | all_drivers) { |
| 7862 | ibm_exit(ibm); |
| 7863 | } |
| 7864 | |
| 7865 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 7866 | |
| 7867 | if (tpacpi_inputdev) { |
| 7868 | if (tp_features.input_device_registered) |
| 7869 | input_unregister_device(tpacpi_inputdev); |
| 7870 | else |
| 7871 | input_free_device(tpacpi_inputdev); |
| 7872 | } |
| 7873 | |
| 7874 | if (tpacpi_hwmon) |
| 7875 | hwmon_device_unregister(tpacpi_hwmon); |
| 7876 | |
| 7877 | if (tp_features.sensors_pdev_attrs_registered) |
| 7878 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 7879 | &dev_attr_thinkpad_acpi_pdev_name); |
| 7880 | if (tpacpi_sensors_pdev) |
| 7881 | platform_device_unregister(tpacpi_sensors_pdev); |
| 7882 | if (tpacpi_pdev) |
| 7883 | platform_device_unregister(tpacpi_pdev); |
| 7884 | |
| 7885 | if (tp_features.sensors_pdrv_attrs_registered) |
| 7886 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 7887 | if (tp_features.platform_drv_attrs_registered) |
| 7888 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 7889 | |
| 7890 | if (tp_features.sensors_pdrv_registered) |
| 7891 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 7892 | |
| 7893 | if (tp_features.platform_drv_registered) |
| 7894 | platform_driver_unregister(&tpacpi_pdriver); |
| 7895 | |
| 7896 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7897 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7898 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7899 | if (tpacpi_wq) |
| 7900 | destroy_workqueue(tpacpi_wq); |
| 7901 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7902 | kfree(thinkpad_id.bios_version_str); |
| 7903 | kfree(thinkpad_id.ec_version_str); |
| 7904 | kfree(thinkpad_id.model_str); |
| 7905 | } |
| 7906 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7907 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 7908 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7909 | { |
| 7910 | int ret, i; |
| 7911 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 7912 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 7913 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 7914 | /* Parameter checking */ |
| 7915 | if (hotkey_report_mode > 2) |
| 7916 | return -EINVAL; |
| 7917 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 7918 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7919 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7920 | ret = get_thinkpad_model_data(&thinkpad_id); |
| 7921 | if (ret) { |
| 7922 | printk(TPACPI_ERR |
| 7923 | "unable to get DMI data: %d\n", ret); |
| 7924 | thinkpad_acpi_module_exit(); |
| 7925 | return ret; |
| 7926 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7927 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7928 | if (ret) { |
| 7929 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7930 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7931 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7932 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 7933 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7934 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7935 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 7936 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7937 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7938 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
| 7939 | if (!tpacpi_wq) { |
| 7940 | thinkpad_acpi_module_exit(); |
| 7941 | return -ENOMEM; |
| 7942 | } |
| 7943 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7944 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7945 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7946 | printk(TPACPI_ERR |
| 7947 | "unable to create proc dir " TPACPI_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 7948 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7949 | return -ENODEV; |
| 7950 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7951 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 7952 | ret = platform_driver_register(&tpacpi_pdriver); |
| 7953 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7954 | printk(TPACPI_ERR |
| 7955 | "unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 7956 | thinkpad_acpi_module_exit(); |
| 7957 | return ret; |
| 7958 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 7959 | tp_features.platform_drv_registered = 1; |
| 7960 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7961 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 7962 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7963 | printk(TPACPI_ERR |
| 7964 | "unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7965 | thinkpad_acpi_module_exit(); |
| 7966 | return ret; |
| 7967 | } |
| 7968 | tp_features.sensors_pdrv_registered = 1; |
| 7969 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 7970 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 7971 | if (!ret) { |
| 7972 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7973 | ret = tpacpi_create_driver_attributes( |
| 7974 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 7975 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 7976 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7977 | printk(TPACPI_ERR |
| 7978 | "unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 7979 | thinkpad_acpi_module_exit(); |
| 7980 | return ret; |
| 7981 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 7982 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 7983 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 7984 | |
| 7985 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7986 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 7987 | NULL, 0); |
| 7988 | if (IS_ERR(tpacpi_pdev)) { |
| 7989 | ret = PTR_ERR(tpacpi_pdev); |
| 7990 | tpacpi_pdev = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7991 | printk(TPACPI_ERR "unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 7992 | thinkpad_acpi_module_exit(); |
| 7993 | return ret; |
| 7994 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7995 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7996 | TPACPI_HWMON_DRVR_NAME, |
| 7997 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7998 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 7999 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 8000 | tpacpi_sensors_pdev = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8001 | printk(TPACPI_ERR |
| 8002 | "unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8003 | thinkpad_acpi_module_exit(); |
| 8004 | return ret; |
| 8005 | } |
| 8006 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 8007 | &dev_attr_thinkpad_acpi_pdev_name); |
| 8008 | if (ret) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8009 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8010 | "unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8011 | thinkpad_acpi_module_exit(); |
| 8012 | return ret; |
| 8013 | } |
| 8014 | tp_features.sensors_pdev_attrs_registered = 1; |
| 8015 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8016 | if (IS_ERR(tpacpi_hwmon)) { |
| 8017 | ret = PTR_ERR(tpacpi_hwmon); |
| 8018 | tpacpi_hwmon = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8019 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8020 | thinkpad_acpi_module_exit(); |
| 8021 | return ret; |
| 8022 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 8023 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8024 | tpacpi_inputdev = input_allocate_device(); |
| 8025 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8026 | printk(TPACPI_ERR "unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8027 | thinkpad_acpi_module_exit(); |
| 8028 | return -ENOMEM; |
| 8029 | } else { |
| 8030 | /* Prepare input device, but don't register */ |
| 8031 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8032 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8033 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 8034 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
| 8035 | thinkpad_id.vendor : |
| 8036 | PCI_VENDOR_ID_IBM; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8037 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 8038 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
| 8039 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8040 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 8041 | ret = ibm_init(&ibms_init[i]); |
| 8042 | if (ret >= 0 && *ibms_init[i].param) |
| 8043 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8044 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8045 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8046 | return ret; |
| 8047 | } |
| 8048 | } |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8049 | ret = input_register_device(tpacpi_inputdev); |
| 8050 | if (ret < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8051 | printk(TPACPI_ERR "unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8052 | thinkpad_acpi_module_exit(); |
| 8053 | return ret; |
| 8054 | } else { |
| 8055 | tp_features.input_device_registered = 1; |
| 8056 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8057 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 8058 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8059 | return 0; |
| 8060 | } |
| 8061 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 8062 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 8063 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8064 | /* |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 8065 | * This will autoload the driver in almost every ThinkPad |
| 8066 | * in widespread use. |
| 8067 | * |
| 8068 | * Only _VERY_ old models, like the 240, 240x and 570 lack |
| 8069 | * the HKEY event interface. |
| 8070 | */ |
| 8071 | MODULE_DEVICE_TABLE(acpi, ibm_htk_device_ids); |
| 8072 | |
| 8073 | /* |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8074 | * DMI matching for module autoloading |
| 8075 | * |
| 8076 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 8077 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 8078 | * |
| 8079 | * Only models listed in thinkwiki will be supported, so add yours |
| 8080 | * if it is not there yet. |
| 8081 | */ |
| 8082 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
Mathieu Chouquet-Stringer | b36a50f | 2009-03-14 16:35:26 +0100 | [diff] [blame] | 8083 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*") |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8084 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8085 | /* Ancient thinkpad BIOSes have to be identified by |
| 8086 | * BIOS type or model number, and there are far less |
| 8087 | * BIOS types than model numbers... */ |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 8088 | IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8089 | |
Henrique de Moraes Holschuh | f68f53a | 2009-04-14 02:44:12 +0000 | [diff] [blame] | 8090 | MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>"); |
| 8091 | MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8092 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 8093 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8094 | MODULE_LICENSE("GPL"); |
| 8095 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8096 | module_init(thinkpad_acpi_module_init); |
| 8097 | module_exit(thinkpad_acpi_module_exit); |