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 | 6a2e293 | 2008-01-08 13:02:56 -0200 | [diff] [blame] | 6 | * Copyright (C) 2006-2008 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 | 1cee5cc | 2008-01-08 13:02:57 -0200 | [diff] [blame] | 24 | #define TPACPI_VERSION "0.19" |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 25 | #define TPACPI_SYSFS_VERSION 0x020200 |
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> |
| 57 | #include <linux/kthread.h> |
| 58 | #include <linux/freezer.h> |
| 59 | #include <linux/delay.h> |
| 60 | |
| 61 | #include <linux/nvram.h> |
| 62 | #include <linux/proc_fs.h> |
| 63 | #include <linux/sysfs.h> |
| 64 | #include <linux/backlight.h> |
| 65 | #include <linux/fb.h> |
| 66 | #include <linux/platform_device.h> |
| 67 | #include <linux/hwmon.h> |
| 68 | #include <linux/hwmon-sysfs.h> |
| 69 | #include <linux/input.h> |
| 70 | #include <asm/uaccess.h> |
| 71 | |
| 72 | #include <linux/dmi.h> |
| 73 | #include <linux/jiffies.h> |
| 74 | #include <linux/workqueue.h> |
| 75 | |
| 76 | #include <acpi/acpi_drivers.h> |
| 77 | #include <acpi/acnamesp.h> |
| 78 | |
| 79 | #include <linux/pci_ids.h> |
| 80 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 81 | |
| 82 | /* ThinkPad CMOS commands */ |
| 83 | #define TP_CMOS_VOLUME_DOWN 0 |
| 84 | #define TP_CMOS_VOLUME_UP 1 |
| 85 | #define TP_CMOS_VOLUME_MUTE 2 |
| 86 | #define TP_CMOS_BRIGHTNESS_UP 4 |
| 87 | #define TP_CMOS_BRIGHTNESS_DOWN 5 |
| 88 | |
| 89 | /* NVRAM Addresses */ |
| 90 | enum tp_nvram_addr { |
| 91 | TP_NVRAM_ADDR_HK2 = 0x57, |
| 92 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, |
| 93 | TP_NVRAM_ADDR_VIDEO = 0x59, |
| 94 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, |
| 95 | TP_NVRAM_ADDR_MIXER = 0x60, |
| 96 | }; |
| 97 | |
| 98 | /* NVRAM bit masks */ |
| 99 | enum { |
| 100 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, |
| 101 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, |
| 102 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, |
| 103 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, |
| 104 | TP_NVRAM_MASK_THINKLIGHT = 0x10, |
| 105 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, |
| 106 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, |
| 107 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, |
| 108 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, |
| 109 | TP_NVRAM_MASK_MUTE = 0x40, |
| 110 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, |
| 111 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, |
| 112 | TP_NVRAM_POS_LEVEL_VOLUME = 0, |
| 113 | }; |
| 114 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 115 | /* ACPI HIDs */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 116 | #define TPACPI_ACPI_HKEY_HID "IBM0068" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 117 | |
| 118 | /* Input IDs */ |
| 119 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ |
| 120 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 |
| 121 | |
| 122 | |
| 123 | /**************************************************************************** |
| 124 | * Main driver |
| 125 | */ |
| 126 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 127 | #define TPACPI_NAME "thinkpad" |
| 128 | #define TPACPI_DESC "ThinkPad ACPI Extras" |
| 129 | #define TPACPI_FILE TPACPI_NAME "_acpi" |
| 130 | #define TPACPI_URL "http://ibm-acpi.sf.net/" |
| 131 | #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 132 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 133 | #define TPACPI_PROC_DIR "ibm" |
| 134 | #define TPACPI_ACPI_EVENT_PREFIX "ibm" |
| 135 | #define TPACPI_DRVR_NAME TPACPI_FILE |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame^] | 136 | #define TPACPI_DRVR_SHORTNAME "tpacpi" |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 137 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 138 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame^] | 139 | #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd" |
| 140 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 141 | #define TPACPI_MAX_ACPI_ARGS 3 |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 142 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 143 | /* Debugging */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 144 | #define TPACPI_LOG TPACPI_FILE ": " |
| 145 | #define TPACPI_ERR KERN_ERR TPACPI_LOG |
| 146 | #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG |
| 147 | #define TPACPI_INFO KERN_INFO TPACPI_LOG |
| 148 | #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 149 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 150 | #define TPACPI_DBG_ALL 0xffff |
| 151 | #define TPACPI_DBG_ALL 0xffff |
| 152 | #define TPACPI_DBG_INIT 0x0001 |
| 153 | #define TPACPI_DBG_EXIT 0x0002 |
| 154 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 155 | do { if (dbg_level & a_dbg_level) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 156 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ |
| 157 | } while (0) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 158 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 159 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 160 | dbg_printk(a_dbg_level, format, ## arg) |
| 161 | static const char *str_supported(int is_supported); |
| 162 | #else |
| 163 | #define vdbg_printk(a_dbg_level, format, arg...) |
| 164 | #endif |
| 165 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 166 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 167 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 168 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 169 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 170 | |
| 171 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 172 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 173 | */ |
| 174 | |
| 175 | struct ibm_struct; |
| 176 | |
| 177 | struct tp_acpi_drv_struct { |
| 178 | const struct acpi_device_id *hid; |
| 179 | struct acpi_driver *driver; |
| 180 | |
| 181 | void (*notify) (struct ibm_struct *, u32); |
| 182 | acpi_handle *handle; |
| 183 | u32 type; |
| 184 | struct acpi_device *device; |
| 185 | }; |
| 186 | |
| 187 | struct ibm_struct { |
| 188 | char *name; |
| 189 | |
| 190 | int (*read) (char *); |
| 191 | int (*write) (char *); |
| 192 | void (*exit) (void); |
| 193 | void (*resume) (void); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 194 | void (*suspend) (pm_message_t state); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 195 | |
| 196 | struct list_head all_drivers; |
| 197 | |
| 198 | struct tp_acpi_drv_struct *acpi; |
| 199 | |
| 200 | struct { |
| 201 | u8 acpi_driver_registered:1; |
| 202 | u8 acpi_notify_installed:1; |
| 203 | u8 proc_created:1; |
| 204 | u8 init_called:1; |
| 205 | u8 experimental:1; |
| 206 | } flags; |
| 207 | }; |
| 208 | |
| 209 | struct ibm_init_struct { |
| 210 | char param[32]; |
| 211 | |
| 212 | int (*init) (struct ibm_init_struct *); |
| 213 | struct ibm_struct *data; |
| 214 | }; |
| 215 | |
| 216 | static struct { |
| 217 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 218 | u32 bay_status:1; |
| 219 | u32 bay_eject:1; |
| 220 | u32 bay_status2:1; |
| 221 | u32 bay_eject2:1; |
| 222 | #endif |
| 223 | u32 bluetooth:1; |
| 224 | u32 hotkey:1; |
| 225 | u32 hotkey_mask:1; |
| 226 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 227 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 228 | u32 light:1; |
| 229 | u32 light_status:1; |
| 230 | u32 bright_16levels:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 231 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 232 | u32 wan:1; |
| 233 | u32 fan_ctrl_status_undef:1; |
| 234 | u32 input_device_registered:1; |
| 235 | u32 platform_drv_registered:1; |
| 236 | u32 platform_drv_attrs_registered:1; |
| 237 | u32 sensors_pdrv_registered:1; |
| 238 | u32 sensors_pdrv_attrs_registered:1; |
| 239 | u32 sensors_pdev_attrs_registered:1; |
| 240 | u32 hotkey_poll_active:1; |
| 241 | } tp_features; |
| 242 | |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 243 | static struct { |
| 244 | u16 hotkey_mask_ff:1; |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 245 | u16 bright_cmos_ec_unsync:1; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 246 | } tp_warned; |
| 247 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 248 | struct thinkpad_id_data { |
| 249 | unsigned int vendor; /* ThinkPad vendor: |
| 250 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 251 | |
| 252 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 253 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 254 | |
| 255 | u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */ |
| 256 | u16 ec_model; |
| 257 | |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 258 | char *model_str; /* ThinkPad T43 */ |
| 259 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 260 | }; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 261 | static struct thinkpad_id_data thinkpad_id; |
| 262 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 263 | static enum { |
| 264 | TPACPI_LIFE_INIT = 0, |
| 265 | TPACPI_LIFE_RUNNING, |
| 266 | TPACPI_LIFE_EXITING, |
| 267 | } tpacpi_lifecycle; |
| 268 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 269 | static int experimental; |
| 270 | static u32 dbg_level; |
| 271 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 272 | /**************************************************************************** |
| 273 | **************************************************************************** |
| 274 | * |
| 275 | * ACPI Helpers and device model |
| 276 | * |
| 277 | **************************************************************************** |
| 278 | ****************************************************************************/ |
| 279 | |
| 280 | /************************************************************************* |
| 281 | * ACPI basic handles |
| 282 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 284 | static acpi_handle root_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 286 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | static acpi_handle object##_handle; \ |
| 288 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 289 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | static char *object##_paths[] = { paths } |
| 291 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 292 | TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 293 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 294 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 295 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 296 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 297 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 298 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 299 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 301 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 302 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 304 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 305 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 306 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 307 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 308 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 309 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 310 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 311 | "^HKEY", /* R30, R31 */ |
| 312 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 313 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 314 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 315 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 316 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 317 | "\\_SB.PCI0.VID0", /* 770e */ |
| 318 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 319 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 320 | ); /* R30, R31 */ |
| 321 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 322 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 323 | /************************************************************************* |
| 324 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 325 | */ |
| 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | static int acpi_evalf(acpi_handle handle, |
| 328 | void *res, char *method, char *fmt, ...) |
| 329 | { |
| 330 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 331 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 332 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 333 | struct acpi_buffer result, *resultp; |
| 334 | union acpi_object out_obj; |
| 335 | acpi_status status; |
| 336 | va_list ap; |
| 337 | char res_type; |
| 338 | int success; |
| 339 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | if (!*fmt) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 342 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | if (*fmt == 'q') { |
| 347 | quiet = 1; |
| 348 | fmt++; |
| 349 | } else |
| 350 | quiet = 0; |
| 351 | |
| 352 | res_type = *(fmt++); |
| 353 | |
| 354 | params.count = 0; |
| 355 | params.pointer = &in_objs[0]; |
| 356 | |
| 357 | va_start(ap, fmt); |
| 358 | while (*fmt) { |
| 359 | char c = *(fmt++); |
| 360 | switch (c) { |
| 361 | case 'd': /* int */ |
| 362 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 363 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 364 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 365 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 367 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | "with invalid format character '%c'\n", c); |
| 369 | return 0; |
| 370 | } |
| 371 | } |
| 372 | va_end(ap); |
| 373 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 374 | if (res_type != 'v') { |
| 375 | result.length = sizeof(out_obj); |
| 376 | result.pointer = &out_obj; |
| 377 | resultp = &result; |
| 378 | } else |
| 379 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 381 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 384 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | if (res) |
| 386 | *(int *)res = out_obj.integer.value; |
| 387 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 388 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 389 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | success = status == AE_OK; |
| 391 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 392 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 394 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | "with invalid format character '%c'\n", res_type); |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | if (!success && !quiet) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 400 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | method, fmt0, status); |
| 402 | |
| 403 | return success; |
| 404 | } |
| 405 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 406 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 407 | { |
| 408 | int v; |
| 409 | |
| 410 | if (ecrd_handle) { |
| 411 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 412 | return 0; |
| 413 | *p = v; |
| 414 | } else { |
| 415 | if (ec_read(i, p) < 0) |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | return 1; |
| 420 | } |
| 421 | |
| 422 | static int acpi_ec_write(int i, u8 v) |
| 423 | { |
| 424 | if (ecwr_handle) { |
| 425 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 426 | return 0; |
| 427 | } else { |
| 428 | if (ec_write(i, v) < 0) |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | return 1; |
| 433 | } |
| 434 | |
Henrique de Moraes Holschuh | 013c40e | 2008-01-08 13:02:54 -0200 | [diff] [blame] | 435 | #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 436 | static int _sta(acpi_handle handle) |
| 437 | { |
| 438 | int status; |
| 439 | |
| 440 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) |
| 441 | status = 0; |
| 442 | |
| 443 | return status; |
| 444 | } |
Henrique de Moraes Holschuh | 013c40e | 2008-01-08 13:02:54 -0200 | [diff] [blame] | 445 | #endif |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 446 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 447 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 448 | { |
| 449 | if (!cmos_handle) |
| 450 | return -ENXIO; |
| 451 | |
| 452 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 453 | return -EIO; |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 458 | /************************************************************************* |
| 459 | * ACPI device model |
| 460 | */ |
| 461 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 462 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 463 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 464 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
| 465 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 466 | static void drv_acpi_handle_init(char *name, |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 467 | acpi_handle *handle, acpi_handle parent, |
| 468 | char **paths, int num_paths, char **path) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 469 | { |
| 470 | int i; |
| 471 | acpi_status status; |
| 472 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 473 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 474 | name); |
| 475 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 476 | for (i = 0; i < num_paths; i++) { |
| 477 | status = acpi_get_handle(parent, paths[i], handle); |
| 478 | if (ACPI_SUCCESS(status)) { |
| 479 | *path = paths[i]; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 480 | dbg_printk(TPACPI_DBG_INIT, |
| 481 | "Found ACPI handle %s for %s\n", |
| 482 | *path, name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 483 | return; |
| 484 | } |
| 485 | } |
| 486 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 487 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 488 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 489 | *handle = NULL; |
| 490 | } |
| 491 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 492 | 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] | 493 | { |
| 494 | struct ibm_struct *ibm = data; |
| 495 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 496 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 497 | return; |
| 498 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 499 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 500 | return; |
| 501 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 502 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 503 | } |
| 504 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 505 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 506 | { |
| 507 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 508 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 509 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 510 | BUG_ON(!ibm->acpi); |
| 511 | |
| 512 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 513 | return 0; |
| 514 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 515 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 516 | "setting up ACPI notify for %s\n", ibm->name); |
| 517 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 518 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 519 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 520 | 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] | 521 | ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 522 | return -ENODEV; |
| 523 | } |
| 524 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 525 | acpi_driver_data(ibm->acpi->device) = ibm; |
| 526 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 527 | TPACPI_ACPI_EVENT_PREFIX, |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 528 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 529 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 530 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 531 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 532 | if (ACPI_FAILURE(status)) { |
| 533 | if (status == AE_ALREADY_EXISTS) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 534 | printk(TPACPI_NOTICE |
| 535 | "another device driver is already " |
| 536 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 537 | } else { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 538 | printk(TPACPI_ERR |
| 539 | "acpi_install_notify_handler(%s) failed: %d\n", |
| 540 | ibm->name, status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 541 | } |
| 542 | return -ENODEV; |
| 543 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 544 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 545 | return 0; |
| 546 | } |
| 547 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 548 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 549 | { |
| 550 | return 0; |
| 551 | } |
| 552 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 553 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 554 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 555 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 556 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 557 | dbg_printk(TPACPI_DBG_INIT, |
| 558 | "registering %s as an ACPI driver\n", ibm->name); |
| 559 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 560 | BUG_ON(!ibm->acpi); |
| 561 | |
| 562 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 563 | if (!ibm->acpi->driver) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 564 | printk(TPACPI_ERR "kzalloc(ibm->driver) failed\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 565 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 566 | } |
| 567 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 568 | 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] | 569 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 570 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 571 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 572 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 573 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 574 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 575 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 576 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 577 | kfree(ibm->acpi->driver); |
| 578 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 579 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 580 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 581 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 582 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
| 586 | /**************************************************************************** |
| 587 | **************************************************************************** |
| 588 | * |
| 589 | * Procfs Helpers |
| 590 | * |
| 591 | **************************************************************************** |
| 592 | ****************************************************************************/ |
| 593 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 594 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 595 | int count, int *eof, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 596 | { |
| 597 | struct ibm_struct *ibm = data; |
| 598 | int len; |
| 599 | |
| 600 | if (!ibm || !ibm->read) |
| 601 | return -EINVAL; |
| 602 | |
| 603 | len = ibm->read(page); |
| 604 | if (len < 0) |
| 605 | return len; |
| 606 | |
| 607 | if (len <= off + count) |
| 608 | *eof = 1; |
| 609 | *start = page + off; |
| 610 | len -= off; |
| 611 | if (len > count) |
| 612 | len = count; |
| 613 | if (len < 0) |
| 614 | len = 0; |
| 615 | |
| 616 | return len; |
| 617 | } |
| 618 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 619 | static int dispatch_procfs_write(struct file *file, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 620 | const char __user *userbuf, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 621 | unsigned long count, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 622 | { |
| 623 | struct ibm_struct *ibm = data; |
| 624 | char *kernbuf; |
| 625 | int ret; |
| 626 | |
| 627 | if (!ibm || !ibm->write) |
| 628 | return -EINVAL; |
| 629 | |
| 630 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 631 | if (!kernbuf) |
| 632 | return -ENOMEM; |
| 633 | |
| 634 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 635 | kfree(kernbuf); |
| 636 | return -EFAULT; |
| 637 | } |
| 638 | |
| 639 | kernbuf[count] = 0; |
| 640 | strcat(kernbuf, ","); |
| 641 | ret = ibm->write(kernbuf); |
| 642 | if (ret == 0) |
| 643 | ret = count; |
| 644 | |
| 645 | kfree(kernbuf); |
| 646 | |
| 647 | return ret; |
| 648 | } |
| 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | static char *next_cmd(char **cmds) |
| 651 | { |
| 652 | char *start = *cmds; |
| 653 | char *end; |
| 654 | |
| 655 | while ((end = strchr(start, ',')) && end == start) |
| 656 | start = end + 1; |
| 657 | |
| 658 | if (!end) |
| 659 | return NULL; |
| 660 | |
| 661 | *end = 0; |
| 662 | *cmds = end + 1; |
| 663 | return start; |
| 664 | } |
| 665 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 666 | |
| 667 | /**************************************************************************** |
| 668 | **************************************************************************** |
| 669 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 670 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 671 | * |
| 672 | **************************************************************************** |
| 673 | ****************************************************************************/ |
| 674 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 675 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 676 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 677 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 678 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 679 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 680 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 681 | |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 682 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
| 683 | pm_message_t state) |
| 684 | { |
| 685 | struct ibm_struct *ibm, *itmp; |
| 686 | |
| 687 | list_for_each_entry_safe(ibm, itmp, |
| 688 | &tpacpi_all_drivers, |
| 689 | all_drivers) { |
| 690 | if (ibm->suspend) |
| 691 | (ibm->suspend)(state); |
| 692 | } |
| 693 | |
| 694 | return 0; |
| 695 | } |
| 696 | |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 697 | static int tpacpi_resume_handler(struct platform_device *pdev) |
| 698 | { |
| 699 | struct ibm_struct *ibm, *itmp; |
| 700 | |
| 701 | list_for_each_entry_safe(ibm, itmp, |
| 702 | &tpacpi_all_drivers, |
| 703 | all_drivers) { |
| 704 | if (ibm->resume) |
| 705 | (ibm->resume)(); |
| 706 | } |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 711 | static struct platform_driver tpacpi_pdriver = { |
| 712 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 713 | .name = TPACPI_DRVR_NAME, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 714 | .owner = THIS_MODULE, |
| 715 | }, |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 716 | .suspend = tpacpi_suspend_handler, |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 717 | .resume = tpacpi_resume_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 718 | }; |
| 719 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 720 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 721 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 722 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 723 | .owner = THIS_MODULE, |
| 724 | }, |
| 725 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 726 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 727 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 728 | * sysfs support helpers |
| 729 | */ |
| 730 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 731 | struct attribute_set { |
| 732 | unsigned int members, max_members; |
| 733 | struct attribute_group group; |
| 734 | }; |
| 735 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 736 | struct attribute_set_obj { |
| 737 | struct attribute_set s; |
| 738 | struct attribute *a; |
| 739 | } __attribute__((packed)); |
| 740 | |
| 741 | 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] | 742 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 743 | { |
| 744 | struct attribute_set_obj *sobj; |
| 745 | |
| 746 | if (max_members == 0) |
| 747 | return NULL; |
| 748 | |
| 749 | /* Allocates space for implicit NULL at the end too */ |
| 750 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 751 | max_members * sizeof(struct attribute *), |
| 752 | GFP_KERNEL); |
| 753 | if (!sobj) |
| 754 | return NULL; |
| 755 | sobj->s.max_members = max_members; |
| 756 | sobj->s.group.attrs = &sobj->a; |
| 757 | sobj->s.group.name = name; |
| 758 | |
| 759 | return &sobj->s; |
| 760 | } |
| 761 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 762 | #define destroy_attr_set(_set) \ |
| 763 | kfree(_set); |
| 764 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 765 | /* 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] | 766 | 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] | 767 | { |
| 768 | if (!s || !attr) |
| 769 | return -EINVAL; |
| 770 | |
| 771 | if (s->members >= s->max_members) |
| 772 | return -ENOMEM; |
| 773 | |
| 774 | s->group.attrs[s->members] = attr; |
| 775 | s->members++; |
| 776 | |
| 777 | return 0; |
| 778 | } |
| 779 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 780 | 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] | 781 | struct attribute **attr, |
| 782 | unsigned int count) |
| 783 | { |
| 784 | int i, res; |
| 785 | |
| 786 | for (i = 0; i < count; i++) { |
| 787 | res = add_to_attr_set(s, attr[i]); |
| 788 | if (res) |
| 789 | return res; |
| 790 | } |
| 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 795 | 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] | 796 | { |
| 797 | sysfs_remove_group(kobj, &s->group); |
| 798 | destroy_attr_set(s); |
| 799 | } |
| 800 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 801 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 802 | sysfs_create_group(_kobj, &_attr_set->group) |
| 803 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 804 | static int parse_strtoul(const char *buf, |
| 805 | unsigned long max, unsigned long *value) |
| 806 | { |
| 807 | char *endp; |
| 808 | |
Henrique de Moraes Holschuh | 32afbf0 | 2007-10-08 10:12:56 -0300 | [diff] [blame] | 809 | while (*buf && isspace(*buf)) |
| 810 | buf++; |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 811 | *value = simple_strtoul(buf, &endp, 0); |
| 812 | while (*endp && isspace(*endp)) |
| 813 | endp++; |
| 814 | if (*endp || *value > max) |
| 815 | return -EINVAL; |
| 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 820 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 821 | { |
| 822 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 823 | union acpi_object *obj; |
| 824 | int rc; |
| 825 | |
| 826 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { |
| 827 | obj = (union acpi_object *)buffer.pointer; |
| 828 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
| 829 | printk(TPACPI_ERR "Unknown _BCL data, " |
| 830 | "please report this to %s\n", TPACPI_MAIL); |
| 831 | rc = 0; |
| 832 | } else { |
| 833 | rc = obj->package.count; |
| 834 | } |
| 835 | } else { |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | kfree(buffer.pointer); |
| 840 | return rc; |
| 841 | } |
| 842 | |
| 843 | static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle, |
| 844 | u32 lvl, void *context, void **rv) |
| 845 | { |
| 846 | char name[ACPI_PATH_SEGMENT_LENGTH]; |
| 847 | struct acpi_buffer buffer = { sizeof(name), &name }; |
| 848 | |
| 849 | if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && |
| 850 | !strncmp("_BCL", name, sizeof(name) - 1)) { |
| 851 | BUG_ON(!rv || !*rv); |
| 852 | **(int **)rv = tpacpi_query_bcl_levels(handle); |
| 853 | return AE_CTRL_TERMINATE; |
| 854 | } else { |
| 855 | return AE_OK; |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | /* |
| 860 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 861 | */ |
| 862 | static int __init tpacpi_check_std_acpi_brightness_support(void) |
| 863 | { |
| 864 | int status; |
| 865 | int bcl_levels = 0; |
| 866 | void *bcl_ptr = &bcl_levels; |
| 867 | |
| 868 | if (!vid_handle) { |
| 869 | TPACPI_ACPIHANDLE_INIT(vid); |
| 870 | } |
| 871 | if (!vid_handle) |
| 872 | return 0; |
| 873 | |
| 874 | /* |
| 875 | * Search for a _BCL method, and execute it. This is safe on all |
| 876 | * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista |
| 877 | * BIOS in ACPI backlight control mode. We do NOT have to care |
| 878 | * about calling the _BCL method in an enabled video device, any |
| 879 | * will do for our purposes. |
| 880 | */ |
| 881 | |
| 882 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, |
| 883 | tpacpi_acpi_walk_find_bcl, NULL, |
| 884 | &bcl_ptr); |
| 885 | |
| 886 | if (ACPI_SUCCESS(status) && bcl_levels > 2) { |
| 887 | tp_features.bright_acpimode = 1; |
| 888 | return (bcl_levels - 2); |
| 889 | } |
| 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 894 | /************************************************************************* |
| 895 | * thinkpad-acpi driver attributes |
| 896 | */ |
| 897 | |
| 898 | /* interface_version --------------------------------------------------- */ |
| 899 | static ssize_t tpacpi_driver_interface_version_show( |
| 900 | struct device_driver *drv, |
| 901 | char *buf) |
| 902 | { |
| 903 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 904 | } |
| 905 | |
| 906 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 907 | tpacpi_driver_interface_version_show, NULL); |
| 908 | |
| 909 | /* debug_level --------------------------------------------------------- */ |
| 910 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 911 | char *buf) |
| 912 | { |
| 913 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 914 | } |
| 915 | |
| 916 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 917 | const char *buf, size_t count) |
| 918 | { |
| 919 | unsigned long t; |
| 920 | |
| 921 | if (parse_strtoul(buf, 0xffff, &t)) |
| 922 | return -EINVAL; |
| 923 | |
| 924 | dbg_level = t; |
| 925 | |
| 926 | return count; |
| 927 | } |
| 928 | |
| 929 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 930 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 931 | |
| 932 | /* version ------------------------------------------------------------- */ |
| 933 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 934 | char *buf) |
| 935 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 936 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 937 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | static DRIVER_ATTR(version, S_IRUGO, |
| 941 | tpacpi_driver_version_show, NULL); |
| 942 | |
| 943 | /* --------------------------------------------------------------------- */ |
| 944 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 945 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 946 | &driver_attr_debug_level, &driver_attr_version, |
| 947 | &driver_attr_interface_version, |
| 948 | }; |
| 949 | |
| 950 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 951 | { |
| 952 | int i, res; |
| 953 | |
| 954 | i = 0; |
| 955 | res = 0; |
| 956 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 957 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 958 | i++; |
| 959 | } |
| 960 | |
| 961 | return res; |
| 962 | } |
| 963 | |
| 964 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 965 | { |
| 966 | int i; |
| 967 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 968 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 969 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
| 970 | } |
| 971 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 972 | /**************************************************************************** |
| 973 | **************************************************************************** |
| 974 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 975 | * Subdrivers |
| 976 | * |
| 977 | **************************************************************************** |
| 978 | ****************************************************************************/ |
| 979 | |
| 980 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 981 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 982 | */ |
| 983 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 984 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 986 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 987 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 989 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 990 | (thinkpad_id.bios_version_str) ? |
| 991 | thinkpad_id.bios_version_str : "unknown", |
| 992 | (thinkpad_id.ec_version_str) ? |
| 993 | thinkpad_id.ec_version_str : "unknown"); |
| 994 | |
| 995 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 996 | printk(TPACPI_INFO "%s %s, model %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 997 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 998 | "IBM" : ((thinkpad_id.vendor == |
| 999 | PCI_VENDOR_ID_LENOVO) ? |
| 1000 | "Lenovo" : "Unknown vendor"), |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1001 | thinkpad_id.model_str, |
| 1002 | (thinkpad_id.nummodel_str) ? |
| 1003 | thinkpad_id.nummodel_str : "unknown"); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 1004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | return 0; |
| 1006 | } |
| 1007 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1008 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | { |
| 1010 | int len = 0; |
| 1011 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1012 | len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); |
| 1013 | len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
| 1015 | return len; |
| 1016 | } |
| 1017 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1018 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1019 | .name = "driver", |
| 1020 | .read = thinkpad_acpi_driver_read, |
| 1021 | }; |
| 1022 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1023 | /************************************************************************* |
| 1024 | * Hotkey subdriver |
| 1025 | */ |
| 1026 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1027 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1028 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1029 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1030 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1031 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1032 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1033 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1034 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1035 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1036 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1037 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1038 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1039 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1040 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1041 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1042 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1043 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1044 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1045 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1046 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1047 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1048 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1049 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1050 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1051 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1052 | }; |
| 1053 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1054 | enum { /* Keys available through NVRAM polling */ |
| 1055 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1056 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1057 | }; |
| 1058 | |
| 1059 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1060 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1061 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1062 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1063 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1064 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1065 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1066 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1067 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1068 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1069 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1070 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1071 | }; |
| 1072 | |
| 1073 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1074 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1075 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1076 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1077 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1078 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1079 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1080 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1081 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1082 | TP_ACPI_HKEY_MUTE_MASK, |
| 1083 | }; |
| 1084 | |
| 1085 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1086 | struct tp_nvram_state { |
| 1087 | u16 thinkpad_toggle:1; |
| 1088 | u16 zoom_toggle:1; |
| 1089 | u16 display_toggle:1; |
| 1090 | u16 thinklight_toggle:1; |
| 1091 | u16 hibernate_toggle:1; |
| 1092 | u16 displayexp_toggle:1; |
| 1093 | u16 display_state:1; |
| 1094 | u16 brightness_toggle:1; |
| 1095 | u16 volume_toggle:1; |
| 1096 | u16 mute:1; |
| 1097 | |
| 1098 | u8 brightness_level; |
| 1099 | u8 volume_level; |
| 1100 | }; |
| 1101 | |
| 1102 | static struct task_struct *tpacpi_hotkey_task; |
| 1103 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 1104 | static int hotkey_poll_freq = 10; /* Hz */ |
| 1105 | static struct mutex hotkey_thread_mutex; |
| 1106 | static struct mutex hotkey_thread_data_mutex; |
| 1107 | static unsigned int hotkey_config_change; |
| 1108 | |
| 1109 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1110 | |
| 1111 | #define hotkey_source_mask 0U |
| 1112 | |
| 1113 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1114 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1115 | static struct mutex hotkey_mutex; |
| 1116 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1117 | static enum { /* Reasons for waking up */ |
| 1118 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 1119 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 1120 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 1121 | } hotkey_wakeup_reason; |
| 1122 | |
| 1123 | static int hotkey_autosleep_ack; |
| 1124 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1125 | static int hotkey_orig_status; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1126 | static u32 hotkey_orig_mask; |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1127 | static u32 hotkey_all_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1128 | static u32 hotkey_reserved_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1129 | static u32 hotkey_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1130 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1131 | static unsigned int hotkey_report_mode; |
| 1132 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1133 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1134 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 1135 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1136 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1137 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1138 | #define HOTKEY_CONFIG_CRITICAL_START \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1139 | do { \ |
| 1140 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 1141 | hotkey_config_change++; \ |
| 1142 | } while (0); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1143 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 1144 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1145 | #else |
| 1146 | #define HOTKEY_CONFIG_CRITICAL_START |
| 1147 | #define HOTKEY_CONFIG_CRITICAL_END |
| 1148 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1149 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1150 | /* HKEY.MHKG() return bits */ |
| 1151 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 1152 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1153 | static int hotkey_get_wlsw(int *status) |
| 1154 | { |
| 1155 | if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) |
| 1156 | return -EIO; |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1160 | static int hotkey_get_tablet_mode(int *status) |
| 1161 | { |
| 1162 | int s; |
| 1163 | |
| 1164 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 1165 | return -EIO; |
| 1166 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 1167 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 1168 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1169 | } |
| 1170 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1171 | /* |
| 1172 | * Call with hotkey_mutex held |
| 1173 | */ |
| 1174 | static int hotkey_mask_get(void) |
| 1175 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1176 | u32 m = 0; |
| 1177 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1178 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1179 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1180 | return -EIO; |
| 1181 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1182 | hotkey_mask = m | (hotkey_source_mask & hotkey_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1183 | |
| 1184 | return 0; |
| 1185 | } |
| 1186 | |
| 1187 | /* |
| 1188 | * Call with hotkey_mutex held |
| 1189 | */ |
| 1190 | static int hotkey_mask_set(u32 mask) |
| 1191 | { |
| 1192 | int i; |
| 1193 | int rc = 0; |
| 1194 | |
| 1195 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 1196 | if (!tp_warned.hotkey_mask_ff && |
| 1197 | (mask == 0xffff || mask == 0xffffff || |
| 1198 | mask == 0xffffffff)) { |
| 1199 | tp_warned.hotkey_mask_ff = 1; |
| 1200 | printk(TPACPI_NOTICE |
| 1201 | "setting the hotkey mask to 0x%08x is likely " |
| 1202 | "not the best way to go about it\n", mask); |
| 1203 | printk(TPACPI_NOTICE |
| 1204 | "please consider using the driver defaults, " |
| 1205 | "and refer to up-to-date thinkpad-acpi " |
| 1206 | "documentation\n"); |
| 1207 | } |
| 1208 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1209 | HOTKEY_CONFIG_CRITICAL_START |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1210 | for (i = 0; i < 32; i++) { |
| 1211 | u32 m = 1 << i; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1212 | /* enable in firmware mask only keys not in NVRAM |
| 1213 | * mode, but enable the key in the cached hotkey_mask |
| 1214 | * regardless of mode, or the key will end up |
| 1215 | * disabled by hotkey_mask_get() */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1216 | if (!acpi_evalf(hkey_handle, |
| 1217 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1218 | !!((mask & ~hotkey_source_mask) & m))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1219 | rc = -EIO; |
| 1220 | break; |
| 1221 | } else { |
| 1222 | hotkey_mask = (hotkey_mask & ~m) | (mask & m); |
| 1223 | } |
| 1224 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1225 | HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1226 | |
| 1227 | /* hotkey_mask_get must be called unconditionally below */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1228 | if (!hotkey_mask_get() && !rc && |
| 1229 | (hotkey_mask & ~hotkey_source_mask) != |
| 1230 | (mask & ~hotkey_source_mask)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1231 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1232 | "requested hot key mask 0x%08x, but " |
| 1233 | "firmware forced it to 0x%08x\n", |
| 1234 | mask, hotkey_mask); |
| 1235 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1236 | } else { |
| 1237 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1238 | HOTKEY_CONFIG_CRITICAL_START |
| 1239 | hotkey_mask = mask & hotkey_source_mask; |
| 1240 | HOTKEY_CONFIG_CRITICAL_END |
| 1241 | hotkey_mask_get(); |
| 1242 | if (hotkey_mask != mask) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1243 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1244 | "requested hot key mask 0x%08x, " |
| 1245 | "forced to 0x%08x (NVRAM poll mask is " |
| 1246 | "0x%08x): no firmware mask support\n", |
| 1247 | mask, hotkey_mask, hotkey_source_mask); |
| 1248 | } |
| 1249 | #else |
| 1250 | hotkey_mask_get(); |
| 1251 | rc = -ENXIO; |
| 1252 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | return rc; |
| 1256 | } |
| 1257 | |
| 1258 | static int hotkey_status_get(int *status) |
| 1259 | { |
| 1260 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 1261 | return -EIO; |
| 1262 | |
| 1263 | return 0; |
| 1264 | } |
| 1265 | |
| 1266 | static int hotkey_status_set(int status) |
| 1267 | { |
| 1268 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) |
| 1269 | return -EIO; |
| 1270 | |
| 1271 | return 0; |
| 1272 | } |
| 1273 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1274 | static void tpacpi_input_send_radiosw(void) |
| 1275 | { |
| 1276 | int wlsw; |
| 1277 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1278 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { |
Henrique de Moraes Holschuh | d147da7 | 2008-02-16 02:17:57 -0200 | [diff] [blame] | 1279 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1280 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1281 | input_report_switch(tpacpi_inputdev, |
| 1282 | SW_RADIO, !!wlsw); |
| 1283 | input_sync(tpacpi_inputdev); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1284 | |
Henrique de Moraes Holschuh | d147da7 | 2008-02-16 02:17:57 -0200 | [diff] [blame] | 1285 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1286 | } |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1287 | } |
| 1288 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1289 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1290 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1291 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1292 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1293 | if (tp_features.hotkey_tablet && |
| 1294 | !hotkey_get_tablet_mode(&state)) { |
| 1295 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1296 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1297 | input_report_switch(tpacpi_inputdev, |
| 1298 | SW_TABLET_MODE, !!state); |
| 1299 | input_sync(tpacpi_inputdev); |
| 1300 | |
| 1301 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1302 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1303 | } |
| 1304 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1305 | static void tpacpi_input_send_key(unsigned int scancode) |
| 1306 | { |
| 1307 | unsigned int keycode; |
| 1308 | |
| 1309 | keycode = hotkey_keycode_map[scancode]; |
| 1310 | |
| 1311 | if (keycode != KEY_RESERVED) { |
| 1312 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1313 | |
| 1314 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 1315 | if (keycode == KEY_UNKNOWN) |
| 1316 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1317 | scancode); |
| 1318 | input_sync(tpacpi_inputdev); |
| 1319 | |
| 1320 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 1321 | if (keycode == KEY_UNKNOWN) |
| 1322 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1323 | scancode); |
| 1324 | input_sync(tpacpi_inputdev); |
| 1325 | |
| 1326 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1327 | } |
| 1328 | } |
| 1329 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1330 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1331 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 1332 | |
| 1333 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 1334 | { |
| 1335 | tpacpi_input_send_key(scancode); |
| 1336 | if (hotkey_report_mode < 2) { |
| 1337 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
| 1338 | 0x80, 0x1001 + scancode); |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m) |
| 1343 | { |
| 1344 | u8 d; |
| 1345 | |
| 1346 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 1347 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 1348 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 1349 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 1350 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 1351 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 1352 | } |
| 1353 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 1354 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 1355 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 1356 | } |
| 1357 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 1358 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 1359 | n->displayexp_toggle = |
| 1360 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 1361 | } |
| 1362 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 1363 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 1364 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 1365 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 1366 | n->brightness_toggle = |
| 1367 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 1368 | } |
| 1369 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 1370 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 1371 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 1372 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 1373 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 1374 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1379 | do { \ |
| 1380 | if ((mask & (1 << __scancode)) && \ |
| 1381 | oldn->__member != newn->__member) \ |
| 1382 | tpacpi_hotkey_send_key(__scancode); \ |
| 1383 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1384 | |
| 1385 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
| 1386 | do { if (mask & (1 << __scancode)) \ |
| 1387 | tpacpi_hotkey_send_key(__scancode); } while (0) |
| 1388 | |
| 1389 | 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] | 1390 | struct tp_nvram_state *newn, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1391 | u32 mask) |
| 1392 | { |
| 1393 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 1394 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 1395 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 1396 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 1397 | |
| 1398 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 1399 | |
| 1400 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 1401 | |
| 1402 | /* handle volume */ |
| 1403 | if (oldn->volume_toggle != newn->volume_toggle) { |
| 1404 | if (oldn->mute != newn->mute) { |
| 1405 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1406 | } |
| 1407 | if (oldn->volume_level > newn->volume_level) { |
| 1408 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1409 | } else if (oldn->volume_level < newn->volume_level) { |
| 1410 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1411 | } else if (oldn->mute == newn->mute) { |
| 1412 | /* repeated key presses that didn't change state */ |
| 1413 | if (newn->mute) { |
| 1414 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1415 | } else if (newn->volume_level != 0) { |
| 1416 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1417 | } else { |
| 1418 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | /* handle brightness */ |
| 1424 | if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 1425 | if (oldn->brightness_level < newn->brightness_level) { |
| 1426 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1427 | } else if (oldn->brightness_level > newn->brightness_level) { |
| 1428 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1429 | } else { |
| 1430 | /* repeated key presses that didn't change state */ |
| 1431 | if (newn->brightness_level != 0) { |
| 1432 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1433 | } else { |
| 1434 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1435 | } |
| 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | #undef TPACPI_COMPARE_KEY |
| 1441 | #undef TPACPI_MAY_SEND_KEY |
| 1442 | |
| 1443 | static int hotkey_kthread(void *data) |
| 1444 | { |
| 1445 | struct tp_nvram_state s[2]; |
| 1446 | u32 mask; |
| 1447 | unsigned int si, so; |
| 1448 | unsigned long t; |
| 1449 | unsigned int change_detector, must_reset; |
| 1450 | |
| 1451 | mutex_lock(&hotkey_thread_mutex); |
| 1452 | |
| 1453 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 1454 | goto exit; |
| 1455 | |
| 1456 | set_freezable(); |
| 1457 | |
| 1458 | so = 0; |
| 1459 | si = 1; |
| 1460 | t = 0; |
| 1461 | |
| 1462 | /* Initial state for compares */ |
| 1463 | mutex_lock(&hotkey_thread_data_mutex); |
| 1464 | change_detector = hotkey_config_change; |
| 1465 | mask = hotkey_source_mask & hotkey_mask; |
| 1466 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1467 | hotkey_read_nvram(&s[so], mask); |
| 1468 | |
| 1469 | while (!kthread_should_stop() && hotkey_poll_freq) { |
| 1470 | if (t == 0) |
| 1471 | t = 1000/hotkey_poll_freq; |
| 1472 | t = msleep_interruptible(t); |
| 1473 | if (unlikely(kthread_should_stop())) |
| 1474 | break; |
| 1475 | must_reset = try_to_freeze(); |
| 1476 | if (t > 0 && !must_reset) |
| 1477 | continue; |
| 1478 | |
| 1479 | mutex_lock(&hotkey_thread_data_mutex); |
| 1480 | if (must_reset || hotkey_config_change != change_detector) { |
| 1481 | /* forget old state on thaw or config change */ |
| 1482 | si = so; |
| 1483 | t = 0; |
| 1484 | change_detector = hotkey_config_change; |
| 1485 | } |
| 1486 | mask = hotkey_source_mask & hotkey_mask; |
| 1487 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1488 | |
| 1489 | if (likely(mask)) { |
| 1490 | hotkey_read_nvram(&s[si], mask); |
| 1491 | if (likely(si != so)) { |
| 1492 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1493 | mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1494 | } |
| 1495 | } |
| 1496 | |
| 1497 | so = si; |
| 1498 | si ^= 1; |
| 1499 | } |
| 1500 | |
| 1501 | exit: |
| 1502 | mutex_unlock(&hotkey_thread_mutex); |
| 1503 | return 0; |
| 1504 | } |
| 1505 | |
| 1506 | static void hotkey_poll_stop_sync(void) |
| 1507 | { |
| 1508 | if (tpacpi_hotkey_task) { |
| 1509 | if (frozen(tpacpi_hotkey_task) || |
| 1510 | freezing(tpacpi_hotkey_task)) |
| 1511 | thaw_process(tpacpi_hotkey_task); |
| 1512 | |
| 1513 | kthread_stop(tpacpi_hotkey_task); |
| 1514 | tpacpi_hotkey_task = NULL; |
| 1515 | mutex_lock(&hotkey_thread_mutex); |
| 1516 | /* at this point, the thread did exit */ |
| 1517 | mutex_unlock(&hotkey_thread_mutex); |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | /* call with hotkey_mutex held */ |
| 1522 | static void hotkey_poll_setup(int may_warn) |
| 1523 | { |
| 1524 | if ((hotkey_source_mask & hotkey_mask) != 0 && |
| 1525 | hotkey_poll_freq > 0 && |
| 1526 | (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { |
| 1527 | if (!tpacpi_hotkey_task) { |
| 1528 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame^] | 1529 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1530 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 1531 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1532 | printk(TPACPI_ERR |
| 1533 | "could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1534 | "for hotkey polling\n"); |
| 1535 | } |
| 1536 | } |
| 1537 | } else { |
| 1538 | hotkey_poll_stop_sync(); |
| 1539 | if (may_warn && |
| 1540 | hotkey_source_mask != 0 && hotkey_poll_freq == 0) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1541 | printk(TPACPI_NOTICE |
| 1542 | "hot keys 0x%08x require polling, " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1543 | "which is currently disabled\n", |
| 1544 | hotkey_source_mask); |
| 1545 | } |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | static void hotkey_poll_setup_safe(int may_warn) |
| 1550 | { |
| 1551 | mutex_lock(&hotkey_mutex); |
| 1552 | hotkey_poll_setup(may_warn); |
| 1553 | mutex_unlock(&hotkey_mutex); |
| 1554 | } |
| 1555 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 1556 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1557 | |
| 1558 | static void hotkey_poll_setup_safe(int __unused) |
| 1559 | { |
| 1560 | } |
| 1561 | |
| 1562 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1563 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1564 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 1565 | { |
| 1566 | switch (tpacpi_lifecycle) { |
| 1567 | case TPACPI_LIFE_INIT: |
| 1568 | /* |
| 1569 | * hotkey_init will call hotkey_poll_setup_safe |
| 1570 | * at the appropriate moment |
| 1571 | */ |
| 1572 | return 0; |
| 1573 | case TPACPI_LIFE_EXITING: |
| 1574 | return -EBUSY; |
| 1575 | case TPACPI_LIFE_RUNNING: |
| 1576 | hotkey_poll_setup_safe(0); |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
| 1580 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 1581 | BUG(); |
| 1582 | return -EBUSY; |
| 1583 | } |
| 1584 | |
| 1585 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 1586 | { |
| 1587 | /* disable hotkey polling when possible */ |
| 1588 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING) |
| 1589 | hotkey_poll_setup_safe(0); |
| 1590 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1591 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1592 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 1593 | static ssize_t hotkey_enable_show(struct device *dev, |
| 1594 | struct device_attribute *attr, |
| 1595 | char *buf) |
| 1596 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1597 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1598 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1599 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1600 | if (res) |
| 1601 | return res; |
| 1602 | |
| 1603 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 1604 | } |
| 1605 | |
| 1606 | static ssize_t hotkey_enable_store(struct device *dev, |
| 1607 | struct device_attribute *attr, |
| 1608 | const char *buf, size_t count) |
| 1609 | { |
| 1610 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1611 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1612 | |
| 1613 | if (parse_strtoul(buf, 1, &t)) |
| 1614 | return -EINVAL; |
| 1615 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1616 | res = hotkey_status_set(t); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1617 | |
| 1618 | return (res) ? res : count; |
| 1619 | } |
| 1620 | |
| 1621 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1622 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1623 | hotkey_enable_show, hotkey_enable_store); |
| 1624 | |
| 1625 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 1626 | static ssize_t hotkey_mask_show(struct device *dev, |
| 1627 | struct device_attribute *attr, |
| 1628 | char *buf) |
| 1629 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1630 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1631 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1632 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1633 | return -ERESTARTSYS; |
| 1634 | res = hotkey_mask_get(); |
| 1635 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1636 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1637 | return (res)? |
| 1638 | res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | static ssize_t hotkey_mask_store(struct device *dev, |
| 1642 | struct device_attribute *attr, |
| 1643 | const char *buf, size_t count) |
| 1644 | { |
| 1645 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1646 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1647 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1648 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1649 | return -EINVAL; |
| 1650 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1651 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1652 | return -ERESTARTSYS; |
| 1653 | |
| 1654 | res = hotkey_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1655 | |
| 1656 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1657 | hotkey_poll_setup(1); |
| 1658 | #endif |
| 1659 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1660 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1661 | |
| 1662 | return (res) ? res : count; |
| 1663 | } |
| 1664 | |
| 1665 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1666 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1667 | hotkey_mask_show, hotkey_mask_store); |
| 1668 | |
| 1669 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 1670 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 1671 | struct device_attribute *attr, |
| 1672 | char *buf) |
| 1673 | { |
| 1674 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status); |
| 1675 | } |
| 1676 | |
| 1677 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1678 | __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] | 1679 | |
| 1680 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 1681 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 1682 | struct device_attribute *attr, |
| 1683 | char *buf) |
| 1684 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1685 | 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] | 1686 | } |
| 1687 | |
| 1688 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1689 | __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] | 1690 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1691 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 1692 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 1693 | struct device_attribute *attr, |
| 1694 | char *buf) |
| 1695 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1696 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 1697 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 1701 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 1702 | |
| 1703 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 1704 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 1705 | struct device_attribute *attr, |
| 1706 | char *buf) |
| 1707 | { |
| 1708 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1709 | (hotkey_all_mask | hotkey_source_mask) |
| 1710 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 1714 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 1715 | hotkey_recommended_mask_show, NULL); |
| 1716 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1717 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1718 | |
| 1719 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 1720 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 1721 | struct device_attribute *attr, |
| 1722 | char *buf) |
| 1723 | { |
| 1724 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 1725 | } |
| 1726 | |
| 1727 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 1728 | struct device_attribute *attr, |
| 1729 | const char *buf, size_t count) |
| 1730 | { |
| 1731 | unsigned long t; |
| 1732 | |
| 1733 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 1734 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 1735 | return -EINVAL; |
| 1736 | |
| 1737 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1738 | return -ERESTARTSYS; |
| 1739 | |
| 1740 | HOTKEY_CONFIG_CRITICAL_START |
| 1741 | hotkey_source_mask = t; |
| 1742 | HOTKEY_CONFIG_CRITICAL_END |
| 1743 | |
| 1744 | hotkey_poll_setup(1); |
| 1745 | |
| 1746 | mutex_unlock(&hotkey_mutex); |
| 1747 | |
| 1748 | return count; |
| 1749 | } |
| 1750 | |
| 1751 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 1752 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 1753 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 1754 | |
| 1755 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 1756 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 1757 | struct device_attribute *attr, |
| 1758 | char *buf) |
| 1759 | { |
| 1760 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 1761 | } |
| 1762 | |
| 1763 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 1764 | struct device_attribute *attr, |
| 1765 | const char *buf, size_t count) |
| 1766 | { |
| 1767 | unsigned long t; |
| 1768 | |
| 1769 | if (parse_strtoul(buf, 25, &t)) |
| 1770 | return -EINVAL; |
| 1771 | |
| 1772 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1773 | return -ERESTARTSYS; |
| 1774 | |
| 1775 | hotkey_poll_freq = t; |
| 1776 | |
| 1777 | hotkey_poll_setup(1); |
| 1778 | mutex_unlock(&hotkey_mutex); |
| 1779 | |
| 1780 | return count; |
| 1781 | } |
| 1782 | |
| 1783 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 1784 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 1785 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 1786 | |
| 1787 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1788 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1789 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1790 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 1791 | struct device_attribute *attr, |
| 1792 | char *buf) |
| 1793 | { |
| 1794 | int res, s; |
| 1795 | res = hotkey_get_wlsw(&s); |
| 1796 | if (res < 0) |
| 1797 | return res; |
| 1798 | |
| 1799 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 1800 | } |
| 1801 | |
| 1802 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 1803 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 1804 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1805 | static void hotkey_radio_sw_notify_change(void) |
| 1806 | { |
| 1807 | if (tp_features.hotkey_wlsw) |
| 1808 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1809 | "hotkey_radio_sw"); |
| 1810 | } |
| 1811 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1812 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 1813 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 1814 | struct device_attribute *attr, |
| 1815 | char *buf) |
| 1816 | { |
| 1817 | int res, s; |
| 1818 | res = hotkey_get_tablet_mode(&s); |
| 1819 | if (res < 0) |
| 1820 | return res; |
| 1821 | |
| 1822 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 1823 | } |
| 1824 | |
| 1825 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 1826 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 1827 | |
| 1828 | static void hotkey_tablet_mode_notify_change(void) |
| 1829 | { |
| 1830 | if (tp_features.hotkey_tablet) |
| 1831 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1832 | "hotkey_tablet_mode"); |
| 1833 | } |
| 1834 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1835 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 1836 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 1837 | struct device_attribute *attr, |
| 1838 | char *buf) |
| 1839 | { |
| 1840 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1841 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 1842 | } |
| 1843 | |
| 1844 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 1845 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 1846 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1847 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1848 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 1849 | struct device_attribute *attr, |
| 1850 | char *buf) |
| 1851 | { |
| 1852 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 1853 | } |
| 1854 | |
| 1855 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 1856 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 1857 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 1858 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1859 | { |
| 1860 | if (tp_features.hotkey_mask) |
| 1861 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1862 | "wakeup_reason"); |
| 1863 | } |
| 1864 | |
| 1865 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1866 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 1867 | struct device_attribute *attr, |
| 1868 | char *buf) |
| 1869 | { |
| 1870 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 1871 | } |
| 1872 | |
| 1873 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 1874 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 1875 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 1876 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 1877 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1878 | { |
| 1879 | if (tp_features.hotkey_mask) |
| 1880 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1881 | "wakeup_hotunplug_complete"); |
| 1882 | } |
| 1883 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1884 | /* --------------------------------------------------------------------- */ |
| 1885 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1886 | static struct attribute *hotkey_attributes[] __initdata = { |
| 1887 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1888 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1889 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1890 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1891 | &dev_attr_hotkey_mask.attr, |
| 1892 | &dev_attr_hotkey_all_mask.attr, |
| 1893 | &dev_attr_hotkey_recommended_mask.attr, |
| 1894 | &dev_attr_hotkey_source_mask.attr, |
| 1895 | &dev_attr_hotkey_poll_freq.attr, |
| 1896 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1897 | }; |
| 1898 | |
| 1899 | static struct attribute *hotkey_mask_attributes[] __initdata = { |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1900 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1901 | #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1902 | &dev_attr_hotkey_mask.attr, |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1903 | &dev_attr_hotkey_all_mask.attr, |
| 1904 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1905 | #endif |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1906 | &dev_attr_hotkey_wakeup_reason.attr, |
| 1907 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1908 | }; |
| 1909 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1910 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1911 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1912 | /* Requirements for changing the default keymaps: |
| 1913 | * |
| 1914 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 1915 | * good reasons. Do not change them unless you have deep |
| 1916 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 1917 | * the various ThinkPad models. The driver behaves |
| 1918 | * differently for KEY_RESERVED: such keys have their |
| 1919 | * hot key mask *unset* in mask_recommended, and also |
| 1920 | * in the initial hot key mask programmed into the |
| 1921 | * firmware at driver load time, which means the firm- |
| 1922 | * ware may react very differently if you change them to |
| 1923 | * something else; |
| 1924 | * |
| 1925 | * 2. You must be subscribed to the linux-thinkpad and |
| 1926 | * ibm-acpi-devel mailing lists, and you should read the |
| 1927 | * list archives since 2007 if you want to change the |
| 1928 | * keymaps. This requirement exists so that you will |
| 1929 | * know the past history of problems with the thinkpad- |
| 1930 | * acpi driver keymaps, and also that you will be |
| 1931 | * listening to any bug reports; |
| 1932 | * |
| 1933 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 1934 | * for merging, *ever*. Send them to the linux-acpi |
| 1935 | * mailinglist for comments. Merging is to be done only |
| 1936 | * through acpi-test and the ACPI maintainer. |
| 1937 | * |
| 1938 | * If the above is too much to ask, don't change the keymap. |
| 1939 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 1940 | */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1941 | static u16 ibm_keycode_map[] __initdata = { |
| 1942 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 1943 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
| 1944 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 1945 | 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] | 1946 | |
| 1947 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1948 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 1949 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 1950 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1951 | |
| 1952 | /* brightness: firmware always reacts to them, unless |
| 1953 | * X.org did some tricks in the radeon BIOS scratch |
| 1954 | * registers of *some* models */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1955 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1956 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1957 | |
| 1958 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1959 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1960 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1961 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 1962 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1963 | |
| 1964 | /* Volume: firmware always react to it and reprograms |
| 1965 | * the built-in *extra* mixer. Never map it to control |
| 1966 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1967 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 1968 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 1969 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1970 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1971 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1972 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1973 | /* (assignments unknown, please report if found) */ |
| 1974 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 1975 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 1976 | }; |
| 1977 | static u16 lenovo_keycode_map[] __initdata = { |
| 1978 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 1979 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
| 1980 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 1981 | 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] | 1982 | |
| 1983 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1984 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 1985 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 1986 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1987 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 1988 | /* These either have to go through ACPI video, or |
| 1989 | * act like in the IBM ThinkPads, so don't ever |
| 1990 | * enable them by default */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 1991 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 1992 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1993 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1994 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1995 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1996 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 1997 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1998 | |
| 1999 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 2000 | * react to it and reprograms the built-in *extra* mixer. |
| 2001 | * Never map it to control another mixer by default. |
| 2002 | * |
| 2003 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 2004 | * these over the regular keyboard, so these are no-ops, |
| 2005 | * but there are still weird bugs re. MUTE, so do not |
| 2006 | * change unless you get test reports from all Lenovo |
| 2007 | * models. May cause the BIOS to interfere with the |
| 2008 | * HDA mixer. |
| 2009 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2010 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2011 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2012 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2013 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2014 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2015 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2016 | /* (assignments unknown, please report if found) */ |
| 2017 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2018 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2019 | }; |
| 2020 | |
| 2021 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) |
| 2022 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) |
| 2023 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) |
| 2024 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2025 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2026 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2027 | int hkeyv; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2028 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2029 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); |
| 2030 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2031 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2032 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 2033 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2034 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2035 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2036 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2037 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2038 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2039 | mutex_init(&hotkey_thread_mutex); |
| 2040 | mutex_init(&hotkey_thread_data_mutex); |
| 2041 | #endif |
| 2042 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2043 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2044 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2045 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2046 | vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2047 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2048 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2049 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2050 | hotkey_dev_attributes = create_attr_set(13, NULL); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2051 | if (!hotkey_dev_attributes) |
| 2052 | return -ENOMEM; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2053 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 2054 | hotkey_attributes, |
| 2055 | ARRAY_SIZE(hotkey_attributes)); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2056 | if (res) |
| 2057 | return res; |
| 2058 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2059 | /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2060 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 2061 | for HKEY interface version 0x100 */ |
| 2062 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 2063 | if ((hkeyv >> 8) != 1) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2064 | printk(TPACPI_ERR "unknown version of the " |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2065 | "HKEY interface: 0x%x\n", hkeyv); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2066 | printk(TPACPI_ERR "please report this to %s\n", |
| 2067 | TPACPI_MAIL); |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2068 | } else { |
| 2069 | /* |
| 2070 | * MHKV 0x100 in A31, R40, R40e, |
| 2071 | * T4x, X31, and later |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2072 | */ |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2073 | tp_features.hotkey_mask = 1; |
| 2074 | } |
| 2075 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2076 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2077 | vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2078 | str_supported(tp_features.hotkey_mask)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2079 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2080 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2081 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2082 | "MHKA", "qd")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2083 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2084 | "missing MHKA handler, " |
| 2085 | "please report this to %s\n", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2086 | TPACPI_MAIL); |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2087 | /* FN+F12, FN+F4, FN+F3 */ |
| 2088 | hotkey_all_mask = 0x080cU; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2089 | } |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2090 | } |
| 2091 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2092 | /* hotkey_source_mask *must* be zero for |
| 2093 | * the first hotkey_mask_get */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2094 | res = hotkey_status_get(&hotkey_orig_status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2095 | if (!res && tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2096 | res = hotkey_mask_get(); |
| 2097 | hotkey_orig_mask = hotkey_mask; |
| 2098 | if (!res) { |
| 2099 | res = add_many_to_attr_set( |
| 2100 | hotkey_dev_attributes, |
| 2101 | hotkey_mask_attributes, |
| 2102 | ARRAY_SIZE(hotkey_mask_attributes)); |
| 2103 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2104 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2105 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2106 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2107 | if (tp_features.hotkey_mask) { |
| 2108 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 2109 | & ~hotkey_all_mask; |
| 2110 | } else { |
| 2111 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK; |
| 2112 | } |
| 2113 | |
| 2114 | vdbg_printk(TPACPI_DBG_INIT, |
| 2115 | "hotkey source mask 0x%08x, polling freq %d\n", |
| 2116 | hotkey_source_mask, hotkey_poll_freq); |
| 2117 | #endif |
| 2118 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2119 | /* Not all thinkpads have a hardware radio switch */ |
| 2120 | if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 2121 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2122 | printk(TPACPI_INFO |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2123 | "radio switch found; radios are %s\n", |
| 2124 | enabled(status, 0)); |
| 2125 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2126 | &dev_attr_hotkey_radio_sw.attr); |
| 2127 | } |
| 2128 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2129 | /* For X41t, X60t, X61t Tablets... */ |
| 2130 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 2131 | tp_features.hotkey_tablet = 1; |
| 2132 | printk(TPACPI_INFO |
| 2133 | "possible tablet mode switch found; " |
| 2134 | "ThinkPad in %s mode\n", |
| 2135 | (status & TP_HOTKEY_TABLET_MASK)? |
| 2136 | "tablet" : "laptop"); |
| 2137 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2138 | &dev_attr_hotkey_tablet_mode.attr); |
| 2139 | } |
| 2140 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2141 | if (!res) |
| 2142 | res = register_attr_set_with_sysfs( |
| 2143 | hotkey_dev_attributes, |
| 2144 | &tpacpi_pdev->dev.kobj); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2145 | if (res) |
| 2146 | return res; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2147 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2148 | /* Set up key map */ |
| 2149 | |
| 2150 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 2151 | GFP_KERNEL); |
| 2152 | if (!hotkey_keycode_map) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2153 | printk(TPACPI_ERR |
| 2154 | "failed to allocate memory for key map\n"); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2155 | return -ENOMEM; |
| 2156 | } |
| 2157 | |
| 2158 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
| 2159 | dbg_printk(TPACPI_DBG_INIT, |
| 2160 | "using Lenovo default hot key map\n"); |
| 2161 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, |
| 2162 | TPACPI_HOTKEY_MAP_SIZE); |
| 2163 | } else { |
| 2164 | dbg_printk(TPACPI_DBG_INIT, |
| 2165 | "using IBM default hot key map\n"); |
| 2166 | memcpy(hotkey_keycode_map, &ibm_keycode_map, |
| 2167 | TPACPI_HOTKEY_MAP_SIZE); |
| 2168 | } |
| 2169 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2170 | set_bit(EV_KEY, tpacpi_inputdev->evbit); |
| 2171 | set_bit(EV_MSC, tpacpi_inputdev->evbit); |
| 2172 | set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2173 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 2174 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 2175 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 2176 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2177 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
| 2178 | set_bit(hotkey_keycode_map[i], |
| 2179 | tpacpi_inputdev->keybit); |
| 2180 | } else { |
| 2181 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 2182 | hotkey_reserved_mask |= 1 << i; |
| 2183 | } |
| 2184 | } |
| 2185 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2186 | if (tp_features.hotkey_wlsw) { |
| 2187 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2188 | set_bit(SW_RADIO, tpacpi_inputdev->swbit); |
| 2189 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2190 | if (tp_features.hotkey_tablet) { |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2191 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2192 | set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit); |
| 2193 | } |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2194 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 2195 | /* Do not issue duplicate brightness change events to |
| 2196 | * userspace */ |
| 2197 | if (!tp_features.bright_acpimode) |
| 2198 | /* update bright_acpimode... */ |
| 2199 | tpacpi_check_std_acpi_brightness_support(); |
| 2200 | |
| 2201 | if (tp_features.bright_acpimode) { |
| 2202 | printk(TPACPI_INFO |
| 2203 | "This ThinkPad has standard ACPI backlight " |
| 2204 | "brightness control, supported by the ACPI " |
| 2205 | "video driver\n"); |
| 2206 | printk(TPACPI_NOTICE |
| 2207 | "Disabling thinkpad-acpi brightness events " |
| 2208 | "by default...\n"); |
| 2209 | |
| 2210 | /* The hotkey_reserved_mask change below is not |
| 2211 | * necessary while the keys are at KEY_RESERVED in the |
| 2212 | * default map, but better safe than sorry, leave it |
| 2213 | * here as a marker of what we have to do, especially |
| 2214 | * when we finally become able to set this at runtime |
| 2215 | * on response to X.org requests */ |
| 2216 | hotkey_reserved_mask |= |
| 2217 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 2218 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
| 2219 | } |
| 2220 | |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2221 | dbg_printk(TPACPI_DBG_INIT, |
| 2222 | "enabling hot key handling\n"); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2223 | res = hotkey_status_set(1); |
| 2224 | if (res) |
| 2225 | return res; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2226 | res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask) |
| 2227 | & ~hotkey_reserved_mask) |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2228 | | hotkey_orig_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2229 | if (res < 0 && res != -ENXIO) |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2230 | return res; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2231 | |
| 2232 | dbg_printk(TPACPI_DBG_INIT, |
| 2233 | "legacy hot key reporting over procfs %s\n", |
| 2234 | (hotkey_report_mode < 2) ? |
| 2235 | "enabled" : "disabled"); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2236 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2237 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 2238 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 2239 | |
| 2240 | hotkey_poll_setup_safe(1); |
Henrique de Moraes Holschuh | 7526696 | 2008-02-16 02:17:53 -0200 | [diff] [blame] | 2241 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2242 | tpacpi_input_send_tabletsw(); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2243 | } |
| 2244 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2245 | return (tp_features.hotkey)? 0 : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | static void hotkey_exit(void) |
| 2249 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2250 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2251 | hotkey_poll_stop_sync(); |
| 2252 | #endif |
| 2253 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2254 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2255 | dbg_printk(TPACPI_DBG_EXIT, |
| 2256 | "restoring original hot key mask\n"); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2257 | /* no short-circuit boolean operator below! */ |
| 2258 | if ((hotkey_mask_set(hotkey_orig_mask) | |
| 2259 | hotkey_status_set(hotkey_orig_status)) != 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2260 | printk(TPACPI_ERR |
| 2261 | "failed to restore hot key mask " |
| 2262 | "to BIOS defaults\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2263 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2264 | |
| 2265 | if (hotkey_dev_attributes) { |
| 2266 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 2267 | hotkey_dev_attributes = NULL; |
| 2268 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 2272 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2273 | u32 hkey; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2274 | unsigned int scancode; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2275 | int send_acpi_ev; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2276 | int ignore_acpi_ev; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2277 | int unk_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2278 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2279 | if (event != 0x80) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2280 | printk(TPACPI_ERR |
| 2281 | "unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2282 | /* 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] | 2283 | acpi_bus_generate_netlink_event( |
| 2284 | ibm->acpi->device->pnp.device_class, |
| 2285 | ibm->acpi->device->dev.bus_id, |
| 2286 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2287 | return; |
| 2288 | } |
| 2289 | |
| 2290 | while (1) { |
| 2291 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2292 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2293 | return; |
| 2294 | } |
| 2295 | |
| 2296 | if (hkey == 0) { |
| 2297 | /* queue empty */ |
| 2298 | return; |
| 2299 | } |
| 2300 | |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2301 | send_acpi_ev = 1; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2302 | ignore_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2303 | unk_ev = 0; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2304 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2305 | switch (hkey >> 12) { |
| 2306 | case 1: |
| 2307 | /* 0x1000-0x1FFF: key presses */ |
| 2308 | scancode = hkey & 0xfff; |
| 2309 | if (scancode > 0 && scancode < 0x21) { |
| 2310 | scancode--; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2311 | if (!(hotkey_source_mask & (1 << scancode))) { |
| 2312 | tpacpi_input_send_key(scancode); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2313 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2314 | } else { |
| 2315 | ignore_acpi_ev = 1; |
| 2316 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2317 | } else { |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2318 | unk_ev = 1; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2319 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2320 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2321 | case 2: |
| 2322 | /* Wakeup reason */ |
| 2323 | switch (hkey) { |
| 2324 | case 0x2304: /* suspend, undock */ |
| 2325 | case 0x2404: /* hibernation, undock */ |
| 2326 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 2327 | ignore_acpi_ev = 1; |
| 2328 | break; |
| 2329 | case 0x2305: /* suspend, bay eject */ |
| 2330 | case 0x2405: /* hibernation, bay eject */ |
| 2331 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 2332 | ignore_acpi_ev = 1; |
| 2333 | break; |
| 2334 | default: |
| 2335 | unk_ev = 1; |
| 2336 | } |
| 2337 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
| 2338 | printk(TPACPI_INFO |
| 2339 | "woke up due to a hot-unplug " |
| 2340 | "request...\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2341 | hotkey_wakeup_reason_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2342 | } |
| 2343 | break; |
| 2344 | case 3: |
| 2345 | /* bay-related wakeups */ |
| 2346 | if (hkey == 0x3003) { |
| 2347 | hotkey_autosleep_ack = 1; |
| 2348 | printk(TPACPI_INFO |
| 2349 | "bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2350 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2351 | } else { |
| 2352 | unk_ev = 1; |
| 2353 | } |
| 2354 | break; |
| 2355 | case 4: |
| 2356 | /* dock-related wakeups */ |
| 2357 | if (hkey == 0x4003) { |
| 2358 | hotkey_autosleep_ack = 1; |
| 2359 | printk(TPACPI_INFO |
| 2360 | "undocked\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2361 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2362 | } else { |
| 2363 | unk_ev = 1; |
| 2364 | } |
| 2365 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2366 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2367 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2368 | switch (hkey) { |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2369 | case 0x5010: /* Lenovo new BIOS: brightness changed */ |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2370 | case 0x500b: /* X61t: tablet pen inserted into bay */ |
| 2371 | case 0x500c: /* X61t: tablet pen removed from bay */ |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2372 | break; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2373 | case 0x5009: /* X41t-X61t: swivel up (tablet mode) */ |
| 2374 | case 0x500a: /* X41t-X61t: swivel down (normal mode) */ |
| 2375 | tpacpi_input_send_tabletsw(); |
| 2376 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2377 | send_acpi_ev = 0; |
| 2378 | break; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2379 | case 0x5001: |
| 2380 | case 0x5002: |
| 2381 | /* LID switch events. Do not propagate */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2382 | ignore_acpi_ev = 1; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2383 | break; |
| 2384 | default: |
| 2385 | unk_ev = 1; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2386 | } |
| 2387 | break; |
| 2388 | case 7: |
| 2389 | /* 0x7000-0x7FFF: misc */ |
| 2390 | if (tp_features.hotkey_wlsw && hkey == 0x7000) { |
| 2391 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2392 | hotkey_radio_sw_notify_change(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2393 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2394 | break; |
| 2395 | } |
| 2396 | /* fallthrough to default */ |
| 2397 | default: |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2398 | unk_ev = 1; |
| 2399 | } |
| 2400 | if (unk_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2401 | printk(TPACPI_NOTICE |
| 2402 | "unhandled HKEY event 0x%04x\n", hkey); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2403 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2404 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2405 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2406 | if (!ignore_acpi_ev && |
| 2407 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 2408 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 2409 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2410 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2411 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2412 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2413 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2414 | acpi_bus_generate_netlink_event( |
| 2415 | ibm->acpi->device->pnp.device_class, |
| 2416 | ibm->acpi->device->dev.bus_id, |
| 2417 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2418 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2419 | } |
| 2420 | } |
| 2421 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2422 | static void hotkey_suspend(pm_message_t state) |
| 2423 | { |
| 2424 | /* Do these on suspend, we get the events on early resume! */ |
| 2425 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 2426 | hotkey_autosleep_ack = 0; |
| 2427 | } |
| 2428 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2429 | static void hotkey_resume(void) |
| 2430 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2431 | if (hotkey_mask_get()) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2432 | printk(TPACPI_ERR |
| 2433 | "error while trying to read hot key mask " |
| 2434 | "from firmware\n"); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2435 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2436 | hotkey_radio_sw_notify_change(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2437 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2438 | hotkey_wakeup_reason_notify_change(); |
| 2439 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2440 | hotkey_poll_setup_safe(0); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2441 | } |
| 2442 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2443 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2444 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2446 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | int len = 0; |
| 2448 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2449 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2450 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 2451 | return len; |
| 2452 | } |
| 2453 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 2454 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2455 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2456 | res = hotkey_status_get(&status); |
| 2457 | if (!res) |
| 2458 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2459 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2460 | if (res) |
| 2461 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | |
| 2463 | 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] | 2464 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2465 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | len += sprintf(p + len, |
| 2467 | "commands:\tenable, disable, reset, <mask>\n"); |
| 2468 | } else { |
| 2469 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 2470 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 2471 | } |
| 2472 | |
| 2473 | return len; |
| 2474 | } |
| 2475 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2476 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2478 | int res, status; |
| 2479 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2482 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | return -ENODEV; |
| 2484 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 2485 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2486 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2487 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2488 | status = -1; |
| 2489 | mask = hotkey_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2490 | |
| 2491 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | while ((cmd = next_cmd(&buf))) { |
| 2493 | if (strlencmp(cmd, "enable") == 0) { |
| 2494 | status = 1; |
| 2495 | } else if (strlencmp(cmd, "disable") == 0) { |
| 2496 | status = 0; |
| 2497 | } else if (strlencmp(cmd, "reset") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2498 | status = hotkey_orig_status; |
| 2499 | mask = hotkey_orig_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 2501 | /* mask set */ |
| 2502 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 2503 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2504 | } else { |
| 2505 | res = -EINVAL; |
| 2506 | goto errexit; |
| 2507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2509 | if (status != -1) |
| 2510 | res = hotkey_status_set(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2512 | if (!res && mask != hotkey_mask) |
| 2513 | res = hotkey_mask_set(mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2515 | errexit: |
| 2516 | mutex_unlock(&hotkey_mutex); |
| 2517 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2518 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2520 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2521 | {TPACPI_ACPI_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2522 | {"", 0}, |
| 2523 | }; |
| 2524 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2525 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2526 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2527 | .notify = hotkey_notify, |
| 2528 | .handle = &hkey_handle, |
| 2529 | .type = ACPI_DEVICE_NOTIFY, |
| 2530 | }; |
| 2531 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2532 | static struct ibm_struct hotkey_driver_data = { |
| 2533 | .name = "hotkey", |
| 2534 | .read = hotkey_read, |
| 2535 | .write = hotkey_write, |
| 2536 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2537 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2538 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2539 | .acpi = &ibm_hotkey_acpidriver, |
| 2540 | }; |
| 2541 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2542 | /************************************************************************* |
| 2543 | * Bluetooth subdriver |
| 2544 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2546 | enum { |
| 2547 | /* ACPI GBDC/SBDC bits */ |
| 2548 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 2549 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
| 2550 | TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */ |
| 2551 | }; |
| 2552 | |
| 2553 | static int bluetooth_get_radiosw(void); |
| 2554 | static int bluetooth_set_radiosw(int radio_on); |
| 2555 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2556 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 2557 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 2558 | struct device_attribute *attr, |
| 2559 | char *buf) |
| 2560 | { |
| 2561 | int status; |
| 2562 | |
| 2563 | status = bluetooth_get_radiosw(); |
| 2564 | if (status < 0) |
| 2565 | return status; |
| 2566 | |
| 2567 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); |
| 2568 | } |
| 2569 | |
| 2570 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 2571 | struct device_attribute *attr, |
| 2572 | const char *buf, size_t count) |
| 2573 | { |
| 2574 | unsigned long t; |
| 2575 | int res; |
| 2576 | |
| 2577 | if (parse_strtoul(buf, 1, &t)) |
| 2578 | return -EINVAL; |
| 2579 | |
| 2580 | res = bluetooth_set_radiosw(t); |
| 2581 | |
| 2582 | return (res) ? res : count; |
| 2583 | } |
| 2584 | |
| 2585 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2586 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2587 | bluetooth_enable_show, bluetooth_enable_store); |
| 2588 | |
| 2589 | /* --------------------------------------------------------------------- */ |
| 2590 | |
| 2591 | static struct attribute *bluetooth_attributes[] = { |
| 2592 | &dev_attr_bluetooth_enable.attr, |
| 2593 | NULL |
| 2594 | }; |
| 2595 | |
| 2596 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2597 | .attrs = bluetooth_attributes, |
| 2598 | }; |
| 2599 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2600 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2602 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2603 | int status = 0; |
| 2604 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2605 | vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n"); |
| 2606 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2607 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2608 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2609 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 2610 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2611 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2612 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2614 | vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n", |
| 2615 | str_supported(tp_features.bluetooth), |
| 2616 | status); |
| 2617 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2618 | if (tp_features.bluetooth) { |
| 2619 | if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 2620 | /* no bluetooth hardware present in system */ |
| 2621 | tp_features.bluetooth = 0; |
| 2622 | dbg_printk(TPACPI_DBG_INIT, |
| 2623 | "bluetooth hardware not installed\n"); |
| 2624 | } else { |
| 2625 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2626 | &bluetooth_attr_group); |
| 2627 | if (res) |
| 2628 | return res; |
| 2629 | } |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2630 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2631 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2632 | return (tp_features.bluetooth)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | } |
| 2634 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2635 | static void bluetooth_exit(void) |
| 2636 | { |
| 2637 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2638 | &bluetooth_attr_group); |
| 2639 | } |
| 2640 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2641 | static int bluetooth_get_radiosw(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | { |
| 2643 | int status; |
| 2644 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2645 | if (!tp_features.bluetooth) |
| 2646 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2648 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 2649 | return -EIO; |
| 2650 | |
| 2651 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0); |
| 2652 | } |
| 2653 | |
| 2654 | static int bluetooth_set_radiosw(int radio_on) |
| 2655 | { |
| 2656 | int status; |
| 2657 | |
| 2658 | if (!tp_features.bluetooth) |
| 2659 | return -ENODEV; |
| 2660 | |
| 2661 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 2662 | return -EIO; |
| 2663 | if (radio_on) |
| 2664 | status |= TP_ACPI_BLUETOOTH_RADIOSSW; |
| 2665 | else |
| 2666 | status &= ~TP_ACPI_BLUETOOTH_RADIOSSW; |
| 2667 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 2668 | return -EIO; |
| 2669 | |
| 2670 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | } |
| 2672 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2673 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2674 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | { |
| 2676 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2677 | int status = bluetooth_get_radiosw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2679 | if (!tp_features.bluetooth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2682 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2683 | (status)? "enabled" : "disabled"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 2685 | } |
| 2686 | |
| 2687 | return len; |
| 2688 | } |
| 2689 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2690 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2694 | if (!tp_features.bluetooth) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2695 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | |
| 2697 | while ((cmd = next_cmd(&buf))) { |
| 2698 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2699 | bluetooth_set_radiosw(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2701 | bluetooth_set_radiosw(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | } else |
| 2703 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | return 0; |
| 2707 | } |
| 2708 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2709 | static struct ibm_struct bluetooth_driver_data = { |
| 2710 | .name = "bluetooth", |
| 2711 | .read = bluetooth_read, |
| 2712 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2713 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2714 | }; |
| 2715 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2716 | /************************************************************************* |
| 2717 | * Wan subdriver |
| 2718 | */ |
| 2719 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2720 | enum { |
| 2721 | /* ACPI GWAN/SWAN bits */ |
| 2722 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 2723 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
| 2724 | TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */ |
| 2725 | }; |
| 2726 | |
| 2727 | static int wan_get_radiosw(void); |
| 2728 | static int wan_set_radiosw(int radio_on); |
| 2729 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2730 | /* sysfs wan enable ---------------------------------------------------- */ |
| 2731 | static ssize_t wan_enable_show(struct device *dev, |
| 2732 | struct device_attribute *attr, |
| 2733 | char *buf) |
| 2734 | { |
| 2735 | int status; |
| 2736 | |
| 2737 | status = wan_get_radiosw(); |
| 2738 | if (status < 0) |
| 2739 | return status; |
| 2740 | |
| 2741 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); |
| 2742 | } |
| 2743 | |
| 2744 | static ssize_t wan_enable_store(struct device *dev, |
| 2745 | struct device_attribute *attr, |
| 2746 | const char *buf, size_t count) |
| 2747 | { |
| 2748 | unsigned long t; |
| 2749 | int res; |
| 2750 | |
| 2751 | if (parse_strtoul(buf, 1, &t)) |
| 2752 | return -EINVAL; |
| 2753 | |
| 2754 | res = wan_set_radiosw(t); |
| 2755 | |
| 2756 | return (res) ? res : count; |
| 2757 | } |
| 2758 | |
| 2759 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2760 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2761 | wan_enable_show, wan_enable_store); |
| 2762 | |
| 2763 | /* --------------------------------------------------------------------- */ |
| 2764 | |
| 2765 | static struct attribute *wan_attributes[] = { |
| 2766 | &dev_attr_wan_enable.attr, |
| 2767 | NULL |
| 2768 | }; |
| 2769 | |
| 2770 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2771 | .attrs = wan_attributes, |
| 2772 | }; |
| 2773 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2774 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2775 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2776 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2777 | int status = 0; |
| 2778 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2779 | vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n"); |
| 2780 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2781 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2782 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2783 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2784 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2785 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2786 | vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n", |
| 2787 | str_supported(tp_features.wan), |
| 2788 | status); |
| 2789 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2790 | if (tp_features.wan) { |
| 2791 | if (!(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 2792 | /* no wan hardware present in system */ |
| 2793 | tp_features.wan = 0; |
| 2794 | dbg_printk(TPACPI_DBG_INIT, |
| 2795 | "wan hardware not installed\n"); |
| 2796 | } else { |
| 2797 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2798 | &wan_attr_group); |
| 2799 | if (res) |
| 2800 | return res; |
| 2801 | } |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2802 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2803 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2804 | return (tp_features.wan)? 0 : 1; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2805 | } |
| 2806 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2807 | static void wan_exit(void) |
| 2808 | { |
| 2809 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2810 | &wan_attr_group); |
| 2811 | } |
| 2812 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2813 | static int wan_get_radiosw(void) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2814 | { |
| 2815 | int status; |
| 2816 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2817 | if (!tp_features.wan) |
| 2818 | return -ENODEV; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2819 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2820 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 2821 | return -EIO; |
| 2822 | |
| 2823 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0); |
| 2824 | } |
| 2825 | |
| 2826 | static int wan_set_radiosw(int radio_on) |
| 2827 | { |
| 2828 | int status; |
| 2829 | |
| 2830 | if (!tp_features.wan) |
| 2831 | return -ENODEV; |
| 2832 | |
| 2833 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 2834 | return -EIO; |
| 2835 | if (radio_on) |
| 2836 | status |= TP_ACPI_WANCARD_RADIOSSW; |
| 2837 | else |
| 2838 | status &= ~TP_ACPI_WANCARD_RADIOSSW; |
| 2839 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 2840 | return -EIO; |
| 2841 | |
| 2842 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2843 | } |
| 2844 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2845 | /* procfs -------------------------------------------------------------- */ |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2846 | static int wan_read(char *p) |
| 2847 | { |
| 2848 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2849 | int status = wan_get_radiosw(); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2850 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2851 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2852 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2853 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2854 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2855 | (status)? "enabled" : "disabled"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2856 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 2857 | } |
| 2858 | |
| 2859 | return len; |
| 2860 | } |
| 2861 | |
| 2862 | static int wan_write(char *buf) |
| 2863 | { |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2864 | char *cmd; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2865 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2866 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2867 | return -ENODEV; |
| 2868 | |
| 2869 | while ((cmd = next_cmd(&buf))) { |
| 2870 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2871 | wan_set_radiosw(1); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2872 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2873 | wan_set_radiosw(0); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2874 | } else |
| 2875 | return -EINVAL; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2876 | } |
| 2877 | |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2878 | return 0; |
| 2879 | } |
| 2880 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2881 | static struct ibm_struct wan_driver_data = { |
| 2882 | .name = "wan", |
| 2883 | .read = wan_read, |
| 2884 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2885 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 2886 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2887 | }; |
| 2888 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2889 | /************************************************************************* |
| 2890 | * Video subdriver |
| 2891 | */ |
| 2892 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 2893 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 2894 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2895 | enum video_access_mode { |
| 2896 | TPACPI_VIDEO_NONE = 0, |
| 2897 | TPACPI_VIDEO_570, /* 570 */ |
| 2898 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 2899 | TPACPI_VIDEO_NEW, /* all others */ |
| 2900 | }; |
| 2901 | |
| 2902 | enum { /* video status flags, based on VIDEO_570 */ |
| 2903 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 2904 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 2905 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 2906 | }; |
| 2907 | |
| 2908 | enum { /* TPACPI_VIDEO_570 constants */ |
| 2909 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 2910 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 2911 | * video_status_flags */ |
| 2912 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 2913 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 2914 | }; |
| 2915 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 2916 | static enum video_access_mode video_supported; |
| 2917 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2918 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2919 | static int video_autosw_get(void); |
| 2920 | static int video_autosw_set(int enable); |
| 2921 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2922 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2923 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2924 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2926 | int ivga; |
| 2927 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2928 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 2929 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2930 | TPACPI_ACPIHANDLE_INIT(vid); |
| 2931 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2932 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2933 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 2934 | /* G41, assume IVGA doesn't change */ |
| 2935 | vid_handle = vid2_handle; |
| 2936 | |
| 2937 | if (!vid_handle) |
| 2938 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2939 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2940 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 2941 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2942 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2943 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 2944 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2945 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2946 | else |
| 2947 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2948 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2950 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 2951 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 2952 | video_supported); |
| 2953 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2954 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2957 | static void video_exit(void) |
| 2958 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2959 | dbg_printk(TPACPI_DBG_EXIT, |
| 2960 | "restoring original video autoswitch mode\n"); |
| 2961 | if (video_autosw_set(video_orig_autosw)) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2962 | printk(TPACPI_ERR "error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2963 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2964 | } |
| 2965 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2966 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | { |
| 2968 | int status = 0; |
| 2969 | int i; |
| 2970 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2971 | switch (video_supported) { |
| 2972 | case TPACPI_VIDEO_570: |
| 2973 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 2974 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 2975 | return -EIO; |
| 2976 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 2977 | break; |
| 2978 | case TPACPI_VIDEO_770: |
| 2979 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 2980 | return -EIO; |
| 2981 | if (i) |
| 2982 | status |= TP_ACPI_VIDEO_S_LCD; |
| 2983 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 2984 | return -EIO; |
| 2985 | if (i) |
| 2986 | status |= TP_ACPI_VIDEO_S_CRT; |
| 2987 | break; |
| 2988 | case TPACPI_VIDEO_NEW: |
| 2989 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 2990 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 2991 | return -EIO; |
| 2992 | if (i) |
| 2993 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2995 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 2996 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 2997 | return -EIO; |
| 2998 | if (i) |
| 2999 | status |= TP_ACPI_VIDEO_S_LCD; |
| 3000 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 3001 | return -EIO; |
| 3002 | if (i) |
| 3003 | status |= TP_ACPI_VIDEO_S_DVI; |
| 3004 | break; |
| 3005 | default: |
| 3006 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3007 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | |
| 3009 | return status; |
| 3010 | } |
| 3011 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3012 | static int video_outputsw_set(int status) |
| 3013 | { |
| 3014 | int autosw; |
| 3015 | int res = 0; |
| 3016 | |
| 3017 | switch (video_supported) { |
| 3018 | case TPACPI_VIDEO_570: |
| 3019 | res = acpi_evalf(NULL, NULL, |
| 3020 | "\\_SB.PHS2", "vdd", |
| 3021 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 3022 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 3023 | break; |
| 3024 | case TPACPI_VIDEO_770: |
| 3025 | autosw = video_autosw_get(); |
| 3026 | if (autosw < 0) |
| 3027 | return autosw; |
| 3028 | |
| 3029 | res = video_autosw_set(1); |
| 3030 | if (res) |
| 3031 | return res; |
| 3032 | res = acpi_evalf(vid_handle, NULL, |
| 3033 | "ASWT", "vdd", status * 0x100, 0); |
| 3034 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3035 | printk(TPACPI_ERR |
| 3036 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3037 | return -EIO; |
| 3038 | } |
| 3039 | break; |
| 3040 | case TPACPI_VIDEO_NEW: |
| 3041 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3042 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3043 | break; |
| 3044 | default: |
| 3045 | return -ENOSYS; |
| 3046 | } |
| 3047 | |
| 3048 | return (res)? 0 : -EIO; |
| 3049 | } |
| 3050 | |
| 3051 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3053 | int autosw = 0; |
| 3054 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3055 | switch (video_supported) { |
| 3056 | case TPACPI_VIDEO_570: |
| 3057 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 3058 | return -EIO; |
| 3059 | break; |
| 3060 | case TPACPI_VIDEO_770: |
| 3061 | case TPACPI_VIDEO_NEW: |
| 3062 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 3063 | return -EIO; |
| 3064 | break; |
| 3065 | default: |
| 3066 | return -ENOSYS; |
| 3067 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3068 | |
| 3069 | return autosw & 1; |
| 3070 | } |
| 3071 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3072 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3073 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3074 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3075 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3076 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3077 | } |
| 3078 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3079 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3080 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3081 | int autosw = video_autosw_get(); |
| 3082 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3083 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3084 | if (autosw < 0) |
| 3085 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3086 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3087 | switch (video_supported) { |
| 3088 | case TPACPI_VIDEO_570: |
| 3089 | res = video_autosw_set(1); |
| 3090 | if (res) |
| 3091 | return res; |
| 3092 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 3093 | break; |
| 3094 | case TPACPI_VIDEO_770: |
| 3095 | case TPACPI_VIDEO_NEW: |
| 3096 | res = video_autosw_set(1); |
| 3097 | if (res) |
| 3098 | return res; |
| 3099 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 3100 | break; |
| 3101 | default: |
| 3102 | return -ENOSYS; |
| 3103 | } |
| 3104 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3105 | printk(TPACPI_ERR |
| 3106 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3107 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3108 | } |
| 3109 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3110 | return (res)? 0 : -EIO; |
| 3111 | } |
| 3112 | |
| 3113 | static int video_expand_toggle(void) |
| 3114 | { |
| 3115 | switch (video_supported) { |
| 3116 | case TPACPI_VIDEO_570: |
| 3117 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 3118 | 0 : -EIO; |
| 3119 | case TPACPI_VIDEO_770: |
| 3120 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 3121 | 0 : -EIO; |
| 3122 | case TPACPI_VIDEO_NEW: |
| 3123 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 3124 | 0 : -EIO; |
| 3125 | default: |
| 3126 | return -ENOSYS; |
| 3127 | } |
| 3128 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3129 | } |
| 3130 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3131 | static int video_read(char *p) |
| 3132 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3133 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3134 | int len = 0; |
| 3135 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3136 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3137 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3138 | return len; |
| 3139 | } |
| 3140 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3141 | status = video_outputsw_get(); |
| 3142 | if (status < 0) |
| 3143 | return status; |
| 3144 | |
| 3145 | autosw = video_autosw_get(); |
| 3146 | if (autosw < 0) |
| 3147 | return autosw; |
| 3148 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3149 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3150 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 3151 | 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] | 3152 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3153 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 3154 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 3155 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 3156 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3157 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3158 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 3159 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 3160 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 3161 | |
| 3162 | return len; |
| 3163 | } |
| 3164 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3165 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | { |
| 3167 | char *cmd; |
| 3168 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3169 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3171 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3172 | return -ENODEV; |
| 3173 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3174 | enable = 0; |
| 3175 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | |
| 3177 | while ((cmd = next_cmd(&buf))) { |
| 3178 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3179 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3181 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3183 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3185 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3186 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3187 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3188 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3189 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3190 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3191 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3193 | res = video_autosw_set(1); |
| 3194 | if (res) |
| 3195 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3197 | res = video_autosw_set(0); |
| 3198 | if (res) |
| 3199 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3201 | res = video_outputsw_cycle(); |
| 3202 | if (res) |
| 3203 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3205 | res = video_expand_toggle(); |
| 3206 | if (res) |
| 3207 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | } else |
| 3209 | return -EINVAL; |
| 3210 | } |
| 3211 | |
| 3212 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3213 | status = video_outputsw_get(); |
| 3214 | if (status < 0) |
| 3215 | return status; |
| 3216 | res = video_outputsw_set((status & ~disable) | enable); |
| 3217 | if (res) |
| 3218 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | return 0; |
| 3222 | } |
| 3223 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3224 | static struct ibm_struct video_driver_data = { |
| 3225 | .name = "video", |
| 3226 | .read = video_read, |
| 3227 | .write = video_write, |
| 3228 | .exit = video_exit, |
| 3229 | }; |
| 3230 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 3231 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 3232 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3233 | /************************************************************************* |
| 3234 | * Light (thinklight) subdriver |
| 3235 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3237 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 3238 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3239 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3240 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3242 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 3243 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3244 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 3245 | TPACPI_ACPIHANDLE_INIT(lght); |
| 3246 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3247 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3248 | /* 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] | 3249 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3250 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3251 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3252 | /* light status not supported on |
| 3253 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3254 | tp_features.light_status = |
| 3255 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3257 | vdbg_printk(TPACPI_DBG_INIT, "light is %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3258 | str_supported(tp_features.light)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3259 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3260 | return (tp_features.light)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | } |
| 3262 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3263 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | { |
| 3265 | int len = 0; |
| 3266 | int status = 0; |
| 3267 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3268 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3269 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3270 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3271 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 3272 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 3273 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 3275 | return -EIO; |
| 3276 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3277 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 3278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | |
| 3280 | return len; |
| 3281 | } |
| 3282 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3283 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | { |
| 3285 | int cmos_cmd, lght_cmd; |
| 3286 | char *cmd; |
| 3287 | int success; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3288 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3289 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3290 | return -ENODEV; |
| 3291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | while ((cmd = next_cmd(&buf))) { |
| 3293 | if (strlencmp(cmd, "on") == 0) { |
| 3294 | cmos_cmd = 0x0c; |
| 3295 | lght_cmd = 1; |
| 3296 | } else if (strlencmp(cmd, "off") == 0) { |
| 3297 | cmos_cmd = 0x0d; |
| 3298 | lght_cmd = 0; |
| 3299 | } else |
| 3300 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | success = cmos_handle ? |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3303 | acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) : |
| 3304 | acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | if (!success) |
| 3306 | return -EIO; |
| 3307 | } |
| 3308 | |
| 3309 | return 0; |
| 3310 | } |
| 3311 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3312 | static struct ibm_struct light_driver_data = { |
| 3313 | .name = "light", |
| 3314 | .read = light_read, |
| 3315 | .write = light_write, |
| 3316 | }; |
| 3317 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3318 | /************************************************************************* |
| 3319 | * Dock subdriver |
| 3320 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3322 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3323 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3324 | static void dock_notify(struct ibm_struct *ibm, u32 event); |
| 3325 | static int dock_read(char *p); |
| 3326 | static int dock_write(char *buf); |
| 3327 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3328 | TPACPI_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3329 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ |
| 3330 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ |
| 3331 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
| 3332 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
| 3333 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3334 | /* don't list other alternatives as we install a notify handler on the 570 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3335 | TPACPI_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3336 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3337 | static const struct acpi_device_id ibm_pci_device_ids[] = { |
| 3338 | {PCI_ROOT_HID_STRING, 0}, |
| 3339 | {"", 0}, |
| 3340 | }; |
| 3341 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3342 | static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = { |
| 3343 | { |
| 3344 | .notify = dock_notify, |
| 3345 | .handle = &dock_handle, |
| 3346 | .type = ACPI_SYSTEM_NOTIFY, |
| 3347 | }, |
| 3348 | { |
Henrique de Moraes Holschuh | 996fba0 | 2007-07-18 23:45:40 -0300 | [diff] [blame] | 3349 | /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING. |
| 3350 | * We just use it to get notifications of dock hotplug |
| 3351 | * in very old thinkpads */ |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3352 | .hid = ibm_pci_device_ids, |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3353 | .notify = dock_notify, |
| 3354 | .handle = &pci_handle, |
| 3355 | .type = ACPI_SYSTEM_NOTIFY, |
| 3356 | }, |
| 3357 | }; |
| 3358 | |
| 3359 | static struct ibm_struct dock_driver_data[2] = { |
| 3360 | { |
| 3361 | .name = "dock", |
| 3362 | .read = dock_read, |
| 3363 | .write = dock_write, |
| 3364 | .acpi = &ibm_dock_acpidriver[0], |
| 3365 | }, |
| 3366 | { |
| 3367 | .name = "dock", |
| 3368 | .acpi = &ibm_dock_acpidriver[1], |
| 3369 | }, |
| 3370 | }; |
| 3371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | #define dock_docked() (_sta(dock_handle) & 1) |
| 3373 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3374 | static int __init dock_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3375 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3376 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n"); |
| 3377 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3378 | TPACPI_ACPIHANDLE_INIT(dock); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3379 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3380 | vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n", |
| 3381 | str_supported(dock_handle != NULL)); |
| 3382 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3383 | return (dock_handle)? 0 : 1; |
| 3384 | } |
| 3385 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3386 | static int __init dock_init2(struct ibm_init_struct *iibm) |
| 3387 | { |
| 3388 | int dock2_needed; |
| 3389 | |
| 3390 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n"); |
| 3391 | |
| 3392 | if (dock_driver_data[0].flags.acpi_driver_registered && |
| 3393 | dock_driver_data[0].flags.acpi_notify_installed) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3394 | TPACPI_ACPIHANDLE_INIT(pci); |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3395 | dock2_needed = (pci_handle != NULL); |
| 3396 | vdbg_printk(TPACPI_DBG_INIT, |
| 3397 | "dock PCI handler for the TP 570 is %s\n", |
| 3398 | str_supported(dock2_needed)); |
| 3399 | } else { |
| 3400 | vdbg_printk(TPACPI_DBG_INIT, |
| 3401 | "dock subdriver part 2 not required\n"); |
| 3402 | dock2_needed = 0; |
| 3403 | } |
| 3404 | |
| 3405 | return (dock2_needed)? 0 : 1; |
| 3406 | } |
| 3407 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3408 | static void dock_notify(struct ibm_struct *ibm, u32 event) |
| 3409 | { |
| 3410 | int docked = dock_docked(); |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3411 | int pci = ibm->acpi->hid && ibm->acpi->device && |
| 3412 | acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3413 | int data; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3414 | |
| 3415 | if (event == 1 && !pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3416 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3417 | else if (event == 1 && pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3418 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3419 | else if (event == 3 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3420 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3421 | else if (event == 3 && !docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3422 | data = 2; /* undock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3423 | else if (event == 0 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3424 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3425 | else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3426 | printk(TPACPI_ERR "unknown dock event %d, status %d\n", |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3427 | event, _sta(dock_handle)); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3428 | data = 0; /* unknown */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3429 | } |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 3430 | acpi_bus_generate_proc_event(ibm->acpi->device, event, data); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3431 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 3432 | ibm->acpi->device->dev.bus_id, |
| 3433 | event, data); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3434 | } |
| 3435 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3436 | static int dock_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | { |
| 3438 | int len = 0; |
| 3439 | int docked = dock_docked(); |
| 3440 | |
| 3441 | if (!dock_handle) |
| 3442 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3443 | else if (!docked) |
| 3444 | len += sprintf(p + len, "status:\t\tundocked\n"); |
| 3445 | else { |
| 3446 | len += sprintf(p + len, "status:\t\tdocked\n"); |
| 3447 | len += sprintf(p + len, "commands:\tdock, undock\n"); |
| 3448 | } |
| 3449 | |
| 3450 | return len; |
| 3451 | } |
| 3452 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3453 | static int dock_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | { |
| 3455 | char *cmd; |
| 3456 | |
| 3457 | if (!dock_docked()) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3458 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | |
| 3460 | while ((cmd = next_cmd(&buf))) { |
| 3461 | if (strlencmp(cmd, "undock") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3462 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || |
| 3463 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | return -EIO; |
| 3465 | } else if (strlencmp(cmd, "dock") == 0) { |
| 3466 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) |
| 3467 | return -EIO; |
| 3468 | } else |
| 3469 | return -EINVAL; |
| 3470 | } |
| 3471 | |
| 3472 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3475 | #endif /* CONFIG_THINKPAD_ACPI_DOCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3477 | /************************************************************************* |
| 3478 | * Bay subdriver |
| 3479 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3481 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3482 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3483 | TPACPI_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3484 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
| 3485 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ |
| 3486 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
| 3487 | ); /* A21e, R30, R31 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3488 | TPACPI_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3489 | "_EJ0", /* all others */ |
| 3490 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3491 | TPACPI_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3492 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ |
| 3493 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3494 | TPACPI_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3495 | "_EJ0", /* 770x */ |
| 3496 | ); /* all others */ |
| 3497 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3498 | static int __init bay_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3500 | vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n"); |
| 3501 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3502 | TPACPI_ACPIHANDLE_INIT(bay); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3503 | if (bay_handle) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3504 | TPACPI_ACPIHANDLE_INIT(bay_ej); |
| 3505 | TPACPI_ACPIHANDLE_INIT(bay2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3506 | if (bay2_handle) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3507 | TPACPI_ACPIHANDLE_INIT(bay2_ej); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3508 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3509 | tp_features.bay_status = bay_handle && |
| 3510 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); |
| 3511 | tp_features.bay_status2 = bay2_handle && |
| 3512 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3513 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3514 | tp_features.bay_eject = bay_handle && bay_ej_handle && |
| 3515 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); |
| 3516 | tp_features.bay_eject2 = bay2_handle && bay2_ej_handle && |
| 3517 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3519 | vdbg_printk(TPACPI_DBG_INIT, |
| 3520 | "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3521 | str_supported(tp_features.bay_status), |
| 3522 | str_supported(tp_features.bay_eject), |
| 3523 | str_supported(tp_features.bay_status2), |
| 3524 | str_supported(tp_features.bay_eject2)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3525 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3526 | return (tp_features.bay_status || tp_features.bay_eject || |
| 3527 | tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | } |
| 3529 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3530 | static void bay_notify(struct ibm_struct *ibm, u32 event) |
| 3531 | { |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 3532 | acpi_bus_generate_proc_event(ibm->acpi->device, event, 0); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3533 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 3534 | ibm->acpi->device->dev.bus_id, |
| 3535 | event, 0); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3536 | } |
| 3537 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3538 | #define bay_occupied(b) (_sta(b##_handle) & 1) |
| 3539 | |
| 3540 | static int bay_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | { |
| 3542 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3543 | int occupied = bay_occupied(bay); |
| 3544 | int occupied2 = bay_occupied(bay2); |
| 3545 | int eject, eject2; |
| 3546 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3547 | len += sprintf(p + len, "status:\t\t%s\n", |
| 3548 | tp_features.bay_status ? |
| 3549 | (occupied ? "occupied" : "unoccupied") : |
| 3550 | "not supported"); |
| 3551 | if (tp_features.bay_status2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3552 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? |
| 3553 | "occupied" : "unoccupied"); |
| 3554 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3555 | eject = tp_features.bay_eject && occupied; |
| 3556 | eject2 = tp_features.bay_eject2 && occupied2; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3557 | |
| 3558 | if (eject && eject2) |
| 3559 | len += sprintf(p + len, "commands:\teject, eject2\n"); |
| 3560 | else if (eject) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | len += sprintf(p + len, "commands:\teject\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3562 | else if (eject2) |
| 3563 | len += sprintf(p + len, "commands:\teject2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | |
| 3565 | return len; |
| 3566 | } |
| 3567 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3568 | static int bay_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | { |
| 3570 | char *cmd; |
| 3571 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3572 | if (!tp_features.bay_eject && !tp_features.bay_eject2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3573 | return -ENODEV; |
| 3574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3575 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3576 | if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3577 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) |
| 3578 | return -EIO; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3579 | } else if (tp_features.bay_eject2 && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3580 | strlencmp(cmd, "eject2") == 0) { |
| 3581 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | return -EIO; |
| 3583 | } else |
| 3584 | return -EINVAL; |
| 3585 | } |
| 3586 | |
| 3587 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3588 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3589 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3590 | static struct tp_acpi_drv_struct ibm_bay_acpidriver = { |
| 3591 | .notify = bay_notify, |
| 3592 | .handle = &bay_handle, |
| 3593 | .type = ACPI_SYSTEM_NOTIFY, |
| 3594 | }; |
| 3595 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3596 | static struct ibm_struct bay_driver_data = { |
| 3597 | .name = "bay", |
| 3598 | .read = bay_read, |
| 3599 | .write = bay_write, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3600 | .acpi = &ibm_bay_acpidriver, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3601 | }; |
| 3602 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3603 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3605 | /************************************************************************* |
| 3606 | * CMOS subdriver |
| 3607 | */ |
| 3608 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3609 | /* sysfs cmos_command -------------------------------------------------- */ |
| 3610 | static ssize_t cmos_command_store(struct device *dev, |
| 3611 | struct device_attribute *attr, |
| 3612 | const char *buf, size_t count) |
| 3613 | { |
| 3614 | unsigned long cmos_cmd; |
| 3615 | int res; |
| 3616 | |
| 3617 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 3618 | return -EINVAL; |
| 3619 | |
| 3620 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 3621 | return (res)? res : count; |
| 3622 | } |
| 3623 | |
| 3624 | static struct device_attribute dev_attr_cmos_command = |
| 3625 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 3626 | |
| 3627 | /* --------------------------------------------------------------------- */ |
| 3628 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3629 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3630 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3631 | int res; |
| 3632 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3633 | vdbg_printk(TPACPI_DBG_INIT, |
| 3634 | "initializing cmos commands subdriver\n"); |
| 3635 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3636 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3637 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3638 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 3639 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3640 | |
| 3641 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 3642 | if (res) |
| 3643 | return res; |
| 3644 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3645 | return (cmos_handle)? 0 : 1; |
| 3646 | } |
| 3647 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3648 | static void cmos_exit(void) |
| 3649 | { |
| 3650 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 3651 | } |
| 3652 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3653 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | { |
| 3655 | int len = 0; |
| 3656 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3657 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 3658 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | if (!cmos_handle) |
| 3660 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3661 | else { |
| 3662 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3663 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | return len; |
| 3667 | } |
| 3668 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3669 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | { |
| 3671 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 3672 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | |
| 3674 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3675 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 3676 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | /* cmos_cmd set */ |
| 3678 | } else |
| 3679 | return -EINVAL; |
| 3680 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 3681 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 3682 | if (res) |
| 3683 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3687 | } |
| 3688 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3689 | static struct ibm_struct cmos_driver_data = { |
| 3690 | .name = "cmos", |
| 3691 | .read = cmos_read, |
| 3692 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3693 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3694 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3695 | |
| 3696 | /************************************************************************* |
| 3697 | * LED subdriver |
| 3698 | */ |
| 3699 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3700 | enum led_access_mode { |
| 3701 | TPACPI_LED_NONE = 0, |
| 3702 | TPACPI_LED_570, /* 570 */ |
| 3703 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 3704 | TPACPI_LED_NEW, /* all others */ |
| 3705 | }; |
| 3706 | |
| 3707 | enum { /* For TPACPI_LED_OLD */ |
| 3708 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 3709 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 3710 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 3711 | }; |
| 3712 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 3713 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3714 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3715 | TPACPI_HANDLE(led, ec, "SLED", /* 570 */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3716 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */ |
| 3717 | /* T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3718 | "LED", /* all others */ |
| 3719 | ); /* R30, R31 */ |
| 3720 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3721 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3722 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3723 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 3724 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3725 | TPACPI_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3726 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3727 | if (!led_handle) |
| 3728 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3729 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3730 | else if (strlencmp(led_path, "SLED") == 0) |
| 3731 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3732 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3733 | else if (strlencmp(led_path, "SYSL") == 0) |
| 3734 | /* 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] | 3735 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3736 | else |
| 3737 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3738 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3739 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3740 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 3741 | str_supported(led_supported), led_supported); |
| 3742 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3743 | return (led_supported != TPACPI_LED_NONE)? 0 : 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking")) |
| 3747 | |
| 3748 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | { |
| 3750 | int len = 0; |
| 3751 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3752 | if (!led_supported) { |
| 3753 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3754 | return len; |
| 3755 | } |
| 3756 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3757 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3758 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3759 | /* 570 */ |
| 3760 | int i, status; |
| 3761 | for (i = 0; i < 8; i++) { |
| 3762 | if (!acpi_evalf(ec_handle, |
| 3763 | &status, "GLED", "dd", 1 << i)) |
| 3764 | return -EIO; |
| 3765 | len += sprintf(p + len, "%d:\t\t%s\n", |
| 3766 | i, led_status(status)); |
| 3767 | } |
| 3768 | } |
| 3769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | len += sprintf(p + len, "commands:\t" |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3771 | "<led> on, <led> off, <led> blink (<led> is 0-7)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | |
| 3773 | return len; |
| 3774 | } |
| 3775 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3776 | /* off, on, blink */ |
| 3777 | static const int led_sled_arg1[] = { 0, 1, 3 }; |
| 3778 | static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */ |
| 3779 | static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */ |
| 3780 | static const int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
| 3781 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3782 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | { |
| 3784 | char *cmd; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3785 | int led, ind, ret; |
| 3786 | |
| 3787 | if (!led_supported) |
| 3788 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | |
| 3790 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3791 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | return -EINVAL; |
| 3793 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3794 | if (strstr(cmd, "off")) { |
| 3795 | ind = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | } else if (strstr(cmd, "on")) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3797 | ind = 1; |
| 3798 | } else if (strstr(cmd, "blink")) { |
| 3799 | ind = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | } else |
| 3801 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3802 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3803 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3804 | /* 570 */ |
| 3805 | led = 1 << led; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3807 | led, led_sled_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | return -EIO; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3809 | } else if (led_supported == TPACPI_LED_OLD) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3810 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
| 3811 | led = 1 << led; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3812 | ret = ec_write(TPACPI_LED_EC_HLMS, led); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3813 | if (ret >= 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3814 | ret = ec_write(TPACPI_LED_EC_HLBL, |
| 3815 | led * led_exp_hlbl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3816 | if (ret >= 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3817 | ret = ec_write(TPACPI_LED_EC_HLCL, |
| 3818 | led * led_exp_hlcl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3819 | if (ret < 0) |
| 3820 | return ret; |
| 3821 | } else { |
| 3822 | /* all others */ |
| 3823 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 3824 | led, led_led_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | } |
| 3828 | |
| 3829 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3830 | } |
| 3831 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3832 | static struct ibm_struct led_driver_data = { |
| 3833 | .name = "led", |
| 3834 | .read = led_read, |
| 3835 | .write = led_write, |
| 3836 | }; |
| 3837 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3838 | /************************************************************************* |
| 3839 | * Beep subdriver |
| 3840 | */ |
| 3841 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3842 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3843 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3844 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3845 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3846 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 3847 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3848 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3849 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3850 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 3851 | str_supported(beep_handle != NULL)); |
| 3852 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3853 | return (beep_handle)? 0 : 1; |
| 3854 | } |
| 3855 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3856 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | { |
| 3858 | int len = 0; |
| 3859 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3860 | if (!beep_handle) |
| 3861 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3862 | else { |
| 3863 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3864 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 3865 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | |
| 3867 | return len; |
| 3868 | } |
| 3869 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3870 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | { |
| 3872 | char *cmd; |
| 3873 | int beep_cmd; |
| 3874 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3875 | if (!beep_handle) |
| 3876 | return -ENODEV; |
| 3877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3879 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 3880 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | /* beep_cmd set */ |
| 3882 | } else |
| 3883 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3884 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3885 | return -EIO; |
| 3886 | } |
| 3887 | |
| 3888 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3889 | } |
| 3890 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3891 | static struct ibm_struct beep_driver_data = { |
| 3892 | .name = "beep", |
| 3893 | .read = beep_read, |
| 3894 | .write = beep_write, |
| 3895 | }; |
| 3896 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3897 | /************************************************************************* |
| 3898 | * Thermal subdriver |
| 3899 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3900 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3901 | enum thermal_access_mode { |
| 3902 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 3903 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 3904 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 3905 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 3906 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 3907 | }; |
| 3908 | |
| 3909 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 3910 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 3911 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 3912 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
| 3913 | }; |
| 3914 | |
| 3915 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 3916 | struct ibm_thermal_sensors_struct { |
| 3917 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 3918 | }; |
| 3919 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 3920 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3921 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 3922 | /* idx is zero-based */ |
| 3923 | static int thermal_get_sensor(int idx, s32 *value) |
| 3924 | { |
| 3925 | int t; |
| 3926 | s8 tmp; |
| 3927 | char tmpi[5]; |
| 3928 | |
| 3929 | t = TP_EC_THERMAL_TMP0; |
| 3930 | |
| 3931 | switch (thermal_read_mode) { |
| 3932 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 3933 | case TPACPI_THERMAL_TPEC_16: |
| 3934 | if (idx >= 8 && idx <= 15) { |
| 3935 | t = TP_EC_THERMAL_TMP8; |
| 3936 | idx -= 8; |
| 3937 | } |
| 3938 | /* fallthrough */ |
| 3939 | #endif |
| 3940 | case TPACPI_THERMAL_TPEC_8: |
| 3941 | if (idx <= 7) { |
| 3942 | if (!acpi_ec_read(t + idx, &tmp)) |
| 3943 | return -EIO; |
| 3944 | *value = tmp * 1000; |
| 3945 | return 0; |
| 3946 | } |
| 3947 | break; |
| 3948 | |
| 3949 | case TPACPI_THERMAL_ACPI_UPDT: |
| 3950 | if (idx <= 7) { |
| 3951 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 3952 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 3953 | return -EIO; |
| 3954 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 3955 | return -EIO; |
| 3956 | *value = (t - 2732) * 100; |
| 3957 | return 0; |
| 3958 | } |
| 3959 | break; |
| 3960 | |
| 3961 | case TPACPI_THERMAL_ACPI_TMP07: |
| 3962 | if (idx <= 7) { |
| 3963 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 3964 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 3965 | return -EIO; |
| 3966 | if (t > 127 || t < -127) |
| 3967 | t = TP_EC_THERMAL_TMP_NA; |
| 3968 | *value = t * 1000; |
| 3969 | return 0; |
| 3970 | } |
| 3971 | break; |
| 3972 | |
| 3973 | case TPACPI_THERMAL_NONE: |
| 3974 | default: |
| 3975 | return -ENOSYS; |
| 3976 | } |
| 3977 | |
| 3978 | return -EINVAL; |
| 3979 | } |
| 3980 | |
| 3981 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 3982 | { |
| 3983 | int res, i; |
| 3984 | int n; |
| 3985 | |
| 3986 | n = 8; |
| 3987 | i = 0; |
| 3988 | |
| 3989 | if (!s) |
| 3990 | return -EINVAL; |
| 3991 | |
| 3992 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 3993 | n = 16; |
| 3994 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3995 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 3996 | res = thermal_get_sensor(i, &s->temp[i]); |
| 3997 | if (res) |
| 3998 | return res; |
| 3999 | } |
| 4000 | |
| 4001 | return n; |
| 4002 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4003 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4004 | /* sysfs temp##_input -------------------------------------------------- */ |
| 4005 | |
| 4006 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 4007 | struct device_attribute *attr, |
| 4008 | char *buf) |
| 4009 | { |
| 4010 | struct sensor_device_attribute *sensor_attr = |
| 4011 | to_sensor_dev_attr(attr); |
| 4012 | int idx = sensor_attr->index; |
| 4013 | s32 value; |
| 4014 | int res; |
| 4015 | |
| 4016 | res = thermal_get_sensor(idx, &value); |
| 4017 | if (res) |
| 4018 | return res; |
| 4019 | if (value == TP_EC_THERMAL_TMP_NA * 1000) |
| 4020 | return -ENXIO; |
| 4021 | |
| 4022 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 4023 | } |
| 4024 | |
| 4025 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4026 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 4027 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4028 | |
| 4029 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 4030 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 4031 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 4032 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 4033 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 4034 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 4035 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 4036 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 4037 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 4038 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 4039 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 4040 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 4041 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 4042 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 4043 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 4044 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 4045 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 4046 | }; |
| 4047 | |
| 4048 | #define THERMAL_ATTRS(X) \ |
| 4049 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 4050 | |
| 4051 | static struct attribute *thermal_temp_input_attr[] = { |
| 4052 | THERMAL_ATTRS(8), |
| 4053 | THERMAL_ATTRS(9), |
| 4054 | THERMAL_ATTRS(10), |
| 4055 | THERMAL_ATTRS(11), |
| 4056 | THERMAL_ATTRS(12), |
| 4057 | THERMAL_ATTRS(13), |
| 4058 | THERMAL_ATTRS(14), |
| 4059 | THERMAL_ATTRS(15), |
| 4060 | THERMAL_ATTRS(0), |
| 4061 | THERMAL_ATTRS(1), |
| 4062 | THERMAL_ATTRS(2), |
| 4063 | THERMAL_ATTRS(3), |
| 4064 | THERMAL_ATTRS(4), |
| 4065 | THERMAL_ATTRS(5), |
| 4066 | THERMAL_ATTRS(6), |
| 4067 | THERMAL_ATTRS(7), |
| 4068 | NULL |
| 4069 | }; |
| 4070 | |
| 4071 | static const struct attribute_group thermal_temp_input16_group = { |
| 4072 | .attrs = thermal_temp_input_attr |
| 4073 | }; |
| 4074 | |
| 4075 | static const struct attribute_group thermal_temp_input8_group = { |
| 4076 | .attrs = &thermal_temp_input_attr[8] |
| 4077 | }; |
| 4078 | |
| 4079 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 4080 | #undef THERMAL_ATTRS |
| 4081 | |
| 4082 | /* --------------------------------------------------------------------- */ |
| 4083 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4084 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4085 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4086 | u8 t, ta1, ta2; |
| 4087 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4088 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4089 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4090 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4091 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 4092 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4093 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4094 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 4095 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4096 | /* |
| 4097 | * Direct EC access mode: sensors at registers |
| 4098 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 4099 | * non-implemented, thermal sensors return 0x80 when |
| 4100 | * not available |
| 4101 | */ |
| 4102 | |
| 4103 | ta1 = ta2 = 0; |
| 4104 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4105 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4106 | ta1 |= t; |
| 4107 | } else { |
| 4108 | ta1 = 0; |
| 4109 | break; |
| 4110 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4111 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4112 | ta2 |= t; |
| 4113 | } else { |
| 4114 | ta1 = 0; |
| 4115 | break; |
| 4116 | } |
| 4117 | } |
| 4118 | if (ta1 == 0) { |
| 4119 | /* This is sheer paranoia, but we handle it anyway */ |
| 4120 | if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4121 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4122 | "ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4123 | "falling back to ACPI TMPx access " |
| 4124 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4125 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4126 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4127 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4128 | "ThinkPad ACPI EC access misbehaving, " |
| 4129 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4130 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4131 | } |
| 4132 | } else { |
| 4133 | thermal_read_mode = |
| 4134 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4135 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4136 | } |
| 4137 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4138 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 4139 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4140 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4141 | } else { |
| 4142 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4143 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4144 | } |
| 4145 | } else { |
| 4146 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4147 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4148 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4149 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4150 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 4151 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 4152 | thermal_read_mode); |
| 4153 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4154 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4155 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4156 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4157 | &thermal_temp_input16_group); |
| 4158 | if (res) |
| 4159 | return res; |
| 4160 | break; |
| 4161 | case TPACPI_THERMAL_TPEC_8: |
| 4162 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4163 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4164 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4165 | &thermal_temp_input8_group); |
| 4166 | if (res) |
| 4167 | return res; |
| 4168 | break; |
| 4169 | case TPACPI_THERMAL_NONE: |
| 4170 | default: |
| 4171 | return 1; |
| 4172 | } |
| 4173 | |
| 4174 | return 0; |
| 4175 | } |
| 4176 | |
| 4177 | static void thermal_exit(void) |
| 4178 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4179 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4180 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4181 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4182 | &thermal_temp_input16_group); |
| 4183 | break; |
| 4184 | case TPACPI_THERMAL_TPEC_8: |
| 4185 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4186 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4187 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4188 | &thermal_temp_input16_group); |
| 4189 | break; |
| 4190 | case TPACPI_THERMAL_NONE: |
| 4191 | default: |
| 4192 | break; |
| 4193 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | static int thermal_read(char *p) |
| 4197 | { |
| 4198 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4199 | int n, i; |
| 4200 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4201 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4202 | n = thermal_get_sensors(&t); |
| 4203 | if (unlikely(n < 0)) |
| 4204 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4205 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4206 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4207 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4208 | if (n > 0) { |
| 4209 | for (i = 0; i < (n - 1); i++) |
| 4210 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 4211 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 4212 | } else |
| 4213 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4214 | |
| 4215 | return len; |
| 4216 | } |
| 4217 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4218 | static struct ibm_struct thermal_driver_data = { |
| 4219 | .name = "thermal", |
| 4220 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4221 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4222 | }; |
| 4223 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4224 | /************************************************************************* |
| 4225 | * EC Dump subdriver |
| 4226 | */ |
| 4227 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4228 | static u8 ecdump_regs[256]; |
| 4229 | |
| 4230 | static int ecdump_read(char *p) |
| 4231 | { |
| 4232 | int len = 0; |
| 4233 | int i, j; |
| 4234 | u8 v; |
| 4235 | |
| 4236 | len += sprintf(p + len, "EC " |
| 4237 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 4238 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 4239 | for (i = 0; i < 256; i += 16) { |
| 4240 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 4241 | for (j = 0; j < 16; j++) { |
| 4242 | if (!acpi_ec_read(i + j, &v)) |
| 4243 | break; |
| 4244 | if (v != ecdump_regs[i + j]) |
| 4245 | len += sprintf(p + len, " *%02x", v); |
| 4246 | else |
| 4247 | len += sprintf(p + len, " %02x", v); |
| 4248 | ecdump_regs[i + j] = v; |
| 4249 | } |
| 4250 | len += sprintf(p + len, "\n"); |
| 4251 | if (j != 16) |
| 4252 | break; |
| 4253 | } |
| 4254 | |
| 4255 | /* These are way too dangerous to advertise openly... */ |
| 4256 | #if 0 |
| 4257 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 4258 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 4259 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 4260 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 4261 | #endif |
| 4262 | return len; |
| 4263 | } |
| 4264 | |
| 4265 | static int ecdump_write(char *buf) |
| 4266 | { |
| 4267 | char *cmd; |
| 4268 | int i, v; |
| 4269 | |
| 4270 | while ((cmd = next_cmd(&buf))) { |
| 4271 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 4272 | /* i and v set */ |
| 4273 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 4274 | /* i and v set */ |
| 4275 | } else |
| 4276 | return -EINVAL; |
| 4277 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 4278 | if (!acpi_ec_write(i, v)) |
| 4279 | return -EIO; |
| 4280 | } else |
| 4281 | return -EINVAL; |
| 4282 | } |
| 4283 | |
| 4284 | return 0; |
| 4285 | } |
| 4286 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4287 | static struct ibm_struct ecdump_driver_data = { |
| 4288 | .name = "ecdump", |
| 4289 | .read = ecdump_read, |
| 4290 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 4291 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4292 | }; |
| 4293 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4294 | /************************************************************************* |
| 4295 | * Backlight/brightness subdriver |
| 4296 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 4297 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4298 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 4299 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4300 | enum { |
| 4301 | TP_EC_BACKLIGHT = 0x31, |
| 4302 | |
| 4303 | /* TP_EC_BACKLIGHT bitmasks */ |
| 4304 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 4305 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 4306 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 4307 | }; |
| 4308 | |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 4309 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4310 | static int brightness_mode; |
| 4311 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 4312 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4313 | static struct mutex brightness_mutex; |
| 4314 | |
| 4315 | /* |
| 4316 | * ThinkPads can read brightness from two places: EC 0x31, or |
| 4317 | * CMOS NVRAM byte 0x5E, bits 0-3. |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4318 | * |
| 4319 | * EC 0x31 has the following layout |
| 4320 | * Bit 7: unknown function |
| 4321 | * Bit 6: unknown function |
| 4322 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 4323 | * Bit 4: must be set to zero to avoid problems |
| 4324 | * Bit 3-0: backlight brightness level |
| 4325 | * |
| 4326 | * brightness_get_raw returns status data in the EC 0x31 layout |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4327 | */ |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4328 | static int brightness_get_raw(int *status) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4329 | { |
| 4330 | u8 lec = 0, lcmos = 0, level = 0; |
| 4331 | |
| 4332 | if (brightness_mode & 1) { |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4333 | if (!acpi_ec_read(TP_EC_BACKLIGHT, &lec)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4334 | return -EIO; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4335 | level = lec & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4336 | }; |
| 4337 | if (brightness_mode & 2) { |
| 4338 | lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 4339 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 4340 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 4341 | lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07; |
| 4342 | level = lcmos; |
| 4343 | } |
| 4344 | |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 4345 | if (brightness_mode == 3) { |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4346 | *status = lec; /* Prefer EC, CMOS is just a backing store */ |
| 4347 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 4348 | if (lec == lcmos) |
| 4349 | tp_warned.bright_cmos_ec_unsync = 0; |
| 4350 | else { |
| 4351 | if (!tp_warned.bright_cmos_ec_unsync) { |
| 4352 | printk(TPACPI_ERR |
| 4353 | "CMOS NVRAM (%u) and EC (%u) do not " |
| 4354 | "agree on display brightness level\n", |
| 4355 | (unsigned int) lcmos, |
| 4356 | (unsigned int) lec); |
| 4357 | tp_warned.bright_cmos_ec_unsync = 1; |
| 4358 | } |
| 4359 | return -EIO; |
| 4360 | } |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4361 | } else { |
| 4362 | *status = level; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4363 | } |
| 4364 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4365 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
| 4369 | static int brightness_set(int value) |
| 4370 | { |
| 4371 | int cmos_cmd, inc, i, res; |
| 4372 | int current_value; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4373 | int command_bits; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4374 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4375 | if (value > ((tp_features.bright_16levels)? 15 : 7) || |
| 4376 | value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4377 | return -EINVAL; |
| 4378 | |
| 4379 | res = mutex_lock_interruptible(&brightness_mutex); |
| 4380 | if (res < 0) |
| 4381 | return res; |
| 4382 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4383 | res = brightness_get_raw(¤t_value); |
| 4384 | if (res < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4385 | goto errout; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4386 | |
| 4387 | command_bits = current_value & TP_EC_BACKLIGHT_CMDMSK; |
| 4388 | current_value &= TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4389 | |
| 4390 | cmos_cmd = value > current_value ? |
| 4391 | TP_CMOS_BRIGHTNESS_UP : |
| 4392 | TP_CMOS_BRIGHTNESS_DOWN; |
| 4393 | inc = (value > current_value)? 1 : -1; |
| 4394 | |
| 4395 | res = 0; |
| 4396 | for (i = current_value; i != value; i += inc) { |
| 4397 | if ((brightness_mode & 2) && |
| 4398 | issue_thinkpad_cmos_command(cmos_cmd)) { |
| 4399 | res = -EIO; |
| 4400 | goto errout; |
| 4401 | } |
| 4402 | if ((brightness_mode & 1) && |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4403 | !acpi_ec_write(TP_EC_BACKLIGHT, |
| 4404 | (i + inc) | command_bits)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4405 | res = -EIO; |
| 4406 | goto errout;; |
| 4407 | } |
| 4408 | } |
| 4409 | |
| 4410 | errout: |
| 4411 | mutex_unlock(&brightness_mutex); |
| 4412 | return res; |
| 4413 | } |
| 4414 | |
| 4415 | /* sysfs backlight class ----------------------------------------------- */ |
| 4416 | |
| 4417 | static int brightness_update_status(struct backlight_device *bd) |
| 4418 | { |
| 4419 | /* it is the backlight class's job (caller) to handle |
| 4420 | * EINTR and other errors properly */ |
| 4421 | return brightness_set( |
| 4422 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 4423 | bd->props.power == FB_BLANK_UNBLANK) ? |
| 4424 | bd->props.brightness : 0); |
| 4425 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 4426 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4427 | static int brightness_get(struct backlight_device *bd) |
| 4428 | { |
| 4429 | int status, res; |
| 4430 | |
| 4431 | res = brightness_get_raw(&status); |
| 4432 | if (res < 0) |
| 4433 | return 0; /* FIXME: teach backlight about error handling */ |
| 4434 | |
| 4435 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 4436 | } |
| 4437 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 4438 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4439 | .get_brightness = brightness_get, |
| 4440 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4441 | }; |
| 4442 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4443 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4444 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4445 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4446 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4447 | int b; |
| 4448 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4449 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 4450 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4451 | mutex_init(&brightness_mutex); |
| 4452 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 4453 | /* |
| 4454 | * We always attempt to detect acpi support, so as to switch |
| 4455 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 4456 | * going to publish a backlight interface |
| 4457 | */ |
| 4458 | b = tpacpi_check_std_acpi_brightness_support(); |
| 4459 | if (b > 0) { |
| 4460 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
| 4461 | printk(TPACPI_NOTICE |
| 4462 | "Lenovo BIOS switched to ACPI backlight " |
| 4463 | "control mode\n"); |
| 4464 | } |
| 4465 | if (brightness_enable > 1) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4466 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4467 | "standard ACPI backlight interface " |
| 4468 | "available, not loading native one...\n"); |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 4469 | return 1; |
| 4470 | } |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 4471 | } |
| 4472 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 4473 | if (!brightness_enable) { |
| 4474 | dbg_printk(TPACPI_DBG_INIT, |
| 4475 | "brightness support disabled by " |
| 4476 | "module parameter\n"); |
| 4477 | return 1; |
| 4478 | } |
| 4479 | |
| 4480 | if (b > 16) { |
| 4481 | printk(TPACPI_ERR |
| 4482 | "Unsupported brightness interface, " |
| 4483 | "please contact %s\n", TPACPI_MAIL); |
| 4484 | return 1; |
| 4485 | } |
| 4486 | if (b == 16) |
| 4487 | tp_features.bright_16levels = 1; |
| 4488 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4489 | if (!brightness_mode) { |
| 4490 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) |
| 4491 | brightness_mode = 2; |
| 4492 | else |
| 4493 | brightness_mode = 3; |
| 4494 | |
| 4495 | dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n", |
| 4496 | brightness_mode); |
| 4497 | } |
| 4498 | |
| 4499 | if (brightness_mode > 3) |
| 4500 | return -EINVAL; |
| 4501 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4502 | if (brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4503 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4504 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4505 | if (tp_features.bright_16levels) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4506 | printk(TPACPI_INFO |
| 4507 | "detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4508 | |
Henrique de Moraes Holschuh | 7d5a015 | 2007-04-24 11:48:20 -0300 | [diff] [blame] | 4509 | ibm_backlight_device = backlight_device_register( |
| 4510 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
| 4511 | &ibm_backlight_data); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4512 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4513 | printk(TPACPI_ERR "Could not register backlight device\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4514 | return PTR_ERR(ibm_backlight_device); |
| 4515 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4516 | vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4517 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4518 | ibm_backlight_device->props.max_brightness = |
| 4519 | (tp_features.bright_16levels)? 15 : 7; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4520 | ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4521 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 4522 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4523 | return 0; |
| 4524 | } |
| 4525 | |
| 4526 | static void brightness_exit(void) |
| 4527 | { |
| 4528 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4529 | vdbg_printk(TPACPI_DBG_EXIT, |
| 4530 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4531 | backlight_device_unregister(ibm_backlight_device); |
| 4532 | ibm_backlight_device = NULL; |
| 4533 | } |
| 4534 | } |
| 4535 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4536 | static int brightness_read(char *p) |
| 4537 | { |
| 4538 | int len = 0; |
| 4539 | int level; |
| 4540 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4541 | level = brightness_get(NULL); |
| 4542 | if (level < 0) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4543 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 4544 | } else { |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4545 | len += sprintf(p + len, "level:\t\t%d\n", level); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4546 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 4547 | len += sprintf(p + len, "commands:\tlevel <level>" |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4548 | " (<level> is 0-%d)\n", |
| 4549 | (tp_features.bright_16levels) ? 15 : 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | return len; |
| 4553 | } |
| 4554 | |
| 4555 | static int brightness_write(char *buf) |
| 4556 | { |
| 4557 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4558 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4559 | char *cmd; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4560 | int max_level = (tp_features.bright_16levels) ? 15 : 7; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4561 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4562 | level = brightness_get(NULL); |
| 4563 | if (level < 0) |
| 4564 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4565 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4566 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4567 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4568 | if (level < max_level) |
| 4569 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4570 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4571 | if (level > 0) |
| 4572 | level--; |
| 4573 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
| 4574 | level >= 0 && level <= max_level) { |
| 4575 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4576 | } else |
| 4577 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4578 | } |
| 4579 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4580 | /* |
| 4581 | * Now we know what the final level should be, so we try to set it. |
| 4582 | * Doing it this way makes the syscall restartable in case of EINTR |
| 4583 | */ |
| 4584 | rc = brightness_set(level); |
| 4585 | return (rc == -EINTR)? ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4586 | } |
| 4587 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4588 | static struct ibm_struct brightness_driver_data = { |
| 4589 | .name = "brightness", |
| 4590 | .read = brightness_read, |
| 4591 | .write = brightness_write, |
| 4592 | .exit = brightness_exit, |
| 4593 | }; |
| 4594 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4595 | /************************************************************************* |
| 4596 | * Volume subdriver |
| 4597 | */ |
| 4598 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4599 | static int volume_offset = 0x30; |
| 4600 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4601 | static int volume_read(char *p) |
| 4602 | { |
| 4603 | int len = 0; |
| 4604 | u8 level; |
| 4605 | |
| 4606 | if (!acpi_ec_read(volume_offset, &level)) { |
| 4607 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 4608 | } else { |
| 4609 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 4610 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 4611 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 4612 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 4613 | " (<level> is 0-15)\n"); |
| 4614 | } |
| 4615 | |
| 4616 | return len; |
| 4617 | } |
| 4618 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4619 | static int volume_write(char *buf) |
| 4620 | { |
| 4621 | int cmos_cmd, inc, i; |
| 4622 | u8 level, mute; |
| 4623 | int new_level, new_mute; |
| 4624 | char *cmd; |
| 4625 | |
| 4626 | while ((cmd = next_cmd(&buf))) { |
| 4627 | if (!acpi_ec_read(volume_offset, &level)) |
| 4628 | return -EIO; |
| 4629 | new_mute = mute = level & 0x40; |
| 4630 | new_level = level = level & 0xf; |
| 4631 | |
| 4632 | if (strlencmp(cmd, "up") == 0) { |
| 4633 | if (mute) |
| 4634 | new_mute = 0; |
| 4635 | else |
| 4636 | new_level = level == 15 ? 15 : level + 1; |
| 4637 | } else if (strlencmp(cmd, "down") == 0) { |
| 4638 | if (mute) |
| 4639 | new_mute = 0; |
| 4640 | else |
| 4641 | new_level = level == 0 ? 0 : level - 1; |
| 4642 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 4643 | new_level >= 0 && new_level <= 15) { |
| 4644 | /* new_level set */ |
| 4645 | } else if (strlencmp(cmd, "mute") == 0) { |
| 4646 | new_mute = 0x40; |
| 4647 | } else |
| 4648 | return -EINVAL; |
| 4649 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4650 | if (new_level != level) { |
| 4651 | /* mute doesn't change */ |
| 4652 | |
| 4653 | cmos_cmd = (new_level > level) ? |
| 4654 | TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4655 | inc = new_level > level ? 1 : -1; |
| 4656 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4657 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4658 | !acpi_ec_write(volume_offset, level))) |
| 4659 | return -EIO; |
| 4660 | |
| 4661 | for (i = level; i != new_level; i += inc) |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4662 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4663 | !acpi_ec_write(volume_offset, i + inc)) |
| 4664 | return -EIO; |
| 4665 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4666 | if (mute && |
| 4667 | (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
| 4668 | !acpi_ec_write(volume_offset, new_level + mute))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4669 | return -EIO; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4670 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4671 | } |
| 4672 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4673 | if (new_mute != mute) { |
| 4674 | /* level doesn't change */ |
| 4675 | |
| 4676 | cmos_cmd = (new_mute) ? |
| 4677 | TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4678 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4679 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4680 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 4681 | return -EIO; |
| 4682 | } |
| 4683 | } |
| 4684 | |
| 4685 | return 0; |
| 4686 | } |
| 4687 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4688 | static struct ibm_struct volume_driver_data = { |
| 4689 | .name = "volume", |
| 4690 | .read = volume_read, |
| 4691 | .write = volume_write, |
| 4692 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4693 | |
| 4694 | /************************************************************************* |
| 4695 | * Fan subdriver |
| 4696 | */ |
| 4697 | |
| 4698 | /* |
| 4699 | * FAN ACCESS MODES |
| 4700 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4701 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4702 | * ACPI GFAN method: returns fan level |
| 4703 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4704 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4705 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4706 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4707 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4708 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 4709 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4710 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 4711 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4712 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4713 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4714 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 4715 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4716 | * |
| 4717 | * Fan speed changes of any sort (including those caused by the |
| 4718 | * disengaged mode) are usually done slowly by the firmware as the |
| 4719 | * maximum ammount of fan duty cycle change per second seems to be |
| 4720 | * limited. |
| 4721 | * |
| 4722 | * Reading is not available if GFAN exists. |
| 4723 | * Writing is not available if SFAN exists. |
| 4724 | * |
| 4725 | * Bits |
| 4726 | * 7 automatic mode engaged; |
| 4727 | * (default operation mode of the ThinkPad) |
| 4728 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4729 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4730 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4731 | * the tachometer while the fan controller ramps up |
| 4732 | * the speed (which can take up to a few *minutes*). |
| 4733 | * Speeds up fan to 100% duty-cycle, which is far above |
| 4734 | * the standard RPM levels. It is not impossible that |
| 4735 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4736 | * 5-3 unused in some models. Extra bits for fan level |
| 4737 | * in others, but still useless as all values above |
| 4738 | * 7 map to the same speed as level 7 in these models. |
| 4739 | * 2-0 fan level (0..7 usually) |
| 4740 | * 0x00 = stop |
| 4741 | * 0x07 = max (set when temperatures critical) |
| 4742 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4743 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4744 | * |
| 4745 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 4746 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 4747 | * does so, its initial value is meaningless (0x07). |
| 4748 | * |
| 4749 | * For firmware bugs, refer to: |
| 4750 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 4751 | * |
| 4752 | * ---- |
| 4753 | * |
| 4754 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 4755 | * Main fan tachometer reading (in RPM) |
| 4756 | * |
| 4757 | * This register is present on all ThinkPads with a new-style EC, and |
| 4758 | * it is known not to be present on the A21m/e, and T22, as there is |
| 4759 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 4760 | * ThinkPads from this same time period (and earlier) probably lack the |
| 4761 | * tachometer as well. |
| 4762 | * |
| 4763 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare |
| 4764 | * was never fixed by IBM to report the EC firmware version string |
| 4765 | * probably support the tachometer (like the early X models), so |
| 4766 | * detecting it is quite hard. We need more data to know for sure. |
| 4767 | * |
| 4768 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 4769 | * might result. |
| 4770 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4771 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 4772 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4773 | * |
| 4774 | * For firmware bugs, refer to: |
| 4775 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 4776 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4777 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4778 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 4779 | * |
| 4780 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 4781 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 4782 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 4783 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 4784 | * |
| 4785 | * The speeds are stored on handles |
| 4786 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 4787 | * |
| 4788 | * There are three default speed sets, acessible as handles: |
| 4789 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 4790 | * |
| 4791 | * ACPI DSDT switches which set is in use depending on various |
| 4792 | * factors. |
| 4793 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4794 | * 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] | 4795 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 4796 | * but the ACPI tables just mention level 7. |
| 4797 | */ |
| 4798 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4799 | enum { /* Fan control constants */ |
| 4800 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 4801 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 4802 | * 0x84 must be read before 0x85 */ |
| 4803 | |
| 4804 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 4805 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 4806 | |
| 4807 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 4808 | }; |
| 4809 | |
| 4810 | enum fan_status_access_mode { |
| 4811 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 4812 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 4813 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 4814 | }; |
| 4815 | |
| 4816 | enum fan_control_access_mode { |
| 4817 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 4818 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 4819 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 4820 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 4821 | }; |
| 4822 | |
| 4823 | enum fan_control_commands { |
| 4824 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 4825 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 4826 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 4827 | * and also watchdog cmd */ |
| 4828 | }; |
| 4829 | |
| 4830 | static int fan_control_allowed; |
| 4831 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 4832 | static enum fan_status_access_mode fan_status_access_mode; |
| 4833 | static enum fan_control_access_mode fan_control_access_mode; |
| 4834 | static enum fan_control_commands fan_control_commands; |
| 4835 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 4836 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 4837 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 4838 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4839 | |
| 4840 | static struct mutex fan_mutex; |
| 4841 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4842 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 4843 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 4844 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4845 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 4846 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4847 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 4848 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4849 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4850 | "JFNS", /* 770x-JL */ |
| 4851 | ); /* all others */ |
| 4852 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 4853 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4854 | * Call with fan_mutex held |
| 4855 | */ |
| 4856 | static void fan_update_desired_level(u8 status) |
| 4857 | { |
| 4858 | if ((status & |
| 4859 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 4860 | if (status > 7) |
| 4861 | fan_control_desired_level = 7; |
| 4862 | else |
| 4863 | fan_control_desired_level = status; |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | static int fan_get_status(u8 *status) |
| 4868 | { |
| 4869 | u8 s; |
| 4870 | |
| 4871 | /* TODO: |
| 4872 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 4873 | |
| 4874 | switch (fan_status_access_mode) { |
| 4875 | case TPACPI_FAN_RD_ACPI_GFAN: |
| 4876 | /* 570, 600e/x, 770e, 770x */ |
| 4877 | |
| 4878 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
| 4879 | return -EIO; |
| 4880 | |
| 4881 | if (likely(status)) |
| 4882 | *status = s & 0x07; |
| 4883 | |
| 4884 | break; |
| 4885 | |
| 4886 | case TPACPI_FAN_RD_TPEC: |
| 4887 | /* all except 570, 600e/x, 770e, 770x */ |
| 4888 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 4889 | return -EIO; |
| 4890 | |
| 4891 | if (likely(status)) |
| 4892 | *status = s; |
| 4893 | |
| 4894 | break; |
| 4895 | |
| 4896 | default: |
| 4897 | return -ENXIO; |
| 4898 | } |
| 4899 | |
| 4900 | return 0; |
| 4901 | } |
| 4902 | |
| 4903 | static int fan_get_status_safe(u8 *status) |
| 4904 | { |
| 4905 | int rc; |
| 4906 | u8 s; |
| 4907 | |
| 4908 | if (mutex_lock_interruptible(&fan_mutex)) |
| 4909 | return -ERESTARTSYS; |
| 4910 | rc = fan_get_status(&s); |
| 4911 | if (!rc) |
| 4912 | fan_update_desired_level(s); |
| 4913 | mutex_unlock(&fan_mutex); |
| 4914 | |
| 4915 | if (status) |
| 4916 | *status = s; |
| 4917 | |
| 4918 | return rc; |
| 4919 | } |
| 4920 | |
| 4921 | static int fan_get_speed(unsigned int *speed) |
| 4922 | { |
| 4923 | u8 hi, lo; |
| 4924 | |
| 4925 | switch (fan_status_access_mode) { |
| 4926 | case TPACPI_FAN_RD_TPEC: |
| 4927 | /* all except 570, 600e/x, 770e, 770x */ |
| 4928 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 4929 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 4930 | return -EIO; |
| 4931 | |
| 4932 | if (likely(speed)) |
| 4933 | *speed = (hi << 8) | lo; |
| 4934 | |
| 4935 | break; |
| 4936 | |
| 4937 | default: |
| 4938 | return -ENXIO; |
| 4939 | } |
| 4940 | |
| 4941 | return 0; |
| 4942 | } |
| 4943 | |
| 4944 | static int fan_set_level(int level) |
| 4945 | { |
| 4946 | if (!fan_control_allowed) |
| 4947 | return -EPERM; |
| 4948 | |
| 4949 | switch (fan_control_access_mode) { |
| 4950 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 4951 | if (level >= 0 && level <= 7) { |
| 4952 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 4953 | return -EIO; |
| 4954 | } else |
| 4955 | return -EINVAL; |
| 4956 | break; |
| 4957 | |
| 4958 | case TPACPI_FAN_WR_ACPI_FANS: |
| 4959 | case TPACPI_FAN_WR_TPEC: |
| 4960 | if ((level != TP_EC_FAN_AUTO) && |
| 4961 | (level != TP_EC_FAN_FULLSPEED) && |
| 4962 | ((level < 0) || (level > 7))) |
| 4963 | return -EINVAL; |
| 4964 | |
| 4965 | /* safety net should the EC not support AUTO |
| 4966 | * or FULLSPEED mode bits and just ignore them */ |
| 4967 | if (level & TP_EC_FAN_FULLSPEED) |
| 4968 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 4969 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4970 | level |= 4; /* safety min speed 4 */ |
| 4971 | |
| 4972 | if (!acpi_ec_write(fan_status_offset, level)) |
| 4973 | return -EIO; |
| 4974 | else |
| 4975 | tp_features.fan_ctrl_status_undef = 0; |
| 4976 | break; |
| 4977 | |
| 4978 | default: |
| 4979 | return -ENXIO; |
| 4980 | } |
| 4981 | return 0; |
| 4982 | } |
| 4983 | |
| 4984 | static int fan_set_level_safe(int level) |
| 4985 | { |
| 4986 | int rc; |
| 4987 | |
| 4988 | if (!fan_control_allowed) |
| 4989 | return -EPERM; |
| 4990 | |
| 4991 | if (mutex_lock_interruptible(&fan_mutex)) |
| 4992 | return -ERESTARTSYS; |
| 4993 | |
| 4994 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 4995 | level = fan_control_desired_level; |
| 4996 | |
| 4997 | rc = fan_set_level(level); |
| 4998 | if (!rc) |
| 4999 | fan_update_desired_level(level); |
| 5000 | |
| 5001 | mutex_unlock(&fan_mutex); |
| 5002 | return rc; |
| 5003 | } |
| 5004 | |
| 5005 | static int fan_set_enable(void) |
| 5006 | { |
| 5007 | u8 s; |
| 5008 | int rc; |
| 5009 | |
| 5010 | if (!fan_control_allowed) |
| 5011 | return -EPERM; |
| 5012 | |
| 5013 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5014 | return -ERESTARTSYS; |
| 5015 | |
| 5016 | switch (fan_control_access_mode) { |
| 5017 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5018 | case TPACPI_FAN_WR_TPEC: |
| 5019 | rc = fan_get_status(&s); |
| 5020 | if (rc < 0) |
| 5021 | break; |
| 5022 | |
| 5023 | /* Don't go out of emergency fan mode */ |
| 5024 | if (s != 7) { |
| 5025 | s &= 0x07; |
| 5026 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 5027 | } |
| 5028 | |
| 5029 | if (!acpi_ec_write(fan_status_offset, s)) |
| 5030 | rc = -EIO; |
| 5031 | else { |
| 5032 | tp_features.fan_ctrl_status_undef = 0; |
| 5033 | rc = 0; |
| 5034 | } |
| 5035 | break; |
| 5036 | |
| 5037 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 5038 | rc = fan_get_status(&s); |
| 5039 | if (rc < 0) |
| 5040 | break; |
| 5041 | |
| 5042 | s &= 0x07; |
| 5043 | |
| 5044 | /* Set fan to at least level 4 */ |
| 5045 | s |= 4; |
| 5046 | |
| 5047 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5048 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5049 | else |
| 5050 | rc = 0; |
| 5051 | break; |
| 5052 | |
| 5053 | default: |
| 5054 | rc = -ENXIO; |
| 5055 | } |
| 5056 | |
| 5057 | mutex_unlock(&fan_mutex); |
| 5058 | return rc; |
| 5059 | } |
| 5060 | |
| 5061 | static int fan_set_disable(void) |
| 5062 | { |
| 5063 | int rc; |
| 5064 | |
| 5065 | if (!fan_control_allowed) |
| 5066 | return -EPERM; |
| 5067 | |
| 5068 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5069 | return -ERESTARTSYS; |
| 5070 | |
| 5071 | rc = 0; |
| 5072 | switch (fan_control_access_mode) { |
| 5073 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5074 | case TPACPI_FAN_WR_TPEC: |
| 5075 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 5076 | rc = -EIO; |
| 5077 | else { |
| 5078 | fan_control_desired_level = 0; |
| 5079 | tp_features.fan_ctrl_status_undef = 0; |
| 5080 | } |
| 5081 | break; |
| 5082 | |
| 5083 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 5084 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 5085 | rc = -EIO; |
| 5086 | else |
| 5087 | fan_control_desired_level = 0; |
| 5088 | break; |
| 5089 | |
| 5090 | default: |
| 5091 | rc = -ENXIO; |
| 5092 | } |
| 5093 | |
| 5094 | |
| 5095 | mutex_unlock(&fan_mutex); |
| 5096 | return rc; |
| 5097 | } |
| 5098 | |
| 5099 | static int fan_set_speed(int speed) |
| 5100 | { |
| 5101 | int rc; |
| 5102 | |
| 5103 | if (!fan_control_allowed) |
| 5104 | return -EPERM; |
| 5105 | |
| 5106 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5107 | return -ERESTARTSYS; |
| 5108 | |
| 5109 | rc = 0; |
| 5110 | switch (fan_control_access_mode) { |
| 5111 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5112 | if (speed >= 0 && speed <= 65535) { |
| 5113 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 5114 | speed, speed, speed)) |
| 5115 | rc = -EIO; |
| 5116 | } else |
| 5117 | rc = -EINVAL; |
| 5118 | break; |
| 5119 | |
| 5120 | default: |
| 5121 | rc = -ENXIO; |
| 5122 | } |
| 5123 | |
| 5124 | mutex_unlock(&fan_mutex); |
| 5125 | return rc; |
| 5126 | } |
| 5127 | |
| 5128 | static void fan_watchdog_reset(void) |
| 5129 | { |
| 5130 | static int fan_watchdog_active; |
| 5131 | |
| 5132 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 5133 | return; |
| 5134 | |
| 5135 | if (fan_watchdog_active) |
| 5136 | cancel_delayed_work(&fan_watchdog_task); |
| 5137 | |
| 5138 | if (fan_watchdog_maxinterval > 0 && |
| 5139 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
| 5140 | fan_watchdog_active = 1; |
| 5141 | if (!schedule_delayed_work(&fan_watchdog_task, |
| 5142 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 5143 | * 1000))) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5144 | printk(TPACPI_ERR |
| 5145 | "failed to schedule the fan watchdog, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5146 | "watchdog will not trigger\n"); |
| 5147 | } |
| 5148 | } else |
| 5149 | fan_watchdog_active = 0; |
| 5150 | } |
| 5151 | |
| 5152 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 5153 | { |
| 5154 | int rc; |
| 5155 | |
| 5156 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 5157 | return; |
| 5158 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5159 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5160 | rc = fan_set_enable(); |
| 5161 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5162 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5163 | "will try again later...\n", -rc); |
| 5164 | /* reschedule for later */ |
| 5165 | fan_watchdog_reset(); |
| 5166 | } |
| 5167 | } |
| 5168 | |
| 5169 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5170 | * SYSFS fan layout: hwmon compatible (device) |
| 5171 | * |
| 5172 | * pwm*_enable: |
| 5173 | * 0: "disengaged" mode |
| 5174 | * 1: manual mode |
| 5175 | * 2: native EC "auto" mode (recommended, hardware default) |
| 5176 | * |
| 5177 | * pwm*: set speed in manual mode, ignored otherwise. |
| 5178 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 5179 | * interpolation. |
| 5180 | * |
| 5181 | * fan*_input: tachometer reading, RPM |
| 5182 | * |
| 5183 | * |
| 5184 | * SYSFS fan layout: extensions |
| 5185 | * |
| 5186 | * fan_watchdog (driver): |
| 5187 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 5188 | */ |
| 5189 | |
| 5190 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 5191 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 5192 | struct device_attribute *attr, |
| 5193 | char *buf) |
| 5194 | { |
| 5195 | int res, mode; |
| 5196 | u8 status; |
| 5197 | |
| 5198 | res = fan_get_status_safe(&status); |
| 5199 | if (res) |
| 5200 | return res; |
| 5201 | |
| 5202 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 5203 | if (status != fan_control_initial_status) { |
| 5204 | tp_features.fan_ctrl_status_undef = 0; |
| 5205 | } else { |
| 5206 | /* Return most likely status. In fact, it |
| 5207 | * might be the only possible status */ |
| 5208 | status = TP_EC_FAN_AUTO; |
| 5209 | } |
| 5210 | } |
| 5211 | |
| 5212 | if (status & TP_EC_FAN_FULLSPEED) { |
| 5213 | mode = 0; |
| 5214 | } else if (status & TP_EC_FAN_AUTO) { |
| 5215 | mode = 2; |
| 5216 | } else |
| 5217 | mode = 1; |
| 5218 | |
| 5219 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 5220 | } |
| 5221 | |
| 5222 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 5223 | struct device_attribute *attr, |
| 5224 | const char *buf, size_t count) |
| 5225 | { |
| 5226 | unsigned long t; |
| 5227 | int res, level; |
| 5228 | |
| 5229 | if (parse_strtoul(buf, 2, &t)) |
| 5230 | return -EINVAL; |
| 5231 | |
| 5232 | switch (t) { |
| 5233 | case 0: |
| 5234 | level = TP_EC_FAN_FULLSPEED; |
| 5235 | break; |
| 5236 | case 1: |
| 5237 | level = TPACPI_FAN_LAST_LEVEL; |
| 5238 | break; |
| 5239 | case 2: |
| 5240 | level = TP_EC_FAN_AUTO; |
| 5241 | break; |
| 5242 | case 3: |
| 5243 | /* reserved for software-controlled auto mode */ |
| 5244 | return -ENOSYS; |
| 5245 | default: |
| 5246 | return -EINVAL; |
| 5247 | } |
| 5248 | |
| 5249 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 5250 | if (res == -ENXIO) |
| 5251 | return -EINVAL; |
| 5252 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5253 | return res; |
| 5254 | |
| 5255 | fan_watchdog_reset(); |
| 5256 | |
| 5257 | return count; |
| 5258 | } |
| 5259 | |
| 5260 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 5261 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 5262 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 5263 | |
| 5264 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 5265 | static ssize_t fan_pwm1_show(struct device *dev, |
| 5266 | struct device_attribute *attr, |
| 5267 | char *buf) |
| 5268 | { |
| 5269 | int res; |
| 5270 | u8 status; |
| 5271 | |
| 5272 | res = fan_get_status_safe(&status); |
| 5273 | if (res) |
| 5274 | return res; |
| 5275 | |
| 5276 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 5277 | if (status != fan_control_initial_status) { |
| 5278 | tp_features.fan_ctrl_status_undef = 0; |
| 5279 | } else { |
| 5280 | status = TP_EC_FAN_AUTO; |
| 5281 | } |
| 5282 | } |
| 5283 | |
| 5284 | if ((status & |
| 5285 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 5286 | status = fan_control_desired_level; |
| 5287 | |
| 5288 | if (status > 7) |
| 5289 | status = 7; |
| 5290 | |
| 5291 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 5292 | } |
| 5293 | |
| 5294 | static ssize_t fan_pwm1_store(struct device *dev, |
| 5295 | struct device_attribute *attr, |
| 5296 | const char *buf, size_t count) |
| 5297 | { |
| 5298 | unsigned long s; |
| 5299 | int rc; |
| 5300 | u8 status, newlevel; |
| 5301 | |
| 5302 | if (parse_strtoul(buf, 255, &s)) |
| 5303 | return -EINVAL; |
| 5304 | |
| 5305 | /* scale down from 0-255 to 0-7 */ |
| 5306 | newlevel = (s >> 5) & 0x07; |
| 5307 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 5308 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5309 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5310 | |
| 5311 | rc = fan_get_status(&status); |
| 5312 | if (!rc && (status & |
| 5313 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 5314 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 5315 | if (rc == -ENXIO) |
| 5316 | rc = -EINVAL; |
| 5317 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5318 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 5319 | fan_watchdog_reset(); |
| 5320 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | mutex_unlock(&fan_mutex); |
| 5324 | return (rc)? rc : count; |
| 5325 | } |
| 5326 | |
| 5327 | static struct device_attribute dev_attr_fan_pwm1 = |
| 5328 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 5329 | fan_pwm1_show, fan_pwm1_store); |
| 5330 | |
| 5331 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 5332 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 5333 | struct device_attribute *attr, |
| 5334 | char *buf) |
| 5335 | { |
| 5336 | int res; |
| 5337 | unsigned int speed; |
| 5338 | |
| 5339 | res = fan_get_speed(&speed); |
| 5340 | if (res < 0) |
| 5341 | return res; |
| 5342 | |
| 5343 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 5344 | } |
| 5345 | |
| 5346 | static struct device_attribute dev_attr_fan_fan1_input = |
| 5347 | __ATTR(fan1_input, S_IRUGO, |
| 5348 | fan_fan1_input_show, NULL); |
| 5349 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5350 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5351 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 5352 | char *buf) |
| 5353 | { |
| 5354 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 5355 | } |
| 5356 | |
| 5357 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 5358 | const char *buf, size_t count) |
| 5359 | { |
| 5360 | unsigned long t; |
| 5361 | |
| 5362 | if (parse_strtoul(buf, 120, &t)) |
| 5363 | return -EINVAL; |
| 5364 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5365 | if (!fan_control_allowed) |
| 5366 | return -EPERM; |
| 5367 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5368 | fan_watchdog_maxinterval = t; |
| 5369 | fan_watchdog_reset(); |
| 5370 | |
| 5371 | return count; |
| 5372 | } |
| 5373 | |
| 5374 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 5375 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 5376 | |
| 5377 | /* --------------------------------------------------------------------- */ |
| 5378 | static struct attribute *fan_attributes[] = { |
| 5379 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 5380 | &dev_attr_fan_fan1_input.attr, |
| 5381 | NULL |
| 5382 | }; |
| 5383 | |
| 5384 | static const struct attribute_group fan_attr_group = { |
| 5385 | .attrs = fan_attributes, |
| 5386 | }; |
| 5387 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5388 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5389 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5390 | int rc; |
| 5391 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5392 | vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n"); |
| 5393 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5394 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5395 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 5396 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5397 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5398 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5399 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5400 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5401 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5402 | TPACPI_ACPIHANDLE_INIT(fans); |
| 5403 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 5404 | TPACPI_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5405 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5406 | if (gfan_handle) { |
| 5407 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5408 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5409 | } else { |
| 5410 | /* all other ThinkPads: note that even old-style |
| 5411 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5412 | if (likely(acpi_ec_read(fan_status_offset, |
| 5413 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5414 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5415 | |
| 5416 | /* In some ThinkPads, neither the EC nor the ACPI |
| 5417 | * DSDT initialize the fan status, and it ends up |
| 5418 | * being set to 0x07 when it *could* be either |
| 5419 | * 0x07 or 0x80. |
| 5420 | * |
| 5421 | * Enable for TP-1Y (T43), TP-78 (R51e), |
| 5422 | * TP-76 (R52), TP-70 (T43, R52), which are known |
| 5423 | * to be buggy. */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5424 | if (fan_control_initial_status == 0x07) { |
| 5425 | switch (thinkpad_id.ec_model) { |
| 5426 | case 0x5931: /* TP-1Y */ |
| 5427 | case 0x3837: /* TP-78 */ |
| 5428 | case 0x3637: /* TP-76 */ |
| 5429 | case 0x3037: /* TP-70 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5430 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5431 | "fan_init: initial fan status " |
| 5432 | "is unknown, assuming it is " |
| 5433 | "in auto mode\n"); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5434 | tp_features.fan_ctrl_status_undef = 1; |
| 5435 | ;; |
| 5436 | } |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5437 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5438 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5439 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5440 | "ThinkPad ACPI EC access misbehaving, " |
| 5441 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5442 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5443 | } |
| 5444 | } |
| 5445 | |
| 5446 | if (sfan_handle) { |
| 5447 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5448 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5449 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5450 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5451 | } else { |
| 5452 | if (!gfan_handle) { |
| 5453 | /* gfan without sfan means no fan control */ |
| 5454 | /* all other models implement TP EC 0x2f control */ |
| 5455 | |
| 5456 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5457 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5458 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5459 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5460 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5461 | TPACPI_FAN_CMD_SPEED | |
| 5462 | TPACPI_FAN_CMD_LEVEL | |
| 5463 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5464 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5465 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5466 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5467 | TPACPI_FAN_CMD_LEVEL | |
| 5468 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5469 | } |
| 5470 | } |
| 5471 | } |
| 5472 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5473 | vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n", |
| 5474 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 5475 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 5476 | fan_status_access_mode, fan_control_access_mode); |
| 5477 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5478 | /* fan control master switch */ |
| 5479 | if (!fan_control_allowed) { |
| 5480 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 5481 | fan_control_commands = 0; |
| 5482 | dbg_printk(TPACPI_DBG_INIT, |
| 5483 | "fan control features disabled by parameter\n"); |
| 5484 | } |
| 5485 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5486 | /* update fan_control_desired_level */ |
| 5487 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 5488 | fan_get_status_safe(NULL); |
| 5489 | |
| 5490 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 5491 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5492 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5493 | &fan_attr_group); |
| 5494 | if (!(rc < 0)) |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5495 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5496 | &driver_attr_fan_watchdog); |
| 5497 | if (rc < 0) |
| 5498 | return rc; |
| 5499 | return 0; |
| 5500 | } else |
| 5501 | return 1; |
| 5502 | } |
| 5503 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5504 | static void fan_exit(void) |
| 5505 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5506 | vdbg_printk(TPACPI_DBG_EXIT, |
| 5507 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5508 | |
| 5509 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5510 | 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] | 5511 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 5512 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5513 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5514 | cancel_delayed_work(&fan_watchdog_task); |
| 5515 | flush_scheduled_work(); |
| 5516 | } |
| 5517 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5518 | static int fan_read(char *p) |
| 5519 | { |
| 5520 | int len = 0; |
| 5521 | int rc; |
| 5522 | u8 status; |
| 5523 | unsigned int speed = 0; |
| 5524 | |
| 5525 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5526 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5527 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5528 | rc = fan_get_status_safe(&status); |
| 5529 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5530 | return rc; |
| 5531 | |
| 5532 | len += sprintf(p + len, "status:\t\t%s\n" |
| 5533 | "level:\t\t%d\n", |
| 5534 | (status != 0) ? "enabled" : "disabled", status); |
| 5535 | break; |
| 5536 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5537 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5538 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5539 | rc = fan_get_status_safe(&status); |
| 5540 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5541 | return rc; |
| 5542 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5543 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5544 | if (status != fan_control_initial_status) |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5545 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5546 | else |
| 5547 | /* Return most likely status. In fact, it |
| 5548 | * might be the only possible status */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5549 | status = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | len += sprintf(p + len, "status:\t\t%s\n", |
| 5553 | (status != 0) ? "enabled" : "disabled"); |
| 5554 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5555 | rc = fan_get_speed(&speed); |
| 5556 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5557 | return rc; |
| 5558 | |
| 5559 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 5560 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5561 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5562 | /* Disengaged mode takes precedence */ |
| 5563 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5564 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5565 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 5566 | else |
| 5567 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 5568 | break; |
| 5569 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5570 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5571 | default: |
| 5572 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5573 | } |
| 5574 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5575 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5576 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 5577 | |
| 5578 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5579 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5580 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 5581 | break; |
| 5582 | |
| 5583 | default: |
| 5584 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5585 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5586 | break; |
| 5587 | } |
| 5588 | } |
| 5589 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5590 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5591 | len += sprintf(p + len, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5592 | "commands:\twatchdog <timeout> (<timeout> " |
| 5593 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5594 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5595 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5596 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 5597 | " (<speed> is 0-65535)\n"); |
| 5598 | |
| 5599 | return len; |
| 5600 | } |
| 5601 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5602 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 5603 | { |
| 5604 | int level; |
| 5605 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5606 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5607 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5608 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5609 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5610 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5611 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5612 | return 0; |
| 5613 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5614 | *rc = fan_set_level_safe(level); |
| 5615 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5616 | printk(TPACPI_ERR "level command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5617 | "access mode %d", fan_control_access_mode); |
| 5618 | |
| 5619 | return 1; |
| 5620 | } |
| 5621 | |
| 5622 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 5623 | { |
| 5624 | if (strlencmp(cmd, "enable") != 0) |
| 5625 | return 0; |
| 5626 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5627 | *rc = fan_set_enable(); |
| 5628 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5629 | printk(TPACPI_ERR "enable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5630 | "access mode %d", fan_control_access_mode); |
| 5631 | |
| 5632 | return 1; |
| 5633 | } |
| 5634 | |
| 5635 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 5636 | { |
| 5637 | if (strlencmp(cmd, "disable") != 0) |
| 5638 | return 0; |
| 5639 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5640 | *rc = fan_set_disable(); |
| 5641 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5642 | printk(TPACPI_ERR "disable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5643 | "access mode %d", fan_control_access_mode); |
| 5644 | |
| 5645 | return 1; |
| 5646 | } |
| 5647 | |
| 5648 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 5649 | { |
| 5650 | int speed; |
| 5651 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5652 | /* TODO: |
| 5653 | * Support speed <low> <medium> <high> ? */ |
| 5654 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5655 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 5656 | return 0; |
| 5657 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5658 | *rc = fan_set_speed(speed); |
| 5659 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5660 | printk(TPACPI_ERR "speed command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5661 | "access mode %d", fan_control_access_mode); |
| 5662 | |
| 5663 | return 1; |
| 5664 | } |
| 5665 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5666 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 5667 | { |
| 5668 | int interval; |
| 5669 | |
| 5670 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 5671 | return 0; |
| 5672 | |
| 5673 | if (interval < 0 || interval > 120) |
| 5674 | *rc = -EINVAL; |
| 5675 | else |
| 5676 | fan_watchdog_maxinterval = interval; |
| 5677 | |
| 5678 | return 1; |
| 5679 | } |
| 5680 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5681 | static int fan_write(char *buf) |
| 5682 | { |
| 5683 | char *cmd; |
| 5684 | int rc = 0; |
| 5685 | |
| 5686 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5687 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5688 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5689 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5690 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5691 | fan_write_cmd_disable(cmd, &rc) || |
| 5692 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5693 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5694 | fan_write_cmd_speed(cmd, &rc)) |
| 5695 | ) |
| 5696 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5697 | else if (!rc) |
| 5698 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5699 | } |
| 5700 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5701 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5702 | } |
| 5703 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5704 | static struct ibm_struct fan_driver_data = { |
| 5705 | .name = "fan", |
| 5706 | .read = fan_read, |
| 5707 | .write = fan_write, |
| 5708 | .exit = fan_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5709 | }; |
| 5710 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5711 | /**************************************************************************** |
| 5712 | **************************************************************************** |
| 5713 | * |
| 5714 | * Infrastructure |
| 5715 | * |
| 5716 | **************************************************************************** |
| 5717 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5719 | /* sysfs name ---------------------------------------------------------- */ |
| 5720 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 5721 | struct device_attribute *attr, |
| 5722 | char *buf) |
| 5723 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5724 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5725 | } |
| 5726 | |
| 5727 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 5728 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 5729 | |
| 5730 | /* --------------------------------------------------------------------- */ |
| 5731 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5732 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5733 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5734 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5735 | /* |
| 5736 | * Module and infrastructure proble, init and exit handling |
| 5737 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5738 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5739 | static int force_load; |
| 5740 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5741 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5742 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5743 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5744 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5745 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5746 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5747 | } |
| 5748 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 5749 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5750 | static void ibm_exit(struct ibm_struct *ibm) |
| 5751 | { |
| 5752 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 5753 | |
| 5754 | list_del_init(&ibm->all_drivers); |
| 5755 | |
| 5756 | if (ibm->flags.acpi_notify_installed) { |
| 5757 | dbg_printk(TPACPI_DBG_EXIT, |
| 5758 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 5759 | BUG_ON(!ibm->acpi); |
| 5760 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 5761 | ibm->acpi->type, |
| 5762 | dispatch_acpi_notify); |
| 5763 | ibm->flags.acpi_notify_installed = 0; |
| 5764 | ibm->flags.acpi_notify_installed = 0; |
| 5765 | } |
| 5766 | |
| 5767 | if (ibm->flags.proc_created) { |
| 5768 | dbg_printk(TPACPI_DBG_EXIT, |
| 5769 | "%s: remove_proc_entry\n", ibm->name); |
| 5770 | remove_proc_entry(ibm->name, proc_dir); |
| 5771 | ibm->flags.proc_created = 0; |
| 5772 | } |
| 5773 | |
| 5774 | if (ibm->flags.acpi_driver_registered) { |
| 5775 | dbg_printk(TPACPI_DBG_EXIT, |
| 5776 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 5777 | BUG_ON(!ibm->acpi); |
| 5778 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 5779 | kfree(ibm->acpi->driver); |
| 5780 | ibm->acpi->driver = NULL; |
| 5781 | ibm->flags.acpi_driver_registered = 0; |
| 5782 | } |
| 5783 | |
| 5784 | if (ibm->flags.init_called && ibm->exit) { |
| 5785 | ibm->exit(); |
| 5786 | ibm->flags.init_called = 0; |
| 5787 | } |
| 5788 | |
| 5789 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 5790 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5791 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5792 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5793 | { |
| 5794 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5795 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5796 | struct proc_dir_entry *entry; |
| 5797 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5798 | BUG_ON(ibm == NULL); |
| 5799 | |
| 5800 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 5801 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5802 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5803 | return 0; |
| 5804 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5805 | dbg_printk(TPACPI_DBG_INIT, |
| 5806 | "probing for %s\n", ibm->name); |
| 5807 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5808 | if (iibm->init) { |
| 5809 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5810 | if (ret > 0) |
| 5811 | return 0; /* probe failed */ |
| 5812 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5813 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5814 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5815 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5816 | } |
| 5817 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5818 | if (ibm->acpi) { |
| 5819 | if (ibm->acpi->hid) { |
| 5820 | ret = register_tpacpi_subdriver(ibm); |
| 5821 | if (ret) |
| 5822 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5823 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5824 | |
| 5825 | if (ibm->acpi->notify) { |
| 5826 | ret = setup_acpi_notify(ibm); |
| 5827 | if (ret == -ENODEV) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5828 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5829 | ibm->name); |
| 5830 | ret = 0; |
| 5831 | goto err_out; |
| 5832 | } |
| 5833 | if (ret < 0) |
| 5834 | goto err_out; |
| 5835 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5836 | } |
| 5837 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5838 | dbg_printk(TPACPI_DBG_INIT, |
| 5839 | "%s installed\n", ibm->name); |
| 5840 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5841 | if (ibm->read) { |
| 5842 | entry = create_proc_entry(ibm->name, |
| 5843 | S_IFREG | S_IRUGO | S_IWUSR, |
| 5844 | proc_dir); |
| 5845 | if (!entry) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5846 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5847 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5848 | ret = -ENODEV; |
| 5849 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5850 | } |
| 5851 | entry->owner = THIS_MODULE; |
| 5852 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5853 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5854 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5855 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5856 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5857 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5858 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5859 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 5860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5861 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5862 | |
| 5863 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5864 | dbg_printk(TPACPI_DBG_INIT, |
| 5865 | "%s: at error exit path with result %d\n", |
| 5866 | ibm->name, ret); |
| 5867 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5868 | ibm_exit(ibm); |
| 5869 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5870 | } |
| 5871 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5872 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5873 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5874 | static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5875 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 5876 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5877 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5878 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5879 | if (!tp) |
| 5880 | return; |
| 5881 | |
| 5882 | memset(tp, 0, sizeof(*tp)); |
| 5883 | |
| 5884 | if (dmi_name_in_vendors("IBM")) |
| 5885 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 5886 | else if (dmi_name_in_vendors("LENOVO")) |
| 5887 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 5888 | else |
| 5889 | return; |
| 5890 | |
| 5891 | tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION), |
| 5892 | GFP_KERNEL); |
| 5893 | if (!tp->bios_version_str) |
| 5894 | return; |
| 5895 | tp->bios_model = tp->bios_version_str[0] |
| 5896 | | (tp->bios_version_str[1] << 8); |
| 5897 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5898 | /* |
| 5899 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 5900 | * X32 or newer, all Z series; Some models must have an |
| 5901 | * up-to-date BIOS or they will not be detected. |
| 5902 | * |
| 5903 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 5904 | */ |
| 5905 | 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] | 5906 | if (sscanf(dev->name, |
| 5907 | "IBM ThinkPad Embedded Controller -[%17c", |
| 5908 | ec_fw_string) == 1) { |
| 5909 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 5910 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5911 | |
| 5912 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
| 5913 | tp->ec_model = ec_fw_string[0] |
| 5914 | | (ec_fw_string[1] << 8); |
| 5915 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5916 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5917 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5918 | |
| 5919 | tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION), |
| 5920 | GFP_KERNEL); |
| 5921 | if (strnicmp(tp->model_str, "ThinkPad", 8) != 0) { |
| 5922 | kfree(tp->model_str); |
| 5923 | tp->model_str = NULL; |
| 5924 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 5925 | |
| 5926 | tp->nummodel_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_NAME), |
| 5927 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5928 | } |
| 5929 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5930 | static int __init probe_for_thinkpad(void) |
| 5931 | { |
| 5932 | int is_thinkpad; |
| 5933 | |
| 5934 | if (acpi_disabled) |
| 5935 | return -ENODEV; |
| 5936 | |
| 5937 | /* |
| 5938 | * Non-ancient models have better DMI tagging, but very old models |
| 5939 | * don't. |
| 5940 | */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5941 | is_thinkpad = (thinkpad_id.model_str != NULL); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5942 | |
| 5943 | /* 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] | 5944 | TPACPI_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5945 | if (!ec_handle) { |
| 5946 | if (is_thinkpad) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5947 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5948 | "Not yet supported ThinkPad detected!\n"); |
| 5949 | return -ENODEV; |
| 5950 | } |
| 5951 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 5952 | /* |
| 5953 | * Risks a regression on very old machines, but reduces potential |
| 5954 | * false positives a damn great deal |
| 5955 | */ |
| 5956 | if (!is_thinkpad) |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5957 | is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 5958 | |
| 5959 | if (!is_thinkpad && !force_load) |
| 5960 | return -ENODEV; |
| 5961 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5962 | return 0; |
| 5963 | } |
| 5964 | |
| 5965 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5966 | /* Module init, exit, parameters */ |
| 5967 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5968 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 5969 | { |
| 5970 | .init = thinkpad_acpi_driver_init, |
| 5971 | .data = &thinkpad_acpi_driver_data, |
| 5972 | }, |
| 5973 | { |
| 5974 | .init = hotkey_init, |
| 5975 | .data = &hotkey_driver_data, |
| 5976 | }, |
| 5977 | { |
| 5978 | .init = bluetooth_init, |
| 5979 | .data = &bluetooth_driver_data, |
| 5980 | }, |
| 5981 | { |
| 5982 | .init = wan_init, |
| 5983 | .data = &wan_driver_data, |
| 5984 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 5985 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5986 | { |
| 5987 | .init = video_init, |
| 5988 | .data = &video_driver_data, |
| 5989 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 5990 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5991 | { |
| 5992 | .init = light_init, |
| 5993 | .data = &light_driver_data, |
| 5994 | }, |
| 5995 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
| 5996 | { |
| 5997 | .init = dock_init, |
| 5998 | .data = &dock_driver_data[0], |
| 5999 | }, |
| 6000 | { |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 6001 | .init = dock_init2, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6002 | .data = &dock_driver_data[1], |
| 6003 | }, |
| 6004 | #endif |
| 6005 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 6006 | { |
| 6007 | .init = bay_init, |
| 6008 | .data = &bay_driver_data, |
| 6009 | }, |
| 6010 | #endif |
| 6011 | { |
| 6012 | .init = cmos_init, |
| 6013 | .data = &cmos_driver_data, |
| 6014 | }, |
| 6015 | { |
| 6016 | .init = led_init, |
| 6017 | .data = &led_driver_data, |
| 6018 | }, |
| 6019 | { |
| 6020 | .init = beep_init, |
| 6021 | .data = &beep_driver_data, |
| 6022 | }, |
| 6023 | { |
| 6024 | .init = thermal_init, |
| 6025 | .data = &thermal_driver_data, |
| 6026 | }, |
| 6027 | { |
| 6028 | .data = &ecdump_driver_data, |
| 6029 | }, |
| 6030 | { |
| 6031 | .init = brightness_init, |
| 6032 | .data = &brightness_driver_data, |
| 6033 | }, |
| 6034 | { |
| 6035 | .data = &volume_driver_data, |
| 6036 | }, |
| 6037 | { |
| 6038 | .init = fan_init, |
| 6039 | .data = &fan_driver_data, |
| 6040 | }, |
| 6041 | }; |
| 6042 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6043 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 6044 | { |
| 6045 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6046 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6047 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 6048 | if (!kp || !kp->name || !val) |
| 6049 | return -EINVAL; |
| 6050 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6051 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 6052 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 6053 | WARN_ON(ibm == NULL); |
| 6054 | |
| 6055 | if (!ibm || !ibm->name) |
| 6056 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6057 | |
| 6058 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 6059 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6060 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6061 | strcpy(ibms_init[i].param, val); |
| 6062 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6063 | return 0; |
| 6064 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6065 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6066 | |
| 6067 | return -EINVAL; |
| 6068 | } |
| 6069 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6070 | module_param(experimental, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6071 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6072 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6073 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 6074 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6075 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 6076 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 6077 | module_param(force_load, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6078 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6079 | "Attempts to load the driver even on a " |
| 6080 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 6081 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 6082 | module_param_named(fan_control, fan_control_allowed, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6083 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6084 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 6085 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6086 | module_param_named(brightness_mode, brightness_mode, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6087 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6088 | "Selects brightness control strategy: " |
| 6089 | "0=auto, 1=EC, 2=CMOS, 3=both"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6090 | |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6091 | module_param(brightness_enable, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6092 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6093 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6094 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6095 | module_param(hotkey_report_mode, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6096 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6097 | "used for backwards compatibility with userspace, " |
| 6098 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6099 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6100 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6101 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 6102 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6103 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6104 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6105 | TPACPI_PARAM(hotkey); |
| 6106 | TPACPI_PARAM(bluetooth); |
| 6107 | TPACPI_PARAM(video); |
| 6108 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6109 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6110 | TPACPI_PARAM(dock); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6111 | #endif |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6112 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6113 | TPACPI_PARAM(bay); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6114 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6115 | TPACPI_PARAM(cmos); |
| 6116 | TPACPI_PARAM(led); |
| 6117 | TPACPI_PARAM(beep); |
| 6118 | TPACPI_PARAM(ecdump); |
| 6119 | TPACPI_PARAM(brightness); |
| 6120 | TPACPI_PARAM(volume); |
| 6121 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6122 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6123 | static void thinkpad_acpi_module_exit(void) |
| 6124 | { |
| 6125 | struct ibm_struct *ibm, *itmp; |
| 6126 | |
| 6127 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 6128 | |
| 6129 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 6130 | &tpacpi_all_drivers, |
| 6131 | all_drivers) { |
| 6132 | ibm_exit(ibm); |
| 6133 | } |
| 6134 | |
| 6135 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 6136 | |
| 6137 | if (tpacpi_inputdev) { |
| 6138 | if (tp_features.input_device_registered) |
| 6139 | input_unregister_device(tpacpi_inputdev); |
| 6140 | else |
| 6141 | input_free_device(tpacpi_inputdev); |
| 6142 | } |
| 6143 | |
| 6144 | if (tpacpi_hwmon) |
| 6145 | hwmon_device_unregister(tpacpi_hwmon); |
| 6146 | |
| 6147 | if (tp_features.sensors_pdev_attrs_registered) |
| 6148 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 6149 | &dev_attr_thinkpad_acpi_pdev_name); |
| 6150 | if (tpacpi_sensors_pdev) |
| 6151 | platform_device_unregister(tpacpi_sensors_pdev); |
| 6152 | if (tpacpi_pdev) |
| 6153 | platform_device_unregister(tpacpi_pdev); |
| 6154 | |
| 6155 | if (tp_features.sensors_pdrv_attrs_registered) |
| 6156 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 6157 | if (tp_features.platform_drv_attrs_registered) |
| 6158 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 6159 | |
| 6160 | if (tp_features.sensors_pdrv_registered) |
| 6161 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 6162 | |
| 6163 | if (tp_features.platform_drv_registered) |
| 6164 | platform_driver_unregister(&tpacpi_pdriver); |
| 6165 | |
| 6166 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6167 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6168 | |
| 6169 | kfree(thinkpad_id.bios_version_str); |
| 6170 | kfree(thinkpad_id.ec_version_str); |
| 6171 | kfree(thinkpad_id.model_str); |
| 6172 | } |
| 6173 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6174 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6175 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6176 | { |
| 6177 | int ret, i; |
| 6178 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6179 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 6180 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6181 | /* Parameter checking */ |
| 6182 | if (hotkey_report_mode > 2) |
| 6183 | return -EINVAL; |
| 6184 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6185 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6186 | |
| 6187 | get_thinkpad_model_data(&thinkpad_id); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6188 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6189 | if (ret) { |
| 6190 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6191 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6193 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6194 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6195 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6196 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 6197 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6198 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6199 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6200 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6201 | printk(TPACPI_ERR |
| 6202 | "unable to create proc dir " TPACPI_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6203 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6204 | return -ENODEV; |
| 6205 | } |
| 6206 | proc_dir->owner = THIS_MODULE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6207 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6208 | ret = platform_driver_register(&tpacpi_pdriver); |
| 6209 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6210 | printk(TPACPI_ERR |
| 6211 | "unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6212 | thinkpad_acpi_module_exit(); |
| 6213 | return ret; |
| 6214 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 6215 | tp_features.platform_drv_registered = 1; |
| 6216 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6217 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 6218 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6219 | printk(TPACPI_ERR |
| 6220 | "unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6221 | thinkpad_acpi_module_exit(); |
| 6222 | return ret; |
| 6223 | } |
| 6224 | tp_features.sensors_pdrv_registered = 1; |
| 6225 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6226 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6227 | if (!ret) { |
| 6228 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6229 | ret = tpacpi_create_driver_attributes( |
| 6230 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6231 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6232 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6233 | printk(TPACPI_ERR |
| 6234 | "unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6235 | thinkpad_acpi_module_exit(); |
| 6236 | return ret; |
| 6237 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6238 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6239 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6240 | |
| 6241 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6242 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6243 | NULL, 0); |
| 6244 | if (IS_ERR(tpacpi_pdev)) { |
| 6245 | ret = PTR_ERR(tpacpi_pdev); |
| 6246 | tpacpi_pdev = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6247 | printk(TPACPI_ERR "unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6248 | thinkpad_acpi_module_exit(); |
| 6249 | return ret; |
| 6250 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6251 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6252 | TPACPI_HWMON_DRVR_NAME, |
| 6253 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6254 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 6255 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 6256 | tpacpi_sensors_pdev = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6257 | printk(TPACPI_ERR |
| 6258 | "unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6259 | thinkpad_acpi_module_exit(); |
| 6260 | return ret; |
| 6261 | } |
| 6262 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 6263 | &dev_attr_thinkpad_acpi_pdev_name); |
| 6264 | if (ret) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6265 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6266 | "unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6267 | thinkpad_acpi_module_exit(); |
| 6268 | return ret; |
| 6269 | } |
| 6270 | tp_features.sensors_pdev_attrs_registered = 1; |
| 6271 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6272 | if (IS_ERR(tpacpi_hwmon)) { |
| 6273 | ret = PTR_ERR(tpacpi_hwmon); |
| 6274 | tpacpi_hwmon = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6275 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6276 | thinkpad_acpi_module_exit(); |
| 6277 | return ret; |
| 6278 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 6279 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6280 | tpacpi_inputdev = input_allocate_device(); |
| 6281 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6282 | printk(TPACPI_ERR "unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6283 | thinkpad_acpi_module_exit(); |
| 6284 | return -ENOMEM; |
| 6285 | } else { |
| 6286 | /* Prepare input device, but don't register */ |
| 6287 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6288 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6289 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 6290 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
| 6291 | thinkpad_id.vendor : |
| 6292 | PCI_VENDOR_ID_IBM; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6293 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 6294 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
| 6295 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6296 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 6297 | ret = ibm_init(&ibms_init[i]); |
| 6298 | if (ret >= 0 && *ibms_init[i].param) |
| 6299 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6300 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6301 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6302 | return ret; |
| 6303 | } |
| 6304 | } |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6305 | ret = input_register_device(tpacpi_inputdev); |
| 6306 | if (ret < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6307 | printk(TPACPI_ERR "unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6308 | thinkpad_acpi_module_exit(); |
| 6309 | return ret; |
| 6310 | } else { |
| 6311 | tp_features.input_device_registered = 1; |
| 6312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6313 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6314 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6315 | return 0; |
| 6316 | } |
| 6317 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6318 | /* Please remove this in year 2009 */ |
| 6319 | MODULE_ALIAS("ibm_acpi"); |
| 6320 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame^] | 6321 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 6322 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6323 | /* |
| 6324 | * DMI matching for module autoloading |
| 6325 | * |
| 6326 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 6327 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 6328 | * |
| 6329 | * Only models listed in thinkwiki will be supported, so add yours |
| 6330 | * if it is not there yet. |
| 6331 | */ |
| 6332 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
| 6333 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW") |
| 6334 | |
| 6335 | /* Non-ancient thinkpads */ |
| 6336 | MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*"); |
| 6337 | MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*"); |
| 6338 | |
| 6339 | /* Ancient thinkpad BIOSes have to be identified by |
| 6340 | * BIOS type or model number, and there are far less |
| 6341 | * BIOS types than model numbers... */ |
| 6342 | IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]"); |
| 6343 | IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]"); |
| 6344 | IBM_BIOS_MODULE_ALIAS("K[U,X-Z]"); |
| 6345 | |
| 6346 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6347 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 6348 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6349 | MODULE_LICENSE("GPL"); |
| 6350 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6351 | module_init(thinkpad_acpi_module_init); |
| 6352 | module_exit(thinkpad_acpi_module_exit); |