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 | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 169 | /* printk headers */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 170 | #define TPACPI_LOG TPACPI_FILE ": " |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 171 | #define TPACPI_EMERG KERN_EMERG TPACPI_LOG |
| 172 | #define TPACPI_ALERT KERN_ALERT TPACPI_LOG |
| 173 | #define TPACPI_CRIT KERN_CRIT TPACPI_LOG |
| 174 | #define TPACPI_ERR KERN_ERR TPACPI_LOG |
| 175 | #define TPACPI_WARN KERN_WARNING TPACPI_LOG |
| 176 | #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG |
| 177 | #define TPACPI_INFO KERN_INFO TPACPI_LOG |
| 178 | #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 179 | |
Henrique de Moraes Holschuh | 7ff8d62 | 2009-04-04 04:25:46 +0000 | [diff] [blame] | 180 | /* Debugging printk groups */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 181 | #define TPACPI_DBG_ALL 0xffff |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 182 | #define TPACPI_DBG_DISCLOSETASK 0x8000 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 183 | #define TPACPI_DBG_INIT 0x0001 |
| 184 | #define TPACPI_DBG_EXIT 0x0002 |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 185 | #define TPACPI_DBG_RFKILL 0x0004 |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 186 | #define TPACPI_DBG_HKEY 0x0008 |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 187 | #define TPACPI_DBG_FAN 0x0010 |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 188 | #define TPACPI_DBG_BRGHT 0x0020 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 189 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 190 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 191 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 192 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 193 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 194 | |
| 195 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 196 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 197 | */ |
| 198 | |
| 199 | struct ibm_struct; |
| 200 | |
| 201 | struct tp_acpi_drv_struct { |
| 202 | const struct acpi_device_id *hid; |
| 203 | struct acpi_driver *driver; |
| 204 | |
| 205 | void (*notify) (struct ibm_struct *, u32); |
| 206 | acpi_handle *handle; |
| 207 | u32 type; |
| 208 | struct acpi_device *device; |
| 209 | }; |
| 210 | |
| 211 | struct ibm_struct { |
| 212 | char *name; |
| 213 | |
| 214 | int (*read) (char *); |
| 215 | int (*write) (char *); |
| 216 | void (*exit) (void); |
| 217 | void (*resume) (void); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 218 | void (*suspend) (pm_message_t state); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 219 | void (*shutdown) (void); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 220 | |
| 221 | struct list_head all_drivers; |
| 222 | |
| 223 | struct tp_acpi_drv_struct *acpi; |
| 224 | |
| 225 | struct { |
| 226 | u8 acpi_driver_registered:1; |
| 227 | u8 acpi_notify_installed:1; |
| 228 | u8 proc_created:1; |
| 229 | u8 init_called:1; |
| 230 | u8 experimental:1; |
| 231 | } flags; |
| 232 | }; |
| 233 | |
| 234 | struct ibm_init_struct { |
| 235 | char param[32]; |
| 236 | |
| 237 | int (*init) (struct ibm_init_struct *); |
| 238 | struct ibm_struct *data; |
| 239 | }; |
| 240 | |
| 241 | static struct { |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 242 | u32 bluetooth:1; |
| 243 | u32 hotkey:1; |
| 244 | u32 hotkey_mask:1; |
| 245 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 246 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 247 | u32 light:1; |
| 248 | u32 light_status:1; |
| 249 | u32 bright_16levels:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 250 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 251 | u32 wan:1; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 252 | u32 uwb:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 253 | u32 fan_ctrl_status_undef:1; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 254 | u32 second_fan:1; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 255 | u32 beep_needs_two_args:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 256 | u32 input_device_registered:1; |
| 257 | u32 platform_drv_registered:1; |
| 258 | u32 platform_drv_attrs_registered:1; |
| 259 | u32 sensors_pdrv_registered:1; |
| 260 | u32 sensors_pdrv_attrs_registered:1; |
| 261 | u32 sensors_pdev_attrs_registered:1; |
| 262 | u32 hotkey_poll_active:1; |
| 263 | } tp_features; |
| 264 | |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 265 | static struct { |
| 266 | u16 hotkey_mask_ff:1; |
| 267 | } tp_warned; |
| 268 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 269 | struct thinkpad_id_data { |
| 270 | unsigned int vendor; /* ThinkPad vendor: |
| 271 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 272 | |
| 273 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 274 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 275 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 276 | u16 bios_model; /* 1Y = 0x5931, 0 = unknown */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 277 | u16 ec_model; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 278 | u16 bios_release; /* 1ZETK1WW = 0x314b, 0 = unknown */ |
| 279 | u16 ec_release; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 280 | |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 281 | char *model_str; /* ThinkPad T43 */ |
| 282 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 283 | }; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 284 | static struct thinkpad_id_data thinkpad_id; |
| 285 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 286 | static enum { |
| 287 | TPACPI_LIFE_INIT = 0, |
| 288 | TPACPI_LIFE_RUNNING, |
| 289 | TPACPI_LIFE_EXITING, |
| 290 | } tpacpi_lifecycle; |
| 291 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 292 | static int experimental; |
| 293 | static u32 dbg_level; |
| 294 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 295 | static struct workqueue_struct *tpacpi_wq; |
| 296 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 297 | enum led_status_t { |
| 298 | TPACPI_LED_OFF = 0, |
| 299 | TPACPI_LED_ON, |
| 300 | TPACPI_LED_BLINK, |
| 301 | }; |
| 302 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 303 | /* Special LED class that can defer work */ |
| 304 | struct tpacpi_led_classdev { |
| 305 | struct led_classdev led_classdev; |
| 306 | struct work_struct work; |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 307 | enum led_status_t new_state; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 308 | unsigned int led; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 309 | }; |
| 310 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 311 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 312 | static int dbg_wlswemul; |
| 313 | static int tpacpi_wlsw_emulstate; |
| 314 | static int dbg_bluetoothemul; |
| 315 | static int tpacpi_bluetooth_emulstate; |
| 316 | static int dbg_wwanemul; |
| 317 | static int tpacpi_wwan_emulstate; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 318 | static int dbg_uwbemul; |
| 319 | static int tpacpi_uwb_emulstate; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 320 | #endif |
| 321 | |
| 322 | |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 323 | /************************************************************************* |
| 324 | * Debugging helpers |
| 325 | */ |
| 326 | |
| 327 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 328 | do { if (dbg_level & (a_dbg_level)) \ |
| 329 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ |
| 330 | } while (0) |
| 331 | |
| 332 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 333 | #define vdbg_printk dbg_printk |
| 334 | static const char *str_supported(int is_supported); |
| 335 | #else |
| 336 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 337 | do { } while (0) |
| 338 | #endif |
| 339 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 340 | static void tpacpi_log_usertask(const char * const what) |
| 341 | { |
| 342 | printk(TPACPI_DEBUG "%s: access by process with PID %d\n", |
| 343 | what, task_tgid_vnr(current)); |
| 344 | } |
| 345 | |
| 346 | #define tpacpi_disclose_usertask(what, format, arg...) \ |
| 347 | do { \ |
| 348 | if (unlikely( \ |
| 349 | (dbg_level & TPACPI_DBG_DISCLOSETASK) && \ |
| 350 | (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \ |
| 351 | printk(TPACPI_DEBUG "%s: PID %d: " format, \ |
| 352 | what, task_tgid_vnr(current), ## arg); \ |
| 353 | } \ |
| 354 | } while (0) |
Henrique de Moraes Holschuh | 3dcc2c3 | 2009-04-04 04:25:45 +0000 | [diff] [blame] | 355 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 356 | /* |
| 357 | * Quirk handling helpers |
| 358 | * |
| 359 | * ThinkPad IDs and versions seen in the field so far |
| 360 | * are two-characters from the set [0-9A-Z], i.e. base 36. |
| 361 | * |
| 362 | * We use values well outside that range as specials. |
| 363 | */ |
| 364 | |
| 365 | #define TPACPI_MATCH_ANY 0xffffU |
| 366 | #define TPACPI_MATCH_UNKNOWN 0U |
| 367 | |
| 368 | /* TPID('1', 'Y') == 0x5931 */ |
| 369 | #define TPID(__c1, __c2) (((__c2) << 8) | (__c1)) |
| 370 | |
| 371 | #define TPACPI_Q_IBM(__id1, __id2, __quirk) \ |
| 372 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 373 | .bios = TPID(__id1, __id2), \ |
| 374 | .ec = TPACPI_MATCH_ANY, \ |
| 375 | .quirks = (__quirk) } |
| 376 | |
| 377 | #define TPACPI_Q_LNV(__id1, __id2, __quirk) \ |
| 378 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 379 | .bios = TPID(__id1, __id2), \ |
| 380 | .ec = TPACPI_MATCH_ANY, \ |
| 381 | .quirks = (__quirk) } |
| 382 | |
| 383 | struct tpacpi_quirk { |
| 384 | unsigned int vendor; |
| 385 | u16 bios; |
| 386 | u16 ec; |
| 387 | unsigned long quirks; |
| 388 | }; |
| 389 | |
| 390 | /** |
| 391 | * tpacpi_check_quirks() - search BIOS/EC version on a list |
| 392 | * @qlist: array of &struct tpacpi_quirk |
| 393 | * @qlist_size: number of elements in @qlist |
| 394 | * |
| 395 | * Iterates over a quirks list until one is found that matches the |
| 396 | * ThinkPad's vendor, BIOS and EC model. |
| 397 | * |
| 398 | * Returns 0 if nothing matches, otherwise returns the quirks field of |
| 399 | * the matching &struct tpacpi_quirk entry. |
| 400 | * |
| 401 | * The match criteria is: vendor, ec and bios much match. |
| 402 | */ |
| 403 | static unsigned long __init tpacpi_check_quirks( |
| 404 | const struct tpacpi_quirk *qlist, |
| 405 | unsigned int qlist_size) |
| 406 | { |
| 407 | while (qlist_size) { |
| 408 | if ((qlist->vendor == thinkpad_id.vendor || |
| 409 | qlist->vendor == TPACPI_MATCH_ANY) && |
| 410 | (qlist->bios == thinkpad_id.bios_model || |
| 411 | qlist->bios == TPACPI_MATCH_ANY) && |
| 412 | (qlist->ec == thinkpad_id.ec_model || |
| 413 | qlist->ec == TPACPI_MATCH_ANY)) |
| 414 | return qlist->quirks; |
| 415 | |
| 416 | qlist_size--; |
| 417 | qlist++; |
| 418 | } |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 423 | /**************************************************************************** |
| 424 | **************************************************************************** |
| 425 | * |
| 426 | * ACPI Helpers and device model |
| 427 | * |
| 428 | **************************************************************************** |
| 429 | ****************************************************************************/ |
| 430 | |
| 431 | /************************************************************************* |
| 432 | * ACPI basic handles |
| 433 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 435 | static acpi_handle root_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 437 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | static acpi_handle object##_handle; \ |
| 439 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 440 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | static char *object##_paths[] = { paths } |
| 442 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 443 | TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 444 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 445 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 446 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 447 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 448 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 449 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 450 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 452 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 453 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 455 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 456 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 457 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 458 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 459 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 460 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 461 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 462 | "^HKEY", /* R30, R31 */ |
| 463 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 464 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 465 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 466 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 467 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 468 | "\\_SB.PCI0.VID0", /* 770e */ |
| 469 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 470 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 471 | ); /* R30, R31 */ |
| 472 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 473 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 474 | /************************************************************************* |
| 475 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 476 | */ |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | static int acpi_evalf(acpi_handle handle, |
| 479 | void *res, char *method, char *fmt, ...) |
| 480 | { |
| 481 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 482 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 483 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 484 | struct acpi_buffer result, *resultp; |
| 485 | union acpi_object out_obj; |
| 486 | acpi_status status; |
| 487 | va_list ap; |
| 488 | char res_type; |
| 489 | int success; |
| 490 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | if (!*fmt) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 493 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | if (*fmt == 'q') { |
| 498 | quiet = 1; |
| 499 | fmt++; |
| 500 | } else |
| 501 | quiet = 0; |
| 502 | |
| 503 | res_type = *(fmt++); |
| 504 | |
| 505 | params.count = 0; |
| 506 | params.pointer = &in_objs[0]; |
| 507 | |
| 508 | va_start(ap, fmt); |
| 509 | while (*fmt) { |
| 510 | char c = *(fmt++); |
| 511 | switch (c) { |
| 512 | case 'd': /* int */ |
| 513 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 514 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 515 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 516 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 518 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | "with invalid format character '%c'\n", c); |
| 520 | return 0; |
| 521 | } |
| 522 | } |
| 523 | va_end(ap); |
| 524 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 525 | if (res_type != 'v') { |
| 526 | result.length = sizeof(out_obj); |
| 527 | result.pointer = &out_obj; |
| 528 | resultp = &result; |
| 529 | } else |
| 530 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 532 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
| 534 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 535 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | if (res) |
| 537 | *(int *)res = out_obj.integer.value; |
| 538 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 539 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 540 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | success = status == AE_OK; |
| 542 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 543 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 545 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | "with invalid format character '%c'\n", res_type); |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | if (!success && !quiet) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 551 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | method, fmt0, status); |
| 553 | |
| 554 | return success; |
| 555 | } |
| 556 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 557 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 558 | { |
| 559 | int v; |
| 560 | |
| 561 | if (ecrd_handle) { |
| 562 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 563 | return 0; |
| 564 | *p = v; |
| 565 | } else { |
| 566 | if (ec_read(i, p) < 0) |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | return 1; |
| 571 | } |
| 572 | |
| 573 | static int acpi_ec_write(int i, u8 v) |
| 574 | { |
| 575 | if (ecwr_handle) { |
| 576 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 577 | return 0; |
| 578 | } else { |
| 579 | if (ec_write(i, v) < 0) |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | return 1; |
| 584 | } |
| 585 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 586 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 587 | { |
| 588 | if (!cmos_handle) |
| 589 | return -ENXIO; |
| 590 | |
| 591 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 592 | return -EIO; |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 597 | /************************************************************************* |
| 598 | * ACPI device model |
| 599 | */ |
| 600 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 601 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 602 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 603 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
| 604 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 605 | static void drv_acpi_handle_init(char *name, |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 606 | acpi_handle *handle, acpi_handle parent, |
| 607 | char **paths, int num_paths, char **path) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 608 | { |
| 609 | int i; |
| 610 | acpi_status status; |
| 611 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 612 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 613 | name); |
| 614 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 615 | for (i = 0; i < num_paths; i++) { |
| 616 | status = acpi_get_handle(parent, paths[i], handle); |
| 617 | if (ACPI_SUCCESS(status)) { |
| 618 | *path = paths[i]; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 619 | dbg_printk(TPACPI_DBG_INIT, |
| 620 | "Found ACPI handle %s for %s\n", |
| 621 | *path, name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 622 | return; |
| 623 | } |
| 624 | } |
| 625 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 626 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 627 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 628 | *handle = NULL; |
| 629 | } |
| 630 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 631 | 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] | 632 | { |
| 633 | struct ibm_struct *ibm = data; |
| 634 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 635 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 636 | return; |
| 637 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 638 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 639 | return; |
| 640 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 641 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 642 | } |
| 643 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 644 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 645 | { |
| 646 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 647 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 648 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 649 | BUG_ON(!ibm->acpi); |
| 650 | |
| 651 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 652 | return 0; |
| 653 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 654 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 655 | "setting up ACPI notify for %s\n", ibm->name); |
| 656 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 657 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 658 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 659 | 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] | 660 | ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 661 | return -ENODEV; |
| 662 | } |
| 663 | |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 664 | ibm->acpi->device->driver_data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 665 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 666 | TPACPI_ACPI_EVENT_PREFIX, |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 667 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 668 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 669 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 670 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 671 | if (ACPI_FAILURE(status)) { |
| 672 | if (status == AE_ALREADY_EXISTS) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 673 | printk(TPACPI_NOTICE |
| 674 | "another device driver is already " |
| 675 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 676 | } else { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 677 | printk(TPACPI_ERR |
| 678 | "acpi_install_notify_handler(%s) failed: %d\n", |
| 679 | ibm->name, status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 680 | } |
| 681 | return -ENODEV; |
| 682 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 683 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 687 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 688 | { |
| 689 | return 0; |
| 690 | } |
| 691 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 692 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 693 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 694 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 695 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 696 | dbg_printk(TPACPI_DBG_INIT, |
| 697 | "registering %s as an ACPI driver\n", ibm->name); |
| 698 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 699 | BUG_ON(!ibm->acpi); |
| 700 | |
| 701 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 702 | if (!ibm->acpi->driver) { |
Mariusz Kozlowski | 4f778b9 | 2008-10-18 14:23:53 -0300 | [diff] [blame] | 703 | printk(TPACPI_ERR |
| 704 | "failed to allocate memory for ibm->acpi->driver\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 705 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 706 | } |
| 707 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 708 | 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] | 709 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 710 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 711 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 712 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 713 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 714 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 715 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 716 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 717 | kfree(ibm->acpi->driver); |
| 718 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 719 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 720 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 721 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 722 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | |
| 726 | /**************************************************************************** |
| 727 | **************************************************************************** |
| 728 | * |
| 729 | * Procfs Helpers |
| 730 | * |
| 731 | **************************************************************************** |
| 732 | ****************************************************************************/ |
| 733 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 734 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 735 | int count, int *eof, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 736 | { |
| 737 | struct ibm_struct *ibm = data; |
| 738 | int len; |
| 739 | |
| 740 | if (!ibm || !ibm->read) |
| 741 | return -EINVAL; |
| 742 | |
| 743 | len = ibm->read(page); |
| 744 | if (len < 0) |
| 745 | return len; |
| 746 | |
| 747 | if (len <= off + count) |
| 748 | *eof = 1; |
| 749 | *start = page + off; |
| 750 | len -= off; |
| 751 | if (len > count) |
| 752 | len = count; |
| 753 | if (len < 0) |
| 754 | len = 0; |
| 755 | |
| 756 | return len; |
| 757 | } |
| 758 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 759 | static int dispatch_procfs_write(struct file *file, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 760 | const char __user *userbuf, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 761 | unsigned long count, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 762 | { |
| 763 | struct ibm_struct *ibm = data; |
| 764 | char *kernbuf; |
| 765 | int ret; |
| 766 | |
| 767 | if (!ibm || !ibm->write) |
| 768 | return -EINVAL; |
Michael Buesch | 5b05d46 | 2009-08-01 12:04:19 -0300 | [diff] [blame] | 769 | if (count > PAGE_SIZE - 2) |
| 770 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 771 | |
| 772 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 773 | if (!kernbuf) |
| 774 | return -ENOMEM; |
| 775 | |
| 776 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 777 | kfree(kernbuf); |
| 778 | return -EFAULT; |
| 779 | } |
| 780 | |
| 781 | kernbuf[count] = 0; |
| 782 | strcat(kernbuf, ","); |
| 783 | ret = ibm->write(kernbuf); |
| 784 | if (ret == 0) |
| 785 | ret = count; |
| 786 | |
| 787 | kfree(kernbuf); |
| 788 | |
| 789 | return ret; |
| 790 | } |
| 791 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | static char *next_cmd(char **cmds) |
| 793 | { |
| 794 | char *start = *cmds; |
| 795 | char *end; |
| 796 | |
| 797 | while ((end = strchr(start, ',')) && end == start) |
| 798 | start = end + 1; |
| 799 | |
| 800 | if (!end) |
| 801 | return NULL; |
| 802 | |
| 803 | *end = 0; |
| 804 | *cmds = end + 1; |
| 805 | return start; |
| 806 | } |
| 807 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 808 | |
| 809 | /**************************************************************************** |
| 810 | **************************************************************************** |
| 811 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 812 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 813 | * |
| 814 | **************************************************************************** |
| 815 | ****************************************************************************/ |
| 816 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 817 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 818 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 819 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 820 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 821 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 822 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 823 | |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 824 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
| 825 | pm_message_t state) |
| 826 | { |
| 827 | struct ibm_struct *ibm, *itmp; |
| 828 | |
| 829 | list_for_each_entry_safe(ibm, itmp, |
| 830 | &tpacpi_all_drivers, |
| 831 | all_drivers) { |
| 832 | if (ibm->suspend) |
| 833 | (ibm->suspend)(state); |
| 834 | } |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 839 | static int tpacpi_resume_handler(struct platform_device *pdev) |
| 840 | { |
| 841 | struct ibm_struct *ibm, *itmp; |
| 842 | |
| 843 | list_for_each_entry_safe(ibm, itmp, |
| 844 | &tpacpi_all_drivers, |
| 845 | all_drivers) { |
| 846 | if (ibm->resume) |
| 847 | (ibm->resume)(); |
| 848 | } |
| 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 853 | static void tpacpi_shutdown_handler(struct platform_device *pdev) |
| 854 | { |
| 855 | struct ibm_struct *ibm, *itmp; |
| 856 | |
| 857 | list_for_each_entry_safe(ibm, itmp, |
| 858 | &tpacpi_all_drivers, |
| 859 | all_drivers) { |
| 860 | if (ibm->shutdown) |
| 861 | (ibm->shutdown)(); |
| 862 | } |
| 863 | } |
| 864 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 865 | static struct platform_driver tpacpi_pdriver = { |
| 866 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 867 | .name = TPACPI_DRVR_NAME, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 868 | .owner = THIS_MODULE, |
| 869 | }, |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 870 | .suspend = tpacpi_suspend_handler, |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 871 | .resume = tpacpi_resume_handler, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 872 | .shutdown = tpacpi_shutdown_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 873 | }; |
| 874 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 875 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 876 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 877 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 878 | .owner = THIS_MODULE, |
| 879 | }, |
| 880 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 881 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 882 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 883 | * sysfs support helpers |
| 884 | */ |
| 885 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 886 | struct attribute_set { |
| 887 | unsigned int members, max_members; |
| 888 | struct attribute_group group; |
| 889 | }; |
| 890 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 891 | struct attribute_set_obj { |
| 892 | struct attribute_set s; |
| 893 | struct attribute *a; |
| 894 | } __attribute__((packed)); |
| 895 | |
| 896 | 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] | 897 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 898 | { |
| 899 | struct attribute_set_obj *sobj; |
| 900 | |
| 901 | if (max_members == 0) |
| 902 | return NULL; |
| 903 | |
| 904 | /* Allocates space for implicit NULL at the end too */ |
| 905 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 906 | max_members * sizeof(struct attribute *), |
| 907 | GFP_KERNEL); |
| 908 | if (!sobj) |
| 909 | return NULL; |
| 910 | sobj->s.max_members = max_members; |
| 911 | sobj->s.group.attrs = &sobj->a; |
| 912 | sobj->s.group.name = name; |
| 913 | |
| 914 | return &sobj->s; |
| 915 | } |
| 916 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 917 | #define destroy_attr_set(_set) \ |
| 918 | kfree(_set); |
| 919 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 920 | /* 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] | 921 | 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] | 922 | { |
| 923 | if (!s || !attr) |
| 924 | return -EINVAL; |
| 925 | |
| 926 | if (s->members >= s->max_members) |
| 927 | return -ENOMEM; |
| 928 | |
| 929 | s->group.attrs[s->members] = attr; |
| 930 | s->members++; |
| 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 935 | 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] | 936 | struct attribute **attr, |
| 937 | unsigned int count) |
| 938 | { |
| 939 | int i, res; |
| 940 | |
| 941 | for (i = 0; i < count; i++) { |
| 942 | res = add_to_attr_set(s, attr[i]); |
| 943 | if (res) |
| 944 | return res; |
| 945 | } |
| 946 | |
| 947 | return 0; |
| 948 | } |
| 949 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 950 | 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] | 951 | { |
| 952 | sysfs_remove_group(kobj, &s->group); |
| 953 | destroy_attr_set(s); |
| 954 | } |
| 955 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 956 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 957 | sysfs_create_group(_kobj, &_attr_set->group) |
| 958 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 959 | static int parse_strtoul(const char *buf, |
| 960 | unsigned long max, unsigned long *value) |
| 961 | { |
| 962 | char *endp; |
| 963 | |
Henrique de Moraes Holschuh | 32afbf0 | 2007-10-08 10:12:56 -0300 | [diff] [blame] | 964 | while (*buf && isspace(*buf)) |
| 965 | buf++; |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 966 | *value = simple_strtoul(buf, &endp, 0); |
| 967 | while (*endp && isspace(*endp)) |
| 968 | endp++; |
| 969 | if (*endp || *value > max) |
| 970 | return -EINVAL; |
| 971 | |
| 972 | return 0; |
| 973 | } |
| 974 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 975 | static void tpacpi_disable_brightness_delay(void) |
| 976 | { |
| 977 | if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0)) |
| 978 | printk(TPACPI_NOTICE |
| 979 | "ACPI backlight control delay disabled\n"); |
| 980 | } |
| 981 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 982 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 983 | { |
| 984 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 985 | union acpi_object *obj; |
| 986 | int rc; |
| 987 | |
| 988 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { |
| 989 | obj = (union acpi_object *)buffer.pointer; |
| 990 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
| 991 | printk(TPACPI_ERR "Unknown _BCL data, " |
| 992 | "please report this to %s\n", TPACPI_MAIL); |
| 993 | rc = 0; |
| 994 | } else { |
| 995 | rc = obj->package.count; |
| 996 | } |
| 997 | } else { |
| 998 | return 0; |
| 999 | } |
| 1000 | |
| 1001 | kfree(buffer.pointer); |
| 1002 | return rc; |
| 1003 | } |
| 1004 | |
| 1005 | static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle, |
| 1006 | u32 lvl, void *context, void **rv) |
| 1007 | { |
| 1008 | char name[ACPI_PATH_SEGMENT_LENGTH]; |
| 1009 | struct acpi_buffer buffer = { sizeof(name), &name }; |
| 1010 | |
| 1011 | if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && |
| 1012 | !strncmp("_BCL", name, sizeof(name) - 1)) { |
| 1013 | BUG_ON(!rv || !*rv); |
| 1014 | **(int **)rv = tpacpi_query_bcl_levels(handle); |
| 1015 | return AE_CTRL_TERMINATE; |
| 1016 | } else { |
| 1017 | return AE_OK; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | /* |
| 1022 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 1023 | */ |
| 1024 | static int __init tpacpi_check_std_acpi_brightness_support(void) |
| 1025 | { |
| 1026 | int status; |
| 1027 | int bcl_levels = 0; |
| 1028 | void *bcl_ptr = &bcl_levels; |
| 1029 | |
| 1030 | if (!vid_handle) { |
| 1031 | TPACPI_ACPIHANDLE_INIT(vid); |
| 1032 | } |
| 1033 | if (!vid_handle) |
| 1034 | return 0; |
| 1035 | |
| 1036 | /* |
| 1037 | * Search for a _BCL method, and execute it. This is safe on all |
| 1038 | * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista |
| 1039 | * BIOS in ACPI backlight control mode. We do NOT have to care |
| 1040 | * about calling the _BCL method in an enabled video device, any |
| 1041 | * will do for our purposes. |
| 1042 | */ |
| 1043 | |
| 1044 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, |
| 1045 | tpacpi_acpi_walk_find_bcl, NULL, |
| 1046 | &bcl_ptr); |
| 1047 | |
| 1048 | if (ACPI_SUCCESS(status) && bcl_levels > 2) { |
| 1049 | tp_features.bright_acpimode = 1; |
| 1050 | return (bcl_levels - 2); |
| 1051 | } |
| 1052 | |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1056 | static void printk_deprecated_attribute(const char * const what, |
| 1057 | const char * const details) |
| 1058 | { |
| 1059 | tpacpi_log_usertask("deprecated sysfs attribute"); |
| 1060 | printk(TPACPI_WARN "WARNING: sysfs attribute %s is deprecated and " |
| 1061 | "will be removed. %s\n", |
| 1062 | what, details); |
| 1063 | } |
| 1064 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1065 | /************************************************************************* |
| 1066 | * rfkill and radio control support helpers |
| 1067 | */ |
| 1068 | |
| 1069 | /* |
| 1070 | * ThinkPad-ACPI firmware handling model: |
| 1071 | * |
| 1072 | * WLSW (master wireless switch) is event-driven, and is common to all |
| 1073 | * firmware-controlled radios. It cannot be controlled, just monitored, |
| 1074 | * as expected. It overrides all radio state in firmware |
| 1075 | * |
| 1076 | * The kernel, a masked-off hotkey, and WLSW can change the radio state |
| 1077 | * (TODO: verify how WLSW interacts with the returned radio state). |
| 1078 | * |
| 1079 | * The only time there are shadow radio state changes, is when |
| 1080 | * masked-off hotkeys are used. |
| 1081 | */ |
| 1082 | |
| 1083 | /* |
| 1084 | * Internal driver API for radio state: |
| 1085 | * |
| 1086 | * int: < 0 = error, otherwise enum tpacpi_rfkill_state |
| 1087 | * bool: true means radio blocked (off) |
| 1088 | */ |
| 1089 | enum tpacpi_rfkill_state { |
| 1090 | TPACPI_RFK_RADIO_OFF = 0, |
| 1091 | TPACPI_RFK_RADIO_ON |
| 1092 | }; |
| 1093 | |
| 1094 | /* rfkill switches */ |
| 1095 | enum tpacpi_rfk_id { |
| 1096 | TPACPI_RFK_BLUETOOTH_SW_ID = 0, |
| 1097 | TPACPI_RFK_WWAN_SW_ID, |
| 1098 | TPACPI_RFK_UWB_SW_ID, |
| 1099 | TPACPI_RFK_SW_MAX |
| 1100 | }; |
| 1101 | |
| 1102 | static const char *tpacpi_rfkill_names[] = { |
| 1103 | [TPACPI_RFK_BLUETOOTH_SW_ID] = "bluetooth", |
| 1104 | [TPACPI_RFK_WWAN_SW_ID] = "wwan", |
| 1105 | [TPACPI_RFK_UWB_SW_ID] = "uwb", |
| 1106 | [TPACPI_RFK_SW_MAX] = NULL |
| 1107 | }; |
| 1108 | |
| 1109 | /* ThinkPad-ACPI rfkill subdriver */ |
| 1110 | struct tpacpi_rfk { |
| 1111 | struct rfkill *rfkill; |
| 1112 | enum tpacpi_rfk_id id; |
| 1113 | const struct tpacpi_rfk_ops *ops; |
| 1114 | }; |
| 1115 | |
| 1116 | struct tpacpi_rfk_ops { |
| 1117 | /* firmware interface */ |
| 1118 | int (*get_status)(void); |
| 1119 | int (*set_status)(const enum tpacpi_rfkill_state); |
| 1120 | }; |
| 1121 | |
| 1122 | static struct tpacpi_rfk *tpacpi_rfkill_switches[TPACPI_RFK_SW_MAX]; |
| 1123 | |
| 1124 | /* Query FW and update rfkill sw state for a given rfkill switch */ |
| 1125 | static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk *tp_rfk) |
| 1126 | { |
| 1127 | int status; |
| 1128 | |
| 1129 | if (!tp_rfk) |
| 1130 | return -ENODEV; |
| 1131 | |
| 1132 | status = (tp_rfk->ops->get_status)(); |
| 1133 | if (status < 0) |
| 1134 | return status; |
| 1135 | |
| 1136 | rfkill_set_sw_state(tp_rfk->rfkill, |
| 1137 | (status == TPACPI_RFK_RADIO_OFF)); |
| 1138 | |
| 1139 | return status; |
| 1140 | } |
| 1141 | |
| 1142 | /* Query FW and update rfkill sw state for all rfkill switches */ |
| 1143 | static void tpacpi_rfk_update_swstate_all(void) |
| 1144 | { |
| 1145 | unsigned int i; |
| 1146 | |
| 1147 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) |
| 1148 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[i]); |
| 1149 | } |
| 1150 | |
| 1151 | /* |
| 1152 | * Sync the HW-blocking state of all rfkill switches, |
| 1153 | * do notice it causes the rfkill core to schedule uevents |
| 1154 | */ |
| 1155 | static void tpacpi_rfk_update_hwblock_state(bool blocked) |
| 1156 | { |
| 1157 | unsigned int i; |
| 1158 | struct tpacpi_rfk *tp_rfk; |
| 1159 | |
| 1160 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) { |
| 1161 | tp_rfk = tpacpi_rfkill_switches[i]; |
| 1162 | if (tp_rfk) { |
| 1163 | if (rfkill_set_hw_state(tp_rfk->rfkill, |
| 1164 | blocked)) { |
| 1165 | /* ignore -- we track sw block */ |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | /* Call to get the WLSW state from the firmware */ |
| 1172 | static int hotkey_get_wlsw(void); |
| 1173 | |
| 1174 | /* Call to query WLSW state and update all rfkill switches */ |
| 1175 | static bool tpacpi_rfk_check_hwblock_state(void) |
| 1176 | { |
| 1177 | int res = hotkey_get_wlsw(); |
| 1178 | int hw_blocked; |
| 1179 | |
| 1180 | /* When unknown or unsupported, we have to assume it is unblocked */ |
| 1181 | if (res < 0) |
| 1182 | return false; |
| 1183 | |
| 1184 | hw_blocked = (res == TPACPI_RFK_RADIO_OFF); |
| 1185 | tpacpi_rfk_update_hwblock_state(hw_blocked); |
| 1186 | |
| 1187 | return hw_blocked; |
| 1188 | } |
| 1189 | |
| 1190 | static int tpacpi_rfk_hook_set_block(void *data, bool blocked) |
| 1191 | { |
| 1192 | struct tpacpi_rfk *tp_rfk = data; |
| 1193 | int res; |
| 1194 | |
| 1195 | dbg_printk(TPACPI_DBG_RFKILL, |
| 1196 | "request to change radio state to %s\n", |
| 1197 | blocked ? "blocked" : "unblocked"); |
| 1198 | |
| 1199 | /* try to set radio state */ |
| 1200 | res = (tp_rfk->ops->set_status)(blocked ? |
| 1201 | TPACPI_RFK_RADIO_OFF : TPACPI_RFK_RADIO_ON); |
| 1202 | |
| 1203 | /* and update the rfkill core with whatever the FW really did */ |
| 1204 | tpacpi_rfk_update_swstate(tp_rfk); |
| 1205 | |
| 1206 | return (res < 0) ? res : 0; |
| 1207 | } |
| 1208 | |
| 1209 | static const struct rfkill_ops tpacpi_rfk_rfkill_ops = { |
| 1210 | .set_block = tpacpi_rfk_hook_set_block, |
| 1211 | }; |
| 1212 | |
| 1213 | static int __init tpacpi_new_rfkill(const enum tpacpi_rfk_id id, |
| 1214 | const struct tpacpi_rfk_ops *tp_rfkops, |
| 1215 | const enum rfkill_type rfktype, |
| 1216 | const char *name, |
| 1217 | const bool set_default) |
| 1218 | { |
| 1219 | struct tpacpi_rfk *atp_rfk; |
| 1220 | int res; |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1221 | bool sw_state = false; |
| 1222 | int sw_status; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1223 | |
| 1224 | BUG_ON(id >= TPACPI_RFK_SW_MAX || tpacpi_rfkill_switches[id]); |
| 1225 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1226 | atp_rfk = kzalloc(sizeof(struct tpacpi_rfk), GFP_KERNEL); |
| 1227 | if (atp_rfk) |
| 1228 | atp_rfk->rfkill = rfkill_alloc(name, |
| 1229 | &tpacpi_pdev->dev, |
| 1230 | rfktype, |
| 1231 | &tpacpi_rfk_rfkill_ops, |
| 1232 | atp_rfk); |
| 1233 | if (!atp_rfk || !atp_rfk->rfkill) { |
| 1234 | printk(TPACPI_ERR |
| 1235 | "failed to allocate memory for rfkill class\n"); |
| 1236 | kfree(atp_rfk); |
| 1237 | return -ENOMEM; |
| 1238 | } |
| 1239 | |
| 1240 | atp_rfk->id = id; |
| 1241 | atp_rfk->ops = tp_rfkops; |
| 1242 | |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1243 | sw_status = (tp_rfkops->get_status)(); |
| 1244 | if (sw_status < 0) { |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1245 | printk(TPACPI_ERR |
| 1246 | "failed to read initial state for %s, error %d\n", |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1247 | name, sw_status); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1248 | } else { |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1249 | sw_state = (sw_status == TPACPI_RFK_RADIO_OFF); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1250 | if (set_default) { |
| 1251 | /* try to keep the initial state, since we ask the |
| 1252 | * firmware to preserve it across S5 in NVRAM */ |
Alan Jenkins | 06d5caf | 2009-06-16 15:39:51 +0100 | [diff] [blame] | 1253 | rfkill_init_sw_state(atp_rfk->rfkill, sw_state); |
Alan Jenkins | b3fa132 | 2009-06-08 13:27:27 +0100 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | rfkill_set_hw_state(atp_rfk->rfkill, tpacpi_rfk_check_hwblock_state()); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1257 | |
| 1258 | res = rfkill_register(atp_rfk->rfkill); |
| 1259 | if (res < 0) { |
| 1260 | printk(TPACPI_ERR |
| 1261 | "failed to register %s rfkill switch: %d\n", |
| 1262 | name, res); |
| 1263 | rfkill_destroy(atp_rfk->rfkill); |
| 1264 | kfree(atp_rfk); |
| 1265 | return res; |
| 1266 | } |
| 1267 | |
| 1268 | tpacpi_rfkill_switches[id] = atp_rfk; |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
| 1272 | static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id) |
| 1273 | { |
| 1274 | struct tpacpi_rfk *tp_rfk; |
| 1275 | |
| 1276 | BUG_ON(id >= TPACPI_RFK_SW_MAX); |
| 1277 | |
| 1278 | tp_rfk = tpacpi_rfkill_switches[id]; |
| 1279 | if (tp_rfk) { |
| 1280 | rfkill_unregister(tp_rfk->rfkill); |
Corentin Chary | 5f0dadb | 2009-09-14 12:43:52 +0200 | [diff] [blame] | 1281 | rfkill_destroy(tp_rfk->rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1282 | tpacpi_rfkill_switches[id] = NULL; |
| 1283 | kfree(tp_rfk); |
| 1284 | } |
| 1285 | } |
| 1286 | |
Henrique de Moraes Holschuh | 73a94d8 | 2009-04-04 04:25:47 +0000 | [diff] [blame] | 1287 | static void printk_deprecated_rfkill_attribute(const char * const what) |
| 1288 | { |
| 1289 | printk_deprecated_attribute(what, |
| 1290 | "Please switch to generic rfkill before year 2010"); |
| 1291 | } |
| 1292 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1293 | /* sysfs <radio> enable ------------------------------------------------ */ |
| 1294 | static ssize_t tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id, |
| 1295 | struct device_attribute *attr, |
| 1296 | char *buf) |
| 1297 | { |
| 1298 | int status; |
| 1299 | |
| 1300 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1301 | |
| 1302 | /* This is in the ABI... */ |
| 1303 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1304 | status = TPACPI_RFK_RADIO_OFF; |
| 1305 | } else { |
| 1306 | status = tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1307 | if (status < 0) |
| 1308 | return status; |
| 1309 | } |
| 1310 | |
| 1311 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1312 | (status == TPACPI_RFK_RADIO_ON) ? 1 : 0); |
| 1313 | } |
| 1314 | |
| 1315 | static ssize_t tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id, |
| 1316 | struct device_attribute *attr, |
| 1317 | const char *buf, size_t count) |
| 1318 | { |
| 1319 | unsigned long t; |
| 1320 | int res; |
| 1321 | |
| 1322 | printk_deprecated_rfkill_attribute(attr->attr.name); |
| 1323 | |
| 1324 | if (parse_strtoul(buf, 1, &t)) |
| 1325 | return -EINVAL; |
| 1326 | |
| 1327 | tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); |
| 1328 | |
| 1329 | /* This is in the ABI... */ |
| 1330 | if (tpacpi_rfk_check_hwblock_state() && !!t) |
| 1331 | return -EPERM; |
| 1332 | |
| 1333 | res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? |
| 1334 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF); |
| 1335 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1336 | |
| 1337 | return (res < 0) ? res : count; |
| 1338 | } |
| 1339 | |
| 1340 | /* procfs -------------------------------------------------------------- */ |
| 1341 | static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id, char *p) |
| 1342 | { |
| 1343 | int len = 0; |
| 1344 | |
| 1345 | if (id >= TPACPI_RFK_SW_MAX) |
| 1346 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1347 | else { |
| 1348 | int status; |
| 1349 | |
| 1350 | /* This is in the ABI... */ |
| 1351 | if (tpacpi_rfk_check_hwblock_state()) { |
| 1352 | status = TPACPI_RFK_RADIO_OFF; |
| 1353 | } else { |
| 1354 | status = tpacpi_rfk_update_swstate( |
| 1355 | tpacpi_rfkill_switches[id]); |
| 1356 | if (status < 0) |
| 1357 | return status; |
| 1358 | } |
| 1359 | |
| 1360 | len += sprintf(p + len, "status:\t\t%s\n", |
| 1361 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1362 | "enabled" : "disabled"); |
| 1363 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 1364 | } |
| 1365 | |
| 1366 | return len; |
| 1367 | } |
| 1368 | |
| 1369 | static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf) |
| 1370 | { |
| 1371 | char *cmd; |
| 1372 | int status = -1; |
| 1373 | int res = 0; |
| 1374 | |
| 1375 | if (id >= TPACPI_RFK_SW_MAX) |
| 1376 | return -ENODEV; |
| 1377 | |
| 1378 | while ((cmd = next_cmd(&buf))) { |
| 1379 | if (strlencmp(cmd, "enable") == 0) |
| 1380 | status = TPACPI_RFK_RADIO_ON; |
| 1381 | else if (strlencmp(cmd, "disable") == 0) |
| 1382 | status = TPACPI_RFK_RADIO_OFF; |
| 1383 | else |
| 1384 | return -EINVAL; |
| 1385 | } |
| 1386 | |
| 1387 | if (status != -1) { |
| 1388 | tpacpi_disclose_usertask("procfs", "attempt to %s %s\n", |
| 1389 | (status == TPACPI_RFK_RADIO_ON) ? |
| 1390 | "enable" : "disable", |
| 1391 | tpacpi_rfkill_names[id]); |
| 1392 | res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); |
| 1393 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); |
| 1394 | } |
| 1395 | |
| 1396 | return res; |
| 1397 | } |
| 1398 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1399 | /************************************************************************* |
| 1400 | * thinkpad-acpi driver attributes |
| 1401 | */ |
| 1402 | |
| 1403 | /* interface_version --------------------------------------------------- */ |
| 1404 | static ssize_t tpacpi_driver_interface_version_show( |
| 1405 | struct device_driver *drv, |
| 1406 | char *buf) |
| 1407 | { |
| 1408 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 1409 | } |
| 1410 | |
| 1411 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 1412 | tpacpi_driver_interface_version_show, NULL); |
| 1413 | |
| 1414 | /* debug_level --------------------------------------------------------- */ |
| 1415 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 1416 | char *buf) |
| 1417 | { |
| 1418 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 1419 | } |
| 1420 | |
| 1421 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 1422 | const char *buf, size_t count) |
| 1423 | { |
| 1424 | unsigned long t; |
| 1425 | |
| 1426 | if (parse_strtoul(buf, 0xffff, &t)) |
| 1427 | return -EINVAL; |
| 1428 | |
| 1429 | dbg_level = t; |
| 1430 | |
| 1431 | return count; |
| 1432 | } |
| 1433 | |
| 1434 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1435 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 1436 | |
| 1437 | /* version ------------------------------------------------------------- */ |
| 1438 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 1439 | char *buf) |
| 1440 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1441 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 1442 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | static DRIVER_ATTR(version, S_IRUGO, |
| 1446 | tpacpi_driver_version_show, NULL); |
| 1447 | |
| 1448 | /* --------------------------------------------------------------------- */ |
| 1449 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1450 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1451 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1452 | /* wlsw_emulstate ------------------------------------------------------ */ |
| 1453 | static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv, |
| 1454 | char *buf) |
| 1455 | { |
| 1456 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate); |
| 1457 | } |
| 1458 | |
| 1459 | static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv, |
| 1460 | const char *buf, size_t count) |
| 1461 | { |
| 1462 | unsigned long t; |
| 1463 | |
| 1464 | if (parse_strtoul(buf, 1, &t)) |
| 1465 | return -EINVAL; |
| 1466 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1467 | if (tpacpi_wlsw_emulstate != !!t) { |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1468 | tpacpi_wlsw_emulstate = !!t; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1469 | tpacpi_rfk_update_hwblock_state(!t); /* negative logic */ |
| 1470 | } |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1471 | |
| 1472 | return count; |
| 1473 | } |
| 1474 | |
| 1475 | static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO, |
| 1476 | tpacpi_driver_wlsw_emulstate_show, |
| 1477 | tpacpi_driver_wlsw_emulstate_store); |
| 1478 | |
| 1479 | /* bluetooth_emulstate ------------------------------------------------- */ |
| 1480 | static ssize_t tpacpi_driver_bluetooth_emulstate_show( |
| 1481 | struct device_driver *drv, |
| 1482 | char *buf) |
| 1483 | { |
| 1484 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate); |
| 1485 | } |
| 1486 | |
| 1487 | static ssize_t tpacpi_driver_bluetooth_emulstate_store( |
| 1488 | struct device_driver *drv, |
| 1489 | const char *buf, size_t count) |
| 1490 | { |
| 1491 | unsigned long t; |
| 1492 | |
| 1493 | if (parse_strtoul(buf, 1, &t)) |
| 1494 | return -EINVAL; |
| 1495 | |
| 1496 | tpacpi_bluetooth_emulstate = !!t; |
| 1497 | |
| 1498 | return count; |
| 1499 | } |
| 1500 | |
| 1501 | static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO, |
| 1502 | tpacpi_driver_bluetooth_emulstate_show, |
| 1503 | tpacpi_driver_bluetooth_emulstate_store); |
| 1504 | |
| 1505 | /* wwan_emulstate ------------------------------------------------- */ |
| 1506 | static ssize_t tpacpi_driver_wwan_emulstate_show( |
| 1507 | struct device_driver *drv, |
| 1508 | char *buf) |
| 1509 | { |
| 1510 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate); |
| 1511 | } |
| 1512 | |
| 1513 | static ssize_t tpacpi_driver_wwan_emulstate_store( |
| 1514 | struct device_driver *drv, |
| 1515 | const char *buf, size_t count) |
| 1516 | { |
| 1517 | unsigned long t; |
| 1518 | |
| 1519 | if (parse_strtoul(buf, 1, &t)) |
| 1520 | return -EINVAL; |
| 1521 | |
| 1522 | tpacpi_wwan_emulstate = !!t; |
| 1523 | |
| 1524 | return count; |
| 1525 | } |
| 1526 | |
| 1527 | static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO, |
| 1528 | tpacpi_driver_wwan_emulstate_show, |
| 1529 | tpacpi_driver_wwan_emulstate_store); |
| 1530 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1531 | /* uwb_emulstate ------------------------------------------------- */ |
| 1532 | static ssize_t tpacpi_driver_uwb_emulstate_show( |
| 1533 | struct device_driver *drv, |
| 1534 | char *buf) |
| 1535 | { |
| 1536 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate); |
| 1537 | } |
| 1538 | |
| 1539 | static ssize_t tpacpi_driver_uwb_emulstate_store( |
| 1540 | struct device_driver *drv, |
| 1541 | const char *buf, size_t count) |
| 1542 | { |
| 1543 | unsigned long t; |
| 1544 | |
| 1545 | if (parse_strtoul(buf, 1, &t)) |
| 1546 | return -EINVAL; |
| 1547 | |
| 1548 | tpacpi_uwb_emulstate = !!t; |
| 1549 | |
| 1550 | return count; |
| 1551 | } |
| 1552 | |
| 1553 | static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO, |
| 1554 | tpacpi_driver_uwb_emulstate_show, |
| 1555 | tpacpi_driver_uwb_emulstate_store); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1556 | #endif |
| 1557 | |
| 1558 | /* --------------------------------------------------------------------- */ |
| 1559 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1560 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1561 | &driver_attr_debug_level, &driver_attr_version, |
| 1562 | &driver_attr_interface_version, |
| 1563 | }; |
| 1564 | |
| 1565 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 1566 | { |
| 1567 | int i, res; |
| 1568 | |
| 1569 | i = 0; |
| 1570 | res = 0; |
| 1571 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 1572 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 1573 | i++; |
| 1574 | } |
| 1575 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1576 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 1577 | if (!res && dbg_wlswemul) |
| 1578 | res = driver_create_file(drv, &driver_attr_wlsw_emulstate); |
| 1579 | if (!res && dbg_bluetoothemul) |
| 1580 | res = driver_create_file(drv, &driver_attr_bluetooth_emulstate); |
| 1581 | if (!res && dbg_wwanemul) |
| 1582 | res = driver_create_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1583 | if (!res && dbg_uwbemul) |
| 1584 | res = driver_create_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1585 | #endif |
| 1586 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1587 | return res; |
| 1588 | } |
| 1589 | |
| 1590 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 1591 | { |
| 1592 | int i; |
| 1593 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1594 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1595 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1596 | |
| 1597 | #ifdef THINKPAD_ACPI_DEBUGFACILITIES |
| 1598 | driver_remove_file(drv, &driver_attr_wlsw_emulstate); |
| 1599 | driver_remove_file(drv, &driver_attr_bluetooth_emulstate); |
| 1600 | driver_remove_file(drv, &driver_attr_wwan_emulstate); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 1601 | driver_remove_file(drv, &driver_attr_uwb_emulstate); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1602 | #endif |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1603 | } |
| 1604 | |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1605 | /************************************************************************* |
| 1606 | * Firmware Data |
| 1607 | */ |
| 1608 | |
| 1609 | /* |
| 1610 | * Table of recommended minimum BIOS versions |
| 1611 | * |
| 1612 | * Reasons for listing: |
| 1613 | * 1. Stable BIOS, listed because the unknown ammount of |
| 1614 | * bugs and bad ACPI behaviour on older versions |
| 1615 | * |
| 1616 | * 2. BIOS or EC fw with known bugs that trigger on Linux |
| 1617 | * |
| 1618 | * 3. BIOS with known reduced functionality in older versions |
| 1619 | * |
| 1620 | * We recommend the latest BIOS and EC version. |
| 1621 | * We only support the latest BIOS and EC fw version as a rule. |
| 1622 | * |
| 1623 | * Sources: IBM ThinkPad Public Web Documents (update changelogs), |
| 1624 | * Information from users in ThinkWiki |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1625 | * |
| 1626 | * WARNING: we use this table also to detect that the machine is |
| 1627 | * a ThinkPad in some cases, so don't remove entries lightly. |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1628 | */ |
| 1629 | |
| 1630 | #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \ |
| 1631 | { .vendor = (__v), \ |
| 1632 | .bios = TPID(__id1, __id2), \ |
| 1633 | .ec = TPACPI_MATCH_ANY, \ |
| 1634 | .quirks = TPACPI_MATCH_ANY << 16 \ |
| 1635 | | (__bv1) << 8 | (__bv2) } |
| 1636 | |
| 1637 | #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \ |
| 1638 | __eid1, __eid2, __ev1, __ev2) \ |
| 1639 | { .vendor = (__v), \ |
| 1640 | .bios = TPID(__bid1, __bid2), \ |
| 1641 | .ec = TPID(__eid1, __eid2), \ |
| 1642 | .quirks = (__ev1) << 24 | (__ev2) << 16 \ |
| 1643 | | (__bv1) << 8 | (__bv2) } |
| 1644 | |
| 1645 | #define TPV_QI0(__id1, __id2, __bv1, __bv2) \ |
| 1646 | TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2) |
| 1647 | |
| 1648 | #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1649 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ |
| 1650 | __bv1, __bv2, __id1, __id2, __ev1, __ev2) |
| 1651 | |
| 1652 | #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \ |
| 1653 | __eid1, __eid2, __ev1, __ev2) \ |
| 1654 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ |
| 1655 | __bv1, __bv2, __eid1, __eid2, __ev1, __ev2) |
| 1656 | |
| 1657 | #define TPV_QL0(__id1, __id2, __bv1, __bv2) \ |
| 1658 | TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2) |
| 1659 | |
| 1660 | #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
| 1661 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \ |
| 1662 | __bv1, __bv2, __id1, __id2, __ev1, __ev2) |
| 1663 | |
| 1664 | #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \ |
| 1665 | __eid1, __eid2, __ev1, __ev2) \ |
| 1666 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \ |
| 1667 | __bv1, __bv2, __eid1, __eid2, __ev1, __ev2) |
| 1668 | |
| 1669 | static const struct tpacpi_quirk tpacpi_bios_version_qtable[] __initconst = { |
| 1670 | /* Numeric models ------------------ */ |
| 1671 | /* FW MODEL BIOS VERS */ |
| 1672 | TPV_QI0('I', 'M', '6', '5'), /* 570 */ |
| 1673 | TPV_QI0('I', 'U', '2', '6'), /* 570E */ |
| 1674 | TPV_QI0('I', 'B', '5', '4'), /* 600 */ |
| 1675 | TPV_QI0('I', 'H', '4', '7'), /* 600E */ |
| 1676 | TPV_QI0('I', 'N', '3', '6'), /* 600E */ |
| 1677 | TPV_QI0('I', 'T', '5', '5'), /* 600X */ |
| 1678 | TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */ |
| 1679 | TPV_QI0('I', 'I', '4', '2'), /* 770X */ |
| 1680 | TPV_QI0('I', 'O', '2', '3'), /* 770Z */ |
| 1681 | |
| 1682 | /* A-series ------------------------- */ |
| 1683 | /* FW MODEL BIOS VERS EC VERS */ |
| 1684 | TPV_QI0('I', 'W', '5', '9'), /* A20m */ |
| 1685 | TPV_QI0('I', 'V', '6', '9'), /* A20p */ |
| 1686 | TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */ |
| 1687 | TPV_QI0('K', 'U', '3', '6'), /* A21e */ |
| 1688 | TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */ |
| 1689 | TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */ |
| 1690 | TPV_QI0('1', 'B', '1', '7'), /* A22e */ |
| 1691 | TPV_QI0('1', '3', '2', '0'), /* A22m */ |
| 1692 | TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */ |
| 1693 | TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */ |
| 1694 | TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */ |
| 1695 | |
| 1696 | /* G-series ------------------------- */ |
| 1697 | /* FW MODEL BIOS VERS */ |
| 1698 | TPV_QI0('1', 'T', 'A', '6'), /* G40 */ |
| 1699 | TPV_QI0('1', 'X', '5', '7'), /* G41 */ |
| 1700 | |
| 1701 | /* R-series, T-series --------------- */ |
| 1702 | /* FW MODEL BIOS VERS EC VERS */ |
| 1703 | TPV_QI0('1', 'C', 'F', '0'), /* R30 */ |
| 1704 | TPV_QI0('1', 'F', 'F', '1'), /* R31 */ |
| 1705 | TPV_QI0('1', 'M', '9', '7'), /* R32 */ |
| 1706 | TPV_QI0('1', 'O', '6', '1'), /* R40 */ |
| 1707 | TPV_QI0('1', 'P', '6', '5'), /* R40 */ |
| 1708 | TPV_QI0('1', 'S', '7', '0'), /* R40e */ |
| 1709 | TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51, |
| 1710 | T40/p, T41/p, T42/p (1) */ |
| 1711 | TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */ |
| 1712 | TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */ |
| 1713 | TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */ |
| 1714 | TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */ |
| 1715 | |
| 1716 | TPV_QI0('I', 'Y', '6', '1'), /* T20 */ |
| 1717 | TPV_QI0('K', 'Z', '3', '4'), /* T21 */ |
| 1718 | TPV_QI0('1', '6', '3', '2'), /* T22 */ |
| 1719 | TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */ |
| 1720 | TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */ |
| 1721 | TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */ |
| 1722 | |
| 1723 | TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */ |
| 1724 | TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */ |
| 1725 | TPV_QL0('7', 'E', 'D', '0'), /* R60e, R60i */ |
| 1726 | |
| 1727 | /* BIOS FW BIOS VERS EC FW EC VERS */ |
| 1728 | TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */ |
| 1729 | TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */ |
| 1730 | |
| 1731 | /* X-series ------------------------- */ |
| 1732 | /* FW MODEL BIOS VERS EC VERS */ |
| 1733 | TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */ |
| 1734 | TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */ |
| 1735 | TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */ |
| 1736 | TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */ |
| 1737 | TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */ |
| 1738 | TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */ |
| 1739 | TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */ |
| 1740 | |
| 1741 | TPV_QL0('7', 'B', 'D', '7'), /* X60/s */ |
| 1742 | TPV_QL0('7', 'J', '3', '0'), /* X60t */ |
| 1743 | |
| 1744 | /* (0) - older versions lack DMI EC fw string and functionality */ |
| 1745 | /* (1) - older versions known to lack functionality */ |
| 1746 | }; |
| 1747 | |
| 1748 | #undef TPV_QL1 |
| 1749 | #undef TPV_QL0 |
| 1750 | #undef TPV_QI2 |
| 1751 | #undef TPV_QI1 |
| 1752 | #undef TPV_QI0 |
| 1753 | #undef TPV_Q_X |
| 1754 | #undef TPV_Q |
| 1755 | |
| 1756 | static void __init tpacpi_check_outdated_fw(void) |
| 1757 | { |
| 1758 | unsigned long fwvers; |
| 1759 | u16 ec_version, bios_version; |
| 1760 | |
| 1761 | fwvers = tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1762 | ARRAY_SIZE(tpacpi_bios_version_qtable)); |
| 1763 | |
| 1764 | if (!fwvers) |
| 1765 | return; |
| 1766 | |
| 1767 | bios_version = fwvers & 0xffffU; |
| 1768 | ec_version = (fwvers >> 16) & 0xffffU; |
| 1769 | |
| 1770 | /* note that unknown versions are set to 0x0000 and we use that */ |
| 1771 | if ((bios_version > thinkpad_id.bios_release) || |
| 1772 | (ec_version > thinkpad_id.ec_release && |
| 1773 | ec_version != TPACPI_MATCH_ANY)) { |
| 1774 | /* |
| 1775 | * The changelogs would let us track down the exact |
| 1776 | * reason, but it is just too much of a pain to track |
| 1777 | * it. We only list BIOSes that are either really |
| 1778 | * broken, or really stable to begin with, so it is |
| 1779 | * best if the user upgrades the firmware anyway. |
| 1780 | */ |
| 1781 | printk(TPACPI_WARN |
| 1782 | "WARNING: Outdated ThinkPad BIOS/EC firmware\n"); |
| 1783 | printk(TPACPI_WARN |
| 1784 | "WARNING: This firmware may be missing critical bug " |
| 1785 | "fixes and/or important features\n"); |
| 1786 | } |
| 1787 | } |
| 1788 | |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 1789 | static bool __init tpacpi_is_fw_known(void) |
| 1790 | { |
| 1791 | return tpacpi_check_quirks(tpacpi_bios_version_qtable, |
| 1792 | ARRAY_SIZE(tpacpi_bios_version_qtable)) != 0; |
| 1793 | } |
| 1794 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1795 | /**************************************************************************** |
| 1796 | **************************************************************************** |
| 1797 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1798 | * Subdrivers |
| 1799 | * |
| 1800 | **************************************************************************** |
| 1801 | ****************************************************************************/ |
| 1802 | |
| 1803 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 1804 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1805 | */ |
| 1806 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1807 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1809 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 1810 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1812 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1813 | (thinkpad_id.bios_version_str) ? |
| 1814 | thinkpad_id.bios_version_str : "unknown", |
| 1815 | (thinkpad_id.ec_version_str) ? |
| 1816 | thinkpad_id.ec_version_str : "unknown"); |
| 1817 | |
| 1818 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1819 | printk(TPACPI_INFO "%s %s, model %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1820 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 1821 | "IBM" : ((thinkpad_id.vendor == |
| 1822 | PCI_VENDOR_ID_LENOVO) ? |
| 1823 | "Lenovo" : "Unknown vendor"), |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1824 | thinkpad_id.model_str, |
| 1825 | (thinkpad_id.nummodel_str) ? |
| 1826 | thinkpad_id.nummodel_str : "unknown"); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 1827 | |
Henrique de Moraes Holschuh | 600a99f | 2009-09-12 15:22:12 -0300 | [diff] [blame] | 1828 | tpacpi_check_outdated_fw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | return 0; |
| 1830 | } |
| 1831 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1832 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | { |
| 1834 | int len = 0; |
| 1835 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1836 | len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); |
| 1837 | len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | |
| 1839 | return len; |
| 1840 | } |
| 1841 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1842 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1843 | .name = "driver", |
| 1844 | .read = thinkpad_acpi_driver_read, |
| 1845 | }; |
| 1846 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1847 | /************************************************************************* |
| 1848 | * Hotkey subdriver |
| 1849 | */ |
| 1850 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1851 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1852 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1853 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1854 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1855 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1856 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1857 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1858 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1859 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1860 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1861 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1862 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1863 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1864 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1865 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1866 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1867 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1868 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1869 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1870 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1871 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1872 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1873 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1874 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1875 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1876 | }; |
| 1877 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1878 | enum { /* Keys available through NVRAM polling */ |
| 1879 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1880 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1881 | }; |
| 1882 | |
| 1883 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1884 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1885 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1886 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1887 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1888 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1889 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1890 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1891 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1892 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1893 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1894 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1895 | }; |
| 1896 | |
| 1897 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1898 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1899 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1900 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1901 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1902 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1903 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1904 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1905 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1906 | TP_ACPI_HKEY_MUTE_MASK, |
| 1907 | }; |
| 1908 | |
| 1909 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1910 | struct tp_nvram_state { |
| 1911 | u16 thinkpad_toggle:1; |
| 1912 | u16 zoom_toggle:1; |
| 1913 | u16 display_toggle:1; |
| 1914 | u16 thinklight_toggle:1; |
| 1915 | u16 hibernate_toggle:1; |
| 1916 | u16 displayexp_toggle:1; |
| 1917 | u16 display_state:1; |
| 1918 | u16 brightness_toggle:1; |
| 1919 | u16 volume_toggle:1; |
| 1920 | u16 mute:1; |
| 1921 | |
| 1922 | u8 brightness_level; |
| 1923 | u8 volume_level; |
| 1924 | }; |
| 1925 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1926 | /* kthread for the hotkey poller */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1927 | static struct task_struct *tpacpi_hotkey_task; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1928 | |
| 1929 | /* Acquired while the poller kthread is running, use to sync start/stop */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1930 | static struct mutex hotkey_thread_mutex; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1931 | |
| 1932 | /* |
| 1933 | * Acquire mutex to write poller control variables. |
| 1934 | * Increment hotkey_config_change when changing them. |
| 1935 | * |
| 1936 | * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END |
| 1937 | */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1938 | static struct mutex hotkey_thread_data_mutex; |
| 1939 | static unsigned int hotkey_config_change; |
| 1940 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1941 | /* |
| 1942 | * hotkey poller control variables |
| 1943 | * |
| 1944 | * Must be atomic or readers will also need to acquire mutex |
| 1945 | */ |
| 1946 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 1947 | static unsigned int hotkey_poll_freq = 10; /* Hz */ |
| 1948 | |
| 1949 | #define HOTKEY_CONFIG_CRITICAL_START \ |
| 1950 | do { \ |
| 1951 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 1952 | hotkey_config_change++; \ |
| 1953 | } while (0); |
| 1954 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 1955 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1956 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1957 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1958 | |
| 1959 | #define hotkey_source_mask 0U |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 1960 | #define HOTKEY_CONFIG_CRITICAL_START |
| 1961 | #define HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1962 | |
| 1963 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1964 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1965 | static struct mutex hotkey_mutex; |
| 1966 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1967 | static enum { /* Reasons for waking up */ |
| 1968 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 1969 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 1970 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 1971 | } hotkey_wakeup_reason; |
| 1972 | |
| 1973 | static int hotkey_autosleep_ack; |
| 1974 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1975 | static u32 hotkey_orig_mask; |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1976 | static u32 hotkey_all_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1977 | static u32 hotkey_reserved_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1978 | static u32 hotkey_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1979 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1980 | static unsigned int hotkey_report_mode; |
| 1981 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1982 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1983 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 1984 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1985 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1986 | /* HKEY.MHKG() return bits */ |
| 1987 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 1988 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1989 | static int hotkey_get_wlsw(void) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1990 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1991 | int status; |
| 1992 | |
| 1993 | if (!tp_features.hotkey_wlsw) |
| 1994 | return -ENODEV; |
| 1995 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 1996 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1997 | if (dbg_wlswemul) |
| 1998 | return (tpacpi_wlsw_emulstate) ? |
| 1999 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 2000 | #endif |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2001 | |
| 2002 | if (!acpi_evalf(hkey_handle, &status, "WLSW", "d")) |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2003 | return -EIO; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2004 | |
| 2005 | return (status) ? TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2006 | } |
| 2007 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2008 | static int hotkey_get_tablet_mode(int *status) |
| 2009 | { |
| 2010 | int s; |
| 2011 | |
| 2012 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 2013 | return -EIO; |
| 2014 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 2015 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 2016 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2017 | } |
| 2018 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2019 | /* |
| 2020 | * Call with hotkey_mutex held |
| 2021 | */ |
| 2022 | static int hotkey_mask_get(void) |
| 2023 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2024 | u32 m = 0; |
| 2025 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2026 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2027 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2028 | return -EIO; |
| 2029 | } |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2030 | HOTKEY_CONFIG_CRITICAL_START |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2031 | hotkey_mask = m | (hotkey_source_mask & hotkey_mask); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2032 | HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2033 | |
| 2034 | return 0; |
| 2035 | } |
| 2036 | |
| 2037 | /* |
| 2038 | * Call with hotkey_mutex held |
| 2039 | */ |
| 2040 | static int hotkey_mask_set(u32 mask) |
| 2041 | { |
| 2042 | int i; |
| 2043 | int rc = 0; |
| 2044 | |
| 2045 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 2046 | if (!tp_warned.hotkey_mask_ff && |
| 2047 | (mask == 0xffff || mask == 0xffffff || |
| 2048 | mask == 0xffffffff)) { |
| 2049 | tp_warned.hotkey_mask_ff = 1; |
| 2050 | printk(TPACPI_NOTICE |
| 2051 | "setting the hotkey mask to 0x%08x is likely " |
| 2052 | "not the best way to go about it\n", mask); |
| 2053 | printk(TPACPI_NOTICE |
| 2054 | "please consider using the driver defaults, " |
| 2055 | "and refer to up-to-date thinkpad-acpi " |
| 2056 | "documentation\n"); |
| 2057 | } |
| 2058 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2059 | HOTKEY_CONFIG_CRITICAL_START |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2060 | for (i = 0; i < 32; i++) { |
| 2061 | u32 m = 1 << i; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2062 | /* enable in firmware mask only keys not in NVRAM |
| 2063 | * mode, but enable the key in the cached hotkey_mask |
| 2064 | * regardless of mode, or the key will end up |
| 2065 | * disabled by hotkey_mask_get() */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2066 | if (!acpi_evalf(hkey_handle, |
| 2067 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2068 | !!((mask & ~hotkey_source_mask) & m))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2069 | rc = -EIO; |
| 2070 | break; |
| 2071 | } else { |
| 2072 | hotkey_mask = (hotkey_mask & ~m) | (mask & m); |
| 2073 | } |
| 2074 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2075 | HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2076 | |
| 2077 | /* hotkey_mask_get must be called unconditionally below */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2078 | if (!hotkey_mask_get() && !rc && |
| 2079 | (hotkey_mask & ~hotkey_source_mask) != |
| 2080 | (mask & ~hotkey_source_mask)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2081 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2082 | "requested hot key mask 0x%08x, but " |
| 2083 | "firmware forced it to 0x%08x\n", |
| 2084 | mask, hotkey_mask); |
| 2085 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2086 | } else { |
| 2087 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2088 | HOTKEY_CONFIG_CRITICAL_START |
| 2089 | hotkey_mask = mask & hotkey_source_mask; |
| 2090 | HOTKEY_CONFIG_CRITICAL_END |
| 2091 | hotkey_mask_get(); |
| 2092 | if (hotkey_mask != mask) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2093 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2094 | "requested hot key mask 0x%08x, " |
| 2095 | "forced to 0x%08x (NVRAM poll mask is " |
| 2096 | "0x%08x): no firmware mask support\n", |
| 2097 | mask, hotkey_mask, hotkey_source_mask); |
| 2098 | } |
| 2099 | #else |
| 2100 | hotkey_mask_get(); |
| 2101 | rc = -ENXIO; |
| 2102 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | return rc; |
| 2106 | } |
| 2107 | |
| 2108 | static int hotkey_status_get(int *status) |
| 2109 | { |
| 2110 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 2111 | return -EIO; |
| 2112 | |
| 2113 | return 0; |
| 2114 | } |
| 2115 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2116 | static int hotkey_status_set(bool enable) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2117 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2118 | 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] | 2119 | return -EIO; |
| 2120 | |
| 2121 | return 0; |
| 2122 | } |
| 2123 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2124 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2125 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2126 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2127 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2128 | if (tp_features.hotkey_tablet && |
| 2129 | !hotkey_get_tablet_mode(&state)) { |
| 2130 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2131 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2132 | input_report_switch(tpacpi_inputdev, |
| 2133 | SW_TABLET_MODE, !!state); |
| 2134 | input_sync(tpacpi_inputdev); |
| 2135 | |
| 2136 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2137 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2138 | } |
| 2139 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2140 | static void tpacpi_input_send_key(unsigned int scancode) |
| 2141 | { |
| 2142 | unsigned int keycode; |
| 2143 | |
| 2144 | keycode = hotkey_keycode_map[scancode]; |
| 2145 | |
| 2146 | if (keycode != KEY_RESERVED) { |
| 2147 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2148 | |
| 2149 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 2150 | if (keycode == KEY_UNKNOWN) |
| 2151 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 2152 | scancode); |
| 2153 | input_sync(tpacpi_inputdev); |
| 2154 | |
| 2155 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 2156 | if (keycode == KEY_UNKNOWN) |
| 2157 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 2158 | scancode); |
| 2159 | input_sync(tpacpi_inputdev); |
| 2160 | |
| 2161 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2162 | } |
| 2163 | } |
| 2164 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2165 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2166 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 2167 | |
| 2168 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 2169 | { |
| 2170 | tpacpi_input_send_key(scancode); |
| 2171 | if (hotkey_report_mode < 2) { |
| 2172 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
| 2173 | 0x80, 0x1001 + scancode); |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m) |
| 2178 | { |
| 2179 | u8 d; |
| 2180 | |
| 2181 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 2182 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 2183 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 2184 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 2185 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 2186 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 2187 | } |
| 2188 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 2189 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 2190 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 2191 | } |
| 2192 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 2193 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 2194 | n->displayexp_toggle = |
| 2195 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 2196 | } |
| 2197 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 2198 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 2199 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 2200 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 2201 | n->brightness_toggle = |
| 2202 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 2203 | } |
| 2204 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 2205 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 2206 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 2207 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 2208 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 2209 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2214 | do { \ |
| 2215 | if ((mask & (1 << __scancode)) && \ |
| 2216 | oldn->__member != newn->__member) \ |
| 2217 | tpacpi_hotkey_send_key(__scancode); \ |
| 2218 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2219 | |
| 2220 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
| 2221 | do { if (mask & (1 << __scancode)) \ |
| 2222 | tpacpi_hotkey_send_key(__scancode); } while (0) |
| 2223 | |
| 2224 | 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] | 2225 | struct tp_nvram_state *newn, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2226 | u32 mask) |
| 2227 | { |
| 2228 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 2229 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 2230 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 2231 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 2232 | |
| 2233 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 2234 | |
| 2235 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 2236 | |
| 2237 | /* handle volume */ |
| 2238 | if (oldn->volume_toggle != newn->volume_toggle) { |
| 2239 | if (oldn->mute != newn->mute) { |
| 2240 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2241 | } |
| 2242 | if (oldn->volume_level > newn->volume_level) { |
| 2243 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2244 | } else if (oldn->volume_level < newn->volume_level) { |
| 2245 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2246 | } else if (oldn->mute == newn->mute) { |
| 2247 | /* repeated key presses that didn't change state */ |
| 2248 | if (newn->mute) { |
| 2249 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 2250 | } else if (newn->volume_level != 0) { |
| 2251 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 2252 | } else { |
| 2253 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 2254 | } |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | /* handle brightness */ |
| 2259 | if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 2260 | if (oldn->brightness_level < newn->brightness_level) { |
| 2261 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2262 | } else if (oldn->brightness_level > newn->brightness_level) { |
| 2263 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2264 | } else { |
| 2265 | /* repeated key presses that didn't change state */ |
| 2266 | if (newn->brightness_level != 0) { |
| 2267 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 2268 | } else { |
| 2269 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 2270 | } |
| 2271 | } |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | #undef TPACPI_COMPARE_KEY |
| 2276 | #undef TPACPI_MAY_SEND_KEY |
| 2277 | |
| 2278 | static int hotkey_kthread(void *data) |
| 2279 | { |
| 2280 | struct tp_nvram_state s[2]; |
| 2281 | u32 mask; |
| 2282 | unsigned int si, so; |
| 2283 | unsigned long t; |
| 2284 | unsigned int change_detector, must_reset; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2285 | unsigned int poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2286 | |
| 2287 | mutex_lock(&hotkey_thread_mutex); |
| 2288 | |
| 2289 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 2290 | goto exit; |
| 2291 | |
| 2292 | set_freezable(); |
| 2293 | |
| 2294 | so = 0; |
| 2295 | si = 1; |
| 2296 | t = 0; |
| 2297 | |
| 2298 | /* Initial state for compares */ |
| 2299 | mutex_lock(&hotkey_thread_data_mutex); |
| 2300 | change_detector = hotkey_config_change; |
| 2301 | mask = hotkey_source_mask & hotkey_mask; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2302 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2303 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2304 | hotkey_read_nvram(&s[so], mask); |
| 2305 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2306 | while (!kthread_should_stop()) { |
| 2307 | if (t == 0) { |
| 2308 | if (likely(poll_freq)) |
| 2309 | t = 1000/poll_freq; |
| 2310 | else |
| 2311 | t = 100; /* should never happen... */ |
| 2312 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2313 | t = msleep_interruptible(t); |
| 2314 | if (unlikely(kthread_should_stop())) |
| 2315 | break; |
| 2316 | must_reset = try_to_freeze(); |
| 2317 | if (t > 0 && !must_reset) |
| 2318 | continue; |
| 2319 | |
| 2320 | mutex_lock(&hotkey_thread_data_mutex); |
| 2321 | if (must_reset || hotkey_config_change != change_detector) { |
| 2322 | /* forget old state on thaw or config change */ |
| 2323 | si = so; |
| 2324 | t = 0; |
| 2325 | change_detector = hotkey_config_change; |
| 2326 | } |
| 2327 | mask = hotkey_source_mask & hotkey_mask; |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2328 | poll_freq = hotkey_poll_freq; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2329 | mutex_unlock(&hotkey_thread_data_mutex); |
| 2330 | |
| 2331 | if (likely(mask)) { |
| 2332 | hotkey_read_nvram(&s[si], mask); |
| 2333 | if (likely(si != so)) { |
| 2334 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2335 | mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2336 | } |
| 2337 | } |
| 2338 | |
| 2339 | so = si; |
| 2340 | si ^= 1; |
| 2341 | } |
| 2342 | |
| 2343 | exit: |
| 2344 | mutex_unlock(&hotkey_thread_mutex); |
| 2345 | return 0; |
| 2346 | } |
| 2347 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2348 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2349 | static void hotkey_poll_stop_sync(void) |
| 2350 | { |
| 2351 | if (tpacpi_hotkey_task) { |
| 2352 | if (frozen(tpacpi_hotkey_task) || |
| 2353 | freezing(tpacpi_hotkey_task)) |
| 2354 | thaw_process(tpacpi_hotkey_task); |
| 2355 | |
| 2356 | kthread_stop(tpacpi_hotkey_task); |
| 2357 | tpacpi_hotkey_task = NULL; |
| 2358 | mutex_lock(&hotkey_thread_mutex); |
| 2359 | /* at this point, the thread did exit */ |
| 2360 | mutex_unlock(&hotkey_thread_mutex); |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | /* call with hotkey_mutex held */ |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2365 | static void hotkey_poll_setup(bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2366 | { |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2367 | u32 hotkeys_to_poll = hotkey_source_mask & hotkey_mask; |
| 2368 | |
| 2369 | if (hotkeys_to_poll != 0 && hotkey_poll_freq > 0 && |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2370 | (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { |
| 2371 | if (!tpacpi_hotkey_task) { |
| 2372 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 2373 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2374 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 2375 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2376 | printk(TPACPI_ERR |
| 2377 | "could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2378 | "for hotkey polling\n"); |
| 2379 | } |
| 2380 | } |
| 2381 | } else { |
| 2382 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2383 | if (may_warn && hotkeys_to_poll != 0 && |
| 2384 | hotkey_poll_freq == 0) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2385 | printk(TPACPI_NOTICE |
| 2386 | "hot keys 0x%08x require polling, " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2387 | "which is currently disabled\n", |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2388 | hotkeys_to_poll); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2393 | static void hotkey_poll_setup_safe(bool may_warn) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2394 | { |
| 2395 | mutex_lock(&hotkey_mutex); |
| 2396 | hotkey_poll_setup(may_warn); |
| 2397 | mutex_unlock(&hotkey_mutex); |
| 2398 | } |
| 2399 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2400 | /* call with hotkey_mutex held */ |
| 2401 | static void hotkey_poll_set_freq(unsigned int freq) |
| 2402 | { |
| 2403 | if (!freq) |
| 2404 | hotkey_poll_stop_sync(); |
| 2405 | |
| 2406 | HOTKEY_CONFIG_CRITICAL_START |
| 2407 | hotkey_poll_freq = freq; |
| 2408 | HOTKEY_CONFIG_CRITICAL_END |
| 2409 | } |
| 2410 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2411 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2412 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2413 | static void hotkey_poll_setup_safe(bool __unused) |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 2414 | { |
| 2415 | } |
| 2416 | |
| 2417 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2418 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2419 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 2420 | { |
| 2421 | switch (tpacpi_lifecycle) { |
| 2422 | case TPACPI_LIFE_INIT: |
| 2423 | /* |
| 2424 | * hotkey_init will call hotkey_poll_setup_safe |
| 2425 | * at the appropriate moment |
| 2426 | */ |
| 2427 | return 0; |
| 2428 | case TPACPI_LIFE_EXITING: |
| 2429 | return -EBUSY; |
| 2430 | case TPACPI_LIFE_RUNNING: |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2431 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2432 | return 0; |
| 2433 | } |
| 2434 | |
| 2435 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 2436 | BUG(); |
| 2437 | return -EBUSY; |
| 2438 | } |
| 2439 | |
| 2440 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 2441 | { |
| 2442 | /* disable hotkey polling when possible */ |
| 2443 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING) |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2444 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2445 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2446 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2447 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 2448 | static ssize_t hotkey_enable_show(struct device *dev, |
| 2449 | struct device_attribute *attr, |
| 2450 | char *buf) |
| 2451 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2452 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2453 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2454 | printk_deprecated_attribute("hotkey_enable", |
| 2455 | "Hotkey reporting is always enabled"); |
| 2456 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2457 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2458 | if (res) |
| 2459 | return res; |
| 2460 | |
| 2461 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 2462 | } |
| 2463 | |
| 2464 | static ssize_t hotkey_enable_store(struct device *dev, |
| 2465 | struct device_attribute *attr, |
| 2466 | const char *buf, size_t count) |
| 2467 | { |
| 2468 | unsigned long t; |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2469 | |
| 2470 | printk_deprecated_attribute("hotkey_enable", |
| 2471 | "Hotkeys can be disabled through hotkey_mask"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2472 | |
| 2473 | if (parse_strtoul(buf, 1, &t)) |
| 2474 | return -EINVAL; |
| 2475 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2476 | if (t == 0) |
| 2477 | return -EPERM; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2478 | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2479 | return count; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2483 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2484 | hotkey_enable_show, hotkey_enable_store); |
| 2485 | |
| 2486 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 2487 | static ssize_t hotkey_mask_show(struct device *dev, |
| 2488 | struct device_attribute *attr, |
| 2489 | char *buf) |
| 2490 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2491 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2492 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2493 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2494 | return -ERESTARTSYS; |
| 2495 | res = hotkey_mask_get(); |
| 2496 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2497 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2498 | return (res)? |
| 2499 | res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | static ssize_t hotkey_mask_store(struct device *dev, |
| 2503 | struct device_attribute *attr, |
| 2504 | const char *buf, size_t count) |
| 2505 | { |
| 2506 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2507 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2508 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2509 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2510 | return -EINVAL; |
| 2511 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2512 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2513 | return -ERESTARTSYS; |
| 2514 | |
| 2515 | res = hotkey_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2516 | |
| 2517 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2518 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2519 | #endif |
| 2520 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2521 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2522 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2523 | tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t); |
| 2524 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2525 | return (res) ? res : count; |
| 2526 | } |
| 2527 | |
| 2528 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2529 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2530 | hotkey_mask_show, hotkey_mask_store); |
| 2531 | |
| 2532 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 2533 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 2534 | struct device_attribute *attr, |
| 2535 | char *buf) |
| 2536 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2537 | return sprintf(buf, "0\n"); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2541 | __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] | 2542 | |
| 2543 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 2544 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 2545 | struct device_attribute *attr, |
| 2546 | char *buf) |
| 2547 | { |
Henrique de Moraes Holschuh | 06777be | 2009-09-12 15:22:15 -0300 | [diff] [blame] | 2548 | printk_deprecated_attribute("hotkey_bios_mask", |
| 2549 | "This attribute is useless."); |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2550 | 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] | 2551 | } |
| 2552 | |
| 2553 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2554 | __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] | 2555 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2556 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 2557 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 2558 | struct device_attribute *attr, |
| 2559 | char *buf) |
| 2560 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2561 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 2562 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 2566 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 2567 | |
| 2568 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 2569 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 2570 | struct device_attribute *attr, |
| 2571 | char *buf) |
| 2572 | { |
| 2573 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2574 | (hotkey_all_mask | hotkey_source_mask) |
| 2575 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 2579 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 2580 | hotkey_recommended_mask_show, NULL); |
| 2581 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2582 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2583 | |
| 2584 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 2585 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 2586 | struct device_attribute *attr, |
| 2587 | char *buf) |
| 2588 | { |
| 2589 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 2590 | } |
| 2591 | |
| 2592 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 2593 | struct device_attribute *attr, |
| 2594 | const char *buf, size_t count) |
| 2595 | { |
| 2596 | unsigned long t; |
| 2597 | |
| 2598 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 2599 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 2600 | return -EINVAL; |
| 2601 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2602 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2603 | return -ERESTARTSYS; |
| 2604 | |
| 2605 | HOTKEY_CONFIG_CRITICAL_START |
| 2606 | hotkey_source_mask = t; |
| 2607 | HOTKEY_CONFIG_CRITICAL_END |
| 2608 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2609 | hotkey_poll_setup(true); |
| 2610 | hotkey_mask_set(hotkey_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2611 | |
| 2612 | mutex_unlock(&hotkey_mutex); |
| 2613 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2614 | tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); |
| 2615 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2616 | return count; |
| 2617 | } |
| 2618 | |
| 2619 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 2620 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 2621 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 2622 | |
| 2623 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 2624 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 2625 | struct device_attribute *attr, |
| 2626 | char *buf) |
| 2627 | { |
| 2628 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 2629 | } |
| 2630 | |
| 2631 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 2632 | struct device_attribute *attr, |
| 2633 | const char *buf, size_t count) |
| 2634 | { |
| 2635 | unsigned long t; |
| 2636 | |
| 2637 | if (parse_strtoul(buf, 25, &t)) |
| 2638 | return -EINVAL; |
| 2639 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 2640 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2641 | return -ERESTARTSYS; |
| 2642 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2643 | hotkey_poll_set_freq(t); |
| 2644 | hotkey_poll_setup(true); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2645 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2646 | mutex_unlock(&hotkey_mutex); |
| 2647 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2648 | tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t); |
| 2649 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2650 | return count; |
| 2651 | } |
| 2652 | |
| 2653 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 2654 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 2655 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 2656 | |
| 2657 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2658 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2659 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2660 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 2661 | struct device_attribute *attr, |
| 2662 | char *buf) |
| 2663 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2664 | int res; |
| 2665 | res = hotkey_get_wlsw(); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2666 | if (res < 0) |
| 2667 | return res; |
| 2668 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2669 | /* Opportunistic update */ |
| 2670 | tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF)); |
| 2671 | |
| 2672 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2673 | (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 2677 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 2678 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2679 | static void hotkey_radio_sw_notify_change(void) |
| 2680 | { |
| 2681 | if (tp_features.hotkey_wlsw) |
| 2682 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2683 | "hotkey_radio_sw"); |
| 2684 | } |
| 2685 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2686 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 2687 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 2688 | struct device_attribute *attr, |
| 2689 | char *buf) |
| 2690 | { |
| 2691 | int res, s; |
| 2692 | res = hotkey_get_tablet_mode(&s); |
| 2693 | if (res < 0) |
| 2694 | return res; |
| 2695 | |
| 2696 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 2697 | } |
| 2698 | |
| 2699 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 2700 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 2701 | |
| 2702 | static void hotkey_tablet_mode_notify_change(void) |
| 2703 | { |
| 2704 | if (tp_features.hotkey_tablet) |
| 2705 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2706 | "hotkey_tablet_mode"); |
| 2707 | } |
| 2708 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2709 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 2710 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 2711 | struct device_attribute *attr, |
| 2712 | char *buf) |
| 2713 | { |
| 2714 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2715 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 2716 | } |
| 2717 | |
| 2718 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 2719 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 2720 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2721 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2722 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 2723 | struct device_attribute *attr, |
| 2724 | char *buf) |
| 2725 | { |
| 2726 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 2727 | } |
| 2728 | |
| 2729 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 2730 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 2731 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2732 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2733 | { |
| 2734 | if (tp_features.hotkey_mask) |
| 2735 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2736 | "wakeup_reason"); |
| 2737 | } |
| 2738 | |
| 2739 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2740 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 2741 | struct device_attribute *attr, |
| 2742 | char *buf) |
| 2743 | { |
| 2744 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 2745 | } |
| 2746 | |
| 2747 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 2748 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 2749 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 2750 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 2751 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2752 | { |
| 2753 | if (tp_features.hotkey_mask) |
| 2754 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 2755 | "wakeup_hotunplug_complete"); |
| 2756 | } |
| 2757 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2758 | /* --------------------------------------------------------------------- */ |
| 2759 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2760 | static struct attribute *hotkey_attributes[] __initdata = { |
| 2761 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2762 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2763 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2764 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2765 | &dev_attr_hotkey_mask.attr, |
| 2766 | &dev_attr_hotkey_all_mask.attr, |
| 2767 | &dev_attr_hotkey_recommended_mask.attr, |
| 2768 | &dev_attr_hotkey_source_mask.attr, |
| 2769 | &dev_attr_hotkey_poll_freq.attr, |
| 2770 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2771 | }; |
| 2772 | |
| 2773 | static struct attribute *hotkey_mask_attributes[] __initdata = { |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2774 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2775 | #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2776 | &dev_attr_hotkey_mask.attr, |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2777 | &dev_attr_hotkey_all_mask.attr, |
| 2778 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2779 | #endif |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2780 | &dev_attr_hotkey_wakeup_reason.attr, |
| 2781 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2782 | }; |
| 2783 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2784 | /* |
| 2785 | * Sync both the hw and sw blocking state of all switches |
| 2786 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2787 | static void tpacpi_send_radiosw_update(void) |
| 2788 | { |
| 2789 | int wlsw; |
| 2790 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2791 | /* |
| 2792 | * We must sync all rfkill controllers *before* issuing any |
| 2793 | * rfkill input events, or we will race the rfkill core input |
| 2794 | * handler. |
| 2795 | * |
| 2796 | * tpacpi_inputdev_send_mutex works as a syncronization point |
| 2797 | * for the above. |
| 2798 | * |
| 2799 | * We optimize to avoid numerous calls to hotkey_get_wlsw. |
| 2800 | */ |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 2801 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2802 | wlsw = hotkey_get_wlsw(); |
| 2803 | |
| 2804 | /* Sync hw blocking state first if it is hw-blocked */ |
| 2805 | if (wlsw == TPACPI_RFK_RADIO_OFF) |
| 2806 | tpacpi_rfk_update_hwblock_state(true); |
| 2807 | |
| 2808 | /* Sync sw blocking state */ |
| 2809 | tpacpi_rfk_update_swstate_all(); |
| 2810 | |
| 2811 | /* Sync hw blocking state last if it is hw-unblocked */ |
| 2812 | if (wlsw == TPACPI_RFK_RADIO_ON) |
| 2813 | tpacpi_rfk_update_hwblock_state(false); |
| 2814 | |
| 2815 | /* Issue rfkill input event for WLSW switch */ |
| 2816 | if (!(wlsw < 0)) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2817 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 2818 | |
| 2819 | input_report_switch(tpacpi_inputdev, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2820 | SW_RFKILL_ALL, (wlsw > 0)); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2821 | input_sync(tpacpi_inputdev); |
| 2822 | |
| 2823 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 2824 | } |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 2825 | |
| 2826 | /* |
| 2827 | * this can be unconditional, as we will poll state again |
| 2828 | * if userspace uses the notify to read data |
| 2829 | */ |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 2830 | hotkey_radio_sw_notify_change(); |
| 2831 | } |
| 2832 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2833 | static void hotkey_exit(void) |
| 2834 | { |
| 2835 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2836 | mutex_lock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2837 | hotkey_poll_stop_sync(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 2838 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2839 | #endif |
| 2840 | |
| 2841 | if (hotkey_dev_attributes) |
| 2842 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 2843 | |
| 2844 | kfree(hotkey_keycode_map); |
| 2845 | |
| 2846 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2847 | dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2848 | "restoring original hot key mask\n"); |
| 2849 | /* no short-circuit boolean operator below! */ |
| 2850 | if ((hotkey_mask_set(hotkey_orig_mask) | |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 2851 | hotkey_status_set(false)) != 0) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 2852 | printk(TPACPI_ERR |
| 2853 | "failed to restore hot key mask " |
| 2854 | "to BIOS defaults\n"); |
| 2855 | } |
| 2856 | } |
| 2857 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 2858 | static void __init hotkey_unmap(const unsigned int scancode) |
| 2859 | { |
| 2860 | if (hotkey_keycode_map[scancode] != KEY_RESERVED) { |
| 2861 | clear_bit(hotkey_keycode_map[scancode], |
| 2862 | tpacpi_inputdev->keybit); |
| 2863 | hotkey_keycode_map[scancode] = KEY_RESERVED; |
| 2864 | } |
| 2865 | } |
| 2866 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2867 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2868 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2869 | /* Requirements for changing the default keymaps: |
| 2870 | * |
| 2871 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 2872 | * good reasons. Do not change them unless you have deep |
| 2873 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 2874 | * the various ThinkPad models. The driver behaves |
| 2875 | * differently for KEY_RESERVED: such keys have their |
| 2876 | * hot key mask *unset* in mask_recommended, and also |
| 2877 | * in the initial hot key mask programmed into the |
| 2878 | * firmware at driver load time, which means the firm- |
| 2879 | * ware may react very differently if you change them to |
| 2880 | * something else; |
| 2881 | * |
| 2882 | * 2. You must be subscribed to the linux-thinkpad and |
| 2883 | * ibm-acpi-devel mailing lists, and you should read the |
| 2884 | * list archives since 2007 if you want to change the |
| 2885 | * keymaps. This requirement exists so that you will |
| 2886 | * know the past history of problems with the thinkpad- |
| 2887 | * acpi driver keymaps, and also that you will be |
| 2888 | * listening to any bug reports; |
| 2889 | * |
| 2890 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 2891 | * for merging, *ever*. Send them to the linux-acpi |
| 2892 | * mailinglist for comments. Merging is to be done only |
| 2893 | * through acpi-test and the ACPI maintainer. |
| 2894 | * |
| 2895 | * If the above is too much to ask, don't change the keymap. |
| 2896 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 2897 | */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2898 | static u16 ibm_keycode_map[] __initdata = { |
| 2899 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 2900 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
| 2901 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 2902 | 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] | 2903 | |
| 2904 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2905 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 2906 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 2907 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2908 | |
| 2909 | /* brightness: firmware always reacts to them, unless |
| 2910 | * X.org did some tricks in the radeon BIOS scratch |
| 2911 | * registers of *some* models */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2912 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2913 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2914 | |
| 2915 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2916 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2917 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2918 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 2919 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2920 | |
| 2921 | /* Volume: firmware always react to it and reprograms |
| 2922 | * the built-in *extra* mixer. Never map it to control |
| 2923 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2924 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2925 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2926 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2927 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2928 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2929 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2930 | /* (assignments unknown, please report if found) */ |
| 2931 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2932 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2933 | }; |
| 2934 | static u16 lenovo_keycode_map[] __initdata = { |
| 2935 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 2936 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
| 2937 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 2938 | 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] | 2939 | |
| 2940 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2941 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 2942 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 2943 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2944 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 2945 | /* These should be enabled --only-- when ACPI video |
| 2946 | * is disabled (i.e. in "vendor" mode), and are handled |
| 2947 | * in a special way by the init code */ |
| 2948 | KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ |
| 2949 | KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2950 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2951 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2952 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2953 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 2954 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2955 | |
| 2956 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 2957 | * react to it and reprograms the built-in *extra* mixer. |
| 2958 | * Never map it to control another mixer by default. |
| 2959 | * |
| 2960 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 2961 | * these over the regular keyboard, so these are no-ops, |
| 2962 | * but there are still weird bugs re. MUTE, so do not |
| 2963 | * change unless you get test reports from all Lenovo |
| 2964 | * models. May cause the BIOS to interfere with the |
| 2965 | * HDA mixer. |
| 2966 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2967 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2968 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2969 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2970 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2971 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2972 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2973 | /* (assignments unknown, please report if found) */ |
| 2974 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2975 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2976 | }; |
| 2977 | |
| 2978 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) |
| 2979 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) |
| 2980 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) |
| 2981 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2982 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2983 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2984 | int hkeyv; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2985 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 2986 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 2987 | "initializing hotkey subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2988 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2989 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2990 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 2991 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2992 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2993 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2994 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2995 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2996 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2997 | mutex_init(&hotkey_thread_mutex); |
| 2998 | mutex_init(&hotkey_thread_data_mutex); |
| 2999 | #endif |
| 3000 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3001 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3002 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3003 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3004 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3005 | "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3006 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3007 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3008 | if (!tp_features.hotkey) |
| 3009 | return 1; |
| 3010 | |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3011 | tpacpi_disable_brightness_delay(); |
| 3012 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3013 | hotkey_dev_attributes = create_attr_set(13, NULL); |
| 3014 | if (!hotkey_dev_attributes) |
| 3015 | return -ENOMEM; |
| 3016 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 3017 | hotkey_attributes, |
| 3018 | ARRAY_SIZE(hotkey_attributes)); |
| 3019 | if (res) |
| 3020 | goto err_exit; |
| 3021 | |
| 3022 | /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 3023 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 3024 | for HKEY interface version 0x100 */ |
| 3025 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 3026 | if ((hkeyv >> 8) != 1) { |
| 3027 | printk(TPACPI_ERR "unknown version of the " |
| 3028 | "HKEY interface: 0x%x\n", hkeyv); |
| 3029 | printk(TPACPI_ERR "please report this to %s\n", |
| 3030 | TPACPI_MAIL); |
| 3031 | } else { |
| 3032 | /* |
| 3033 | * MHKV 0x100 in A31, R40, R40e, |
| 3034 | * T4x, X31, and later |
| 3035 | */ |
| 3036 | tp_features.hotkey_mask = 1; |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3037 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3038 | "firmware HKEY interface version: 0x%x\n", |
| 3039 | hkeyv); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3040 | } |
| 3041 | } |
| 3042 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3043 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3044 | "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3045 | str_supported(tp_features.hotkey_mask)); |
| 3046 | |
| 3047 | if (tp_features.hotkey_mask) { |
| 3048 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
| 3049 | "MHKA", "qd")) { |
| 3050 | printk(TPACPI_ERR |
| 3051 | "missing MHKA handler, " |
| 3052 | "please report this to %s\n", |
| 3053 | TPACPI_MAIL); |
| 3054 | /* FN+F12, FN+F4, FN+F3 */ |
| 3055 | hotkey_all_mask = 0x080cU; |
| 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | /* hotkey_source_mask *must* be zero for |
| 3060 | * the first hotkey_mask_get */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3061 | if (tp_features.hotkey_mask) { |
| 3062 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3063 | if (res) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3064 | goto err_exit; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3065 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3066 | hotkey_orig_mask = hotkey_mask; |
| 3067 | res = add_many_to_attr_set( |
| 3068 | hotkey_dev_attributes, |
| 3069 | hotkey_mask_attributes, |
| 3070 | ARRAY_SIZE(hotkey_mask_attributes)); |
| 3071 | if (res) |
| 3072 | goto err_exit; |
| 3073 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3074 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3075 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3076 | if (dbg_wlswemul) { |
| 3077 | tp_features.hotkey_wlsw = 1; |
| 3078 | printk(TPACPI_INFO |
| 3079 | "radio switch emulation enabled\n"); |
| 3080 | } else |
| 3081 | #endif |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3082 | /* Not all thinkpads have a hardware radio switch */ |
| 3083 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 3084 | tp_features.hotkey_wlsw = 1; |
| 3085 | printk(TPACPI_INFO |
| 3086 | "radio switch found; radios are %s\n", |
| 3087 | enabled(status, 0)); |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3088 | } |
| 3089 | if (tp_features.hotkey_wlsw) |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3090 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3091 | &dev_attr_hotkey_radio_sw.attr); |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 3092 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3093 | /* For X41t, X60t, X61t Tablets... */ |
| 3094 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 3095 | tp_features.hotkey_tablet = 1; |
| 3096 | printk(TPACPI_INFO |
| 3097 | "possible tablet mode switch found; " |
| 3098 | "ThinkPad in %s mode\n", |
| 3099 | (status & TP_HOTKEY_TABLET_MASK)? |
| 3100 | "tablet" : "laptop"); |
| 3101 | res = add_to_attr_set(hotkey_dev_attributes, |
| 3102 | &dev_attr_hotkey_tablet_mode.attr); |
| 3103 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3104 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3105 | if (!res) |
| 3106 | res = register_attr_set_with_sysfs( |
| 3107 | hotkey_dev_attributes, |
| 3108 | &tpacpi_pdev->dev.kobj); |
| 3109 | if (res) |
| 3110 | goto err_exit; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3111 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3112 | /* Set up key map */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3113 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3114 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 3115 | GFP_KERNEL); |
| 3116 | if (!hotkey_keycode_map) { |
| 3117 | printk(TPACPI_ERR |
| 3118 | "failed to allocate memory for key map\n"); |
| 3119 | res = -ENOMEM; |
| 3120 | goto err_exit; |
| 3121 | } |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3122 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3123 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3124 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3125 | "using Lenovo default hot key map\n"); |
| 3126 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, |
| 3127 | TPACPI_HOTKEY_MAP_SIZE); |
| 3128 | } else { |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3129 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3130 | "using IBM default hot key map\n"); |
| 3131 | memcpy(hotkey_keycode_map, &ibm_keycode_map, |
| 3132 | TPACPI_HOTKEY_MAP_SIZE); |
| 3133 | } |
| 3134 | |
| 3135 | set_bit(EV_KEY, tpacpi_inputdev->evbit); |
| 3136 | set_bit(EV_MSC, tpacpi_inputdev->evbit); |
| 3137 | set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); |
| 3138 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 3139 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 3140 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 3141 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
| 3142 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
| 3143 | set_bit(hotkey_keycode_map[i], |
| 3144 | tpacpi_inputdev->keybit); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3145 | } else { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3146 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 3147 | hotkey_reserved_mask |= 1 << i; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 3148 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3149 | } |
| 3150 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3151 | if (tp_features.hotkey_wlsw) { |
| 3152 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 3153 | set_bit(SW_RFKILL_ALL, tpacpi_inputdev->swbit); |
| 3154 | } |
| 3155 | if (tp_features.hotkey_tablet) { |
| 3156 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 3157 | set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3158 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3159 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3160 | /* Do not issue duplicate brightness change events to |
| 3161 | * userspace */ |
| 3162 | if (!tp_features.bright_acpimode) |
| 3163 | /* update bright_acpimode... */ |
| 3164 | tpacpi_check_std_acpi_brightness_support(); |
| 3165 | |
Henrique de Moraes Holschuh | 8bf3d4c | 2009-05-30 13:25:09 -0300 | [diff] [blame] | 3166 | if (tp_features.bright_acpimode && acpi_video_backlight_support()) { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3167 | printk(TPACPI_INFO |
| 3168 | "This ThinkPad has standard ACPI backlight " |
| 3169 | "brightness control, supported by the ACPI " |
| 3170 | "video driver\n"); |
| 3171 | printk(TPACPI_NOTICE |
| 3172 | "Disabling thinkpad-acpi brightness events " |
| 3173 | "by default...\n"); |
| 3174 | |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3175 | /* Disable brightness up/down on Lenovo thinkpads when |
| 3176 | * ACPI is handling them, otherwise it is plain impossible |
| 3177 | * for userspace to do something even remotely sane */ |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3178 | hotkey_reserved_mask |= |
| 3179 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 3180 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | de4c8cc | 2009-09-12 15:22:18 -0300 | [diff] [blame] | 3181 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 3182 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3183 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3184 | |
Henrique de Moraes Holschuh | 230d8cf25 | 2009-09-12 15:22:17 -0300 | [diff] [blame] | 3185 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 3186 | if (tp_features.hotkey_mask) { |
| 3187 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 3188 | & ~hotkey_all_mask |
| 3189 | & ~hotkey_reserved_mask; |
| 3190 | } else { |
| 3191 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 3192 | & ~hotkey_reserved_mask; |
| 3193 | } |
| 3194 | |
| 3195 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3196 | "hotkey source mask 0x%08x, polling freq %u\n", |
| 3197 | hotkey_source_mask, hotkey_poll_freq); |
| 3198 | #endif |
| 3199 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3200 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3201 | "enabling firmware HKEY event interface...\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3202 | res = hotkey_status_set(true); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3203 | if (res) { |
| 3204 | hotkey_exit(); |
| 3205 | return res; |
| 3206 | } |
| 3207 | res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask) |
| 3208 | & ~hotkey_reserved_mask) |
| 3209 | | hotkey_orig_mask); |
| 3210 | if (res < 0 && res != -ENXIO) { |
| 3211 | hotkey_exit(); |
| 3212 | return res; |
| 3213 | } |
| 3214 | |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3215 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
| 3216 | "legacy ibm/hotkey event reporting over procfs %s\n", |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3217 | (hotkey_report_mode < 2) ? |
| 3218 | "enabled" : "disabled"); |
| 3219 | |
| 3220 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 3221 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 3222 | |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3223 | hotkey_poll_setup_safe(true); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3224 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 3225 | tpacpi_input_send_tabletsw(); |
| 3226 | |
| 3227 | return 0; |
| 3228 | |
| 3229 | err_exit: |
| 3230 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 3231 | hotkey_dev_attributes = NULL; |
| 3232 | |
| 3233 | return (res < 0)? res : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3234 | } |
| 3235 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3236 | static bool hotkey_notify_hotkey(const u32 hkey, |
| 3237 | bool *send_acpi_ev, |
| 3238 | bool *ignore_acpi_ev) |
| 3239 | { |
| 3240 | /* 0x1000-0x1FFF: key presses */ |
| 3241 | unsigned int scancode = hkey & 0xfff; |
| 3242 | *send_acpi_ev = true; |
| 3243 | *ignore_acpi_ev = false; |
| 3244 | |
| 3245 | if (scancode > 0 && scancode < 0x21) { |
| 3246 | scancode--; |
| 3247 | if (!(hotkey_source_mask & (1 << scancode))) { |
| 3248 | tpacpi_input_send_key(scancode); |
| 3249 | *send_acpi_ev = false; |
| 3250 | } else { |
| 3251 | *ignore_acpi_ev = true; |
| 3252 | } |
| 3253 | return true; |
| 3254 | } |
| 3255 | return false; |
| 3256 | } |
| 3257 | |
| 3258 | static bool hotkey_notify_wakeup(const u32 hkey, |
| 3259 | bool *send_acpi_ev, |
| 3260 | bool *ignore_acpi_ev) |
| 3261 | { |
| 3262 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3263 | *send_acpi_ev = true; |
| 3264 | *ignore_acpi_ev = false; |
| 3265 | |
| 3266 | switch (hkey) { |
| 3267 | case 0x2304: /* suspend, undock */ |
| 3268 | case 0x2404: /* hibernation, undock */ |
| 3269 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 3270 | *ignore_acpi_ev = true; |
| 3271 | break; |
| 3272 | |
| 3273 | case 0x2305: /* suspend, bay eject */ |
| 3274 | case 0x2405: /* hibernation, bay eject */ |
| 3275 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 3276 | *ignore_acpi_ev = true; |
| 3277 | break; |
| 3278 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3279 | case 0x2313: /* Battery on critical low level (S3) */ |
| 3280 | case 0x2413: /* Battery on critical low level (S4) */ |
| 3281 | printk(TPACPI_ALERT |
| 3282 | "EMERGENCY WAKEUP: battery almost empty\n"); |
| 3283 | /* how to auto-heal: */ |
| 3284 | /* 2313: woke up from S3, go to S4/S5 */ |
| 3285 | /* 2413: woke up from S4, go to S5 */ |
| 3286 | break; |
| 3287 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3288 | default: |
| 3289 | return false; |
| 3290 | } |
| 3291 | |
| 3292 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
| 3293 | printk(TPACPI_INFO |
| 3294 | "woke up due to a hot-unplug " |
| 3295 | "request...\n"); |
| 3296 | hotkey_wakeup_reason_notify_change(); |
| 3297 | } |
| 3298 | return true; |
| 3299 | } |
| 3300 | |
| 3301 | static bool hotkey_notify_usrevent(const u32 hkey, |
| 3302 | bool *send_acpi_ev, |
| 3303 | bool *ignore_acpi_ev) |
| 3304 | { |
| 3305 | /* 0x5000-0x5FFF: human interface helpers */ |
| 3306 | *send_acpi_ev = true; |
| 3307 | *ignore_acpi_ev = false; |
| 3308 | |
| 3309 | switch (hkey) { |
| 3310 | case 0x5010: /* Lenovo new BIOS: brightness changed */ |
| 3311 | case 0x500b: /* X61t: tablet pen inserted into bay */ |
| 3312 | case 0x500c: /* X61t: tablet pen removed from bay */ |
| 3313 | return true; |
| 3314 | |
| 3315 | case 0x5009: /* X41t-X61t: swivel up (tablet mode) */ |
| 3316 | case 0x500a: /* X41t-X61t: swivel down (normal mode) */ |
| 3317 | tpacpi_input_send_tabletsw(); |
| 3318 | hotkey_tablet_mode_notify_change(); |
| 3319 | *send_acpi_ev = false; |
| 3320 | return true; |
| 3321 | |
| 3322 | case 0x5001: |
| 3323 | case 0x5002: |
| 3324 | /* LID switch events. Do not propagate */ |
| 3325 | *ignore_acpi_ev = true; |
| 3326 | return true; |
| 3327 | |
| 3328 | default: |
| 3329 | return false; |
| 3330 | } |
| 3331 | } |
| 3332 | |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3333 | static bool hotkey_notify_thermal(const u32 hkey, |
| 3334 | bool *send_acpi_ev, |
| 3335 | bool *ignore_acpi_ev) |
| 3336 | { |
| 3337 | /* 0x6000-0x6FFF: thermal alarms */ |
| 3338 | *send_acpi_ev = true; |
| 3339 | *ignore_acpi_ev = false; |
| 3340 | |
| 3341 | switch (hkey) { |
| 3342 | case 0x6011: |
| 3343 | printk(TPACPI_CRIT |
| 3344 | "THERMAL ALARM: battery is too hot!\n"); |
| 3345 | /* recommended action: warn user through gui */ |
| 3346 | return true; |
| 3347 | case 0x6012: |
| 3348 | printk(TPACPI_ALERT |
| 3349 | "THERMAL EMERGENCY: battery is extremely hot!\n"); |
| 3350 | /* recommended action: immediate sleep/hibernate */ |
| 3351 | return true; |
| 3352 | case 0x6021: |
| 3353 | printk(TPACPI_CRIT |
| 3354 | "THERMAL ALARM: " |
| 3355 | "a sensor reports something is too hot!\n"); |
| 3356 | /* recommended action: warn user through gui, that */ |
| 3357 | /* some internal component is too hot */ |
| 3358 | return true; |
| 3359 | case 0x6022: |
| 3360 | printk(TPACPI_ALERT |
| 3361 | "THERMAL EMERGENCY: " |
| 3362 | "a sensor reports something is extremely hot!\n"); |
| 3363 | /* recommended action: immediate sleep/hibernate */ |
| 3364 | return true; |
Henrique de Moraes Holschuh | 54926ce | 2009-01-11 03:01:09 -0200 | [diff] [blame] | 3365 | case 0x6030: |
| 3366 | printk(TPACPI_INFO |
| 3367 | "EC reports that Thermal Table has changed\n"); |
| 3368 | /* recommended action: do nothing, we don't have |
| 3369 | * Lenovo ATM information */ |
| 3370 | return true; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3371 | default: |
| 3372 | printk(TPACPI_ALERT |
| 3373 | "THERMAL ALERT: unknown thermal alarm received\n"); |
| 3374 | return false; |
| 3375 | } |
| 3376 | } |
| 3377 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3378 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 3379 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3380 | u32 hkey; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3381 | bool send_acpi_ev; |
| 3382 | bool ignore_acpi_ev; |
| 3383 | bool known_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3384 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3385 | if (event != 0x80) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3386 | printk(TPACPI_ERR |
| 3387 | "unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3388 | /* 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] | 3389 | acpi_bus_generate_netlink_event( |
| 3390 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3391 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3392 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3393 | return; |
| 3394 | } |
| 3395 | |
| 3396 | while (1) { |
| 3397 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3398 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3399 | return; |
| 3400 | } |
| 3401 | |
| 3402 | if (hkey == 0) { |
| 3403 | /* queue empty */ |
| 3404 | return; |
| 3405 | } |
| 3406 | |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3407 | send_acpi_ev = true; |
| 3408 | ignore_acpi_ev = false; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3409 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3410 | switch (hkey >> 12) { |
| 3411 | case 1: |
| 3412 | /* 0x1000-0x1FFF: key presses */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3413 | known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev, |
| 3414 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3415 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3416 | case 2: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3417 | /* 0x2000-0x2FFF: Wakeup reason */ |
| 3418 | known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev, |
| 3419 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3420 | break; |
| 3421 | case 3: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3422 | /* 0x3000-0x3FFF: bay-related wakeups */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3423 | if (hkey == 0x3003) { |
| 3424 | hotkey_autosleep_ack = 1; |
| 3425 | printk(TPACPI_INFO |
| 3426 | "bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3427 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3428 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3429 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3430 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3431 | } |
| 3432 | break; |
| 3433 | case 4: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3434 | /* 0x4000-0x4FFF: dock-related wakeups */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3435 | if (hkey == 0x4003) { |
| 3436 | hotkey_autosleep_ack = 1; |
| 3437 | printk(TPACPI_INFO |
| 3438 | "undocked\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3439 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3440 | known_ev = true; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3441 | } else { |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3442 | known_ev = false; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3443 | } |
| 3444 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3445 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 3446 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3447 | known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev, |
| 3448 | &ignore_acpi_ev); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3449 | break; |
Henrique de Moraes Holschuh | 106b4e6 | 2009-01-11 03:01:06 -0200 | [diff] [blame] | 3450 | case 6: |
| 3451 | /* 0x6000-0x6FFF: thermal alarms */ |
| 3452 | known_ev = hotkey_notify_thermal(hkey, &send_acpi_ev, |
| 3453 | &ignore_acpi_ev); |
| 3454 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3455 | case 7: |
| 3456 | /* 0x7000-0x7FFF: misc */ |
| 3457 | if (tp_features.hotkey_wlsw && hkey == 0x7000) { |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3458 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3459 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3460 | known_ev = true; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3461 | break; |
| 3462 | } |
| 3463 | /* fallthrough to default */ |
| 3464 | default: |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3465 | known_ev = false; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 3466 | } |
Henrique de Moraes Holschuh | 3827e7a | 2009-01-11 03:01:05 -0200 | [diff] [blame] | 3467 | if (!known_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3468 | printk(TPACPI_NOTICE |
| 3469 | "unhandled HKEY event 0x%04x\n", hkey); |
Henrique de Moraes Holschuh | cb42935 | 2009-01-11 03:01:07 -0200 | [diff] [blame] | 3470 | printk(TPACPI_NOTICE |
| 3471 | "please report the conditions when this " |
| 3472 | "event happened to %s\n", TPACPI_MAIL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 3473 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3474 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3475 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3476 | if (!ignore_acpi_ev && |
| 3477 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 3478 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 3479 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3480 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 3481 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3482 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 3483 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3484 | acpi_bus_generate_netlink_event( |
| 3485 | ibm->acpi->device->pnp.device_class, |
Kay Sievers | e0b36fc | 2009-01-11 03:00:59 -0200 | [diff] [blame] | 3486 | dev_name(&ibm->acpi->device->dev), |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3487 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 3488 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3489 | } |
| 3490 | } |
| 3491 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3492 | static void hotkey_suspend(pm_message_t state) |
| 3493 | { |
| 3494 | /* Do these on suspend, we get the events on early resume! */ |
| 3495 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 3496 | hotkey_autosleep_ack = 0; |
| 3497 | } |
| 3498 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3499 | static void hotkey_resume(void) |
| 3500 | { |
Henrique de Moraes Holschuh | d64c81c | 2008-10-18 14:23:55 -0300 | [diff] [blame] | 3501 | tpacpi_disable_brightness_delay(); |
| 3502 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3503 | if (hotkey_mask_get()) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3504 | printk(TPACPI_ERR |
| 3505 | "error while trying to read hot key mask " |
| 3506 | "from firmware\n"); |
Henrique de Moraes Holschuh | 733e27c | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3507 | tpacpi_send_radiosw_update(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 3508 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 3509 | hotkey_wakeup_reason_notify_change(); |
| 3510 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | db25f16 | 2009-09-12 15:22:14 -0300 | [diff] [blame] | 3511 | hotkey_poll_setup_safe(false); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3512 | } |
| 3513 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 3514 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3515 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3517 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | int len = 0; |
| 3519 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3520 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3521 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3522 | return len; |
| 3523 | } |
| 3524 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3525 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3526 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3527 | res = hotkey_status_get(&status); |
| 3528 | if (!res) |
| 3529 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3530 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 3531 | if (res) |
| 3532 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | |
| 3534 | 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] | 3535 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3536 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | len += sprintf(p + len, |
| 3538 | "commands:\tenable, disable, reset, <mask>\n"); |
| 3539 | } else { |
| 3540 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 3541 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 3542 | } |
| 3543 | |
| 3544 | return len; |
| 3545 | } |
| 3546 | |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3547 | static void hotkey_enabledisable_warn(bool enable) |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3548 | { |
| 3549 | tpacpi_log_usertask("procfs hotkey enable/disable"); |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3550 | if (!WARN((tpacpi_lifecycle == TPACPI_LIFE_RUNNING || !enable), |
| 3551 | TPACPI_WARN |
| 3552 | "hotkey enable/disable functionality has been " |
| 3553 | "removed from the driver. Hotkeys are always " |
| 3554 | "enabled\n")) |
| 3555 | printk(TPACPI_ERR |
| 3556 | "Please remove the hotkey=enable module " |
| 3557 | "parameter, it is deprecated. Hotkeys are always " |
| 3558 | "enabled\n"); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3559 | } |
| 3560 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3561 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | { |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3563 | int res; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 3564 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3567 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | return -ENODEV; |
| 3569 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 3570 | if (mutex_lock_killable(&hotkey_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 3571 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3572 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3573 | mask = hotkey_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3574 | |
| 3575 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | while ((cmd = next_cmd(&buf))) { |
| 3577 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3578 | hotkey_enabledisable_warn(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | 406e988 | 2009-04-14 02:44:10 +0000 | [diff] [blame] | 3580 | hotkey_enabledisable_warn(0); |
Henrique de Moraes Holschuh | 2586d56 | 2009-04-04 04:25:48 +0000 | [diff] [blame] | 3581 | res = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | } else if (strlencmp(cmd, "reset") == 0) { |
Henrique de Moraes Holschuh | 20c9aa4 | 2009-09-12 15:22:16 -0300 | [diff] [blame] | 3583 | mask = (hotkey_all_mask | hotkey_source_mask) |
| 3584 | & ~hotkey_reserved_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 3586 | /* mask set */ |
| 3587 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 3588 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3589 | } else { |
| 3590 | res = -EINVAL; |
| 3591 | goto errexit; |
| 3592 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | } |
Henrique de Moraes Holschuh | 56e2c20 | 2009-04-04 04:25:51 +0000 | [diff] [blame] | 3594 | |
| 3595 | if (!res) |
| 3596 | tpacpi_disclose_usertask("procfs hotkey", |
| 3597 | "set mask to 0x%08x\n", mask); |
| 3598 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 3599 | if (!res && mask != hotkey_mask) |
| 3600 | res = hotkey_mask_set(mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3602 | errexit: |
| 3603 | mutex_unlock(&hotkey_mutex); |
| 3604 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3605 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3607 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3608 | {TPACPI_ACPI_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3609 | {"", 0}, |
| 3610 | }; |
| 3611 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3612 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3613 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3614 | .notify = hotkey_notify, |
| 3615 | .handle = &hkey_handle, |
| 3616 | .type = ACPI_DEVICE_NOTIFY, |
| 3617 | }; |
| 3618 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3619 | static struct ibm_struct hotkey_driver_data = { |
| 3620 | .name = "hotkey", |
| 3621 | .read = hotkey_read, |
| 3622 | .write = hotkey_write, |
| 3623 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 3624 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 3625 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3626 | .acpi = &ibm_hotkey_acpidriver, |
| 3627 | }; |
| 3628 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3629 | /************************************************************************* |
| 3630 | * Bluetooth subdriver |
| 3631 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3633 | enum { |
| 3634 | /* ACPI GBDC/SBDC bits */ |
| 3635 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 3636 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3637 | TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: |
| 3638 | off / last state */ |
| 3639 | }; |
| 3640 | |
| 3641 | enum { |
| 3642 | /* ACPI \BLTH commands */ |
| 3643 | TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */ |
| 3644 | TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */ |
| 3645 | TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */ |
| 3646 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */ |
| 3647 | 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] | 3648 | }; |
| 3649 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3650 | #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" |
| 3651 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3652 | static void bluetooth_suspend(pm_message_t state) |
| 3653 | { |
| 3654 | /* Try to make sure radio will resume powered off */ |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3655 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 3656 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME)) |
| 3657 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3658 | "bluetooth power down on resume request failed\n"); |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3659 | } |
| 3660 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3661 | static int bluetooth_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3662 | { |
| 3663 | int status; |
| 3664 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3665 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3666 | if (dbg_bluetoothemul) |
| 3667 | return (tpacpi_bluetooth_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3668 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3669 | #endif |
| 3670 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3671 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 3672 | return -EIO; |
| 3673 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3674 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3675 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3676 | } |
| 3677 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3678 | static int bluetooth_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3679 | { |
| 3680 | int status; |
| 3681 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3682 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3683 | "will attempt to %s bluetooth\n", |
| 3684 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3685 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3686 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3687 | if (dbg_bluetoothemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3688 | tpacpi_bluetooth_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3689 | return 0; |
| 3690 | } |
| 3691 | #endif |
| 3692 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3693 | /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */ |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3694 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3695 | status = TP_ACPI_BLUETOOTH_RADIOSSW; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3696 | else |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3697 | status = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3698 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3699 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 3700 | return -EIO; |
| 3701 | |
| 3702 | return 0; |
| 3703 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3704 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3705 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 3706 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 3707 | struct device_attribute *attr, |
| 3708 | char *buf) |
| 3709 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3710 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3711 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3712 | } |
| 3713 | |
| 3714 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 3715 | struct device_attribute *attr, |
| 3716 | const char *buf, size_t count) |
| 3717 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3718 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3719 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 3723 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3724 | bluetooth_enable_show, bluetooth_enable_store); |
| 3725 | |
| 3726 | /* --------------------------------------------------------------------- */ |
| 3727 | |
| 3728 | static struct attribute *bluetooth_attributes[] = { |
| 3729 | &dev_attr_bluetooth_enable.attr, |
| 3730 | NULL |
| 3731 | }; |
| 3732 | |
| 3733 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3734 | .attrs = bluetooth_attributes, |
| 3735 | }; |
| 3736 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3737 | static const struct tpacpi_rfk_ops bluetooth_tprfk_ops = { |
| 3738 | .get_status = bluetooth_get_status, |
| 3739 | .set_status = bluetooth_set_status, |
| 3740 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3741 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3742 | static void bluetooth_shutdown(void) |
| 3743 | { |
| 3744 | /* Order firmware to save current state to NVRAM */ |
| 3745 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", |
| 3746 | TP_ACPI_BLTH_SAVE_STATE)) |
| 3747 | printk(TPACPI_NOTICE |
| 3748 | "failed to save bluetooth state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3749 | else |
| 3750 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3751 | "bluestooth state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3752 | } |
| 3753 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3754 | static void bluetooth_exit(void) |
| 3755 | { |
| 3756 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 3757 | &bluetooth_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3758 | |
| 3759 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
| 3760 | |
| 3761 | bluetooth_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3762 | } |
| 3763 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3764 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3766 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3767 | int status = 0; |
| 3768 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3769 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3770 | "initializing bluetooth subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3771 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3772 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3773 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3774 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 3775 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3776 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3777 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3779 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3780 | "bluetooth is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3781 | str_supported(tp_features.bluetooth), |
| 3782 | status); |
| 3783 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3784 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3785 | if (dbg_bluetoothemul) { |
| 3786 | tp_features.bluetooth = 1; |
| 3787 | printk(TPACPI_INFO |
| 3788 | "bluetooth switch emulation enabled\n"); |
| 3789 | } else |
| 3790 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3791 | if (tp_features.bluetooth && |
| 3792 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 3793 | /* no bluetooth hardware present in system */ |
| 3794 | tp_features.bluetooth = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3795 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3796 | "bluetooth hardware not installed\n"); |
| 3797 | } |
| 3798 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3799 | if (!tp_features.bluetooth) |
| 3800 | return 1; |
| 3801 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3802 | res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, |
| 3803 | &bluetooth_tprfk_ops, |
| 3804 | RFKILL_TYPE_BLUETOOTH, |
| 3805 | TPACPI_RFK_BLUETOOTH_SW_NAME, |
| 3806 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3807 | if (res) |
| 3808 | return res; |
| 3809 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3810 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 3811 | &bluetooth_attr_group); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3812 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3813 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3814 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3815 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3816 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3817 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | } |
| 3819 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3820 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3821 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3823 | return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | } |
| 3825 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3826 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3828 | return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3831 | static struct ibm_struct bluetooth_driver_data = { |
| 3832 | .name = "bluetooth", |
| 3833 | .read = bluetooth_read, |
| 3834 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3835 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3836 | .suspend = bluetooth_suspend, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3837 | .shutdown = bluetooth_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3838 | }; |
| 3839 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3840 | /************************************************************************* |
| 3841 | * Wan subdriver |
| 3842 | */ |
| 3843 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3844 | enum { |
| 3845 | /* ACPI GWAN/SWAN bits */ |
| 3846 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 3847 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3848 | TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: |
| 3849 | off / last state */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3850 | }; |
| 3851 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3852 | #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" |
| 3853 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3854 | static void wan_suspend(pm_message_t state) |
| 3855 | { |
| 3856 | /* Try to make sure radio will resume powered off */ |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3857 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "qvd", |
| 3858 | TP_ACPI_WGSV_PWR_OFF_ON_RESUME)) |
| 3859 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3860 | "WWAN power down on resume request failed\n"); |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3861 | } |
| 3862 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3863 | static int wan_get_status(void) |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3864 | { |
| 3865 | int status; |
| 3866 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3867 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3868 | if (dbg_wwanemul) |
| 3869 | return (tpacpi_wwan_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3870 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3871 | #endif |
| 3872 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3873 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 3874 | return -EIO; |
| 3875 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3876 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3877 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3878 | } |
| 3879 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3880 | static int wan_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3881 | { |
| 3882 | int status; |
| 3883 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3884 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3885 | "will attempt to %s wwan\n", |
| 3886 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3887 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3888 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3889 | if (dbg_wwanemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3890 | tpacpi_wwan_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3891 | return 0; |
| 3892 | } |
| 3893 | #endif |
| 3894 | |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3895 | /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */ |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3896 | if (state == TPACPI_RFK_RADIO_ON) |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3897 | status = TP_ACPI_WANCARD_RADIOSSW; |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3898 | else |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 3899 | status = 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3900 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3901 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 3902 | return -EIO; |
| 3903 | |
| 3904 | return 0; |
| 3905 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3906 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3907 | /* sysfs wan enable ---------------------------------------------------- */ |
| 3908 | static ssize_t wan_enable_show(struct device *dev, |
| 3909 | struct device_attribute *attr, |
| 3910 | char *buf) |
| 3911 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3912 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID, |
| 3913 | attr, buf); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | static ssize_t wan_enable_store(struct device *dev, |
| 3917 | struct device_attribute *attr, |
| 3918 | const char *buf, size_t count) |
| 3919 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3920 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID, |
| 3921 | attr, buf, count); |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3922 | } |
| 3923 | |
| 3924 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 3925 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3926 | wan_enable_show, wan_enable_store); |
| 3927 | |
| 3928 | /* --------------------------------------------------------------------- */ |
| 3929 | |
| 3930 | static struct attribute *wan_attributes[] = { |
| 3931 | &dev_attr_wan_enable.attr, |
| 3932 | NULL |
| 3933 | }; |
| 3934 | |
| 3935 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3936 | .attrs = wan_attributes, |
| 3937 | }; |
| 3938 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3939 | static const struct tpacpi_rfk_ops wan_tprfk_ops = { |
| 3940 | .get_status = wan_get_status, |
| 3941 | .set_status = wan_set_status, |
| 3942 | }; |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3943 | |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3944 | static void wan_shutdown(void) |
| 3945 | { |
| 3946 | /* Order firmware to save current state to NVRAM */ |
| 3947 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd", |
| 3948 | TP_ACPI_WGSV_SAVE_STATE)) |
| 3949 | printk(TPACPI_NOTICE |
| 3950 | "failed to save WWAN state to NVRAM\n"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3951 | else |
| 3952 | vdbg_printk(TPACPI_DBG_RFKILL, |
| 3953 | "WWAN state saved to NVRAM\n"); |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 3954 | } |
| 3955 | |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3956 | static void wan_exit(void) |
| 3957 | { |
| 3958 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 3959 | &wan_attr_group); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 3960 | |
| 3961 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
| 3962 | |
| 3963 | wan_shutdown(); |
Henrique de Moraes Holschuh | 07431ec | 2008-07-21 09:15:50 -0300 | [diff] [blame] | 3964 | } |
| 3965 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3966 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3967 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 3968 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3969 | int status = 0; |
| 3970 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3971 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3972 | "initializing wan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3973 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3974 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3975 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3976 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3977 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 3978 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3979 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 3980 | "wan is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 3981 | str_supported(tp_features.wan), |
| 3982 | status); |
| 3983 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 3984 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 3985 | if (dbg_wwanemul) { |
| 3986 | tp_features.wan = 1; |
| 3987 | printk(TPACPI_INFO |
| 3988 | "wwan switch emulation enabled\n"); |
| 3989 | } else |
| 3990 | #endif |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3991 | if (tp_features.wan && |
| 3992 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 3993 | /* no wan hardware present in system */ |
| 3994 | tp_features.wan = 0; |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 3995 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
Henrique de Moraes Holschuh | 3a87208 | 2008-07-21 09:15:49 -0300 | [diff] [blame] | 3996 | "wan hardware not installed\n"); |
| 3997 | } |
| 3998 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 3999 | if (!tp_features.wan) |
| 4000 | return 1; |
| 4001 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4002 | res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, |
| 4003 | &wan_tprfk_ops, |
| 4004 | RFKILL_TYPE_WWAN, |
| 4005 | TPACPI_RFK_WWAN_SW_NAME, |
| 4006 | true); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4007 | if (res) |
| 4008 | return res; |
| 4009 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4010 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 4011 | &wan_attr_group); |
| 4012 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4013 | if (res) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4014 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4015 | return res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 4016 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4017 | |
Henrique de Moraes Holschuh | 0e74dc2 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 4018 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4019 | } |
| 4020 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4021 | /* procfs -------------------------------------------------------------- */ |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4022 | static int wan_read(char *p) |
| 4023 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4024 | return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID, p); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4025 | } |
| 4026 | |
| 4027 | static int wan_write(char *buf) |
| 4028 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4029 | return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID, buf); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 4030 | } |
| 4031 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4032 | static struct ibm_struct wan_driver_data = { |
| 4033 | .name = "wan", |
| 4034 | .read = wan_read, |
| 4035 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 4036 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 153f822 | 2009-01-11 03:01:01 -0200 | [diff] [blame] | 4037 | .suspend = wan_suspend, |
Henrique de Moraes Holschuh | 90d9d3c | 2009-01-11 03:01:02 -0200 | [diff] [blame] | 4038 | .shutdown = wan_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4039 | }; |
| 4040 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4041 | /************************************************************************* |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4042 | * UWB subdriver |
| 4043 | */ |
| 4044 | |
| 4045 | enum { |
| 4046 | /* ACPI GUWB/SUWB bits */ |
| 4047 | TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */ |
| 4048 | TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */ |
| 4049 | }; |
| 4050 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4051 | #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" |
| 4052 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4053 | static int uwb_get_status(void) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4054 | { |
| 4055 | int status; |
| 4056 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4057 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4058 | if (dbg_uwbemul) |
| 4059 | return (tpacpi_uwb_emulstate) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4060 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4061 | #endif |
| 4062 | |
| 4063 | if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) |
| 4064 | return -EIO; |
| 4065 | |
| 4066 | return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4067 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4068 | } |
| 4069 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4070 | static int uwb_set_status(enum tpacpi_rfkill_state state) |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4071 | { |
| 4072 | int status; |
| 4073 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4074 | vdbg_printk(TPACPI_DBG_RFKILL, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4075 | "will attempt to %s UWB\n", |
| 4076 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4077 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4078 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4079 | if (dbg_uwbemul) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4080 | tpacpi_uwb_emulstate = (state == TPACPI_RFK_RADIO_ON); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4081 | return 0; |
| 4082 | } |
| 4083 | #endif |
| 4084 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4085 | if (state == TPACPI_RFK_RADIO_ON) |
| 4086 | status = TP_ACPI_UWB_RADIOSSW; |
| 4087 | else |
| 4088 | status = 0; |
| 4089 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4090 | if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) |
| 4091 | return -EIO; |
| 4092 | |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4093 | return 0; |
| 4094 | } |
| 4095 | |
| 4096 | /* --------------------------------------------------------------------- */ |
| 4097 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4098 | static const struct tpacpi_rfk_ops uwb_tprfk_ops = { |
| 4099 | .get_status = uwb_get_status, |
| 4100 | .set_status = uwb_set_status, |
| 4101 | }; |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4102 | |
| 4103 | static void uwb_exit(void) |
| 4104 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4105 | tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | static int __init uwb_init(struct ibm_init_struct *iibm) |
| 4109 | { |
| 4110 | int res; |
| 4111 | int status = 0; |
| 4112 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4113 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4114 | "initializing uwb subdriver\n"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4115 | |
| 4116 | TPACPI_ACPIHANDLE_INIT(hkey); |
| 4117 | |
| 4118 | tp_features.uwb = hkey_handle && |
| 4119 | acpi_evalf(hkey_handle, &status, "GUWB", "qd"); |
| 4120 | |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4121 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
| 4122 | "uwb is %s, status 0x%02x\n", |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4123 | str_supported(tp_features.uwb), |
| 4124 | status); |
| 4125 | |
| 4126 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 4127 | if (dbg_uwbemul) { |
| 4128 | tp_features.uwb = 1; |
| 4129 | printk(TPACPI_INFO |
| 4130 | "uwb switch emulation enabled\n"); |
| 4131 | } else |
| 4132 | #endif |
| 4133 | if (tp_features.uwb && |
| 4134 | !(status & TP_ACPI_UWB_HWPRESENT)) { |
| 4135 | /* no uwb hardware present in system */ |
| 4136 | tp_features.uwb = 0; |
| 4137 | dbg_printk(TPACPI_DBG_INIT, |
| 4138 | "uwb hardware not installed\n"); |
| 4139 | } |
| 4140 | |
| 4141 | if (!tp_features.uwb) |
| 4142 | return 1; |
| 4143 | |
| 4144 | res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4145 | &uwb_tprfk_ops, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4146 | RFKILL_TYPE_UWB, |
Henrique de Moraes Holschuh | bee4cd9 | 2009-04-04 04:25:50 +0000 | [diff] [blame] | 4147 | TPACPI_RFK_UWB_SW_NAME, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 4148 | false); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 4149 | return res; |
| 4150 | } |
| 4151 | |
| 4152 | static struct ibm_struct uwb_driver_data = { |
| 4153 | .name = "uwb", |
| 4154 | .exit = uwb_exit, |
| 4155 | .flags.experimental = 1, |
| 4156 | }; |
| 4157 | |
| 4158 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4159 | * Video subdriver |
| 4160 | */ |
| 4161 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4162 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 4163 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4164 | enum video_access_mode { |
| 4165 | TPACPI_VIDEO_NONE = 0, |
| 4166 | TPACPI_VIDEO_570, /* 570 */ |
| 4167 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 4168 | TPACPI_VIDEO_NEW, /* all others */ |
| 4169 | }; |
| 4170 | |
| 4171 | enum { /* video status flags, based on VIDEO_570 */ |
| 4172 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 4173 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 4174 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 4175 | }; |
| 4176 | |
| 4177 | enum { /* TPACPI_VIDEO_570 constants */ |
| 4178 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 4179 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 4180 | * video_status_flags */ |
| 4181 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 4182 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 4183 | }; |
| 4184 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4185 | static enum video_access_mode video_supported; |
| 4186 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4187 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4188 | static int video_autosw_get(void); |
| 4189 | static int video_autosw_set(int enable); |
| 4190 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4191 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4192 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4193 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4195 | int ivga; |
| 4196 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4197 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 4198 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4199 | TPACPI_ACPIHANDLE_INIT(vid); |
| 4200 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4201 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4202 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 4203 | /* G41, assume IVGA doesn't change */ |
| 4204 | vid_handle = vid2_handle; |
| 4205 | |
| 4206 | if (!vid_handle) |
| 4207 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4208 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4209 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 4210 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4211 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4212 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 4213 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4214 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4215 | else |
| 4216 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4217 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4219 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 4220 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 4221 | video_supported); |
| 4222 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4223 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | } |
| 4225 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4226 | static void video_exit(void) |
| 4227 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4228 | dbg_printk(TPACPI_DBG_EXIT, |
| 4229 | "restoring original video autoswitch mode\n"); |
| 4230 | if (video_autosw_set(video_orig_autosw)) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4231 | printk(TPACPI_ERR "error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4232 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4233 | } |
| 4234 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4235 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | { |
| 4237 | int status = 0; |
| 4238 | int i; |
| 4239 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4240 | switch (video_supported) { |
| 4241 | case TPACPI_VIDEO_570: |
| 4242 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 4243 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 4244 | return -EIO; |
| 4245 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 4246 | break; |
| 4247 | case TPACPI_VIDEO_770: |
| 4248 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4249 | return -EIO; |
| 4250 | if (i) |
| 4251 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4252 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4253 | return -EIO; |
| 4254 | if (i) |
| 4255 | status |= TP_ACPI_VIDEO_S_CRT; |
| 4256 | break; |
| 4257 | case TPACPI_VIDEO_NEW: |
| 4258 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 4259 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 4260 | return -EIO; |
| 4261 | if (i) |
| 4262 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4263 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4264 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 4265 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 4266 | return -EIO; |
| 4267 | if (i) |
| 4268 | status |= TP_ACPI_VIDEO_S_LCD; |
| 4269 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 4270 | return -EIO; |
| 4271 | if (i) |
| 4272 | status |= TP_ACPI_VIDEO_S_DVI; |
| 4273 | break; |
| 4274 | default: |
| 4275 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | |
| 4278 | return status; |
| 4279 | } |
| 4280 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4281 | static int video_outputsw_set(int status) |
| 4282 | { |
| 4283 | int autosw; |
| 4284 | int res = 0; |
| 4285 | |
| 4286 | switch (video_supported) { |
| 4287 | case TPACPI_VIDEO_570: |
| 4288 | res = acpi_evalf(NULL, NULL, |
| 4289 | "\\_SB.PHS2", "vdd", |
| 4290 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 4291 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 4292 | break; |
| 4293 | case TPACPI_VIDEO_770: |
| 4294 | autosw = video_autosw_get(); |
| 4295 | if (autosw < 0) |
| 4296 | return autosw; |
| 4297 | |
| 4298 | res = video_autosw_set(1); |
| 4299 | if (res) |
| 4300 | return res; |
| 4301 | res = acpi_evalf(vid_handle, NULL, |
| 4302 | "ASWT", "vdd", status * 0x100, 0); |
| 4303 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4304 | printk(TPACPI_ERR |
| 4305 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4306 | return -EIO; |
| 4307 | } |
| 4308 | break; |
| 4309 | case TPACPI_VIDEO_NEW: |
| 4310 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4311 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4312 | break; |
| 4313 | default: |
| 4314 | return -ENOSYS; |
| 4315 | } |
| 4316 | |
| 4317 | return (res)? 0 : -EIO; |
| 4318 | } |
| 4319 | |
| 4320 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4322 | int autosw = 0; |
| 4323 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4324 | switch (video_supported) { |
| 4325 | case TPACPI_VIDEO_570: |
| 4326 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 4327 | return -EIO; |
| 4328 | break; |
| 4329 | case TPACPI_VIDEO_770: |
| 4330 | case TPACPI_VIDEO_NEW: |
| 4331 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 4332 | return -EIO; |
| 4333 | break; |
| 4334 | default: |
| 4335 | return -ENOSYS; |
| 4336 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4337 | |
| 4338 | return autosw & 1; |
| 4339 | } |
| 4340 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4341 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4342 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4343 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4344 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4345 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4346 | } |
| 4347 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4348 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4349 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4350 | int autosw = video_autosw_get(); |
| 4351 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4352 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4353 | if (autosw < 0) |
| 4354 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4355 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4356 | switch (video_supported) { |
| 4357 | case TPACPI_VIDEO_570: |
| 4358 | res = video_autosw_set(1); |
| 4359 | if (res) |
| 4360 | return res; |
| 4361 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 4362 | break; |
| 4363 | case TPACPI_VIDEO_770: |
| 4364 | case TPACPI_VIDEO_NEW: |
| 4365 | res = video_autosw_set(1); |
| 4366 | if (res) |
| 4367 | return res; |
| 4368 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 4369 | break; |
| 4370 | default: |
| 4371 | return -ENOSYS; |
| 4372 | } |
| 4373 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4374 | printk(TPACPI_ERR |
| 4375 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4376 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4377 | } |
| 4378 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4379 | return (res)? 0 : -EIO; |
| 4380 | } |
| 4381 | |
| 4382 | static int video_expand_toggle(void) |
| 4383 | { |
| 4384 | switch (video_supported) { |
| 4385 | case TPACPI_VIDEO_570: |
| 4386 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 4387 | 0 : -EIO; |
| 4388 | case TPACPI_VIDEO_770: |
| 4389 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 4390 | 0 : -EIO; |
| 4391 | case TPACPI_VIDEO_NEW: |
| 4392 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 4393 | 0 : -EIO; |
| 4394 | default: |
| 4395 | return -ENOSYS; |
| 4396 | } |
| 4397 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4398 | } |
| 4399 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4400 | static int video_read(char *p) |
| 4401 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4402 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4403 | int len = 0; |
| 4404 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4405 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4406 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4407 | return len; |
| 4408 | } |
| 4409 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4410 | status = video_outputsw_get(); |
| 4411 | if (status < 0) |
| 4412 | return status; |
| 4413 | |
| 4414 | autosw = video_autosw_get(); |
| 4415 | if (autosw < 0) |
| 4416 | return autosw; |
| 4417 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4418 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 4419 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 4420 | 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] | 4421 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4422 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 4423 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 4424 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 4425 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4426 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4427 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 4428 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 4429 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 4430 | |
| 4431 | return len; |
| 4432 | } |
| 4433 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4434 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | { |
| 4436 | char *cmd; |
| 4437 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4438 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4440 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4441 | return -ENODEV; |
| 4442 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4443 | enable = 0; |
| 4444 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | |
| 4446 | while ((cmd = next_cmd(&buf))) { |
| 4447 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4448 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4450 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4452 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4454 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4455 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4456 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4457 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4458 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4459 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4460 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4462 | res = video_autosw_set(1); |
| 4463 | if (res) |
| 4464 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4466 | res = video_autosw_set(0); |
| 4467 | if (res) |
| 4468 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4470 | res = video_outputsw_cycle(); |
| 4471 | if (res) |
| 4472 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4474 | res = video_expand_toggle(); |
| 4475 | if (res) |
| 4476 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | } else |
| 4478 | return -EINVAL; |
| 4479 | } |
| 4480 | |
| 4481 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 4482 | status = video_outputsw_get(); |
| 4483 | if (status < 0) |
| 4484 | return status; |
| 4485 | res = video_outputsw_set((status & ~disable) | enable); |
| 4486 | if (res) |
| 4487 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | return 0; |
| 4491 | } |
| 4492 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4493 | static struct ibm_struct video_driver_data = { |
| 4494 | .name = "video", |
| 4495 | .read = video_read, |
| 4496 | .write = video_write, |
| 4497 | .exit = video_exit, |
| 4498 | }; |
| 4499 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 4500 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 4501 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4502 | /************************************************************************* |
| 4503 | * Light (thinklight) subdriver |
| 4504 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4506 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 4507 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4508 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4509 | static int light_get_status(void) |
| 4510 | { |
| 4511 | int status = 0; |
| 4512 | |
| 4513 | if (tp_features.light_status) { |
| 4514 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 4515 | return -EIO; |
| 4516 | return (!!status); |
| 4517 | } |
| 4518 | |
| 4519 | return -ENXIO; |
| 4520 | } |
| 4521 | |
| 4522 | static int light_set_status(int status) |
| 4523 | { |
| 4524 | int rc; |
| 4525 | |
| 4526 | if (tp_features.light) { |
| 4527 | if (cmos_handle) { |
| 4528 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", |
| 4529 | (status)? |
| 4530 | TP_CMOS_THINKLIGHT_ON : |
| 4531 | TP_CMOS_THINKLIGHT_OFF); |
| 4532 | } else { |
| 4533 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", |
| 4534 | (status)? 1 : 0); |
| 4535 | } |
| 4536 | return (rc)? 0 : -EIO; |
| 4537 | } |
| 4538 | |
| 4539 | return -ENXIO; |
| 4540 | } |
| 4541 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4542 | static void light_set_status_worker(struct work_struct *work) |
| 4543 | { |
| 4544 | struct tpacpi_led_classdev *data = |
| 4545 | container_of(work, struct tpacpi_led_classdev, work); |
| 4546 | |
| 4547 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4548 | light_set_status((data->new_state != TPACPI_LED_OFF)); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | static void light_sysfs_set(struct led_classdev *led_cdev, |
| 4552 | enum led_brightness brightness) |
| 4553 | { |
| 4554 | struct tpacpi_led_classdev *data = |
| 4555 | container_of(led_cdev, |
| 4556 | struct tpacpi_led_classdev, |
| 4557 | led_classdev); |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4558 | data->new_state = (brightness != LED_OFF) ? |
| 4559 | TPACPI_LED_ON : TPACPI_LED_OFF; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4560 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4561 | } |
| 4562 | |
| 4563 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) |
| 4564 | { |
| 4565 | return (light_get_status() == 1)? LED_FULL : LED_OFF; |
| 4566 | } |
| 4567 | |
| 4568 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { |
| 4569 | .led_classdev = { |
| 4570 | .name = "tpacpi::thinklight", |
| 4571 | .brightness_set = &light_sysfs_set, |
| 4572 | .brightness_get = &light_sysfs_get, |
| 4573 | } |
| 4574 | }; |
| 4575 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4576 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | { |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4578 | int rc; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4579 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4580 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 4581 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4582 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 4583 | TPACPI_ACPIHANDLE_INIT(lght); |
| 4584 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4585 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4586 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4587 | /* 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] | 4588 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4589 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4590 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4591 | /* light status not supported on |
| 4592 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4593 | tp_features.light_status = |
| 4594 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4596 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
| 4597 | str_supported(tp_features.light), |
| 4598 | str_supported(tp_features.light_status)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4599 | |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4600 | if (!tp_features.light) |
| 4601 | return 1; |
| 4602 | |
| 4603 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 4604 | &tpacpi_led_thinklight.led_classdev); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4605 | |
| 4606 | if (rc < 0) { |
| 4607 | tp_features.light = 0; |
| 4608 | tp_features.light_status = 0; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4609 | } else { |
| 4610 | rc = 0; |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4611 | } |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 4612 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4613 | return rc; |
| 4614 | } |
| 4615 | |
| 4616 | static void light_exit(void) |
| 4617 | { |
| 4618 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); |
| 4619 | if (work_pending(&tpacpi_led_thinklight.work)) |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4620 | flush_workqueue(tpacpi_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | } |
| 4622 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4623 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | { |
| 4625 | int len = 0; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4626 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4628 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4629 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4630 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4631 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 4632 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 4633 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4634 | status = light_get_status(); |
| 4635 | if (status < 0) |
| 4636 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4638 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 4639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | |
| 4641 | return len; |
| 4642 | } |
| 4643 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4644 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4646 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4647 | int newstatus = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4648 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 4649 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4650 | return -ENODEV; |
| 4651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | while ((cmd = next_cmd(&buf))) { |
| 4653 | if (strlencmp(cmd, "on") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4654 | newstatus = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | } else if (strlencmp(cmd, "off") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4656 | newstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | } else |
| 4658 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | } |
| 4660 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4661 | return light_set_status(newstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4662 | } |
| 4663 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4664 | static struct ibm_struct light_driver_data = { |
| 4665 | .name = "light", |
| 4666 | .read = light_read, |
| 4667 | .write = light_write, |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 4668 | .exit = light_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4669 | }; |
| 4670 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4671 | /************************************************************************* |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4672 | * CMOS subdriver |
| 4673 | */ |
| 4674 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4675 | /* sysfs cmos_command -------------------------------------------------- */ |
| 4676 | static ssize_t cmos_command_store(struct device *dev, |
| 4677 | struct device_attribute *attr, |
| 4678 | const char *buf, size_t count) |
| 4679 | { |
| 4680 | unsigned long cmos_cmd; |
| 4681 | int res; |
| 4682 | |
| 4683 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 4684 | return -EINVAL; |
| 4685 | |
| 4686 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4687 | return (res)? res : count; |
| 4688 | } |
| 4689 | |
| 4690 | static struct device_attribute dev_attr_cmos_command = |
| 4691 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 4692 | |
| 4693 | /* --------------------------------------------------------------------- */ |
| 4694 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4695 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4696 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4697 | int res; |
| 4698 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4699 | vdbg_printk(TPACPI_DBG_INIT, |
| 4700 | "initializing cmos commands subdriver\n"); |
| 4701 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4702 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4703 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4704 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 4705 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4706 | |
| 4707 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4708 | if (res) |
| 4709 | return res; |
| 4710 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4711 | return (cmos_handle)? 0 : 1; |
| 4712 | } |
| 4713 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4714 | static void cmos_exit(void) |
| 4715 | { |
| 4716 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 4717 | } |
| 4718 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4719 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | { |
| 4721 | int len = 0; |
| 4722 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4723 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 4724 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | if (!cmos_handle) |
| 4726 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4727 | else { |
| 4728 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4729 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | return len; |
| 4733 | } |
| 4734 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4735 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | { |
| 4737 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4738 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | |
| 4740 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4741 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 4742 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | /* cmos_cmd set */ |
| 4744 | } else |
| 4745 | return -EINVAL; |
| 4746 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4747 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 4748 | if (res) |
| 4749 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4753 | } |
| 4754 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4755 | static struct ibm_struct cmos_driver_data = { |
| 4756 | .name = "cmos", |
| 4757 | .read = cmos_read, |
| 4758 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 4759 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4760 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4761 | |
| 4762 | /************************************************************************* |
| 4763 | * LED subdriver |
| 4764 | */ |
| 4765 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4766 | enum led_access_mode { |
| 4767 | TPACPI_LED_NONE = 0, |
| 4768 | TPACPI_LED_570, /* 570 */ |
| 4769 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 4770 | TPACPI_LED_NEW, /* all others */ |
| 4771 | }; |
| 4772 | |
| 4773 | enum { /* For TPACPI_LED_OLD */ |
| 4774 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 4775 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 4776 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 4777 | }; |
| 4778 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 4779 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4780 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4781 | TPACPI_HANDLE(led, ec, "SLED", /* 570 */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4782 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */ |
| 4783 | /* T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4784 | "LED", /* all others */ |
| 4785 | ); /* R30, R31 */ |
| 4786 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4787 | #define TPACPI_LED_NUMLEDS 16 |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4788 | static struct tpacpi_led_classdev *tpacpi_leds; |
| 4789 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; |
Harvey Harrison | e3aa51f | 2008-05-29 17:51:57 -0700 | [diff] [blame] | 4790 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4791 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
| 4792 | "tpacpi::power", |
| 4793 | "tpacpi:orange:batt", |
| 4794 | "tpacpi:green:batt", |
| 4795 | "tpacpi::dock_active", |
| 4796 | "tpacpi::bay_active", |
| 4797 | "tpacpi::dock_batt", |
| 4798 | "tpacpi::unknown_led", |
| 4799 | "tpacpi::standby", |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4800 | "tpacpi::dock_status1", |
| 4801 | "tpacpi::dock_status2", |
| 4802 | "tpacpi::unknown_led2", |
| 4803 | "tpacpi::unknown_led3", |
| 4804 | "tpacpi::thinkvantage", |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4805 | }; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4806 | #define TPACPI_SAFE_LEDS 0x1081U |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4807 | |
| 4808 | static inline bool tpacpi_is_led_restricted(const unsigned int led) |
| 4809 | { |
| 4810 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
| 4811 | return false; |
| 4812 | #else |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4813 | return (1U & (TPACPI_SAFE_LEDS >> led)) == 0; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4814 | #endif |
| 4815 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4816 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4817 | static int led_get_status(const unsigned int led) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4818 | { |
| 4819 | int status; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4820 | enum led_status_t led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4821 | |
| 4822 | switch (led_supported) { |
| 4823 | case TPACPI_LED_570: |
| 4824 | if (!acpi_evalf(ec_handle, |
| 4825 | &status, "GLED", "dd", 1 << led)) |
| 4826 | return -EIO; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4827 | led_s = (status == 0)? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4828 | TPACPI_LED_OFF : |
| 4829 | ((status == 1)? |
| 4830 | TPACPI_LED_ON : |
| 4831 | TPACPI_LED_BLINK); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4832 | tpacpi_led_state_cache[led] = led_s; |
| 4833 | return led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4834 | default: |
| 4835 | return -ENXIO; |
| 4836 | } |
| 4837 | |
| 4838 | /* not reached */ |
| 4839 | } |
| 4840 | |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4841 | static int led_set_status(const unsigned int led, |
| 4842 | const enum led_status_t ledstatus) |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4843 | { |
| 4844 | /* off, on, blink. Index is led_status_t */ |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4845 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
| 4846 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4847 | |
| 4848 | int rc = 0; |
| 4849 | |
| 4850 | switch (led_supported) { |
| 4851 | case TPACPI_LED_570: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4852 | /* 570 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4853 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4854 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4855 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 4856 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4857 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 4858 | (1 << led), led_sled_arg1[ledstatus])) |
| 4859 | rc = -EIO; |
| 4860 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4861 | case TPACPI_LED_OLD: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4862 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4863 | if (unlikely(led > 7)) |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4864 | return -EINVAL; |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4865 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 4866 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4867 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
| 4868 | if (rc >= 0) |
| 4869 | rc = ec_write(TPACPI_LED_EC_HLBL, |
| 4870 | (ledstatus == TPACPI_LED_BLINK) << led); |
| 4871 | if (rc >= 0) |
| 4872 | rc = ec_write(TPACPI_LED_EC_HLCL, |
| 4873 | (ledstatus != TPACPI_LED_OFF) << led); |
| 4874 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4875 | case TPACPI_LED_NEW: |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4876 | /* all others */ |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4877 | if (unlikely(led >= TPACPI_LED_NUMLEDS)) |
| 4878 | return -EINVAL; |
| 4879 | if (unlikely(tpacpi_is_led_restricted(led))) |
| 4880 | return -EPERM; |
Henrique de Moraes Holschuh | 24e45bb | 2008-06-03 23:36:11 -0300 | [diff] [blame] | 4881 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 4882 | led, led_led_arg1[ledstatus])) |
| 4883 | rc = -EIO; |
| 4884 | break; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4885 | default: |
| 4886 | rc = -ENXIO; |
| 4887 | } |
| 4888 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4889 | if (!rc) |
| 4890 | tpacpi_led_state_cache[led] = ledstatus; |
| 4891 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4892 | return rc; |
| 4893 | } |
| 4894 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4895 | static void led_set_status_worker(struct work_struct *work) |
| 4896 | { |
| 4897 | struct tpacpi_led_classdev *data = |
| 4898 | container_of(work, struct tpacpi_led_classdev, work); |
| 4899 | |
| 4900 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4901 | led_set_status(data->led, data->new_state); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4902 | } |
| 4903 | |
| 4904 | static void led_sysfs_set(struct led_classdev *led_cdev, |
| 4905 | enum led_brightness brightness) |
| 4906 | { |
| 4907 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 4908 | struct tpacpi_led_classdev, led_classdev); |
| 4909 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4910 | if (brightness == LED_OFF) |
| 4911 | data->new_state = TPACPI_LED_OFF; |
| 4912 | else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) |
| 4913 | data->new_state = TPACPI_LED_ON; |
| 4914 | else |
| 4915 | data->new_state = TPACPI_LED_BLINK; |
| 4916 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4917 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4918 | } |
| 4919 | |
| 4920 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, |
| 4921 | unsigned long *delay_on, unsigned long *delay_off) |
| 4922 | { |
| 4923 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 4924 | struct tpacpi_led_classdev, led_classdev); |
| 4925 | |
| 4926 | /* Can we choose the flash rate? */ |
| 4927 | if (*delay_on == 0 && *delay_off == 0) { |
| 4928 | /* yes. set them to the hardware blink rate (1 Hz) */ |
| 4929 | *delay_on = 500; /* ms */ |
| 4930 | *delay_off = 500; /* ms */ |
| 4931 | } else if ((*delay_on != 500) || (*delay_off != 500)) |
| 4932 | return -EINVAL; |
| 4933 | |
Henrique de Moraes Holschuh | 75bd3bf | 2009-04-14 02:44:11 +0000 | [diff] [blame] | 4934 | data->new_state = TPACPI_LED_BLINK; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 4935 | queue_work(tpacpi_wq, &data->work); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4936 | |
| 4937 | return 0; |
| 4938 | } |
| 4939 | |
| 4940 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) |
| 4941 | { |
| 4942 | int rc; |
| 4943 | |
| 4944 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 4945 | struct tpacpi_led_classdev, led_classdev); |
| 4946 | |
| 4947 | rc = led_get_status(data->led); |
| 4948 | |
| 4949 | if (rc == TPACPI_LED_OFF || rc < 0) |
| 4950 | rc = LED_OFF; /* no error handling in led class :( */ |
| 4951 | else |
| 4952 | rc = LED_FULL; |
| 4953 | |
| 4954 | return rc; |
| 4955 | } |
| 4956 | |
| 4957 | static void led_exit(void) |
| 4958 | { |
| 4959 | unsigned int i; |
| 4960 | |
| 4961 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 4962 | if (tpacpi_leds[i].led_classdev.name) |
| 4963 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); |
| 4964 | } |
| 4965 | |
| 4966 | kfree(tpacpi_leds); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4967 | } |
| 4968 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4969 | static int __init tpacpi_init_led(unsigned int led) |
| 4970 | { |
| 4971 | int rc; |
| 4972 | |
| 4973 | tpacpi_leds[led].led = led; |
| 4974 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4975 | /* LEDs with no name don't get registered */ |
| 4976 | if (!tpacpi_led_names[led]) |
| 4977 | return 0; |
| 4978 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 4979 | tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set; |
| 4980 | tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set; |
| 4981 | if (led_supported == TPACPI_LED_570) |
| 4982 | tpacpi_leds[led].led_classdev.brightness_get = |
| 4983 | &led_sysfs_get; |
| 4984 | |
| 4985 | tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led]; |
| 4986 | |
| 4987 | INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker); |
| 4988 | |
| 4989 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 4990 | &tpacpi_leds[led].led_classdev); |
| 4991 | if (rc < 0) |
| 4992 | tpacpi_leds[led].led_classdev.name = NULL; |
| 4993 | |
| 4994 | return rc; |
| 4995 | } |
| 4996 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 4997 | static const struct tpacpi_quirk led_useful_qtable[] __initconst = { |
| 4998 | TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */ |
| 4999 | TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */ |
| 5000 | TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */ |
| 5001 | |
| 5002 | TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */ |
| 5003 | TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */ |
| 5004 | TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */ |
| 5005 | TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */ |
| 5006 | TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */ |
| 5007 | TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */ |
| 5008 | TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */ |
| 5009 | TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */ |
| 5010 | |
| 5011 | TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */ |
| 5012 | TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */ |
| 5013 | TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */ |
| 5014 | TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */ |
| 5015 | TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */ |
| 5016 | |
| 5017 | TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */ |
| 5018 | TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */ |
| 5019 | TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */ |
| 5020 | TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */ |
| 5021 | |
| 5022 | /* (1) - may have excess leds enabled on MSB */ |
| 5023 | |
| 5024 | /* Defaults (order matters, keep last, don't reorder!) */ |
| 5025 | { /* Lenovo */ |
| 5026 | .vendor = PCI_VENDOR_ID_LENOVO, |
| 5027 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5028 | .quirks = 0x1fffU, |
| 5029 | }, |
| 5030 | { /* IBM ThinkPads with no EC version string */ |
| 5031 | .vendor = PCI_VENDOR_ID_IBM, |
| 5032 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_UNKNOWN, |
| 5033 | .quirks = 0x00ffU, |
| 5034 | }, |
| 5035 | { /* IBM ThinkPads with EC version string */ |
| 5036 | .vendor = PCI_VENDOR_ID_IBM, |
| 5037 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, |
| 5038 | .quirks = 0x00bfU, |
| 5039 | }, |
| 5040 | }; |
| 5041 | |
| 5042 | #undef TPACPI_LEDQ_IBM |
| 5043 | #undef TPACPI_LEDQ_LNV |
| 5044 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5045 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5046 | { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5047 | unsigned int i; |
| 5048 | int rc; |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5049 | unsigned long useful_leds; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5050 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5051 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 5052 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5053 | TPACPI_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5054 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5055 | if (!led_handle) |
| 5056 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5057 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5058 | else if (strlencmp(led_path, "SLED") == 0) |
| 5059 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5060 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5061 | else if (strlencmp(led_path, "SYSL") == 0) |
| 5062 | /* 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] | 5063 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5064 | else |
| 5065 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5066 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5067 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5068 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 5069 | str_supported(led_supported), led_supported); |
| 5070 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5071 | if (led_supported == TPACPI_LED_NONE) |
| 5072 | return 1; |
| 5073 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5074 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
| 5075 | GFP_KERNEL); |
| 5076 | if (!tpacpi_leds) { |
| 5077 | printk(TPACPI_ERR "Out of memory for LED data\n"); |
| 5078 | return -ENOMEM; |
| 5079 | } |
| 5080 | |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5081 | useful_leds = tpacpi_check_quirks(led_useful_qtable, |
| 5082 | ARRAY_SIZE(led_useful_qtable)); |
| 5083 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5084 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5085 | if (!tpacpi_is_led_restricted(i) && |
| 5086 | test_bit(i, &useful_leds)) { |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5087 | rc = tpacpi_init_led(i); |
| 5088 | if (rc < 0) { |
| 5089 | led_exit(); |
| 5090 | return rc; |
| 5091 | } |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5092 | } |
| 5093 | } |
| 5094 | |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5095 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5096 | printk(TPACPI_NOTICE |
| 5097 | "warning: userspace override of important " |
| 5098 | "firmware LEDs is enabled\n"); |
Henrique de Moraes Holschuh | a4d5eff | 2009-04-04 04:25:49 +0000 | [diff] [blame] | 5099 | #endif |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5100 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5101 | } |
| 5102 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5103 | #define str_led_status(s) \ |
| 5104 | ((s) == TPACPI_LED_OFF ? "off" : \ |
| 5105 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5106 | |
| 5107 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | { |
| 5109 | int len = 0; |
| 5110 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5111 | if (!led_supported) { |
| 5112 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5113 | return len; |
| 5114 | } |
| 5115 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 5116 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5117 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5118 | /* 570 */ |
| 5119 | int i, status; |
| 5120 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5121 | status = led_get_status(i); |
| 5122 | if (status < 0) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5123 | return -EIO; |
| 5124 | len += sprintf(p + len, "%d:\t\t%s\n", |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5125 | i, str_led_status(status)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5126 | } |
| 5127 | } |
| 5128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | len += sprintf(p + len, "commands:\t" |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5130 | "<led> on, <led> off, <led> blink (<led> is 0-15)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | |
| 5132 | return len; |
| 5133 | } |
| 5134 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5135 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5136 | { |
| 5137 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5138 | int led, rc; |
| 5139 | enum led_status_t s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5140 | |
| 5141 | if (!led_supported) |
| 5142 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | |
| 5144 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | f21179a | 2009-05-30 13:25:08 -0300 | [diff] [blame] | 5145 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5146 | return -EINVAL; |
| 5147 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5148 | if (strstr(cmd, "off")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5149 | s = TPACPI_LED_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5150 | } else if (strstr(cmd, "on")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5151 | s = TPACPI_LED_ON; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5152 | } else if (strstr(cmd, "blink")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5153 | s = TPACPI_LED_BLINK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5154 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5155 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5156 | } |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 5157 | |
| 5158 | rc = led_set_status(led, s); |
| 5159 | if (rc < 0) |
| 5160 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5164 | } |
| 5165 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5166 | static struct ibm_struct led_driver_data = { |
| 5167 | .name = "led", |
| 5168 | .read = led_read, |
| 5169 | .write = led_write, |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 5170 | .exit = led_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5171 | }; |
| 5172 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5173 | /************************************************************************* |
| 5174 | * Beep subdriver |
| 5175 | */ |
| 5176 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5177 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5178 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5179 | #define TPACPI_BEEP_Q1 0x0001 |
| 5180 | |
| 5181 | static const struct tpacpi_quirk beep_quirk_table[] __initconst = { |
| 5182 | TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1), /* 570 */ |
| 5183 | TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */ |
| 5184 | }; |
| 5185 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5186 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5187 | { |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5188 | unsigned long quirks; |
| 5189 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5190 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 5191 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5192 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5193 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5194 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 5195 | str_supported(beep_handle != NULL)); |
| 5196 | |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5197 | quirks = tpacpi_check_quirks(beep_quirk_table, |
| 5198 | ARRAY_SIZE(beep_quirk_table)); |
| 5199 | |
| 5200 | tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); |
| 5201 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5202 | return (beep_handle)? 0 : 1; |
| 5203 | } |
| 5204 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5205 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5206 | { |
| 5207 | int len = 0; |
| 5208 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5209 | if (!beep_handle) |
| 5210 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5211 | else { |
| 5212 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 5213 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 5214 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5215 | |
| 5216 | return len; |
| 5217 | } |
| 5218 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5219 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5220 | { |
| 5221 | char *cmd; |
| 5222 | int beep_cmd; |
| 5223 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5224 | if (!beep_handle) |
| 5225 | return -ENODEV; |
| 5226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5227 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5228 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 5229 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | /* beep_cmd set */ |
| 5231 | } else |
| 5232 | return -EINVAL; |
Henrique de Moraes Holschuh | 6020173 | 2009-05-30 13:25:07 -0300 | [diff] [blame] | 5233 | if (tp_features.beep_needs_two_args) { |
| 5234 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", |
| 5235 | beep_cmd, 0)) |
| 5236 | return -EIO; |
| 5237 | } else { |
| 5238 | if (!acpi_evalf(beep_handle, NULL, NULL, "vd", |
| 5239 | beep_cmd)) |
| 5240 | return -EIO; |
| 5241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5245 | } |
| 5246 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5247 | static struct ibm_struct beep_driver_data = { |
| 5248 | .name = "beep", |
| 5249 | .read = beep_read, |
| 5250 | .write = beep_write, |
| 5251 | }; |
| 5252 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5253 | /************************************************************************* |
| 5254 | * Thermal subdriver |
| 5255 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5256 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5257 | enum thermal_access_mode { |
| 5258 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 5259 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 5260 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 5261 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 5262 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 5263 | }; |
| 5264 | |
| 5265 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 5266 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 5267 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 5268 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
| 5269 | }; |
| 5270 | |
| 5271 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 5272 | struct ibm_thermal_sensors_struct { |
| 5273 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 5274 | }; |
| 5275 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5276 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5277 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5278 | /* idx is zero-based */ |
| 5279 | static int thermal_get_sensor(int idx, s32 *value) |
| 5280 | { |
| 5281 | int t; |
| 5282 | s8 tmp; |
| 5283 | char tmpi[5]; |
| 5284 | |
| 5285 | t = TP_EC_THERMAL_TMP0; |
| 5286 | |
| 5287 | switch (thermal_read_mode) { |
| 5288 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 5289 | case TPACPI_THERMAL_TPEC_16: |
| 5290 | if (idx >= 8 && idx <= 15) { |
| 5291 | t = TP_EC_THERMAL_TMP8; |
| 5292 | idx -= 8; |
| 5293 | } |
| 5294 | /* fallthrough */ |
| 5295 | #endif |
| 5296 | case TPACPI_THERMAL_TPEC_8: |
| 5297 | if (idx <= 7) { |
| 5298 | if (!acpi_ec_read(t + idx, &tmp)) |
| 5299 | return -EIO; |
| 5300 | *value = tmp * 1000; |
| 5301 | return 0; |
| 5302 | } |
| 5303 | break; |
| 5304 | |
| 5305 | case TPACPI_THERMAL_ACPI_UPDT: |
| 5306 | if (idx <= 7) { |
| 5307 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5308 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 5309 | return -EIO; |
| 5310 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5311 | return -EIO; |
| 5312 | *value = (t - 2732) * 100; |
| 5313 | return 0; |
| 5314 | } |
| 5315 | break; |
| 5316 | |
| 5317 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5318 | if (idx <= 7) { |
| 5319 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 5320 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 5321 | return -EIO; |
| 5322 | if (t > 127 || t < -127) |
| 5323 | t = TP_EC_THERMAL_TMP_NA; |
| 5324 | *value = t * 1000; |
| 5325 | return 0; |
| 5326 | } |
| 5327 | break; |
| 5328 | |
| 5329 | case TPACPI_THERMAL_NONE: |
| 5330 | default: |
| 5331 | return -ENOSYS; |
| 5332 | } |
| 5333 | |
| 5334 | return -EINVAL; |
| 5335 | } |
| 5336 | |
| 5337 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 5338 | { |
| 5339 | int res, i; |
| 5340 | int n; |
| 5341 | |
| 5342 | n = 8; |
| 5343 | i = 0; |
| 5344 | |
| 5345 | if (!s) |
| 5346 | return -EINVAL; |
| 5347 | |
| 5348 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 5349 | n = 16; |
| 5350 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5351 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5352 | res = thermal_get_sensor(i, &s->temp[i]); |
| 5353 | if (res) |
| 5354 | return res; |
| 5355 | } |
| 5356 | |
| 5357 | return n; |
| 5358 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5359 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5360 | /* sysfs temp##_input -------------------------------------------------- */ |
| 5361 | |
| 5362 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 5363 | struct device_attribute *attr, |
| 5364 | char *buf) |
| 5365 | { |
| 5366 | struct sensor_device_attribute *sensor_attr = |
| 5367 | to_sensor_dev_attr(attr); |
| 5368 | int idx = sensor_attr->index; |
| 5369 | s32 value; |
| 5370 | int res; |
| 5371 | |
| 5372 | res = thermal_get_sensor(idx, &value); |
| 5373 | if (res) |
| 5374 | return res; |
| 5375 | if (value == TP_EC_THERMAL_TMP_NA * 1000) |
| 5376 | return -ENXIO; |
| 5377 | |
| 5378 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 5379 | } |
| 5380 | |
| 5381 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5382 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 5383 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5384 | |
| 5385 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 5386 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 5387 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 5388 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 5389 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 5390 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 5391 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 5392 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 5393 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 5394 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 5395 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 5396 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 5397 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 5398 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 5399 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 5400 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 5401 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 5402 | }; |
| 5403 | |
| 5404 | #define THERMAL_ATTRS(X) \ |
| 5405 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 5406 | |
| 5407 | static struct attribute *thermal_temp_input_attr[] = { |
| 5408 | THERMAL_ATTRS(8), |
| 5409 | THERMAL_ATTRS(9), |
| 5410 | THERMAL_ATTRS(10), |
| 5411 | THERMAL_ATTRS(11), |
| 5412 | THERMAL_ATTRS(12), |
| 5413 | THERMAL_ATTRS(13), |
| 5414 | THERMAL_ATTRS(14), |
| 5415 | THERMAL_ATTRS(15), |
| 5416 | THERMAL_ATTRS(0), |
| 5417 | THERMAL_ATTRS(1), |
| 5418 | THERMAL_ATTRS(2), |
| 5419 | THERMAL_ATTRS(3), |
| 5420 | THERMAL_ATTRS(4), |
| 5421 | THERMAL_ATTRS(5), |
| 5422 | THERMAL_ATTRS(6), |
| 5423 | THERMAL_ATTRS(7), |
| 5424 | NULL |
| 5425 | }; |
| 5426 | |
| 5427 | static const struct attribute_group thermal_temp_input16_group = { |
| 5428 | .attrs = thermal_temp_input_attr |
| 5429 | }; |
| 5430 | |
| 5431 | static const struct attribute_group thermal_temp_input8_group = { |
| 5432 | .attrs = &thermal_temp_input_attr[8] |
| 5433 | }; |
| 5434 | |
| 5435 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 5436 | #undef THERMAL_ATTRS |
| 5437 | |
| 5438 | /* --------------------------------------------------------------------- */ |
| 5439 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5440 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5441 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5442 | u8 t, ta1, ta2; |
| 5443 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5444 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5445 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5446 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5447 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 5448 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5449 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5450 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 5451 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5452 | /* |
| 5453 | * Direct EC access mode: sensors at registers |
| 5454 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 5455 | * non-implemented, thermal sensors return 0x80 when |
| 5456 | * not available |
| 5457 | */ |
| 5458 | |
| 5459 | ta1 = ta2 = 0; |
| 5460 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5461 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5462 | ta1 |= t; |
| 5463 | } else { |
| 5464 | ta1 = 0; |
| 5465 | break; |
| 5466 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 5467 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5468 | ta2 |= t; |
| 5469 | } else { |
| 5470 | ta1 = 0; |
| 5471 | break; |
| 5472 | } |
| 5473 | } |
| 5474 | if (ta1 == 0) { |
| 5475 | /* This is sheer paranoia, but we handle it anyway */ |
| 5476 | if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5477 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5478 | "ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5479 | "falling back to ACPI TMPx access " |
| 5480 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5481 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5482 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5483 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5484 | "ThinkPad ACPI EC access misbehaving, " |
| 5485 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5486 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5487 | } |
| 5488 | } else { |
| 5489 | thermal_read_mode = |
| 5490 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5491 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5492 | } |
| 5493 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5494 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 5495 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5496 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5497 | } else { |
| 5498 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5499 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5500 | } |
| 5501 | } else { |
| 5502 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5503 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5504 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5505 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5506 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 5507 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 5508 | thermal_read_mode); |
| 5509 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5510 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5511 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5512 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5513 | &thermal_temp_input16_group); |
| 5514 | if (res) |
| 5515 | return res; |
| 5516 | break; |
| 5517 | case TPACPI_THERMAL_TPEC_8: |
| 5518 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5519 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5520 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5521 | &thermal_temp_input8_group); |
| 5522 | if (res) |
| 5523 | return res; |
| 5524 | break; |
| 5525 | case TPACPI_THERMAL_NONE: |
| 5526 | default: |
| 5527 | return 1; |
| 5528 | } |
| 5529 | |
| 5530 | return 0; |
| 5531 | } |
| 5532 | |
| 5533 | static void thermal_exit(void) |
| 5534 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5535 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5536 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5537 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5538 | &thermal_temp_input16_group); |
| 5539 | break; |
| 5540 | case TPACPI_THERMAL_TPEC_8: |
| 5541 | case TPACPI_THERMAL_ACPI_TMP07: |
| 5542 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5543 | sysfs_remove_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 | break; |
| 5546 | case TPACPI_THERMAL_NONE: |
| 5547 | default: |
| 5548 | break; |
| 5549 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | static int thermal_read(char *p) |
| 5553 | { |
| 5554 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5555 | int n, i; |
| 5556 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5557 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5558 | n = thermal_get_sensors(&t); |
| 5559 | if (unlikely(n < 0)) |
| 5560 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5561 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5562 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5563 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5564 | if (n > 0) { |
| 5565 | for (i = 0; i < (n - 1); i++) |
| 5566 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 5567 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 5568 | } else |
| 5569 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5570 | |
| 5571 | return len; |
| 5572 | } |
| 5573 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5574 | static struct ibm_struct thermal_driver_data = { |
| 5575 | .name = "thermal", |
| 5576 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 5577 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5578 | }; |
| 5579 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5580 | /************************************************************************* |
| 5581 | * EC Dump subdriver |
| 5582 | */ |
| 5583 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5584 | static u8 ecdump_regs[256]; |
| 5585 | |
| 5586 | static int ecdump_read(char *p) |
| 5587 | { |
| 5588 | int len = 0; |
| 5589 | int i, j; |
| 5590 | u8 v; |
| 5591 | |
| 5592 | len += sprintf(p + len, "EC " |
| 5593 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 5594 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 5595 | for (i = 0; i < 256; i += 16) { |
| 5596 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 5597 | for (j = 0; j < 16; j++) { |
| 5598 | if (!acpi_ec_read(i + j, &v)) |
| 5599 | break; |
| 5600 | if (v != ecdump_regs[i + j]) |
| 5601 | len += sprintf(p + len, " *%02x", v); |
| 5602 | else |
| 5603 | len += sprintf(p + len, " %02x", v); |
| 5604 | ecdump_regs[i + j] = v; |
| 5605 | } |
| 5606 | len += sprintf(p + len, "\n"); |
| 5607 | if (j != 16) |
| 5608 | break; |
| 5609 | } |
| 5610 | |
| 5611 | /* These are way too dangerous to advertise openly... */ |
| 5612 | #if 0 |
| 5613 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 5614 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 5615 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 5616 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 5617 | #endif |
| 5618 | return len; |
| 5619 | } |
| 5620 | |
| 5621 | static int ecdump_write(char *buf) |
| 5622 | { |
| 5623 | char *cmd; |
| 5624 | int i, v; |
| 5625 | |
| 5626 | while ((cmd = next_cmd(&buf))) { |
| 5627 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 5628 | /* i and v set */ |
| 5629 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 5630 | /* i and v set */ |
| 5631 | } else |
| 5632 | return -EINVAL; |
| 5633 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 5634 | if (!acpi_ec_write(i, v)) |
| 5635 | return -EIO; |
| 5636 | } else |
| 5637 | return -EINVAL; |
| 5638 | } |
| 5639 | |
| 5640 | return 0; |
| 5641 | } |
| 5642 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5643 | static struct ibm_struct ecdump_driver_data = { |
| 5644 | .name = "ecdump", |
| 5645 | .read = ecdump_read, |
| 5646 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5647 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5648 | }; |
| 5649 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5650 | /************************************************************************* |
| 5651 | * Backlight/brightness subdriver |
| 5652 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 5653 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5654 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 5655 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5656 | /* |
| 5657 | * ThinkPads can read brightness from two places: EC HBRV (0x31), or |
| 5658 | * CMOS NVRAM byte 0x5E, bits 0-3. |
| 5659 | * |
| 5660 | * EC HBRV (0x31) has the following layout |
| 5661 | * Bit 7: unknown function |
| 5662 | * Bit 6: unknown function |
| 5663 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 5664 | * Bit 4: must be set to zero to avoid problems |
| 5665 | * Bit 3-0: backlight brightness level |
| 5666 | * |
| 5667 | * brightness_get_raw returns status data in the HBRV layout |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 5668 | * |
| 5669 | * WARNING: The X61 has been verified to use HBRV for something else, so |
| 5670 | * this should be used _only_ on IBM ThinkPads, and maybe with some careful |
| 5671 | * testing on the very early *60 Lenovo models... |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5672 | */ |
| 5673 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5674 | enum { |
| 5675 | TP_EC_BACKLIGHT = 0x31, |
| 5676 | |
| 5677 | /* TP_EC_BACKLIGHT bitmasks */ |
| 5678 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 5679 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 5680 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 5681 | }; |
| 5682 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5683 | enum tpacpi_brightness_access_mode { |
| 5684 | TPACPI_BRGHT_MODE_AUTO = 0, /* Not implemented yet */ |
| 5685 | TPACPI_BRGHT_MODE_EC, /* EC control */ |
| 5686 | TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */ |
| 5687 | TPACPI_BRGHT_MODE_ECNVRAM, /* EC control w/ NVRAM store */ |
| 5688 | TPACPI_BRGHT_MODE_MAX |
| 5689 | }; |
| 5690 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5691 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5692 | |
| 5693 | static enum tpacpi_brightness_access_mode brightness_mode = |
| 5694 | TPACPI_BRGHT_MODE_MAX; |
| 5695 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5696 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 5697 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5698 | static struct mutex brightness_mutex; |
| 5699 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5700 | /* NVRAM brightness access, |
| 5701 | * call with brightness_mutex held! */ |
| 5702 | static unsigned int tpacpi_brightness_nvram_get(void) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5703 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5704 | u8 lnvram; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5705 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5706 | lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 5707 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5708 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 5709 | lnvram &= (tp_features.bright_16levels) ? 0x0f : 0x07; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5710 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5711 | return lnvram; |
| 5712 | } |
| 5713 | |
| 5714 | static void tpacpi_brightness_checkpoint_nvram(void) |
| 5715 | { |
| 5716 | u8 lec = 0; |
| 5717 | u8 b_nvram; |
| 5718 | |
| 5719 | if (brightness_mode != TPACPI_BRGHT_MODE_ECNVRAM) |
| 5720 | return; |
| 5721 | |
| 5722 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5723 | "trying to checkpoint backlight level to NVRAM...\n"); |
| 5724 | |
| 5725 | if (mutex_lock_killable(&brightness_mutex) < 0) |
| 5726 | return; |
| 5727 | |
| 5728 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5729 | goto unlock; |
| 5730 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
| 5731 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 5732 | |
| 5733 | if (lec != ((b_nvram & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 5734 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS)) { |
| 5735 | /* NVRAM needs update */ |
| 5736 | b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS << |
| 5737 | TP_NVRAM_POS_LEVEL_BRIGHTNESS); |
| 5738 | b_nvram |= lec; |
| 5739 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_BRIGHTNESS); |
| 5740 | dbg_printk(TPACPI_DBG_BRGHT, |
| 5741 | "updated NVRAM backlight level to %u (0x%02x)\n", |
| 5742 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5743 | } else |
| 5744 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5745 | "NVRAM backlight level already is %u (0x%02x)\n", |
| 5746 | (unsigned int) lec, (unsigned int) b_nvram); |
| 5747 | |
| 5748 | unlock: |
| 5749 | mutex_unlock(&brightness_mutex); |
| 5750 | } |
| 5751 | |
| 5752 | |
| 5753 | /* call with brightness_mutex held! */ |
| 5754 | static int tpacpi_brightness_get_raw(int *status) |
| 5755 | { |
| 5756 | u8 lec = 0; |
| 5757 | |
| 5758 | switch (brightness_mode) { |
| 5759 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 5760 | *status = tpacpi_brightness_nvram_get(); |
| 5761 | return 0; |
| 5762 | case TPACPI_BRGHT_MODE_EC: |
| 5763 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 5764 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 5765 | return -EIO; |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5766 | *status = lec; |
| 5767 | return 0; |
| 5768 | default: |
| 5769 | return -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5770 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5771 | } |
| 5772 | |
| 5773 | /* call with brightness_mutex held! */ |
| 5774 | /* do NOT call with illegal backlight level value */ |
| 5775 | static int tpacpi_brightness_set_ec(unsigned int value) |
| 5776 | { |
| 5777 | u8 lec = 0; |
| 5778 | |
| 5779 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) |
| 5780 | return -EIO; |
| 5781 | |
| 5782 | if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT, |
| 5783 | (lec & TP_EC_BACKLIGHT_CMDMSK) | |
| 5784 | (value & TP_EC_BACKLIGHT_LVLMSK)))) |
| 5785 | return -EIO; |
| 5786 | |
| 5787 | return 0; |
| 5788 | } |
| 5789 | |
| 5790 | /* call with brightness_mutex held! */ |
| 5791 | static int tpacpi_brightness_set_ucmsstep(unsigned int value) |
| 5792 | { |
| 5793 | int cmos_cmd, inc; |
| 5794 | unsigned int current_value, i; |
| 5795 | |
| 5796 | current_value = tpacpi_brightness_nvram_get(); |
| 5797 | |
| 5798 | if (value == current_value) |
| 5799 | return 0; |
| 5800 | |
| 5801 | cmos_cmd = (value > current_value) ? |
| 5802 | TP_CMOS_BRIGHTNESS_UP : |
| 5803 | TP_CMOS_BRIGHTNESS_DOWN; |
| 5804 | inc = (value > current_value) ? 1 : -1; |
| 5805 | |
| 5806 | for (i = current_value; i != value; i += inc) |
| 5807 | if (issue_thinkpad_cmos_command(cmos_cmd)) |
| 5808 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5809 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5810 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5814 | static int brightness_set(unsigned int value) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5815 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5816 | int res; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5817 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5818 | if (value > ((tp_features.bright_16levels)? 15 : 7) || |
| 5819 | value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5820 | return -EINVAL; |
| 5821 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5822 | vdbg_printk(TPACPI_DBG_BRGHT, |
| 5823 | "set backlight level to %d\n", value); |
| 5824 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 5825 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5826 | if (res < 0) |
| 5827 | return res; |
| 5828 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5829 | switch (brightness_mode) { |
| 5830 | case TPACPI_BRGHT_MODE_EC: |
| 5831 | case TPACPI_BRGHT_MODE_ECNVRAM: |
| 5832 | res = tpacpi_brightness_set_ec(value); |
| 5833 | break; |
| 5834 | case TPACPI_BRGHT_MODE_UCMS_STEP: |
| 5835 | res = tpacpi_brightness_set_ucmsstep(value); |
| 5836 | break; |
| 5837 | default: |
| 5838 | res = -ENXIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5839 | } |
| 5840 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5841 | mutex_unlock(&brightness_mutex); |
| 5842 | return res; |
| 5843 | } |
| 5844 | |
| 5845 | /* sysfs backlight class ----------------------------------------------- */ |
| 5846 | |
| 5847 | static int brightness_update_status(struct backlight_device *bd) |
| 5848 | { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5849 | unsigned int level = |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5850 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 5851 | bd->props.power == FB_BLANK_UNBLANK) ? |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5852 | bd->props.brightness : 0; |
| 5853 | |
| 5854 | dbg_printk(TPACPI_DBG_BRGHT, |
| 5855 | "backlight: attempt to set level to %d\n", |
| 5856 | level); |
| 5857 | |
| 5858 | /* it is the backlight class's job (caller) to handle |
| 5859 | * EINTR and other errors properly */ |
| 5860 | return brightness_set(level); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5861 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 5862 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5863 | static int brightness_get(struct backlight_device *bd) |
| 5864 | { |
| 5865 | int status, res; |
| 5866 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5867 | res = mutex_lock_killable(&brightness_mutex); |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5868 | if (res < 0) |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5869 | return 0; |
| 5870 | |
| 5871 | res = tpacpi_brightness_get_raw(&status); |
| 5872 | |
| 5873 | mutex_unlock(&brightness_mutex); |
| 5874 | |
| 5875 | if (res < 0) |
| 5876 | return 0; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 5877 | |
| 5878 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 5879 | } |
| 5880 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 5881 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5882 | .get_brightness = brightness_get, |
| 5883 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 5884 | }; |
| 5885 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5886 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 5887 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 5888 | /* |
| 5889 | * These are only useful for models that have only one possibility |
| 5890 | * of GPU. If the BIOS model handles both ATI and Intel, don't use |
| 5891 | * these quirks. |
| 5892 | */ |
| 5893 | #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */ |
| 5894 | #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */ |
| 5895 | #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */ |
| 5896 | |
| 5897 | static const struct tpacpi_quirk brightness_quirk_table[] __initconst = { |
| 5898 | /* Models with ATI GPUs known to require ECNVRAM mode */ |
| 5899 | TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */ |
| 5900 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 5901 | /* Models with ATI GPUs that can use ECNVRAM */ |
| 5902 | TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 5903 | TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 5904 | TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 5905 | TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
| 5906 | |
Henrique de Moraes Holschuh | 6da25bf | 2009-09-12 15:22:11 -0300 | [diff] [blame] | 5907 | /* Models with Intel Extreme Graphics 2 */ |
| 5908 | TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 5909 | TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_NOEC), |
| 5910 | TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_NOEC), |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 5911 | |
| 5912 | /* Models with Intel GMA900 */ |
| 5913 | TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC), /* T43, R52 */ |
| 5914 | TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC), /* X41 */ |
| 5915 | TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC), /* X41 Tablet */ |
| 5916 | }; |
| 5917 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5918 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 5919 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 5920 | int b; |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 5921 | unsigned long quirks; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 5922 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5923 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 5924 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 5925 | mutex_init(&brightness_mutex); |
| 5926 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 5927 | quirks = tpacpi_check_quirks(brightness_quirk_table, |
| 5928 | ARRAY_SIZE(brightness_quirk_table)); |
| 5929 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 5930 | /* |
| 5931 | * We always attempt to detect acpi support, so as to switch |
| 5932 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 5933 | * going to publish a backlight interface |
| 5934 | */ |
| 5935 | b = tpacpi_check_std_acpi_brightness_support(); |
| 5936 | if (b > 0) { |
Thomas Renninger | 2dba1b5 | 2008-08-01 17:38:03 +0200 | [diff] [blame] | 5937 | |
| 5938 | if (acpi_video_backlight_support()) { |
| 5939 | if (brightness_enable > 1) { |
| 5940 | printk(TPACPI_NOTICE |
| 5941 | "Standard ACPI backlight interface " |
| 5942 | "available, not loading native one.\n"); |
| 5943 | return 1; |
| 5944 | } else if (brightness_enable == 1) { |
| 5945 | printk(TPACPI_NOTICE |
| 5946 | "Backlight control force enabled, even if standard " |
| 5947 | "ACPI backlight interface is available\n"); |
| 5948 | } |
| 5949 | } else { |
| 5950 | if (brightness_enable > 1) { |
| 5951 | printk(TPACPI_NOTICE |
| 5952 | "Standard ACPI backlight interface not " |
| 5953 | "available, thinkpad_acpi native " |
| 5954 | "brightness control enabled\n"); |
| 5955 | } |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 5956 | } |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 5957 | } |
| 5958 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 5959 | if (!brightness_enable) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5960 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 5961 | "brightness support disabled by " |
| 5962 | "module parameter\n"); |
| 5963 | return 1; |
| 5964 | } |
| 5965 | |
| 5966 | if (b > 16) { |
| 5967 | printk(TPACPI_ERR |
| 5968 | "Unsupported brightness interface, " |
| 5969 | "please contact %s\n", TPACPI_MAIL); |
| 5970 | return 1; |
| 5971 | } |
| 5972 | if (b == 16) |
| 5973 | tp_features.bright_16levels = 1; |
| 5974 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5975 | /* |
| 5976 | * Check for module parameter bogosity, note that we |
| 5977 | * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be |
| 5978 | * able to detect "unspecified" |
| 5979 | */ |
| 5980 | if (brightness_mode > TPACPI_BRGHT_MODE_MAX) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 5981 | return -EINVAL; |
| 5982 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5983 | /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */ |
| 5984 | if (brightness_mode == TPACPI_BRGHT_MODE_AUTO || |
| 5985 | brightness_mode == TPACPI_BRGHT_MODE_MAX) { |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 5986 | if (quirks & TPACPI_BRGHT_Q_EC) |
| 5987 | brightness_mode = TPACPI_BRGHT_MODE_ECNVRAM; |
| 5988 | else |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5989 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
| 5990 | |
| 5991 | dbg_printk(TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 5992 | "driver auto-selected brightness_mode=%d\n", |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 5993 | brightness_mode); |
| 5994 | } |
| 5995 | |
Henrique de Moraes Holschuh | d7880f1 | 2009-06-18 00:40:16 -0300 | [diff] [blame] | 5996 | /* Safety */ |
| 5997 | if (thinkpad_id.vendor != PCI_VENDOR_ID_IBM && |
| 5998 | (brightness_mode == TPACPI_BRGHT_MODE_ECNVRAM || |
| 5999 | brightness_mode == TPACPI_BRGHT_MODE_EC)) |
| 6000 | return -EINVAL; |
| 6001 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6002 | if (tpacpi_brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6003 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6004 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6005 | if (tp_features.bright_16levels) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6006 | printk(TPACPI_INFO |
| 6007 | "detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6008 | |
Henrique de Moraes Holschuh | 7d5a015 | 2007-04-24 11:48:20 -0300 | [diff] [blame] | 6009 | ibm_backlight_device = backlight_device_register( |
| 6010 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
| 6011 | &ibm_backlight_data); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6012 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame^] | 6013 | int rc = PTR_ERR(ibm_backlight_device); |
| 6014 | ibm_backlight_device = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6015 | printk(TPACPI_ERR "Could not register backlight device\n"); |
Henrique de Moraes Holschuh | 435c47e | 2009-09-20 14:09:22 -0300 | [diff] [blame^] | 6016 | return rc; |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6017 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6018 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
| 6019 | "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6020 | |
Henrique de Moraes Holschuh | 59fe4fe | 2009-08-01 12:04:20 -0300 | [diff] [blame] | 6021 | if (quirks & TPACPI_BRGHT_Q_ASK) { |
| 6022 | printk(TPACPI_NOTICE |
| 6023 | "brightness: will use unverified default: " |
| 6024 | "brightness_mode=%d\n", brightness_mode); |
| 6025 | printk(TPACPI_NOTICE |
| 6026 | "brightness: please report to %s whether it works well " |
| 6027 | "or not on your ThinkPad\n", TPACPI_MAIL); |
| 6028 | } |
| 6029 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6030 | ibm_backlight_device->props.max_brightness = |
| 6031 | (tp_features.bright_16levels)? 15 : 7; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 6032 | ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 6033 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 6034 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6035 | return 0; |
| 6036 | } |
| 6037 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6038 | static void brightness_suspend(pm_message_t state) |
| 6039 | { |
| 6040 | tpacpi_brightness_checkpoint_nvram(); |
| 6041 | } |
| 6042 | |
| 6043 | static void brightness_shutdown(void) |
| 6044 | { |
| 6045 | tpacpi_brightness_checkpoint_nvram(); |
| 6046 | } |
| 6047 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6048 | static void brightness_exit(void) |
| 6049 | { |
| 6050 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6051 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_BRGHT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6052 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6053 | backlight_device_unregister(ibm_backlight_device); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6054 | } |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6055 | |
| 6056 | tpacpi_brightness_checkpoint_nvram(); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 6057 | } |
| 6058 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6059 | static int brightness_read(char *p) |
| 6060 | { |
| 6061 | int len = 0; |
| 6062 | int level; |
| 6063 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6064 | level = brightness_get(NULL); |
| 6065 | if (level < 0) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6066 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 6067 | } else { |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6068 | len += sprintf(p + len, "level:\t\t%d\n", level); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6069 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 6070 | len += sprintf(p + len, "commands:\tlevel <level>" |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6071 | " (<level> is 0-%d)\n", |
| 6072 | (tp_features.bright_16levels) ? 15 : 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6073 | } |
| 6074 | |
| 6075 | return len; |
| 6076 | } |
| 6077 | |
| 6078 | static int brightness_write(char *buf) |
| 6079 | { |
| 6080 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6081 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6082 | char *cmd; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 6083 | int max_level = (tp_features.bright_16levels) ? 15 : 7; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6084 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6085 | level = brightness_get(NULL); |
| 6086 | if (level < 0) |
| 6087 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6088 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6089 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6090 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6091 | if (level < max_level) |
| 6092 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6093 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6094 | if (level > 0) |
| 6095 | level--; |
| 6096 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
| 6097 | level >= 0 && level <= max_level) { |
| 6098 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6099 | } else |
| 6100 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6101 | } |
| 6102 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6103 | tpacpi_disclose_usertask("procfs brightness", |
| 6104 | "set level to %d\n", level); |
| 6105 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 6106 | /* |
| 6107 | * Now we know what the final level should be, so we try to set it. |
| 6108 | * Doing it this way makes the syscall restartable in case of EINTR |
| 6109 | */ |
| 6110 | rc = brightness_set(level); |
| 6111 | return (rc == -EINTR)? ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6112 | } |
| 6113 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6114 | static struct ibm_struct brightness_driver_data = { |
| 6115 | .name = "brightness", |
| 6116 | .read = brightness_read, |
| 6117 | .write = brightness_write, |
| 6118 | .exit = brightness_exit, |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 6119 | .suspend = brightness_suspend, |
| 6120 | .shutdown = brightness_shutdown, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6121 | }; |
| 6122 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6123 | /************************************************************************* |
| 6124 | * Volume subdriver |
| 6125 | */ |
| 6126 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6127 | static int volume_offset = 0x30; |
| 6128 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6129 | static int volume_read(char *p) |
| 6130 | { |
| 6131 | int len = 0; |
| 6132 | u8 level; |
| 6133 | |
| 6134 | if (!acpi_ec_read(volume_offset, &level)) { |
| 6135 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 6136 | } else { |
| 6137 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 6138 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 6139 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 6140 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 6141 | " (<level> is 0-15)\n"); |
| 6142 | } |
| 6143 | |
| 6144 | return len; |
| 6145 | } |
| 6146 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6147 | static int volume_write(char *buf) |
| 6148 | { |
| 6149 | int cmos_cmd, inc, i; |
| 6150 | u8 level, mute; |
| 6151 | int new_level, new_mute; |
| 6152 | char *cmd; |
| 6153 | |
| 6154 | while ((cmd = next_cmd(&buf))) { |
| 6155 | if (!acpi_ec_read(volume_offset, &level)) |
| 6156 | return -EIO; |
| 6157 | new_mute = mute = level & 0x40; |
| 6158 | new_level = level = level & 0xf; |
| 6159 | |
| 6160 | if (strlencmp(cmd, "up") == 0) { |
| 6161 | if (mute) |
| 6162 | new_mute = 0; |
| 6163 | else |
| 6164 | new_level = level == 15 ? 15 : level + 1; |
| 6165 | } else if (strlencmp(cmd, "down") == 0) { |
| 6166 | if (mute) |
| 6167 | new_mute = 0; |
| 6168 | else |
| 6169 | new_level = level == 0 ? 0 : level - 1; |
| 6170 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 6171 | new_level >= 0 && new_level <= 15) { |
| 6172 | /* new_level set */ |
| 6173 | } else if (strlencmp(cmd, "mute") == 0) { |
| 6174 | new_mute = 0x40; |
| 6175 | } else |
| 6176 | return -EINVAL; |
| 6177 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6178 | if (new_level != level) { |
| 6179 | /* mute doesn't change */ |
| 6180 | |
| 6181 | cmos_cmd = (new_level > level) ? |
| 6182 | TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6183 | inc = new_level > level ? 1 : -1; |
| 6184 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6185 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6186 | !acpi_ec_write(volume_offset, level))) |
| 6187 | return -EIO; |
| 6188 | |
| 6189 | for (i = level; i != new_level; i += inc) |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6190 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6191 | !acpi_ec_write(volume_offset, i + inc)) |
| 6192 | return -EIO; |
| 6193 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6194 | if (mute && |
| 6195 | (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
| 6196 | !acpi_ec_write(volume_offset, new_level + mute))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6197 | return -EIO; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6198 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6199 | } |
| 6200 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6201 | if (new_mute != mute) { |
| 6202 | /* level doesn't change */ |
| 6203 | |
| 6204 | cmos_cmd = (new_mute) ? |
| 6205 | TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6206 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 6207 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6208 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 6209 | return -EIO; |
| 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | return 0; |
| 6214 | } |
| 6215 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6216 | static struct ibm_struct volume_driver_data = { |
| 6217 | .name = "volume", |
| 6218 | .read = volume_read, |
| 6219 | .write = volume_write, |
| 6220 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6221 | |
| 6222 | /************************************************************************* |
| 6223 | * Fan subdriver |
| 6224 | */ |
| 6225 | |
| 6226 | /* |
| 6227 | * FAN ACCESS MODES |
| 6228 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6229 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6230 | * ACPI GFAN method: returns fan level |
| 6231 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6232 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6233 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6234 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6235 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6236 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 6237 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6238 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 6239 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6240 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6241 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6242 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 6243 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6244 | * |
| 6245 | * Fan speed changes of any sort (including those caused by the |
| 6246 | * disengaged mode) are usually done slowly by the firmware as the |
| 6247 | * maximum ammount of fan duty cycle change per second seems to be |
| 6248 | * limited. |
| 6249 | * |
| 6250 | * Reading is not available if GFAN exists. |
| 6251 | * Writing is not available if SFAN exists. |
| 6252 | * |
| 6253 | * Bits |
| 6254 | * 7 automatic mode engaged; |
| 6255 | * (default operation mode of the ThinkPad) |
| 6256 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6257 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6258 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6259 | * the tachometer while the fan controller ramps up |
| 6260 | * the speed (which can take up to a few *minutes*). |
| 6261 | * Speeds up fan to 100% duty-cycle, which is far above |
| 6262 | * the standard RPM levels. It is not impossible that |
| 6263 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6264 | * 5-3 unused in some models. Extra bits for fan level |
| 6265 | * in others, but still useless as all values above |
| 6266 | * 7 map to the same speed as level 7 in these models. |
| 6267 | * 2-0 fan level (0..7 usually) |
| 6268 | * 0x00 = stop |
| 6269 | * 0x07 = max (set when temperatures critical) |
| 6270 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6271 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6272 | * |
| 6273 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 6274 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 6275 | * does so, its initial value is meaningless (0x07). |
| 6276 | * |
| 6277 | * For firmware bugs, refer to: |
| 6278 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 6279 | * |
| 6280 | * ---- |
| 6281 | * |
| 6282 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 6283 | * Main fan tachometer reading (in RPM) |
| 6284 | * |
| 6285 | * This register is present on all ThinkPads with a new-style EC, and |
| 6286 | * it is known not to be present on the A21m/e, and T22, as there is |
| 6287 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 6288 | * ThinkPads from this same time period (and earlier) probably lack the |
| 6289 | * tachometer as well. |
| 6290 | * |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 6291 | * 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] | 6292 | * was never fixed by IBM to report the EC firmware version string |
| 6293 | * probably support the tachometer (like the early X models), so |
| 6294 | * detecting it is quite hard. We need more data to know for sure. |
| 6295 | * |
| 6296 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 6297 | * might result. |
| 6298 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 6299 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 6300 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6301 | * |
| 6302 | * For firmware bugs, refer to: |
| 6303 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 6304 | * |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6305 | * ---- |
| 6306 | * |
| 6307 | * ThinkPad EC register 0x31 bit 0 (only on select models) |
| 6308 | * |
| 6309 | * When bit 0 of EC register 0x31 is zero, the tachometer registers |
| 6310 | * show the speed of the main fan. When bit 0 of EC register 0x31 |
| 6311 | * is one, the tachometer registers show the speed of the auxiliary |
| 6312 | * fan. |
| 6313 | * |
| 6314 | * Fan control seems to affect both fans, regardless of the state |
| 6315 | * of this bit. |
| 6316 | * |
| 6317 | * So far, only the firmware for the X60/X61 non-tablet versions |
| 6318 | * seem to support this (firmware TP-7M). |
| 6319 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6320 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6321 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 6322 | * |
| 6323 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 6324 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 6325 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 6326 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 6327 | * |
| 6328 | * The speeds are stored on handles |
| 6329 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 6330 | * |
| 6331 | * There are three default speed sets, acessible as handles: |
| 6332 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 6333 | * |
| 6334 | * ACPI DSDT switches which set is in use depending on various |
| 6335 | * factors. |
| 6336 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 6337 | * 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] | 6338 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 6339 | * but the ACPI tables just mention level 7. |
| 6340 | */ |
| 6341 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6342 | enum { /* Fan control constants */ |
| 6343 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 6344 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 6345 | * 0x84 must be read before 0x85 */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6346 | fan_select_offset = 0x31, /* EC register 0x31 (Firmware 7M) |
| 6347 | bit 0 selects which fan is active */ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6348 | |
| 6349 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 6350 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 6351 | |
| 6352 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 6353 | }; |
| 6354 | |
| 6355 | enum fan_status_access_mode { |
| 6356 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 6357 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 6358 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 6359 | }; |
| 6360 | |
| 6361 | enum fan_control_access_mode { |
| 6362 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 6363 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 6364 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 6365 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 6366 | }; |
| 6367 | |
| 6368 | enum fan_control_commands { |
| 6369 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 6370 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 6371 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 6372 | * and also watchdog cmd */ |
| 6373 | }; |
| 6374 | |
| 6375 | static int fan_control_allowed; |
| 6376 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 6377 | static enum fan_status_access_mode fan_status_access_mode; |
| 6378 | static enum fan_control_access_mode fan_control_access_mode; |
| 6379 | static enum fan_control_commands fan_control_commands; |
| 6380 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6381 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6382 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 6383 | static u8 fan_control_resume_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6384 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6385 | |
| 6386 | static struct mutex fan_mutex; |
| 6387 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6388 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 6389 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 6390 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6391 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 6392 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6393 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 6394 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6395 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6396 | "JFNS", /* 770x-JL */ |
| 6397 | ); /* all others */ |
| 6398 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6399 | /* |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6400 | * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the |
| 6401 | * HFSP register at boot, so it contains 0x07 but the Thinkpad could |
| 6402 | * be in auto mode (0x80). |
| 6403 | * |
| 6404 | * This is corrected by any write to HFSP either by the driver, or |
| 6405 | * by the firmware. |
| 6406 | * |
| 6407 | * We assume 0x07 really means auto mode while this quirk is active, |
| 6408 | * as this is far more likely than the ThinkPad being in level 7, |
| 6409 | * which is only used by the firmware during thermal emergencies. |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6410 | * |
| 6411 | * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52), |
| 6412 | * TP-70 (T43, R52), which are known to be buggy. |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6413 | */ |
| 6414 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6415 | static void fan_quirk1_setup(void) |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6416 | { |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6417 | if (fan_control_initial_status == 0x07) { |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 6418 | printk(TPACPI_NOTICE |
| 6419 | "fan_init: initial fan status is unknown, " |
| 6420 | "assuming it is in auto mode\n"); |
| 6421 | tp_features.fan_ctrl_status_undef = 1; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6422 | } |
| 6423 | } |
| 6424 | |
| 6425 | static void fan_quirk1_handle(u8 *fan_status) |
| 6426 | { |
| 6427 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 6428 | if (*fan_status != fan_control_initial_status) { |
| 6429 | /* something changed the HFSP regisnter since |
| 6430 | * driver init time, so it is not undefined |
| 6431 | * anymore */ |
| 6432 | tp_features.fan_ctrl_status_undef = 0; |
| 6433 | } else { |
| 6434 | /* Return most likely status. In fact, it |
| 6435 | * might be the only possible status */ |
| 6436 | *fan_status = TP_EC_FAN_AUTO; |
| 6437 | } |
| 6438 | } |
| 6439 | } |
| 6440 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6441 | /* Select main fan on X60/X61, NOOP on others */ |
| 6442 | static bool fan_select_fan1(void) |
| 6443 | { |
| 6444 | if (tp_features.second_fan) { |
| 6445 | u8 val; |
| 6446 | |
| 6447 | if (ec_read(fan_select_offset, &val) < 0) |
| 6448 | return false; |
| 6449 | val &= 0xFEU; |
| 6450 | if (ec_write(fan_select_offset, val) < 0) |
| 6451 | return false; |
| 6452 | } |
| 6453 | return true; |
| 6454 | } |
| 6455 | |
| 6456 | /* Select secondary fan on X60/X61 */ |
| 6457 | static bool fan_select_fan2(void) |
| 6458 | { |
| 6459 | u8 val; |
| 6460 | |
| 6461 | if (!tp_features.second_fan) |
| 6462 | return false; |
| 6463 | |
| 6464 | if (ec_read(fan_select_offset, &val) < 0) |
| 6465 | return false; |
| 6466 | val |= 0x01U; |
| 6467 | if (ec_write(fan_select_offset, val) < 0) |
| 6468 | return false; |
| 6469 | |
| 6470 | return true; |
| 6471 | } |
| 6472 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6473 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6474 | * Call with fan_mutex held |
| 6475 | */ |
| 6476 | static void fan_update_desired_level(u8 status) |
| 6477 | { |
| 6478 | if ((status & |
| 6479 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 6480 | if (status > 7) |
| 6481 | fan_control_desired_level = 7; |
| 6482 | else |
| 6483 | fan_control_desired_level = status; |
| 6484 | } |
| 6485 | } |
| 6486 | |
| 6487 | static int fan_get_status(u8 *status) |
| 6488 | { |
| 6489 | u8 s; |
| 6490 | |
| 6491 | /* TODO: |
| 6492 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 6493 | |
| 6494 | switch (fan_status_access_mode) { |
| 6495 | case TPACPI_FAN_RD_ACPI_GFAN: |
| 6496 | /* 570, 600e/x, 770e, 770x */ |
| 6497 | |
| 6498 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
| 6499 | return -EIO; |
| 6500 | |
| 6501 | if (likely(status)) |
| 6502 | *status = s & 0x07; |
| 6503 | |
| 6504 | break; |
| 6505 | |
| 6506 | case TPACPI_FAN_RD_TPEC: |
| 6507 | /* all except 570, 600e/x, 770e, 770x */ |
| 6508 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 6509 | return -EIO; |
| 6510 | |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6511 | if (likely(status)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6512 | *status = s; |
Henrique de Moraes Holschuh | 1c2ece7 | 2009-01-11 03:01:08 -0200 | [diff] [blame] | 6513 | fan_quirk1_handle(status); |
| 6514 | } |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6515 | |
| 6516 | break; |
| 6517 | |
| 6518 | default: |
| 6519 | return -ENXIO; |
| 6520 | } |
| 6521 | |
| 6522 | return 0; |
| 6523 | } |
| 6524 | |
| 6525 | static int fan_get_status_safe(u8 *status) |
| 6526 | { |
| 6527 | int rc; |
| 6528 | u8 s; |
| 6529 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6530 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6531 | return -ERESTARTSYS; |
| 6532 | rc = fan_get_status(&s); |
| 6533 | if (!rc) |
| 6534 | fan_update_desired_level(s); |
| 6535 | mutex_unlock(&fan_mutex); |
| 6536 | |
| 6537 | if (status) |
| 6538 | *status = s; |
| 6539 | |
| 6540 | return rc; |
| 6541 | } |
| 6542 | |
| 6543 | static int fan_get_speed(unsigned int *speed) |
| 6544 | { |
| 6545 | u8 hi, lo; |
| 6546 | |
| 6547 | switch (fan_status_access_mode) { |
| 6548 | case TPACPI_FAN_RD_TPEC: |
| 6549 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6550 | if (unlikely(!fan_select_fan1())) |
| 6551 | return -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6552 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 6553 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 6554 | return -EIO; |
| 6555 | |
| 6556 | if (likely(speed)) |
| 6557 | *speed = (hi << 8) | lo; |
| 6558 | |
| 6559 | break; |
| 6560 | |
| 6561 | default: |
| 6562 | return -ENXIO; |
| 6563 | } |
| 6564 | |
| 6565 | return 0; |
| 6566 | } |
| 6567 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 6568 | static int fan2_get_speed(unsigned int *speed) |
| 6569 | { |
| 6570 | u8 hi, lo; |
| 6571 | bool rc; |
| 6572 | |
| 6573 | switch (fan_status_access_mode) { |
| 6574 | case TPACPI_FAN_RD_TPEC: |
| 6575 | /* all except 570, 600e/x, 770e, 770x */ |
| 6576 | if (unlikely(!fan_select_fan2())) |
| 6577 | return -EIO; |
| 6578 | rc = !acpi_ec_read(fan_rpm_offset, &lo) || |
| 6579 | !acpi_ec_read(fan_rpm_offset + 1, &hi); |
| 6580 | fan_select_fan1(); /* play it safe */ |
| 6581 | if (rc) |
| 6582 | return -EIO; |
| 6583 | |
| 6584 | if (likely(speed)) |
| 6585 | *speed = (hi << 8) | lo; |
| 6586 | |
| 6587 | break; |
| 6588 | |
| 6589 | default: |
| 6590 | return -ENXIO; |
| 6591 | } |
| 6592 | |
| 6593 | return 0; |
| 6594 | } |
| 6595 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6596 | static int fan_set_level(int level) |
| 6597 | { |
| 6598 | if (!fan_control_allowed) |
| 6599 | return -EPERM; |
| 6600 | |
| 6601 | switch (fan_control_access_mode) { |
| 6602 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6603 | if (level >= 0 && level <= 7) { |
| 6604 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 6605 | return -EIO; |
| 6606 | } else |
| 6607 | return -EINVAL; |
| 6608 | break; |
| 6609 | |
| 6610 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6611 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 6612 | if (!(level & TP_EC_FAN_AUTO) && |
| 6613 | !(level & TP_EC_FAN_FULLSPEED) && |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6614 | ((level < 0) || (level > 7))) |
| 6615 | return -EINVAL; |
| 6616 | |
| 6617 | /* safety net should the EC not support AUTO |
| 6618 | * or FULLSPEED mode bits and just ignore them */ |
| 6619 | if (level & TP_EC_FAN_FULLSPEED) |
| 6620 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 6621 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6622 | level |= 4; /* safety min speed 4 */ |
| 6623 | |
| 6624 | if (!acpi_ec_write(fan_status_offset, level)) |
| 6625 | return -EIO; |
| 6626 | else |
| 6627 | tp_features.fan_ctrl_status_undef = 0; |
| 6628 | break; |
| 6629 | |
| 6630 | default: |
| 6631 | return -ENXIO; |
| 6632 | } |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6633 | |
| 6634 | vdbg_printk(TPACPI_DBG_FAN, |
| 6635 | "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] | 6636 | return 0; |
| 6637 | } |
| 6638 | |
| 6639 | static int fan_set_level_safe(int level) |
| 6640 | { |
| 6641 | int rc; |
| 6642 | |
| 6643 | if (!fan_control_allowed) |
| 6644 | return -EPERM; |
| 6645 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6646 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6647 | return -ERESTARTSYS; |
| 6648 | |
| 6649 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 6650 | level = fan_control_desired_level; |
| 6651 | |
| 6652 | rc = fan_set_level(level); |
| 6653 | if (!rc) |
| 6654 | fan_update_desired_level(level); |
| 6655 | |
| 6656 | mutex_unlock(&fan_mutex); |
| 6657 | return rc; |
| 6658 | } |
| 6659 | |
| 6660 | static int fan_set_enable(void) |
| 6661 | { |
| 6662 | u8 s; |
| 6663 | int rc; |
| 6664 | |
| 6665 | if (!fan_control_allowed) |
| 6666 | return -EPERM; |
| 6667 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6668 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6669 | return -ERESTARTSYS; |
| 6670 | |
| 6671 | switch (fan_control_access_mode) { |
| 6672 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6673 | case TPACPI_FAN_WR_TPEC: |
| 6674 | rc = fan_get_status(&s); |
| 6675 | if (rc < 0) |
| 6676 | break; |
| 6677 | |
| 6678 | /* Don't go out of emergency fan mode */ |
| 6679 | if (s != 7) { |
| 6680 | s &= 0x07; |
| 6681 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 6682 | } |
| 6683 | |
| 6684 | if (!acpi_ec_write(fan_status_offset, s)) |
| 6685 | rc = -EIO; |
| 6686 | else { |
| 6687 | tp_features.fan_ctrl_status_undef = 0; |
| 6688 | rc = 0; |
| 6689 | } |
| 6690 | break; |
| 6691 | |
| 6692 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6693 | rc = fan_get_status(&s); |
| 6694 | if (rc < 0) |
| 6695 | break; |
| 6696 | |
| 6697 | s &= 0x07; |
| 6698 | |
| 6699 | /* Set fan to at least level 4 */ |
| 6700 | s |= 4; |
| 6701 | |
| 6702 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6703 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6704 | else |
| 6705 | rc = 0; |
| 6706 | break; |
| 6707 | |
| 6708 | default: |
| 6709 | rc = -ENXIO; |
| 6710 | } |
| 6711 | |
| 6712 | mutex_unlock(&fan_mutex); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6713 | |
| 6714 | if (!rc) |
| 6715 | vdbg_printk(TPACPI_DBG_FAN, |
| 6716 | "fan control: set fan control register to 0x%02x\n", |
| 6717 | s); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6718 | return rc; |
| 6719 | } |
| 6720 | |
| 6721 | static int fan_set_disable(void) |
| 6722 | { |
| 6723 | int rc; |
| 6724 | |
| 6725 | if (!fan_control_allowed) |
| 6726 | return -EPERM; |
| 6727 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6728 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6729 | return -ERESTARTSYS; |
| 6730 | |
| 6731 | rc = 0; |
| 6732 | switch (fan_control_access_mode) { |
| 6733 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6734 | case TPACPI_FAN_WR_TPEC: |
| 6735 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 6736 | rc = -EIO; |
| 6737 | else { |
| 6738 | fan_control_desired_level = 0; |
| 6739 | tp_features.fan_ctrl_status_undef = 0; |
| 6740 | } |
| 6741 | break; |
| 6742 | |
| 6743 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 6744 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 6745 | rc = -EIO; |
| 6746 | else |
| 6747 | fan_control_desired_level = 0; |
| 6748 | break; |
| 6749 | |
| 6750 | default: |
| 6751 | rc = -ENXIO; |
| 6752 | } |
| 6753 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6754 | if (!rc) |
| 6755 | vdbg_printk(TPACPI_DBG_FAN, |
| 6756 | "fan control: set fan control register to 0\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6757 | |
| 6758 | mutex_unlock(&fan_mutex); |
| 6759 | return rc; |
| 6760 | } |
| 6761 | |
| 6762 | static int fan_set_speed(int speed) |
| 6763 | { |
| 6764 | int rc; |
| 6765 | |
| 6766 | if (!fan_control_allowed) |
| 6767 | return -EPERM; |
| 6768 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6769 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6770 | return -ERESTARTSYS; |
| 6771 | |
| 6772 | rc = 0; |
| 6773 | switch (fan_control_access_mode) { |
| 6774 | case TPACPI_FAN_WR_ACPI_FANS: |
| 6775 | if (speed >= 0 && speed <= 65535) { |
| 6776 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 6777 | speed, speed, speed)) |
| 6778 | rc = -EIO; |
| 6779 | } else |
| 6780 | rc = -EINVAL; |
| 6781 | break; |
| 6782 | |
| 6783 | default: |
| 6784 | rc = -ENXIO; |
| 6785 | } |
| 6786 | |
| 6787 | mutex_unlock(&fan_mutex); |
| 6788 | return rc; |
| 6789 | } |
| 6790 | |
| 6791 | static void fan_watchdog_reset(void) |
| 6792 | { |
| 6793 | static int fan_watchdog_active; |
| 6794 | |
| 6795 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 6796 | return; |
| 6797 | |
| 6798 | if (fan_watchdog_active) |
| 6799 | cancel_delayed_work(&fan_watchdog_task); |
| 6800 | |
| 6801 | if (fan_watchdog_maxinterval > 0 && |
| 6802 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
| 6803 | fan_watchdog_active = 1; |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 6804 | if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task, |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6805 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 6806 | * 1000))) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6807 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 6808 | "failed to queue the fan watchdog, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6809 | "watchdog will not trigger\n"); |
| 6810 | } |
| 6811 | } else |
| 6812 | fan_watchdog_active = 0; |
| 6813 | } |
| 6814 | |
| 6815 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 6816 | { |
| 6817 | int rc; |
| 6818 | |
| 6819 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 6820 | return; |
| 6821 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6822 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6823 | rc = fan_set_enable(); |
| 6824 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6825 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6826 | "will try again later...\n", -rc); |
| 6827 | /* reschedule for later */ |
| 6828 | fan_watchdog_reset(); |
| 6829 | } |
| 6830 | } |
| 6831 | |
| 6832 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6833 | * SYSFS fan layout: hwmon compatible (device) |
| 6834 | * |
| 6835 | * pwm*_enable: |
| 6836 | * 0: "disengaged" mode |
| 6837 | * 1: manual mode |
| 6838 | * 2: native EC "auto" mode (recommended, hardware default) |
| 6839 | * |
| 6840 | * pwm*: set speed in manual mode, ignored otherwise. |
| 6841 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 6842 | * interpolation. |
| 6843 | * |
| 6844 | * fan*_input: tachometer reading, RPM |
| 6845 | * |
| 6846 | * |
| 6847 | * SYSFS fan layout: extensions |
| 6848 | * |
| 6849 | * fan_watchdog (driver): |
| 6850 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 6851 | */ |
| 6852 | |
| 6853 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 6854 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 6855 | struct device_attribute *attr, |
| 6856 | char *buf) |
| 6857 | { |
| 6858 | int res, mode; |
| 6859 | u8 status; |
| 6860 | |
| 6861 | res = fan_get_status_safe(&status); |
| 6862 | if (res) |
| 6863 | return res; |
| 6864 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6865 | if (status & TP_EC_FAN_FULLSPEED) { |
| 6866 | mode = 0; |
| 6867 | } else if (status & TP_EC_FAN_AUTO) { |
| 6868 | mode = 2; |
| 6869 | } else |
| 6870 | mode = 1; |
| 6871 | |
| 6872 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 6873 | } |
| 6874 | |
| 6875 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 6876 | struct device_attribute *attr, |
| 6877 | const char *buf, size_t count) |
| 6878 | { |
| 6879 | unsigned long t; |
| 6880 | int res, level; |
| 6881 | |
| 6882 | if (parse_strtoul(buf, 2, &t)) |
| 6883 | return -EINVAL; |
| 6884 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6885 | tpacpi_disclose_usertask("hwmon pwm1_enable", |
| 6886 | "set fan mode to %lu\n", t); |
| 6887 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6888 | switch (t) { |
| 6889 | case 0: |
| 6890 | level = TP_EC_FAN_FULLSPEED; |
| 6891 | break; |
| 6892 | case 1: |
| 6893 | level = TPACPI_FAN_LAST_LEVEL; |
| 6894 | break; |
| 6895 | case 2: |
| 6896 | level = TP_EC_FAN_AUTO; |
| 6897 | break; |
| 6898 | case 3: |
| 6899 | /* reserved for software-controlled auto mode */ |
| 6900 | return -ENOSYS; |
| 6901 | default: |
| 6902 | return -EINVAL; |
| 6903 | } |
| 6904 | |
| 6905 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 6906 | if (res == -ENXIO) |
| 6907 | return -EINVAL; |
| 6908 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6909 | return res; |
| 6910 | |
| 6911 | fan_watchdog_reset(); |
| 6912 | |
| 6913 | return count; |
| 6914 | } |
| 6915 | |
| 6916 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 6917 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 6918 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 6919 | |
| 6920 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 6921 | static ssize_t fan_pwm1_show(struct device *dev, |
| 6922 | struct device_attribute *attr, |
| 6923 | char *buf) |
| 6924 | { |
| 6925 | int res; |
| 6926 | u8 status; |
| 6927 | |
| 6928 | res = fan_get_status_safe(&status); |
| 6929 | if (res) |
| 6930 | return res; |
| 6931 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6932 | if ((status & |
| 6933 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 6934 | status = fan_control_desired_level; |
| 6935 | |
| 6936 | if (status > 7) |
| 6937 | status = 7; |
| 6938 | |
| 6939 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 6940 | } |
| 6941 | |
| 6942 | static ssize_t fan_pwm1_store(struct device *dev, |
| 6943 | struct device_attribute *attr, |
| 6944 | const char *buf, size_t count) |
| 6945 | { |
| 6946 | unsigned long s; |
| 6947 | int rc; |
| 6948 | u8 status, newlevel; |
| 6949 | |
| 6950 | if (parse_strtoul(buf, 255, &s)) |
| 6951 | return -EINVAL; |
| 6952 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 6953 | tpacpi_disclose_usertask("hwmon pwm1", |
| 6954 | "set fan speed to %lu\n", s); |
| 6955 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6956 | /* scale down from 0-255 to 0-7 */ |
| 6957 | newlevel = (s >> 5) & 0x07; |
| 6958 | |
Henrique de Moraes Holschuh | 7646ea8 | 2009-01-11 03:01:04 -0200 | [diff] [blame] | 6959 | if (mutex_lock_killable(&fan_mutex)) |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 6960 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6961 | |
| 6962 | rc = fan_get_status(&status); |
| 6963 | if (!rc && (status & |
| 6964 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 6965 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 6966 | if (rc == -ENXIO) |
| 6967 | rc = -EINVAL; |
| 6968 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6969 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 6970 | fan_watchdog_reset(); |
| 6971 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | mutex_unlock(&fan_mutex); |
| 6975 | return (rc)? rc : count; |
| 6976 | } |
| 6977 | |
| 6978 | static struct device_attribute dev_attr_fan_pwm1 = |
| 6979 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 6980 | fan_pwm1_show, fan_pwm1_store); |
| 6981 | |
| 6982 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 6983 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 6984 | struct device_attribute *attr, |
| 6985 | char *buf) |
| 6986 | { |
| 6987 | int res; |
| 6988 | unsigned int speed; |
| 6989 | |
| 6990 | res = fan_get_speed(&speed); |
| 6991 | if (res < 0) |
| 6992 | return res; |
| 6993 | |
| 6994 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 6995 | } |
| 6996 | |
| 6997 | static struct device_attribute dev_attr_fan_fan1_input = |
| 6998 | __ATTR(fan1_input, S_IRUGO, |
| 6999 | fan_fan1_input_show, NULL); |
| 7000 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7001 | /* sysfs fan fan2_input ------------------------------------------------ */ |
| 7002 | static ssize_t fan_fan2_input_show(struct device *dev, |
| 7003 | struct device_attribute *attr, |
| 7004 | char *buf) |
| 7005 | { |
| 7006 | int res; |
| 7007 | unsigned int speed; |
| 7008 | |
| 7009 | res = fan2_get_speed(&speed); |
| 7010 | if (res < 0) |
| 7011 | return res; |
| 7012 | |
| 7013 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 7014 | } |
| 7015 | |
| 7016 | static struct device_attribute dev_attr_fan_fan2_input = |
| 7017 | __ATTR(fan2_input, S_IRUGO, |
| 7018 | fan_fan2_input_show, NULL); |
| 7019 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7020 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7021 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 7022 | char *buf) |
| 7023 | { |
| 7024 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 7025 | } |
| 7026 | |
| 7027 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 7028 | const char *buf, size_t count) |
| 7029 | { |
| 7030 | unsigned long t; |
| 7031 | |
| 7032 | if (parse_strtoul(buf, 120, &t)) |
| 7033 | return -EINVAL; |
| 7034 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7035 | if (!fan_control_allowed) |
| 7036 | return -EPERM; |
| 7037 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7038 | fan_watchdog_maxinterval = t; |
| 7039 | fan_watchdog_reset(); |
| 7040 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7041 | tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t); |
| 7042 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7043 | return count; |
| 7044 | } |
| 7045 | |
| 7046 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 7047 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 7048 | |
| 7049 | /* --------------------------------------------------------------------- */ |
| 7050 | static struct attribute *fan_attributes[] = { |
| 7051 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 7052 | &dev_attr_fan_fan1_input.attr, |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7053 | NULL, /* for fan2_input */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7054 | NULL |
| 7055 | }; |
| 7056 | |
| 7057 | static const struct attribute_group fan_attr_group = { |
| 7058 | .attrs = fan_attributes, |
| 7059 | }; |
| 7060 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7061 | #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */ |
| 7062 | #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */ |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7063 | |
| 7064 | #define TPACPI_FAN_QI(__id1, __id2, __quirks) \ |
| 7065 | { .vendor = PCI_VENDOR_ID_IBM, \ |
| 7066 | .bios = TPACPI_MATCH_ANY, \ |
| 7067 | .ec = TPID(__id1, __id2), \ |
| 7068 | .quirks = __quirks } |
| 7069 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7070 | #define TPACPI_FAN_QL(__id1, __id2, __quirks) \ |
| 7071 | { .vendor = PCI_VENDOR_ID_LENOVO, \ |
| 7072 | .bios = TPACPI_MATCH_ANY, \ |
| 7073 | .ec = TPID(__id1, __id2), \ |
| 7074 | .quirks = __quirks } |
| 7075 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7076 | static const struct tpacpi_quirk fan_quirk_table[] __initconst = { |
| 7077 | TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1), |
| 7078 | TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1), |
| 7079 | TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1), |
| 7080 | TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1), |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7081 | TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN), |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7082 | }; |
| 7083 | |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7084 | #undef TPACPI_FAN_QL |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7085 | #undef TPACPI_FAN_QI |
| 7086 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7087 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7088 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7089 | int rc; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7090 | unsigned long quirks; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7091 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7092 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7093 | "initializing fan subdriver\n"); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7094 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 7095 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7096 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 7097 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7098 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7099 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 7100 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7101 | tp_features.second_fan = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7102 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7103 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7104 | TPACPI_ACPIHANDLE_INIT(fans); |
| 7105 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 7106 | TPACPI_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7107 | |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7108 | quirks = tpacpi_check_quirks(fan_quirk_table, |
| 7109 | ARRAY_SIZE(fan_quirk_table)); |
| 7110 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7111 | if (gfan_handle) { |
| 7112 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7113 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7114 | } else { |
| 7115 | /* all other ThinkPads: note that even old-style |
| 7116 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7117 | if (likely(acpi_ec_read(fan_status_offset, |
| 7118 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7119 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 7d95a3d | 2009-05-30 13:25:06 -0300 | [diff] [blame] | 7120 | if (quirks & TPACPI_FAN_Q1) |
| 7121 | fan_quirk1_setup(); |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7122 | if (quirks & TPACPI_FAN_2FAN) { |
| 7123 | tp_features.second_fan = 1; |
| 7124 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7125 | "secondary fan support enabled\n"); |
| 7126 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7127 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7128 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7129 | "ThinkPad ACPI EC access misbehaving, " |
| 7130 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7131 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7132 | } |
| 7133 | } |
| 7134 | |
| 7135 | if (sfan_handle) { |
| 7136 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7137 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 7138 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7139 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7140 | } else { |
| 7141 | if (!gfan_handle) { |
| 7142 | /* gfan without sfan means no fan control */ |
| 7143 | /* all other models implement TP EC 0x2f control */ |
| 7144 | |
| 7145 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7146 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7147 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7148 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7149 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7150 | TPACPI_FAN_CMD_SPEED | |
| 7151 | TPACPI_FAN_CMD_LEVEL | |
| 7152 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7153 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7154 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7155 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7156 | TPACPI_FAN_CMD_LEVEL | |
| 7157 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 7158 | } |
| 7159 | } |
| 7160 | } |
| 7161 | |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7162 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
| 7163 | "fan is %s, modes %d, %d\n", |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7164 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 7165 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 7166 | fan_status_access_mode, fan_control_access_mode); |
| 7167 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7168 | /* fan control master switch */ |
| 7169 | if (!fan_control_allowed) { |
| 7170 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 7171 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7172 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7173 | "fan control features disabled by parameter\n"); |
| 7174 | } |
| 7175 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7176 | /* update fan_control_desired_level */ |
| 7177 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 7178 | fan_get_status_safe(NULL); |
| 7179 | |
| 7180 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 7181 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | d737724 | 2009-06-18 00:40:17 -0300 | [diff] [blame] | 7182 | if (tp_features.second_fan) { |
| 7183 | /* attach second fan tachometer */ |
| 7184 | fan_attributes[ARRAY_SIZE(fan_attributes)-2] = |
| 7185 | &dev_attr_fan_fan2_input.attr; |
| 7186 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7187 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7188 | &fan_attr_group); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7189 | if (rc < 0) |
| 7190 | return rc; |
Henrique de Moraes Holschuh | 9c0a76e | 2008-06-03 23:36:10 -0300 | [diff] [blame] | 7191 | |
| 7192 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
| 7193 | &driver_attr_fan_watchdog); |
| 7194 | if (rc < 0) { |
| 7195 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
| 7196 | &fan_attr_group); |
| 7197 | return rc; |
| 7198 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7199 | return 0; |
| 7200 | } else |
| 7201 | return 1; |
| 7202 | } |
| 7203 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7204 | static void fan_exit(void) |
| 7205 | { |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7206 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_FAN, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7207 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7208 | |
| 7209 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7210 | 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] | 7211 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 7212 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7213 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7214 | cancel_delayed_work(&fan_watchdog_task); |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 7215 | flush_workqueue(tpacpi_wq); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7216 | } |
| 7217 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7218 | static void fan_suspend(pm_message_t state) |
| 7219 | { |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7220 | int rc; |
| 7221 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7222 | if (!fan_control_allowed) |
| 7223 | return; |
| 7224 | |
| 7225 | /* Store fan status in cache */ |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7226 | fan_control_resume_level = 0; |
| 7227 | rc = fan_get_status_safe(&fan_control_resume_level); |
| 7228 | if (rc < 0) |
| 7229 | printk(TPACPI_NOTICE |
| 7230 | "failed to read fan level for later " |
| 7231 | "restore during resume: %d\n", rc); |
| 7232 | |
| 7233 | /* if it is undefined, don't attempt to restore it. |
| 7234 | * KEEP THIS LAST */ |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7235 | if (tp_features.fan_ctrl_status_undef) |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7236 | fan_control_resume_level = 0; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7237 | } |
| 7238 | |
| 7239 | static void fan_resume(void) |
| 7240 | { |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7241 | u8 current_level = 7; |
| 7242 | bool do_set = false; |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7243 | int rc; |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7244 | |
| 7245 | /* DSDT *always* updates status on resume */ |
| 7246 | tp_features.fan_ctrl_status_undef = 0; |
| 7247 | |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7248 | if (!fan_control_allowed || |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7249 | !fan_control_resume_level || |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7250 | (fan_get_status_safe(¤t_level) < 0)) |
| 7251 | return; |
| 7252 | |
| 7253 | switch (fan_control_access_mode) { |
| 7254 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7255 | /* never decrease fan level */ |
| 7256 | do_set = (fan_control_resume_level > current_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7257 | break; |
| 7258 | case TPACPI_FAN_WR_ACPI_FANS: |
| 7259 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7260 | /* never decrease fan level, scale is: |
| 7261 | * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO |
| 7262 | * |
| 7263 | * We expect the firmware to set either 7 or AUTO, but we |
| 7264 | * handle FULLSPEED out of paranoia. |
| 7265 | * |
| 7266 | * So, we can safely only restore FULLSPEED or 7, anything |
| 7267 | * else could slow the fan. Restoring AUTO is useless, at |
| 7268 | * best that's exactly what the DSDT already set (it is the |
| 7269 | * slower it uses). |
| 7270 | * |
| 7271 | * Always keep in mind that the DSDT *will* have set the |
| 7272 | * fans to what the vendor supposes is the best level. We |
| 7273 | * muck with it only to speed the fan up. |
| 7274 | */ |
| 7275 | if (fan_control_resume_level != 7 && |
| 7276 | !(fan_control_resume_level & TP_EC_FAN_FULLSPEED)) |
| 7277 | return; |
| 7278 | else |
| 7279 | do_set = !(current_level & TP_EC_FAN_FULLSPEED) && |
| 7280 | (current_level != fan_control_resume_level); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7281 | break; |
| 7282 | default: |
| 7283 | return; |
| 7284 | } |
| 7285 | if (do_set) { |
| 7286 | printk(TPACPI_NOTICE |
| 7287 | "restoring fan level to 0x%02x\n", |
Henrique de Moraes Holschuh | 0081b16 | 2008-11-09 10:54:02 -0200 | [diff] [blame] | 7288 | fan_control_resume_level); |
| 7289 | rc = fan_set_level_safe(fan_control_resume_level); |
| 7290 | if (rc < 0) |
| 7291 | printk(TPACPI_NOTICE |
| 7292 | "failed to restore fan level: %d\n", rc); |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7293 | } |
| 7294 | } |
| 7295 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7296 | static int fan_read(char *p) |
| 7297 | { |
| 7298 | int len = 0; |
| 7299 | int rc; |
| 7300 | u8 status; |
| 7301 | unsigned int speed = 0; |
| 7302 | |
| 7303 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7304 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7305 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7306 | rc = fan_get_status_safe(&status); |
| 7307 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7308 | return rc; |
| 7309 | |
| 7310 | len += sprintf(p + len, "status:\t\t%s\n" |
| 7311 | "level:\t\t%d\n", |
| 7312 | (status != 0) ? "enabled" : "disabled", status); |
| 7313 | break; |
| 7314 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7315 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7316 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7317 | rc = fan_get_status_safe(&status); |
| 7318 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7319 | return rc; |
| 7320 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7321 | len += sprintf(p + len, "status:\t\t%s\n", |
| 7322 | (status != 0) ? "enabled" : "disabled"); |
| 7323 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7324 | rc = fan_get_speed(&speed); |
| 7325 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7326 | return rc; |
| 7327 | |
| 7328 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 7329 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7330 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7331 | /* Disengaged mode takes precedence */ |
| 7332 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7333 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7334 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 7335 | else |
| 7336 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 7337 | break; |
| 7338 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7339 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7340 | default: |
| 7341 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 7342 | } |
| 7343 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7344 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7345 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 7346 | |
| 7347 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7348 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7349 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 7350 | break; |
| 7351 | |
| 7352 | default: |
| 7353 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7354 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7355 | break; |
| 7356 | } |
| 7357 | } |
| 7358 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7359 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7360 | len += sprintf(p + len, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7361 | "commands:\twatchdog <timeout> (<timeout> " |
| 7362 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7363 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7364 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7365 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 7366 | " (<speed> is 0-65535)\n"); |
| 7367 | |
| 7368 | return len; |
| 7369 | } |
| 7370 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7371 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 7372 | { |
| 7373 | int level; |
| 7374 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7375 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7376 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 7377 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7378 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7379 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7380 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7381 | return 0; |
| 7382 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7383 | *rc = fan_set_level_safe(level); |
| 7384 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7385 | printk(TPACPI_ERR "level command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7386 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7387 | else if (!*rc) |
| 7388 | tpacpi_disclose_usertask("procfs fan", |
| 7389 | "set level to %d\n", level); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7390 | |
| 7391 | return 1; |
| 7392 | } |
| 7393 | |
| 7394 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 7395 | { |
| 7396 | if (strlencmp(cmd, "enable") != 0) |
| 7397 | return 0; |
| 7398 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7399 | *rc = fan_set_enable(); |
| 7400 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7401 | printk(TPACPI_ERR "enable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7402 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7403 | else if (!*rc) |
| 7404 | tpacpi_disclose_usertask("procfs fan", "enable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7405 | |
| 7406 | return 1; |
| 7407 | } |
| 7408 | |
| 7409 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 7410 | { |
| 7411 | if (strlencmp(cmd, "disable") != 0) |
| 7412 | return 0; |
| 7413 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7414 | *rc = fan_set_disable(); |
| 7415 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7416 | printk(TPACPI_ERR "disable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7417 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7418 | else if (!*rc) |
| 7419 | tpacpi_disclose_usertask("procfs fan", "disable\n"); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7420 | |
| 7421 | return 1; |
| 7422 | } |
| 7423 | |
| 7424 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 7425 | { |
| 7426 | int speed; |
| 7427 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7428 | /* TODO: |
| 7429 | * Support speed <low> <medium> <high> ? */ |
| 7430 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7431 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 7432 | return 0; |
| 7433 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7434 | *rc = fan_set_speed(speed); |
| 7435 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7436 | printk(TPACPI_ERR "speed command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7437 | "access mode %d", fan_control_access_mode); |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7438 | else if (!*rc) |
| 7439 | tpacpi_disclose_usertask("procfs fan", |
| 7440 | "set speed to %d\n", speed); |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7441 | |
| 7442 | return 1; |
| 7443 | } |
| 7444 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7445 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 7446 | { |
| 7447 | int interval; |
| 7448 | |
| 7449 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 7450 | return 0; |
| 7451 | |
| 7452 | if (interval < 0 || interval > 120) |
| 7453 | *rc = -EINVAL; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7454 | else { |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7455 | fan_watchdog_maxinterval = interval; |
Henrique de Moraes Holschuh | 74a60c0 | 2009-04-04 04:25:52 +0000 | [diff] [blame] | 7456 | tpacpi_disclose_usertask("procfs fan", |
| 7457 | "set watchdog timer to %d\n", |
| 7458 | interval); |
| 7459 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7460 | |
| 7461 | return 1; |
| 7462 | } |
| 7463 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7464 | static int fan_write(char *buf) |
| 7465 | { |
| 7466 | char *cmd; |
| 7467 | int rc = 0; |
| 7468 | |
| 7469 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7470 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7471 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7472 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7473 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7474 | fan_write_cmd_disable(cmd, &rc) || |
| 7475 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 7476 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7477 | fan_write_cmd_speed(cmd, &rc)) |
| 7478 | ) |
| 7479 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 7480 | else if (!rc) |
| 7481 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7482 | } |
| 7483 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 7484 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7485 | } |
| 7486 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7487 | static struct ibm_struct fan_driver_data = { |
| 7488 | .name = "fan", |
| 7489 | .read = fan_read, |
| 7490 | .write = fan_write, |
| 7491 | .exit = fan_exit, |
Henrique de Moraes Holschuh | 75700e5 | 2008-10-18 14:23:52 -0300 | [diff] [blame] | 7492 | .suspend = fan_suspend, |
| 7493 | .resume = fan_resume, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7494 | }; |
| 7495 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7496 | /**************************************************************************** |
| 7497 | **************************************************************************** |
| 7498 | * |
| 7499 | * Infrastructure |
| 7500 | * |
| 7501 | **************************************************************************** |
| 7502 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7503 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7504 | /* sysfs name ---------------------------------------------------------- */ |
| 7505 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 7506 | struct device_attribute *attr, |
| 7507 | char *buf) |
| 7508 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7509 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 7513 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 7514 | |
| 7515 | /* --------------------------------------------------------------------- */ |
| 7516 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7517 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 7518 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7519 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7520 | /* |
| 7521 | * Module and infrastructure proble, init and exit handling |
| 7522 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7523 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7524 | static int force_load; |
| 7525 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7526 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7527 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7528 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7529 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7530 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7531 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7532 | } |
| 7533 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 7534 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7535 | static void ibm_exit(struct ibm_struct *ibm) |
| 7536 | { |
| 7537 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 7538 | |
| 7539 | list_del_init(&ibm->all_drivers); |
| 7540 | |
| 7541 | if (ibm->flags.acpi_notify_installed) { |
| 7542 | dbg_printk(TPACPI_DBG_EXIT, |
| 7543 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 7544 | BUG_ON(!ibm->acpi); |
| 7545 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 7546 | ibm->acpi->type, |
| 7547 | dispatch_acpi_notify); |
| 7548 | ibm->flags.acpi_notify_installed = 0; |
| 7549 | ibm->flags.acpi_notify_installed = 0; |
| 7550 | } |
| 7551 | |
| 7552 | if (ibm->flags.proc_created) { |
| 7553 | dbg_printk(TPACPI_DBG_EXIT, |
| 7554 | "%s: remove_proc_entry\n", ibm->name); |
| 7555 | remove_proc_entry(ibm->name, proc_dir); |
| 7556 | ibm->flags.proc_created = 0; |
| 7557 | } |
| 7558 | |
| 7559 | if (ibm->flags.acpi_driver_registered) { |
| 7560 | dbg_printk(TPACPI_DBG_EXIT, |
| 7561 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 7562 | BUG_ON(!ibm->acpi); |
| 7563 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 7564 | kfree(ibm->acpi->driver); |
| 7565 | ibm->acpi->driver = NULL; |
| 7566 | ibm->flags.acpi_driver_registered = 0; |
| 7567 | } |
| 7568 | |
| 7569 | if (ibm->flags.init_called && ibm->exit) { |
| 7570 | ibm->exit(); |
| 7571 | ibm->flags.init_called = 0; |
| 7572 | } |
| 7573 | |
| 7574 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 7575 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 7576 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7577 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7578 | { |
| 7579 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7580 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7581 | struct proc_dir_entry *entry; |
| 7582 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7583 | BUG_ON(ibm == NULL); |
| 7584 | |
| 7585 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 7586 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7587 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7588 | return 0; |
| 7589 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7590 | dbg_printk(TPACPI_DBG_INIT, |
| 7591 | "probing for %s\n", ibm->name); |
| 7592 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7593 | if (iibm->init) { |
| 7594 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7595 | if (ret > 0) |
| 7596 | return 0; /* probe failed */ |
| 7597 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7598 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7599 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7600 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7601 | } |
| 7602 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7603 | if (ibm->acpi) { |
| 7604 | if (ibm->acpi->hid) { |
| 7605 | ret = register_tpacpi_subdriver(ibm); |
| 7606 | if (ret) |
| 7607 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7608 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7609 | |
| 7610 | if (ibm->acpi->notify) { |
| 7611 | ret = setup_acpi_notify(ibm); |
| 7612 | if (ret == -ENODEV) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7613 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7614 | ibm->name); |
| 7615 | ret = 0; |
| 7616 | goto err_out; |
| 7617 | } |
| 7618 | if (ret < 0) |
| 7619 | goto err_out; |
| 7620 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7621 | } |
| 7622 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7623 | dbg_printk(TPACPI_DBG_INIT, |
| 7624 | "%s installed\n", ibm->name); |
| 7625 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7626 | if (ibm->read) { |
| 7627 | entry = create_proc_entry(ibm->name, |
| 7628 | S_IFREG | S_IRUGO | S_IWUSR, |
| 7629 | proc_dir); |
| 7630 | if (!entry) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7631 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7632 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7633 | ret = -ENODEV; |
| 7634 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7635 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7636 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7637 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7638 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 7639 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 7640 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 7641 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7642 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7643 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 7644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7645 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7646 | |
| 7647 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 7648 | dbg_printk(TPACPI_DBG_INIT, |
| 7649 | "%s: at error exit path with result %d\n", |
| 7650 | ibm->name, ret); |
| 7651 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7652 | ibm_exit(ibm); |
| 7653 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7654 | } |
| 7655 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7656 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7657 | |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7658 | static bool __pure __init tpacpi_is_fw_digit(const char c) |
| 7659 | { |
| 7660 | return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); |
| 7661 | } |
| 7662 | |
| 7663 | /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */ |
| 7664 | static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, |
| 7665 | const char t) |
| 7666 | { |
| 7667 | return s && strlen(s) >= 8 && |
| 7668 | tpacpi_is_fw_digit(s[0]) && |
| 7669 | tpacpi_is_fw_digit(s[1]) && |
| 7670 | s[2] == t && s[3] == 'T' && |
| 7671 | tpacpi_is_fw_digit(s[4]) && |
| 7672 | tpacpi_is_fw_digit(s[5]) && |
| 7673 | s[6] == 'W' && s[7] == 'W'; |
| 7674 | } |
| 7675 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7676 | /* returns 0 - probe ok, or < 0 - probe error. |
| 7677 | * Probe ok doesn't mean thinkpad found. |
| 7678 | * On error, kfree() cleanup on tp->* is not performed, caller must do it */ |
| 7679 | static int __must_check __init get_thinkpad_model_data( |
| 7680 | struct thinkpad_id_data *tp) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7681 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 7682 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7683 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7684 | char const *s; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7685 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7686 | if (!tp) |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7687 | return -EINVAL; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7688 | |
| 7689 | memset(tp, 0, sizeof(*tp)); |
| 7690 | |
| 7691 | if (dmi_name_in_vendors("IBM")) |
| 7692 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 7693 | else if (dmi_name_in_vendors("LENOVO")) |
| 7694 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 7695 | else |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7696 | return 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7697 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7698 | s = dmi_get_system_info(DMI_BIOS_VERSION); |
| 7699 | tp->bios_version_str = kstrdup(s, GFP_KERNEL); |
| 7700 | if (s && !tp->bios_version_str) |
| 7701 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7702 | |
| 7703 | /* Really ancient ThinkPad 240X will fail this, which is fine */ |
| 7704 | 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] | 7705 | return 0; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7706 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7707 | tp->bios_model = tp->bios_version_str[0] |
| 7708 | | (tp->bios_version_str[1] << 8); |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7709 | tp->bios_release = (tp->bios_version_str[4] << 8) |
| 7710 | | tp->bios_version_str[5]; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7711 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7712 | /* |
| 7713 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 7714 | * X32 or newer, all Z series; Some models must have an |
| 7715 | * up-to-date BIOS or they will not be detected. |
| 7716 | * |
| 7717 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 7718 | */ |
| 7719 | 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] | 7720 | if (sscanf(dev->name, |
| 7721 | "IBM ThinkPad Embedded Controller -[%17c", |
| 7722 | ec_fw_string) == 1) { |
| 7723 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 7724 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7725 | |
| 7726 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7727 | if (!tp->ec_version_str) |
| 7728 | return -ENOMEM; |
Henrique de Moraes Holschuh | 050df10 | 2009-05-30 13:25:05 -0300 | [diff] [blame] | 7729 | |
| 7730 | if (tpacpi_is_valid_fw_id(ec_fw_string, 'H')) { |
| 7731 | tp->ec_model = ec_fw_string[0] |
| 7732 | | (ec_fw_string[1] << 8); |
| 7733 | tp->ec_release = (ec_fw_string[4] << 8) |
| 7734 | | ec_fw_string[5]; |
| 7735 | } else { |
| 7736 | printk(TPACPI_NOTICE |
| 7737 | "ThinkPad firmware release %s " |
| 7738 | "doesn't match the known patterns\n", |
| 7739 | ec_fw_string); |
| 7740 | printk(TPACPI_NOTICE |
| 7741 | "please report this to %s\n", |
| 7742 | TPACPI_MAIL); |
| 7743 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7744 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 7745 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 7746 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7747 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7748 | s = dmi_get_system_info(DMI_PRODUCT_VERSION); |
| 7749 | if (s && !strnicmp(s, "ThinkPad", 8)) { |
| 7750 | tp->model_str = kstrdup(s, GFP_KERNEL); |
| 7751 | if (!tp->model_str) |
| 7752 | return -ENOMEM; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 7753 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 7754 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 7755 | s = dmi_get_system_info(DMI_PRODUCT_NAME); |
| 7756 | tp->nummodel_str = kstrdup(s, GFP_KERNEL); |
| 7757 | if (s && !tp->nummodel_str) |
| 7758 | return -ENOMEM; |
| 7759 | |
| 7760 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7761 | } |
| 7762 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7763 | static int __init probe_for_thinkpad(void) |
| 7764 | { |
| 7765 | int is_thinkpad; |
| 7766 | |
| 7767 | if (acpi_disabled) |
| 7768 | return -ENODEV; |
| 7769 | |
| 7770 | /* |
| 7771 | * Non-ancient models have better DMI tagging, but very old models |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 7772 | * don't. tpacpi_is_fw_known() is a cheat to help in that case. |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7773 | */ |
Henrique de Moraes Holschuh | e675aba | 2009-09-12 15:22:13 -0300 | [diff] [blame] | 7774 | is_thinkpad = (thinkpad_id.model_str != NULL) || |
| 7775 | (thinkpad_id.ec_model != 0) || |
| 7776 | tpacpi_is_fw_known(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7777 | |
| 7778 | /* 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] | 7779 | TPACPI_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7780 | if (!ec_handle) { |
| 7781 | if (is_thinkpad) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7782 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7783 | "Not yet supported ThinkPad detected!\n"); |
| 7784 | return -ENODEV; |
| 7785 | } |
| 7786 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 7787 | if (!is_thinkpad && !force_load) |
| 7788 | return -ENODEV; |
| 7789 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 7790 | return 0; |
| 7791 | } |
| 7792 | |
| 7793 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7794 | /* Module init, exit, parameters */ |
| 7795 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7796 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 7797 | { |
| 7798 | .init = thinkpad_acpi_driver_init, |
| 7799 | .data = &thinkpad_acpi_driver_data, |
| 7800 | }, |
| 7801 | { |
| 7802 | .init = hotkey_init, |
| 7803 | .data = &hotkey_driver_data, |
| 7804 | }, |
| 7805 | { |
| 7806 | .init = bluetooth_init, |
| 7807 | .data = &bluetooth_driver_data, |
| 7808 | }, |
| 7809 | { |
| 7810 | .init = wan_init, |
| 7811 | .data = &wan_driver_data, |
| 7812 | }, |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 7813 | { |
| 7814 | .init = uwb_init, |
| 7815 | .data = &uwb_driver_data, |
| 7816 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 7817 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7818 | { |
| 7819 | .init = video_init, |
| 7820 | .data = &video_driver_data, |
| 7821 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 7822 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7823 | { |
| 7824 | .init = light_init, |
| 7825 | .data = &light_driver_data, |
| 7826 | }, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7827 | { |
| 7828 | .init = cmos_init, |
| 7829 | .data = &cmos_driver_data, |
| 7830 | }, |
| 7831 | { |
| 7832 | .init = led_init, |
| 7833 | .data = &led_driver_data, |
| 7834 | }, |
| 7835 | { |
| 7836 | .init = beep_init, |
| 7837 | .data = &beep_driver_data, |
| 7838 | }, |
| 7839 | { |
| 7840 | .init = thermal_init, |
| 7841 | .data = &thermal_driver_data, |
| 7842 | }, |
| 7843 | { |
| 7844 | .data = &ecdump_driver_data, |
| 7845 | }, |
| 7846 | { |
| 7847 | .init = brightness_init, |
| 7848 | .data = &brightness_driver_data, |
| 7849 | }, |
| 7850 | { |
| 7851 | .data = &volume_driver_data, |
| 7852 | }, |
| 7853 | { |
| 7854 | .init = fan_init, |
| 7855 | .data = &fan_driver_data, |
| 7856 | }, |
| 7857 | }; |
| 7858 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7859 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 7860 | { |
| 7861 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7862 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7863 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 7864 | if (!kp || !kp->name || !val) |
| 7865 | return -EINVAL; |
| 7866 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7867 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 7868 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 7869 | WARN_ON(ibm == NULL); |
| 7870 | |
| 7871 | if (!ibm || !ibm->name) |
| 7872 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7873 | |
| 7874 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 7875 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7876 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7877 | strcpy(ibms_init[i].param, val); |
| 7878 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7879 | return 0; |
| 7880 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 7881 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7882 | |
| 7883 | return -EINVAL; |
| 7884 | } |
| 7885 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7886 | module_param(experimental, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7887 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7888 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7889 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 7890 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7891 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 7892 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 7893 | module_param(force_load, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7894 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7895 | "Attempts to load the driver even on a " |
| 7896 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 7897 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 7898 | module_param_named(fan_control, fan_control_allowed, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7899 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7900 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 7901 | |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 7902 | module_param_named(brightness_mode, brightness_mode, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7903 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7904 | "Selects brightness control strategy: " |
Henrique de Moraes Holschuh | 0e50183 | 2009-04-04 04:25:53 +0000 | [diff] [blame] | 7905 | "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 7906 | |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 7907 | module_param(brightness_enable, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7908 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7909 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 7910 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 7911 | module_param(hotkey_report_mode, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7912 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7913 | "used for backwards compatibility with userspace, " |
| 7914 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 7915 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7916 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 7917 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 7918 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 7919 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7920 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7921 | TPACPI_PARAM(hotkey); |
| 7922 | TPACPI_PARAM(bluetooth); |
| 7923 | TPACPI_PARAM(video); |
| 7924 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 7925 | TPACPI_PARAM(cmos); |
| 7926 | TPACPI_PARAM(led); |
| 7927 | TPACPI_PARAM(beep); |
| 7928 | TPACPI_PARAM(ecdump); |
| 7929 | TPACPI_PARAM(brightness); |
| 7930 | TPACPI_PARAM(volume); |
| 7931 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 7932 | |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 7933 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
| 7934 | module_param(dbg_wlswemul, uint, 0); |
| 7935 | MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation"); |
| 7936 | module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0); |
| 7937 | MODULE_PARM_DESC(wlsw_state, |
| 7938 | "Initial state of the emulated WLSW switch"); |
| 7939 | |
| 7940 | module_param(dbg_bluetoothemul, uint, 0); |
| 7941 | MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation"); |
| 7942 | module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0); |
| 7943 | MODULE_PARM_DESC(bluetooth_state, |
| 7944 | "Initial state of the emulated bluetooth switch"); |
| 7945 | |
| 7946 | module_param(dbg_wwanemul, uint, 0); |
| 7947 | MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation"); |
| 7948 | module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0); |
| 7949 | MODULE_PARM_DESC(wwan_state, |
| 7950 | "Initial state of the emulated WWAN switch"); |
Henrique de Moraes Holschuh | 0045c0a | 2009-01-11 03:01:03 -0200 | [diff] [blame] | 7951 | |
| 7952 | module_param(dbg_uwbemul, uint, 0); |
| 7953 | MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation"); |
| 7954 | module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0); |
| 7955 | MODULE_PARM_DESC(uwb_state, |
| 7956 | "Initial state of the emulated UWB switch"); |
Henrique de Moraes Holschuh | a73f309 | 2009-01-11 03:01:00 -0200 | [diff] [blame] | 7957 | #endif |
| 7958 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 7959 | static void thinkpad_acpi_module_exit(void) |
| 7960 | { |
| 7961 | struct ibm_struct *ibm, *itmp; |
| 7962 | |
| 7963 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 7964 | |
| 7965 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 7966 | &tpacpi_all_drivers, |
| 7967 | all_drivers) { |
| 7968 | ibm_exit(ibm); |
| 7969 | } |
| 7970 | |
| 7971 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 7972 | |
| 7973 | if (tpacpi_inputdev) { |
| 7974 | if (tp_features.input_device_registered) |
| 7975 | input_unregister_device(tpacpi_inputdev); |
| 7976 | else |
| 7977 | input_free_device(tpacpi_inputdev); |
| 7978 | } |
| 7979 | |
| 7980 | if (tpacpi_hwmon) |
| 7981 | hwmon_device_unregister(tpacpi_hwmon); |
| 7982 | |
| 7983 | if (tp_features.sensors_pdev_attrs_registered) |
| 7984 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 7985 | &dev_attr_thinkpad_acpi_pdev_name); |
| 7986 | if (tpacpi_sensors_pdev) |
| 7987 | platform_device_unregister(tpacpi_sensors_pdev); |
| 7988 | if (tpacpi_pdev) |
| 7989 | platform_device_unregister(tpacpi_pdev); |
| 7990 | |
| 7991 | if (tp_features.sensors_pdrv_attrs_registered) |
| 7992 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 7993 | if (tp_features.platform_drv_attrs_registered) |
| 7994 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 7995 | |
| 7996 | if (tp_features.sensors_pdrv_registered) |
| 7997 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 7998 | |
| 7999 | if (tp_features.platform_drv_registered) |
| 8000 | platform_driver_unregister(&tpacpi_pdriver); |
| 8001 | |
| 8002 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8003 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8004 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8005 | if (tpacpi_wq) |
| 8006 | destroy_workqueue(tpacpi_wq); |
| 8007 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 8008 | kfree(thinkpad_id.bios_version_str); |
| 8009 | kfree(thinkpad_id.ec_version_str); |
| 8010 | kfree(thinkpad_id.model_str); |
| 8011 | } |
| 8012 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 8013 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8014 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8015 | { |
| 8016 | int ret, i; |
| 8017 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 8018 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 8019 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 8020 | /* Parameter checking */ |
| 8021 | if (hotkey_report_mode > 2) |
| 8022 | return -EINVAL; |
| 8023 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8024 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8025 | |
Henrique de Moraes Holschuh | bf20e74 | 2008-07-21 09:15:51 -0300 | [diff] [blame] | 8026 | ret = get_thinkpad_model_data(&thinkpad_id); |
| 8027 | if (ret) { |
| 8028 | printk(TPACPI_ERR |
| 8029 | "unable to get DMI data: %d\n", ret); |
| 8030 | thinkpad_acpi_module_exit(); |
| 8031 | return ret; |
| 8032 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8033 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8034 | if (ret) { |
| 8035 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 8036 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8037 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8038 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8039 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 8040 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8041 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 8042 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8043 | |
Henrique de Moraes Holschuh | e0e3c06 | 2008-04-26 01:02:28 -0300 | [diff] [blame] | 8044 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
| 8045 | if (!tpacpi_wq) { |
| 8046 | thinkpad_acpi_module_exit(); |
| 8047 | return -ENOMEM; |
| 8048 | } |
| 8049 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8050 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8051 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8052 | printk(TPACPI_ERR |
| 8053 | "unable to create proc dir " TPACPI_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8054 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8055 | return -ENODEV; |
| 8056 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 8057 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8058 | ret = platform_driver_register(&tpacpi_pdriver); |
| 8059 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8060 | printk(TPACPI_ERR |
| 8061 | "unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8062 | thinkpad_acpi_module_exit(); |
| 8063 | return ret; |
| 8064 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 8065 | tp_features.platform_drv_registered = 1; |
| 8066 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8067 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 8068 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8069 | printk(TPACPI_ERR |
| 8070 | "unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8071 | thinkpad_acpi_module_exit(); |
| 8072 | return ret; |
| 8073 | } |
| 8074 | tp_features.sensors_pdrv_registered = 1; |
| 8075 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8076 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8077 | if (!ret) { |
| 8078 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8079 | ret = tpacpi_create_driver_attributes( |
| 8080 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8081 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8082 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8083 | printk(TPACPI_ERR |
| 8084 | "unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8085 | thinkpad_acpi_module_exit(); |
| 8086 | return ret; |
| 8087 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 8088 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 8089 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8090 | |
| 8091 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8092 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8093 | NULL, 0); |
| 8094 | if (IS_ERR(tpacpi_pdev)) { |
| 8095 | ret = PTR_ERR(tpacpi_pdev); |
| 8096 | tpacpi_pdev = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8097 | printk(TPACPI_ERR "unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8098 | thinkpad_acpi_module_exit(); |
| 8099 | return ret; |
| 8100 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8101 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8102 | TPACPI_HWMON_DRVR_NAME, |
| 8103 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8104 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 8105 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 8106 | tpacpi_sensors_pdev = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8107 | printk(TPACPI_ERR |
| 8108 | "unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8109 | thinkpad_acpi_module_exit(); |
| 8110 | return ret; |
| 8111 | } |
| 8112 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 8113 | &dev_attr_thinkpad_acpi_pdev_name); |
| 8114 | if (ret) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8115 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 8116 | "unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 8117 | thinkpad_acpi_module_exit(); |
| 8118 | return ret; |
| 8119 | } |
| 8120 | tp_features.sensors_pdev_attrs_registered = 1; |
| 8121 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8122 | if (IS_ERR(tpacpi_hwmon)) { |
| 8123 | ret = PTR_ERR(tpacpi_hwmon); |
| 8124 | tpacpi_hwmon = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8125 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 8126 | thinkpad_acpi_module_exit(); |
| 8127 | return ret; |
| 8128 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 8129 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8130 | tpacpi_inputdev = input_allocate_device(); |
| 8131 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8132 | printk(TPACPI_ERR "unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8133 | thinkpad_acpi_module_exit(); |
| 8134 | return -ENOMEM; |
| 8135 | } else { |
| 8136 | /* Prepare input device, but don't register */ |
| 8137 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8138 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8139 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 8140 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
| 8141 | thinkpad_id.vendor : |
| 8142 | PCI_VENDOR_ID_IBM; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8143 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 8144 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
| 8145 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 8146 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 8147 | ret = ibm_init(&ibms_init[i]); |
| 8148 | if (ret >= 0 && *ibms_init[i].param) |
| 8149 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8150 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8151 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8152 | return ret; |
| 8153 | } |
| 8154 | } |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8155 | ret = input_register_device(tpacpi_inputdev); |
| 8156 | if (ret < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8157 | printk(TPACPI_ERR "unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 8158 | thinkpad_acpi_module_exit(); |
| 8159 | return ret; |
| 8160 | } else { |
| 8161 | tp_features.input_device_registered = 1; |
| 8162 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8163 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 8164 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8165 | return 0; |
| 8166 | } |
| 8167 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 8168 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 8169 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8170 | /* |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 8171 | * This will autoload the driver in almost every ThinkPad |
| 8172 | * in widespread use. |
| 8173 | * |
| 8174 | * Only _VERY_ old models, like the 240, 240x and 570 lack |
| 8175 | * the HKEY event interface. |
| 8176 | */ |
| 8177 | MODULE_DEVICE_TABLE(acpi, ibm_htk_device_ids); |
| 8178 | |
| 8179 | /* |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8180 | * DMI matching for module autoloading |
| 8181 | * |
| 8182 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 8183 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 8184 | * |
| 8185 | * Only models listed in thinkwiki will be supported, so add yours |
| 8186 | * if it is not there yet. |
| 8187 | */ |
| 8188 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
Mathieu Chouquet-Stringer | b36a50f | 2009-03-14 16:35:26 +0100 | [diff] [blame] | 8189 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*") |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8190 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8191 | /* Ancient thinkpad BIOSes have to be identified by |
| 8192 | * BIOS type or model number, and there are far less |
| 8193 | * BIOS types than model numbers... */ |
Henrique de Moraes Holschuh | 922fe09 | 2009-04-14 02:44:13 +0000 | [diff] [blame] | 8194 | IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8195 | |
Henrique de Moraes Holschuh | f68f53a | 2009-04-14 02:44:12 +0000 | [diff] [blame] | 8196 | MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>"); |
| 8197 | MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 8198 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 8199 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 8200 | MODULE_LICENSE("GPL"); |
| 8201 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 8202 | module_init(thinkpad_acpi_module_init); |
| 8203 | module_exit(thinkpad_acpi_module_exit); |