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 |
| 136 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 137 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 138 | #define TPACPI_MAX_ACPI_ARGS 3 |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 139 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 140 | /* Debugging */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 141 | #define TPACPI_LOG TPACPI_FILE ": " |
| 142 | #define TPACPI_ERR KERN_ERR TPACPI_LOG |
| 143 | #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG |
| 144 | #define TPACPI_INFO KERN_INFO TPACPI_LOG |
| 145 | #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 146 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 147 | #define TPACPI_DBG_ALL 0xffff |
| 148 | #define TPACPI_DBG_ALL 0xffff |
| 149 | #define TPACPI_DBG_INIT 0x0001 |
| 150 | #define TPACPI_DBG_EXIT 0x0002 |
| 151 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 152 | do { if (dbg_level & a_dbg_level) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 153 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ |
| 154 | } while (0) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 155 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 156 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 157 | dbg_printk(a_dbg_level, format, ## arg) |
| 158 | static const char *str_supported(int is_supported); |
| 159 | #else |
| 160 | #define vdbg_printk(a_dbg_level, format, arg...) |
| 161 | #endif |
| 162 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 163 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 164 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 165 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 166 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 167 | |
| 168 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 169 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 170 | */ |
| 171 | |
| 172 | struct ibm_struct; |
| 173 | |
| 174 | struct tp_acpi_drv_struct { |
| 175 | const struct acpi_device_id *hid; |
| 176 | struct acpi_driver *driver; |
| 177 | |
| 178 | void (*notify) (struct ibm_struct *, u32); |
| 179 | acpi_handle *handle; |
| 180 | u32 type; |
| 181 | struct acpi_device *device; |
| 182 | }; |
| 183 | |
| 184 | struct ibm_struct { |
| 185 | char *name; |
| 186 | |
| 187 | int (*read) (char *); |
| 188 | int (*write) (char *); |
| 189 | void (*exit) (void); |
| 190 | void (*resume) (void); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 191 | void (*suspend) (pm_message_t state); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 192 | |
| 193 | struct list_head all_drivers; |
| 194 | |
| 195 | struct tp_acpi_drv_struct *acpi; |
| 196 | |
| 197 | struct { |
| 198 | u8 acpi_driver_registered:1; |
| 199 | u8 acpi_notify_installed:1; |
| 200 | u8 proc_created:1; |
| 201 | u8 init_called:1; |
| 202 | u8 experimental:1; |
| 203 | } flags; |
| 204 | }; |
| 205 | |
| 206 | struct ibm_init_struct { |
| 207 | char param[32]; |
| 208 | |
| 209 | int (*init) (struct ibm_init_struct *); |
| 210 | struct ibm_struct *data; |
| 211 | }; |
| 212 | |
| 213 | static struct { |
| 214 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 215 | u32 bay_status:1; |
| 216 | u32 bay_eject:1; |
| 217 | u32 bay_status2:1; |
| 218 | u32 bay_eject2:1; |
| 219 | #endif |
| 220 | u32 bluetooth:1; |
| 221 | u32 hotkey:1; |
| 222 | u32 hotkey_mask:1; |
| 223 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 224 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 225 | u32 light:1; |
| 226 | u32 light_status:1; |
| 227 | u32 bright_16levels:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 228 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 229 | u32 wan:1; |
| 230 | u32 fan_ctrl_status_undef:1; |
| 231 | u32 input_device_registered:1; |
| 232 | u32 platform_drv_registered:1; |
| 233 | u32 platform_drv_attrs_registered:1; |
| 234 | u32 sensors_pdrv_registered:1; |
| 235 | u32 sensors_pdrv_attrs_registered:1; |
| 236 | u32 sensors_pdev_attrs_registered:1; |
| 237 | u32 hotkey_poll_active:1; |
| 238 | } tp_features; |
| 239 | |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 240 | static struct { |
| 241 | u16 hotkey_mask_ff:1; |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 242 | u16 bright_cmos_ec_unsync:1; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 243 | } tp_warned; |
| 244 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 245 | struct thinkpad_id_data { |
| 246 | unsigned int vendor; /* ThinkPad vendor: |
| 247 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 248 | |
| 249 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 250 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 251 | |
| 252 | u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */ |
| 253 | u16 ec_model; |
| 254 | |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 255 | char *model_str; /* ThinkPad T43 */ |
| 256 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 257 | }; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 258 | static struct thinkpad_id_data thinkpad_id; |
| 259 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 260 | static enum { |
| 261 | TPACPI_LIFE_INIT = 0, |
| 262 | TPACPI_LIFE_RUNNING, |
| 263 | TPACPI_LIFE_EXITING, |
| 264 | } tpacpi_lifecycle; |
| 265 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 266 | static int experimental; |
| 267 | static u32 dbg_level; |
| 268 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 269 | /**************************************************************************** |
| 270 | **************************************************************************** |
| 271 | * |
| 272 | * ACPI Helpers and device model |
| 273 | * |
| 274 | **************************************************************************** |
| 275 | ****************************************************************************/ |
| 276 | |
| 277 | /************************************************************************* |
| 278 | * ACPI basic handles |
| 279 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 281 | static acpi_handle root_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 283 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | static acpi_handle object##_handle; \ |
| 285 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 286 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | static char *object##_paths[] = { paths } |
| 288 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 289 | TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 290 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 291 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 292 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 293 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 294 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 295 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 296 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 298 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 299 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 301 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 302 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 303 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 304 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 305 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 306 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 307 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 308 | "^HKEY", /* R30, R31 */ |
| 309 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 310 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 311 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 312 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 313 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 314 | "\\_SB.PCI0.VID0", /* 770e */ |
| 315 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 316 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 317 | ); /* R30, R31 */ |
| 318 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 319 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 320 | /************************************************************************* |
| 321 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 322 | */ |
| 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | static int acpi_evalf(acpi_handle handle, |
| 325 | void *res, char *method, char *fmt, ...) |
| 326 | { |
| 327 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 328 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 329 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 330 | struct acpi_buffer result, *resultp; |
| 331 | union acpi_object out_obj; |
| 332 | acpi_status status; |
| 333 | va_list ap; |
| 334 | char res_type; |
| 335 | int success; |
| 336 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
| 338 | if (!*fmt) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 339 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | if (*fmt == 'q') { |
| 344 | quiet = 1; |
| 345 | fmt++; |
| 346 | } else |
| 347 | quiet = 0; |
| 348 | |
| 349 | res_type = *(fmt++); |
| 350 | |
| 351 | params.count = 0; |
| 352 | params.pointer = &in_objs[0]; |
| 353 | |
| 354 | va_start(ap, fmt); |
| 355 | while (*fmt) { |
| 356 | char c = *(fmt++); |
| 357 | switch (c) { |
| 358 | case 'd': /* int */ |
| 359 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 360 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 361 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 362 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 364 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | "with invalid format character '%c'\n", c); |
| 366 | return 0; |
| 367 | } |
| 368 | } |
| 369 | va_end(ap); |
| 370 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 371 | if (res_type != 'v') { |
| 372 | result.length = sizeof(out_obj); |
| 373 | result.pointer = &out_obj; |
| 374 | resultp = &result; |
| 375 | } else |
| 376 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 378 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
| 380 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 381 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | if (res) |
| 383 | *(int *)res = out_obj.integer.value; |
| 384 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 385 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 386 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | success = status == AE_OK; |
| 388 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 389 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 391 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | "with invalid format character '%c'\n", res_type); |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | if (!success && !quiet) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 397 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | method, fmt0, status); |
| 399 | |
| 400 | return success; |
| 401 | } |
| 402 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 403 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 404 | { |
| 405 | int v; |
| 406 | |
| 407 | if (ecrd_handle) { |
| 408 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 409 | return 0; |
| 410 | *p = v; |
| 411 | } else { |
| 412 | if (ec_read(i, p) < 0) |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | return 1; |
| 417 | } |
| 418 | |
| 419 | static int acpi_ec_write(int i, u8 v) |
| 420 | { |
| 421 | if (ecwr_handle) { |
| 422 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 423 | return 0; |
| 424 | } else { |
| 425 | if (ec_write(i, v) < 0) |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | return 1; |
| 430 | } |
| 431 | |
Henrique de Moraes Holschuh | 013c40e | 2008-01-08 13:02:54 -0200 | [diff] [blame] | 432 | #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] | 433 | static int _sta(acpi_handle handle) |
| 434 | { |
| 435 | int status; |
| 436 | |
| 437 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) |
| 438 | status = 0; |
| 439 | |
| 440 | return status; |
| 441 | } |
Henrique de Moraes Holschuh | 013c40e | 2008-01-08 13:02:54 -0200 | [diff] [blame] | 442 | #endif |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 443 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 444 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 445 | { |
| 446 | if (!cmos_handle) |
| 447 | return -ENXIO; |
| 448 | |
| 449 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 450 | return -EIO; |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 455 | /************************************************************************* |
| 456 | * ACPI device model |
| 457 | */ |
| 458 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 459 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 460 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 461 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
| 462 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 463 | static void drv_acpi_handle_init(char *name, |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 464 | acpi_handle *handle, acpi_handle parent, |
| 465 | char **paths, int num_paths, char **path) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 466 | { |
| 467 | int i; |
| 468 | acpi_status status; |
| 469 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 470 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 471 | name); |
| 472 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 473 | for (i = 0; i < num_paths; i++) { |
| 474 | status = acpi_get_handle(parent, paths[i], handle); |
| 475 | if (ACPI_SUCCESS(status)) { |
| 476 | *path = paths[i]; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 477 | dbg_printk(TPACPI_DBG_INIT, |
| 478 | "Found ACPI handle %s for %s\n", |
| 479 | *path, name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 480 | return; |
| 481 | } |
| 482 | } |
| 483 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 484 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 485 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 486 | *handle = NULL; |
| 487 | } |
| 488 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 489 | 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] | 490 | { |
| 491 | struct ibm_struct *ibm = data; |
| 492 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 493 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 494 | return; |
| 495 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 496 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 497 | return; |
| 498 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 499 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 500 | } |
| 501 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 502 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 503 | { |
| 504 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 505 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 506 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 507 | BUG_ON(!ibm->acpi); |
| 508 | |
| 509 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 510 | return 0; |
| 511 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 512 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 513 | "setting up ACPI notify for %s\n", ibm->name); |
| 514 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 515 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 516 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 517 | 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] | 518 | ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 519 | return -ENODEV; |
| 520 | } |
| 521 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 522 | acpi_driver_data(ibm->acpi->device) = ibm; |
| 523 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 524 | TPACPI_ACPI_EVENT_PREFIX, |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 525 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 526 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 527 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 528 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 529 | if (ACPI_FAILURE(status)) { |
| 530 | if (status == AE_ALREADY_EXISTS) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 531 | printk(TPACPI_NOTICE |
| 532 | "another device driver is already " |
| 533 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 534 | } else { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 535 | printk(TPACPI_ERR |
| 536 | "acpi_install_notify_handler(%s) failed: %d\n", |
| 537 | ibm->name, status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 538 | } |
| 539 | return -ENODEV; |
| 540 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 541 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 542 | return 0; |
| 543 | } |
| 544 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 545 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 546 | { |
| 547 | return 0; |
| 548 | } |
| 549 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 550 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 551 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 552 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 553 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 554 | dbg_printk(TPACPI_DBG_INIT, |
| 555 | "registering %s as an ACPI driver\n", ibm->name); |
| 556 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 557 | BUG_ON(!ibm->acpi); |
| 558 | |
| 559 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 560 | if (!ibm->acpi->driver) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 561 | printk(TPACPI_ERR "kzalloc(ibm->driver) failed\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 562 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 563 | } |
| 564 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 565 | 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] | 566 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 567 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 568 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 569 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 570 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 571 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 572 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 573 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 574 | kfree(ibm->acpi->driver); |
| 575 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 576 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 577 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 578 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 579 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | |
| 583 | /**************************************************************************** |
| 584 | **************************************************************************** |
| 585 | * |
| 586 | * Procfs Helpers |
| 587 | * |
| 588 | **************************************************************************** |
| 589 | ****************************************************************************/ |
| 590 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 591 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 592 | int count, int *eof, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 593 | { |
| 594 | struct ibm_struct *ibm = data; |
| 595 | int len; |
| 596 | |
| 597 | if (!ibm || !ibm->read) |
| 598 | return -EINVAL; |
| 599 | |
| 600 | len = ibm->read(page); |
| 601 | if (len < 0) |
| 602 | return len; |
| 603 | |
| 604 | if (len <= off + count) |
| 605 | *eof = 1; |
| 606 | *start = page + off; |
| 607 | len -= off; |
| 608 | if (len > count) |
| 609 | len = count; |
| 610 | if (len < 0) |
| 611 | len = 0; |
| 612 | |
| 613 | return len; |
| 614 | } |
| 615 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 616 | static int dispatch_procfs_write(struct file *file, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 617 | const char __user *userbuf, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 618 | unsigned long count, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 619 | { |
| 620 | struct ibm_struct *ibm = data; |
| 621 | char *kernbuf; |
| 622 | int ret; |
| 623 | |
| 624 | if (!ibm || !ibm->write) |
| 625 | return -EINVAL; |
| 626 | |
| 627 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 628 | if (!kernbuf) |
| 629 | return -ENOMEM; |
| 630 | |
| 631 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 632 | kfree(kernbuf); |
| 633 | return -EFAULT; |
| 634 | } |
| 635 | |
| 636 | kernbuf[count] = 0; |
| 637 | strcat(kernbuf, ","); |
| 638 | ret = ibm->write(kernbuf); |
| 639 | if (ret == 0) |
| 640 | ret = count; |
| 641 | |
| 642 | kfree(kernbuf); |
| 643 | |
| 644 | return ret; |
| 645 | } |
| 646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | static char *next_cmd(char **cmds) |
| 648 | { |
| 649 | char *start = *cmds; |
| 650 | char *end; |
| 651 | |
| 652 | while ((end = strchr(start, ',')) && end == start) |
| 653 | start = end + 1; |
| 654 | |
| 655 | if (!end) |
| 656 | return NULL; |
| 657 | |
| 658 | *end = 0; |
| 659 | *cmds = end + 1; |
| 660 | return start; |
| 661 | } |
| 662 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 663 | |
| 664 | /**************************************************************************** |
| 665 | **************************************************************************** |
| 666 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 667 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 668 | * |
| 669 | **************************************************************************** |
| 670 | ****************************************************************************/ |
| 671 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 672 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 673 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 674 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 675 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 676 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 677 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 678 | |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 679 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
| 680 | pm_message_t state) |
| 681 | { |
| 682 | struct ibm_struct *ibm, *itmp; |
| 683 | |
| 684 | list_for_each_entry_safe(ibm, itmp, |
| 685 | &tpacpi_all_drivers, |
| 686 | all_drivers) { |
| 687 | if (ibm->suspend) |
| 688 | (ibm->suspend)(state); |
| 689 | } |
| 690 | |
| 691 | return 0; |
| 692 | } |
| 693 | |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 694 | static int tpacpi_resume_handler(struct platform_device *pdev) |
| 695 | { |
| 696 | struct ibm_struct *ibm, *itmp; |
| 697 | |
| 698 | list_for_each_entry_safe(ibm, itmp, |
| 699 | &tpacpi_all_drivers, |
| 700 | all_drivers) { |
| 701 | if (ibm->resume) |
| 702 | (ibm->resume)(); |
| 703 | } |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 708 | static struct platform_driver tpacpi_pdriver = { |
| 709 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 710 | .name = TPACPI_DRVR_NAME, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 711 | .owner = THIS_MODULE, |
| 712 | }, |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 713 | .suspend = tpacpi_suspend_handler, |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 714 | .resume = tpacpi_resume_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 715 | }; |
| 716 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 717 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 718 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 719 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 720 | .owner = THIS_MODULE, |
| 721 | }, |
| 722 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 723 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 724 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 725 | * sysfs support helpers |
| 726 | */ |
| 727 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 728 | struct attribute_set { |
| 729 | unsigned int members, max_members; |
| 730 | struct attribute_group group; |
| 731 | }; |
| 732 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 733 | struct attribute_set_obj { |
| 734 | struct attribute_set s; |
| 735 | struct attribute *a; |
| 736 | } __attribute__((packed)); |
| 737 | |
| 738 | 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] | 739 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 740 | { |
| 741 | struct attribute_set_obj *sobj; |
| 742 | |
| 743 | if (max_members == 0) |
| 744 | return NULL; |
| 745 | |
| 746 | /* Allocates space for implicit NULL at the end too */ |
| 747 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 748 | max_members * sizeof(struct attribute *), |
| 749 | GFP_KERNEL); |
| 750 | if (!sobj) |
| 751 | return NULL; |
| 752 | sobj->s.max_members = max_members; |
| 753 | sobj->s.group.attrs = &sobj->a; |
| 754 | sobj->s.group.name = name; |
| 755 | |
| 756 | return &sobj->s; |
| 757 | } |
| 758 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 759 | #define destroy_attr_set(_set) \ |
| 760 | kfree(_set); |
| 761 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 762 | /* 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] | 763 | 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] | 764 | { |
| 765 | if (!s || !attr) |
| 766 | return -EINVAL; |
| 767 | |
| 768 | if (s->members >= s->max_members) |
| 769 | return -ENOMEM; |
| 770 | |
| 771 | s->group.attrs[s->members] = attr; |
| 772 | s->members++; |
| 773 | |
| 774 | return 0; |
| 775 | } |
| 776 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 777 | 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] | 778 | struct attribute **attr, |
| 779 | unsigned int count) |
| 780 | { |
| 781 | int i, res; |
| 782 | |
| 783 | for (i = 0; i < count; i++) { |
| 784 | res = add_to_attr_set(s, attr[i]); |
| 785 | if (res) |
| 786 | return res; |
| 787 | } |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 792 | 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] | 793 | { |
| 794 | sysfs_remove_group(kobj, &s->group); |
| 795 | destroy_attr_set(s); |
| 796 | } |
| 797 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 798 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 799 | sysfs_create_group(_kobj, &_attr_set->group) |
| 800 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 801 | static int parse_strtoul(const char *buf, |
| 802 | unsigned long max, unsigned long *value) |
| 803 | { |
| 804 | char *endp; |
| 805 | |
Henrique de Moraes Holschuh | 32afbf0 | 2007-10-08 10:12:56 -0300 | [diff] [blame] | 806 | while (*buf && isspace(*buf)) |
| 807 | buf++; |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 808 | *value = simple_strtoul(buf, &endp, 0); |
| 809 | while (*endp && isspace(*endp)) |
| 810 | endp++; |
| 811 | if (*endp || *value > max) |
| 812 | return -EINVAL; |
| 813 | |
| 814 | return 0; |
| 815 | } |
| 816 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 817 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 818 | { |
| 819 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 820 | union acpi_object *obj; |
| 821 | int rc; |
| 822 | |
| 823 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { |
| 824 | obj = (union acpi_object *)buffer.pointer; |
| 825 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
| 826 | printk(TPACPI_ERR "Unknown _BCL data, " |
| 827 | "please report this to %s\n", TPACPI_MAIL); |
| 828 | rc = 0; |
| 829 | } else { |
| 830 | rc = obj->package.count; |
| 831 | } |
| 832 | } else { |
| 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | kfree(buffer.pointer); |
| 837 | return rc; |
| 838 | } |
| 839 | |
| 840 | static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle, |
| 841 | u32 lvl, void *context, void **rv) |
| 842 | { |
| 843 | char name[ACPI_PATH_SEGMENT_LENGTH]; |
| 844 | struct acpi_buffer buffer = { sizeof(name), &name }; |
| 845 | |
| 846 | if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && |
| 847 | !strncmp("_BCL", name, sizeof(name) - 1)) { |
| 848 | BUG_ON(!rv || !*rv); |
| 849 | **(int **)rv = tpacpi_query_bcl_levels(handle); |
| 850 | return AE_CTRL_TERMINATE; |
| 851 | } else { |
| 852 | return AE_OK; |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | /* |
| 857 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 858 | */ |
| 859 | static int __init tpacpi_check_std_acpi_brightness_support(void) |
| 860 | { |
| 861 | int status; |
| 862 | int bcl_levels = 0; |
| 863 | void *bcl_ptr = &bcl_levels; |
| 864 | |
| 865 | if (!vid_handle) { |
| 866 | TPACPI_ACPIHANDLE_INIT(vid); |
| 867 | } |
| 868 | if (!vid_handle) |
| 869 | return 0; |
| 870 | |
| 871 | /* |
| 872 | * Search for a _BCL method, and execute it. This is safe on all |
| 873 | * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista |
| 874 | * BIOS in ACPI backlight control mode. We do NOT have to care |
| 875 | * about calling the _BCL method in an enabled video device, any |
| 876 | * will do for our purposes. |
| 877 | */ |
| 878 | |
| 879 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, |
| 880 | tpacpi_acpi_walk_find_bcl, NULL, |
| 881 | &bcl_ptr); |
| 882 | |
| 883 | if (ACPI_SUCCESS(status) && bcl_levels > 2) { |
| 884 | tp_features.bright_acpimode = 1; |
| 885 | return (bcl_levels - 2); |
| 886 | } |
| 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 891 | /************************************************************************* |
| 892 | * thinkpad-acpi driver attributes |
| 893 | */ |
| 894 | |
| 895 | /* interface_version --------------------------------------------------- */ |
| 896 | static ssize_t tpacpi_driver_interface_version_show( |
| 897 | struct device_driver *drv, |
| 898 | char *buf) |
| 899 | { |
| 900 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 901 | } |
| 902 | |
| 903 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 904 | tpacpi_driver_interface_version_show, NULL); |
| 905 | |
| 906 | /* debug_level --------------------------------------------------------- */ |
| 907 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 908 | char *buf) |
| 909 | { |
| 910 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 911 | } |
| 912 | |
| 913 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 914 | const char *buf, size_t count) |
| 915 | { |
| 916 | unsigned long t; |
| 917 | |
| 918 | if (parse_strtoul(buf, 0xffff, &t)) |
| 919 | return -EINVAL; |
| 920 | |
| 921 | dbg_level = t; |
| 922 | |
| 923 | return count; |
| 924 | } |
| 925 | |
| 926 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 927 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 928 | |
| 929 | /* version ------------------------------------------------------------- */ |
| 930 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 931 | char *buf) |
| 932 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 933 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 934 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | static DRIVER_ATTR(version, S_IRUGO, |
| 938 | tpacpi_driver_version_show, NULL); |
| 939 | |
| 940 | /* --------------------------------------------------------------------- */ |
| 941 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 942 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 943 | &driver_attr_debug_level, &driver_attr_version, |
| 944 | &driver_attr_interface_version, |
| 945 | }; |
| 946 | |
| 947 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 948 | { |
| 949 | int i, res; |
| 950 | |
| 951 | i = 0; |
| 952 | res = 0; |
| 953 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 954 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 955 | i++; |
| 956 | } |
| 957 | |
| 958 | return res; |
| 959 | } |
| 960 | |
| 961 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 962 | { |
| 963 | int i; |
| 964 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 965 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 966 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
| 967 | } |
| 968 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 969 | /**************************************************************************** |
| 970 | **************************************************************************** |
| 971 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 972 | * Subdrivers |
| 973 | * |
| 974 | **************************************************************************** |
| 975 | ****************************************************************************/ |
| 976 | |
| 977 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 978 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 979 | */ |
| 980 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 981 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 983 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 984 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
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 "ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 987 | (thinkpad_id.bios_version_str) ? |
| 988 | thinkpad_id.bios_version_str : "unknown", |
| 989 | (thinkpad_id.ec_version_str) ? |
| 990 | thinkpad_id.ec_version_str : "unknown"); |
| 991 | |
| 992 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 993 | printk(TPACPI_INFO "%s %s, model %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 994 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 995 | "IBM" : ((thinkpad_id.vendor == |
| 996 | PCI_VENDOR_ID_LENOVO) ? |
| 997 | "Lenovo" : "Unknown vendor"), |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 998 | thinkpad_id.model_str, |
| 999 | (thinkpad_id.nummodel_str) ? |
| 1000 | thinkpad_id.nummodel_str : "unknown"); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 1001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | return 0; |
| 1003 | } |
| 1004 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1005 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | { |
| 1007 | int len = 0; |
| 1008 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1009 | len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); |
| 1010 | len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
| 1012 | return len; |
| 1013 | } |
| 1014 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1015 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1016 | .name = "driver", |
| 1017 | .read = thinkpad_acpi_driver_read, |
| 1018 | }; |
| 1019 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1020 | /************************************************************************* |
| 1021 | * Hotkey subdriver |
| 1022 | */ |
| 1023 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1024 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1025 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1026 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1027 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1028 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1029 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1030 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1031 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1032 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1033 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1034 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1035 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1036 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1037 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1038 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1039 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1040 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1041 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1042 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1043 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1044 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1045 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1046 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1047 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1048 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1049 | }; |
| 1050 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1051 | enum { /* Keys available through NVRAM polling */ |
| 1052 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1053 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1054 | }; |
| 1055 | |
| 1056 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1057 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1058 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1059 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1060 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1061 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1062 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1063 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1064 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1065 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1066 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1067 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1068 | }; |
| 1069 | |
| 1070 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1071 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1072 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1073 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1074 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1075 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1076 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1077 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1078 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1079 | TP_ACPI_HKEY_MUTE_MASK, |
| 1080 | }; |
| 1081 | |
| 1082 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1083 | struct tp_nvram_state { |
| 1084 | u16 thinkpad_toggle:1; |
| 1085 | u16 zoom_toggle:1; |
| 1086 | u16 display_toggle:1; |
| 1087 | u16 thinklight_toggle:1; |
| 1088 | u16 hibernate_toggle:1; |
| 1089 | u16 displayexp_toggle:1; |
| 1090 | u16 display_state:1; |
| 1091 | u16 brightness_toggle:1; |
| 1092 | u16 volume_toggle:1; |
| 1093 | u16 mute:1; |
| 1094 | |
| 1095 | u8 brightness_level; |
| 1096 | u8 volume_level; |
| 1097 | }; |
| 1098 | |
| 1099 | static struct task_struct *tpacpi_hotkey_task; |
| 1100 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 1101 | static int hotkey_poll_freq = 10; /* Hz */ |
| 1102 | static struct mutex hotkey_thread_mutex; |
| 1103 | static struct mutex hotkey_thread_data_mutex; |
| 1104 | static unsigned int hotkey_config_change; |
| 1105 | |
| 1106 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1107 | |
| 1108 | #define hotkey_source_mask 0U |
| 1109 | |
| 1110 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1111 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1112 | static struct mutex hotkey_mutex; |
| 1113 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1114 | static enum { /* Reasons for waking up */ |
| 1115 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 1116 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 1117 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 1118 | } hotkey_wakeup_reason; |
| 1119 | |
| 1120 | static int hotkey_autosleep_ack; |
| 1121 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1122 | static int hotkey_orig_status; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1123 | static u32 hotkey_orig_mask; |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1124 | static u32 hotkey_all_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1125 | static u32 hotkey_reserved_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1126 | static u32 hotkey_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1127 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1128 | static unsigned int hotkey_report_mode; |
| 1129 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1130 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1131 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 1132 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1133 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1134 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1135 | #define HOTKEY_CONFIG_CRITICAL_START \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1136 | do { \ |
| 1137 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 1138 | hotkey_config_change++; \ |
| 1139 | } while (0); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1140 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 1141 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1142 | #else |
| 1143 | #define HOTKEY_CONFIG_CRITICAL_START |
| 1144 | #define HOTKEY_CONFIG_CRITICAL_END |
| 1145 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1146 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1147 | /* HKEY.MHKG() return bits */ |
| 1148 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 1149 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1150 | static int hotkey_get_wlsw(int *status) |
| 1151 | { |
| 1152 | if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) |
| 1153 | return -EIO; |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1157 | static int hotkey_get_tablet_mode(int *status) |
| 1158 | { |
| 1159 | int s; |
| 1160 | |
| 1161 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 1162 | return -EIO; |
| 1163 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 1164 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 1165 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1166 | } |
| 1167 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1168 | /* |
| 1169 | * Call with hotkey_mutex held |
| 1170 | */ |
| 1171 | static int hotkey_mask_get(void) |
| 1172 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1173 | u32 m = 0; |
| 1174 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1175 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1176 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1177 | return -EIO; |
| 1178 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1179 | hotkey_mask = m | (hotkey_source_mask & hotkey_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1180 | |
| 1181 | return 0; |
| 1182 | } |
| 1183 | |
| 1184 | /* |
| 1185 | * Call with hotkey_mutex held |
| 1186 | */ |
| 1187 | static int hotkey_mask_set(u32 mask) |
| 1188 | { |
| 1189 | int i; |
| 1190 | int rc = 0; |
| 1191 | |
| 1192 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 1193 | if (!tp_warned.hotkey_mask_ff && |
| 1194 | (mask == 0xffff || mask == 0xffffff || |
| 1195 | mask == 0xffffffff)) { |
| 1196 | tp_warned.hotkey_mask_ff = 1; |
| 1197 | printk(TPACPI_NOTICE |
| 1198 | "setting the hotkey mask to 0x%08x is likely " |
| 1199 | "not the best way to go about it\n", mask); |
| 1200 | printk(TPACPI_NOTICE |
| 1201 | "please consider using the driver defaults, " |
| 1202 | "and refer to up-to-date thinkpad-acpi " |
| 1203 | "documentation\n"); |
| 1204 | } |
| 1205 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1206 | HOTKEY_CONFIG_CRITICAL_START |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1207 | for (i = 0; i < 32; i++) { |
| 1208 | u32 m = 1 << i; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1209 | /* enable in firmware mask only keys not in NVRAM |
| 1210 | * mode, but enable the key in the cached hotkey_mask |
| 1211 | * regardless of mode, or the key will end up |
| 1212 | * disabled by hotkey_mask_get() */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1213 | if (!acpi_evalf(hkey_handle, |
| 1214 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1215 | !!((mask & ~hotkey_source_mask) & m))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1216 | rc = -EIO; |
| 1217 | break; |
| 1218 | } else { |
| 1219 | hotkey_mask = (hotkey_mask & ~m) | (mask & m); |
| 1220 | } |
| 1221 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1222 | HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1223 | |
| 1224 | /* hotkey_mask_get must be called unconditionally below */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1225 | if (!hotkey_mask_get() && !rc && |
| 1226 | (hotkey_mask & ~hotkey_source_mask) != |
| 1227 | (mask & ~hotkey_source_mask)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1228 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1229 | "requested hot key mask 0x%08x, but " |
| 1230 | "firmware forced it to 0x%08x\n", |
| 1231 | mask, hotkey_mask); |
| 1232 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1233 | } else { |
| 1234 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1235 | HOTKEY_CONFIG_CRITICAL_START |
| 1236 | hotkey_mask = mask & hotkey_source_mask; |
| 1237 | HOTKEY_CONFIG_CRITICAL_END |
| 1238 | hotkey_mask_get(); |
| 1239 | if (hotkey_mask != mask) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1240 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1241 | "requested hot key mask 0x%08x, " |
| 1242 | "forced to 0x%08x (NVRAM poll mask is " |
| 1243 | "0x%08x): no firmware mask support\n", |
| 1244 | mask, hotkey_mask, hotkey_source_mask); |
| 1245 | } |
| 1246 | #else |
| 1247 | hotkey_mask_get(); |
| 1248 | rc = -ENXIO; |
| 1249 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | return rc; |
| 1253 | } |
| 1254 | |
| 1255 | static int hotkey_status_get(int *status) |
| 1256 | { |
| 1257 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 1258 | return -EIO; |
| 1259 | |
| 1260 | return 0; |
| 1261 | } |
| 1262 | |
| 1263 | static int hotkey_status_set(int status) |
| 1264 | { |
| 1265 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) |
| 1266 | return -EIO; |
| 1267 | |
| 1268 | return 0; |
| 1269 | } |
| 1270 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1271 | static void tpacpi_input_send_radiosw(void) |
| 1272 | { |
| 1273 | int wlsw; |
| 1274 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1275 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { |
Henrique de Moraes Holschuh | d147da7 | 2008-02-16 02:17:57 -0200 | [diff] [blame] | 1276 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1277 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1278 | input_report_switch(tpacpi_inputdev, |
| 1279 | SW_RADIO, !!wlsw); |
| 1280 | input_sync(tpacpi_inputdev); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1281 | |
Henrique de Moraes Holschuh | d147da7 | 2008-02-16 02:17:57 -0200 | [diff] [blame] | 1282 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1283 | } |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1284 | } |
| 1285 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1286 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1287 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1288 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1289 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1290 | if (tp_features.hotkey_tablet && |
| 1291 | !hotkey_get_tablet_mode(&state)) { |
| 1292 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1293 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1294 | input_report_switch(tpacpi_inputdev, |
| 1295 | SW_TABLET_MODE, !!state); |
| 1296 | input_sync(tpacpi_inputdev); |
| 1297 | |
| 1298 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1299 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1300 | } |
| 1301 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1302 | static void tpacpi_input_send_key(unsigned int scancode) |
| 1303 | { |
| 1304 | unsigned int keycode; |
| 1305 | |
| 1306 | keycode = hotkey_keycode_map[scancode]; |
| 1307 | |
| 1308 | if (keycode != KEY_RESERVED) { |
| 1309 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1310 | |
| 1311 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 1312 | if (keycode == KEY_UNKNOWN) |
| 1313 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1314 | scancode); |
| 1315 | input_sync(tpacpi_inputdev); |
| 1316 | |
| 1317 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 1318 | if (keycode == KEY_UNKNOWN) |
| 1319 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1320 | scancode); |
| 1321 | input_sync(tpacpi_inputdev); |
| 1322 | |
| 1323 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1324 | } |
| 1325 | } |
| 1326 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1327 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1328 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 1329 | |
| 1330 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 1331 | { |
| 1332 | tpacpi_input_send_key(scancode); |
| 1333 | if (hotkey_report_mode < 2) { |
| 1334 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
| 1335 | 0x80, 0x1001 + scancode); |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m) |
| 1340 | { |
| 1341 | u8 d; |
| 1342 | |
| 1343 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 1344 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 1345 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 1346 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 1347 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 1348 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 1349 | } |
| 1350 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 1351 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 1352 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 1353 | } |
| 1354 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 1355 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 1356 | n->displayexp_toggle = |
| 1357 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 1358 | } |
| 1359 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 1360 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 1361 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 1362 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 1363 | n->brightness_toggle = |
| 1364 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 1365 | } |
| 1366 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 1367 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 1368 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 1369 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 1370 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 1371 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1376 | do { \ |
| 1377 | if ((mask & (1 << __scancode)) && \ |
| 1378 | oldn->__member != newn->__member) \ |
| 1379 | tpacpi_hotkey_send_key(__scancode); \ |
| 1380 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1381 | |
| 1382 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
| 1383 | do { if (mask & (1 << __scancode)) \ |
| 1384 | tpacpi_hotkey_send_key(__scancode); } while (0) |
| 1385 | |
| 1386 | 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] | 1387 | struct tp_nvram_state *newn, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1388 | u32 mask) |
| 1389 | { |
| 1390 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 1391 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 1392 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 1393 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 1394 | |
| 1395 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 1396 | |
| 1397 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 1398 | |
| 1399 | /* handle volume */ |
| 1400 | if (oldn->volume_toggle != newn->volume_toggle) { |
| 1401 | if (oldn->mute != newn->mute) { |
| 1402 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1403 | } |
| 1404 | if (oldn->volume_level > newn->volume_level) { |
| 1405 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1406 | } else if (oldn->volume_level < newn->volume_level) { |
| 1407 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1408 | } else if (oldn->mute == newn->mute) { |
| 1409 | /* repeated key presses that didn't change state */ |
| 1410 | if (newn->mute) { |
| 1411 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1412 | } else if (newn->volume_level != 0) { |
| 1413 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1414 | } else { |
| 1415 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1416 | } |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | /* handle brightness */ |
| 1421 | if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 1422 | if (oldn->brightness_level < newn->brightness_level) { |
| 1423 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1424 | } else if (oldn->brightness_level > newn->brightness_level) { |
| 1425 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1426 | } else { |
| 1427 | /* repeated key presses that didn't change state */ |
| 1428 | if (newn->brightness_level != 0) { |
| 1429 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1430 | } else { |
| 1431 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | #undef TPACPI_COMPARE_KEY |
| 1438 | #undef TPACPI_MAY_SEND_KEY |
| 1439 | |
| 1440 | static int hotkey_kthread(void *data) |
| 1441 | { |
| 1442 | struct tp_nvram_state s[2]; |
| 1443 | u32 mask; |
| 1444 | unsigned int si, so; |
| 1445 | unsigned long t; |
| 1446 | unsigned int change_detector, must_reset; |
| 1447 | |
| 1448 | mutex_lock(&hotkey_thread_mutex); |
| 1449 | |
| 1450 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 1451 | goto exit; |
| 1452 | |
| 1453 | set_freezable(); |
| 1454 | |
| 1455 | so = 0; |
| 1456 | si = 1; |
| 1457 | t = 0; |
| 1458 | |
| 1459 | /* Initial state for compares */ |
| 1460 | mutex_lock(&hotkey_thread_data_mutex); |
| 1461 | change_detector = hotkey_config_change; |
| 1462 | mask = hotkey_source_mask & hotkey_mask; |
| 1463 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1464 | hotkey_read_nvram(&s[so], mask); |
| 1465 | |
| 1466 | while (!kthread_should_stop() && hotkey_poll_freq) { |
| 1467 | if (t == 0) |
| 1468 | t = 1000/hotkey_poll_freq; |
| 1469 | t = msleep_interruptible(t); |
| 1470 | if (unlikely(kthread_should_stop())) |
| 1471 | break; |
| 1472 | must_reset = try_to_freeze(); |
| 1473 | if (t > 0 && !must_reset) |
| 1474 | continue; |
| 1475 | |
| 1476 | mutex_lock(&hotkey_thread_data_mutex); |
| 1477 | if (must_reset || hotkey_config_change != change_detector) { |
| 1478 | /* forget old state on thaw or config change */ |
| 1479 | si = so; |
| 1480 | t = 0; |
| 1481 | change_detector = hotkey_config_change; |
| 1482 | } |
| 1483 | mask = hotkey_source_mask & hotkey_mask; |
| 1484 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1485 | |
| 1486 | if (likely(mask)) { |
| 1487 | hotkey_read_nvram(&s[si], mask); |
| 1488 | if (likely(si != so)) { |
| 1489 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1490 | mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | so = si; |
| 1495 | si ^= 1; |
| 1496 | } |
| 1497 | |
| 1498 | exit: |
| 1499 | mutex_unlock(&hotkey_thread_mutex); |
| 1500 | return 0; |
| 1501 | } |
| 1502 | |
| 1503 | static void hotkey_poll_stop_sync(void) |
| 1504 | { |
| 1505 | if (tpacpi_hotkey_task) { |
| 1506 | if (frozen(tpacpi_hotkey_task) || |
| 1507 | freezing(tpacpi_hotkey_task)) |
| 1508 | thaw_process(tpacpi_hotkey_task); |
| 1509 | |
| 1510 | kthread_stop(tpacpi_hotkey_task); |
| 1511 | tpacpi_hotkey_task = NULL; |
| 1512 | mutex_lock(&hotkey_thread_mutex); |
| 1513 | /* at this point, the thread did exit */ |
| 1514 | mutex_unlock(&hotkey_thread_mutex); |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | /* call with hotkey_mutex held */ |
| 1519 | static void hotkey_poll_setup(int may_warn) |
| 1520 | { |
| 1521 | if ((hotkey_source_mask & hotkey_mask) != 0 && |
| 1522 | hotkey_poll_freq > 0 && |
| 1523 | (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { |
| 1524 | if (!tpacpi_hotkey_task) { |
| 1525 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1526 | NULL, |
| 1527 | TPACPI_FILE "d"); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1528 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 1529 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1530 | printk(TPACPI_ERR |
| 1531 | "could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1532 | "for hotkey polling\n"); |
| 1533 | } |
| 1534 | } |
| 1535 | } else { |
| 1536 | hotkey_poll_stop_sync(); |
| 1537 | if (may_warn && |
| 1538 | hotkey_source_mask != 0 && hotkey_poll_freq == 0) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1539 | printk(TPACPI_NOTICE |
| 1540 | "hot keys 0x%08x require polling, " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1541 | "which is currently disabled\n", |
| 1542 | hotkey_source_mask); |
| 1543 | } |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | static void hotkey_poll_setup_safe(int may_warn) |
| 1548 | { |
| 1549 | mutex_lock(&hotkey_mutex); |
| 1550 | hotkey_poll_setup(may_warn); |
| 1551 | mutex_unlock(&hotkey_mutex); |
| 1552 | } |
| 1553 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 1554 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1555 | |
| 1556 | static void hotkey_poll_setup_safe(int __unused) |
| 1557 | { |
| 1558 | } |
| 1559 | |
| 1560 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1561 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1562 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 1563 | { |
| 1564 | switch (tpacpi_lifecycle) { |
| 1565 | case TPACPI_LIFE_INIT: |
| 1566 | /* |
| 1567 | * hotkey_init will call hotkey_poll_setup_safe |
| 1568 | * at the appropriate moment |
| 1569 | */ |
| 1570 | return 0; |
| 1571 | case TPACPI_LIFE_EXITING: |
| 1572 | return -EBUSY; |
| 1573 | case TPACPI_LIFE_RUNNING: |
| 1574 | hotkey_poll_setup_safe(0); |
| 1575 | return 0; |
| 1576 | } |
| 1577 | |
| 1578 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 1579 | BUG(); |
| 1580 | return -EBUSY; |
| 1581 | } |
| 1582 | |
| 1583 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 1584 | { |
| 1585 | /* disable hotkey polling when possible */ |
| 1586 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING) |
| 1587 | hotkey_poll_setup_safe(0); |
| 1588 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1589 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1590 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 1591 | static ssize_t hotkey_enable_show(struct device *dev, |
| 1592 | struct device_attribute *attr, |
| 1593 | char *buf) |
| 1594 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1595 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1596 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1597 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1598 | if (res) |
| 1599 | return res; |
| 1600 | |
| 1601 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 1602 | } |
| 1603 | |
| 1604 | static ssize_t hotkey_enable_store(struct device *dev, |
| 1605 | struct device_attribute *attr, |
| 1606 | const char *buf, size_t count) |
| 1607 | { |
| 1608 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1609 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1610 | |
| 1611 | if (parse_strtoul(buf, 1, &t)) |
| 1612 | return -EINVAL; |
| 1613 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1614 | res = hotkey_status_set(t); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1615 | |
| 1616 | return (res) ? res : count; |
| 1617 | } |
| 1618 | |
| 1619 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1620 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1621 | hotkey_enable_show, hotkey_enable_store); |
| 1622 | |
| 1623 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 1624 | static ssize_t hotkey_mask_show(struct device *dev, |
| 1625 | struct device_attribute *attr, |
| 1626 | char *buf) |
| 1627 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1628 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1629 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1630 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1631 | return -ERESTARTSYS; |
| 1632 | res = hotkey_mask_get(); |
| 1633 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1634 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1635 | return (res)? |
| 1636 | res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | static ssize_t hotkey_mask_store(struct device *dev, |
| 1640 | struct device_attribute *attr, |
| 1641 | const char *buf, size_t count) |
| 1642 | { |
| 1643 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1644 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1645 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1646 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1647 | return -EINVAL; |
| 1648 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1649 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1650 | return -ERESTARTSYS; |
| 1651 | |
| 1652 | res = hotkey_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1653 | |
| 1654 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1655 | hotkey_poll_setup(1); |
| 1656 | #endif |
| 1657 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1658 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1659 | |
| 1660 | return (res) ? res : count; |
| 1661 | } |
| 1662 | |
| 1663 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1664 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1665 | hotkey_mask_show, hotkey_mask_store); |
| 1666 | |
| 1667 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 1668 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 1669 | struct device_attribute *attr, |
| 1670 | char *buf) |
| 1671 | { |
| 1672 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status); |
| 1673 | } |
| 1674 | |
| 1675 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1676 | __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] | 1677 | |
| 1678 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 1679 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 1680 | struct device_attribute *attr, |
| 1681 | char *buf) |
| 1682 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1683 | 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] | 1684 | } |
| 1685 | |
| 1686 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1687 | __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] | 1688 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1689 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 1690 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 1691 | struct device_attribute *attr, |
| 1692 | char *buf) |
| 1693 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1694 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 1695 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 1699 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 1700 | |
| 1701 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 1702 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 1703 | struct device_attribute *attr, |
| 1704 | char *buf) |
| 1705 | { |
| 1706 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1707 | (hotkey_all_mask | hotkey_source_mask) |
| 1708 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 1712 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 1713 | hotkey_recommended_mask_show, NULL); |
| 1714 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1715 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1716 | |
| 1717 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 1718 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 1719 | struct device_attribute *attr, |
| 1720 | char *buf) |
| 1721 | { |
| 1722 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 1723 | } |
| 1724 | |
| 1725 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 1726 | struct device_attribute *attr, |
| 1727 | const char *buf, size_t count) |
| 1728 | { |
| 1729 | unsigned long t; |
| 1730 | |
| 1731 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 1732 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 1733 | return -EINVAL; |
| 1734 | |
| 1735 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1736 | return -ERESTARTSYS; |
| 1737 | |
| 1738 | HOTKEY_CONFIG_CRITICAL_START |
| 1739 | hotkey_source_mask = t; |
| 1740 | HOTKEY_CONFIG_CRITICAL_END |
| 1741 | |
| 1742 | hotkey_poll_setup(1); |
| 1743 | |
| 1744 | mutex_unlock(&hotkey_mutex); |
| 1745 | |
| 1746 | return count; |
| 1747 | } |
| 1748 | |
| 1749 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 1750 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 1751 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 1752 | |
| 1753 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 1754 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 1755 | struct device_attribute *attr, |
| 1756 | char *buf) |
| 1757 | { |
| 1758 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 1759 | } |
| 1760 | |
| 1761 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 1762 | struct device_attribute *attr, |
| 1763 | const char *buf, size_t count) |
| 1764 | { |
| 1765 | unsigned long t; |
| 1766 | |
| 1767 | if (parse_strtoul(buf, 25, &t)) |
| 1768 | return -EINVAL; |
| 1769 | |
| 1770 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1771 | return -ERESTARTSYS; |
| 1772 | |
| 1773 | hotkey_poll_freq = t; |
| 1774 | |
| 1775 | hotkey_poll_setup(1); |
| 1776 | mutex_unlock(&hotkey_mutex); |
| 1777 | |
| 1778 | return count; |
| 1779 | } |
| 1780 | |
| 1781 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 1782 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 1783 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 1784 | |
| 1785 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1786 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1787 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1788 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 1789 | struct device_attribute *attr, |
| 1790 | char *buf) |
| 1791 | { |
| 1792 | int res, s; |
| 1793 | res = hotkey_get_wlsw(&s); |
| 1794 | if (res < 0) |
| 1795 | return res; |
| 1796 | |
| 1797 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 1798 | } |
| 1799 | |
| 1800 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 1801 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 1802 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1803 | static void hotkey_radio_sw_notify_change(void) |
| 1804 | { |
| 1805 | if (tp_features.hotkey_wlsw) |
| 1806 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1807 | "hotkey_radio_sw"); |
| 1808 | } |
| 1809 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1810 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 1811 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 1812 | struct device_attribute *attr, |
| 1813 | char *buf) |
| 1814 | { |
| 1815 | int res, s; |
| 1816 | res = hotkey_get_tablet_mode(&s); |
| 1817 | if (res < 0) |
| 1818 | return res; |
| 1819 | |
| 1820 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 1821 | } |
| 1822 | |
| 1823 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 1824 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 1825 | |
| 1826 | static void hotkey_tablet_mode_notify_change(void) |
| 1827 | { |
| 1828 | if (tp_features.hotkey_tablet) |
| 1829 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1830 | "hotkey_tablet_mode"); |
| 1831 | } |
| 1832 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1833 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 1834 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 1835 | struct device_attribute *attr, |
| 1836 | char *buf) |
| 1837 | { |
| 1838 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1839 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 1840 | } |
| 1841 | |
| 1842 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 1843 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 1844 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1845 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1846 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 1847 | struct device_attribute *attr, |
| 1848 | char *buf) |
| 1849 | { |
| 1850 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 1851 | } |
| 1852 | |
| 1853 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 1854 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 1855 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 1856 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1857 | { |
| 1858 | if (tp_features.hotkey_mask) |
| 1859 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1860 | "wakeup_reason"); |
| 1861 | } |
| 1862 | |
| 1863 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1864 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 1865 | struct device_attribute *attr, |
| 1866 | char *buf) |
| 1867 | { |
| 1868 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 1869 | } |
| 1870 | |
| 1871 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 1872 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 1873 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 1874 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 1875 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1876 | { |
| 1877 | if (tp_features.hotkey_mask) |
| 1878 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1879 | "wakeup_hotunplug_complete"); |
| 1880 | } |
| 1881 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1882 | /* --------------------------------------------------------------------- */ |
| 1883 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1884 | static struct attribute *hotkey_attributes[] __initdata = { |
| 1885 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1886 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1887 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1888 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1889 | &dev_attr_hotkey_mask.attr, |
| 1890 | &dev_attr_hotkey_all_mask.attr, |
| 1891 | &dev_attr_hotkey_recommended_mask.attr, |
| 1892 | &dev_attr_hotkey_source_mask.attr, |
| 1893 | &dev_attr_hotkey_poll_freq.attr, |
| 1894 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1895 | }; |
| 1896 | |
| 1897 | static struct attribute *hotkey_mask_attributes[] __initdata = { |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1898 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1899 | #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1900 | &dev_attr_hotkey_mask.attr, |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1901 | &dev_attr_hotkey_all_mask.attr, |
| 1902 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1903 | #endif |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1904 | &dev_attr_hotkey_wakeup_reason.attr, |
| 1905 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1906 | }; |
| 1907 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1908 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1909 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1910 | /* Requirements for changing the default keymaps: |
| 1911 | * |
| 1912 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 1913 | * good reasons. Do not change them unless you have deep |
| 1914 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 1915 | * the various ThinkPad models. The driver behaves |
| 1916 | * differently for KEY_RESERVED: such keys have their |
| 1917 | * hot key mask *unset* in mask_recommended, and also |
| 1918 | * in the initial hot key mask programmed into the |
| 1919 | * firmware at driver load time, which means the firm- |
| 1920 | * ware may react very differently if you change them to |
| 1921 | * something else; |
| 1922 | * |
| 1923 | * 2. You must be subscribed to the linux-thinkpad and |
| 1924 | * ibm-acpi-devel mailing lists, and you should read the |
| 1925 | * list archives since 2007 if you want to change the |
| 1926 | * keymaps. This requirement exists so that you will |
| 1927 | * know the past history of problems with the thinkpad- |
| 1928 | * acpi driver keymaps, and also that you will be |
| 1929 | * listening to any bug reports; |
| 1930 | * |
| 1931 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 1932 | * for merging, *ever*. Send them to the linux-acpi |
| 1933 | * mailinglist for comments. Merging is to be done only |
| 1934 | * through acpi-test and the ACPI maintainer. |
| 1935 | * |
| 1936 | * If the above is too much to ask, don't change the keymap. |
| 1937 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 1938 | */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1939 | static u16 ibm_keycode_map[] __initdata = { |
| 1940 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 1941 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
| 1942 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 1943 | 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] | 1944 | |
| 1945 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1946 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 1947 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 1948 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1949 | |
| 1950 | /* brightness: firmware always reacts to them, unless |
| 1951 | * X.org did some tricks in the radeon BIOS scratch |
| 1952 | * registers of *some* models */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1953 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1954 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1955 | |
| 1956 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1957 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1958 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1959 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 1960 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1961 | |
| 1962 | /* Volume: firmware always react to it and reprograms |
| 1963 | * the built-in *extra* mixer. Never map it to control |
| 1964 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1965 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 1966 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 1967 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1968 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1969 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
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 | /* (assignments unknown, please report if found) */ |
| 1972 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 1973 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 1974 | }; |
| 1975 | static u16 lenovo_keycode_map[] __initdata = { |
| 1976 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 1977 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
| 1978 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 1979 | 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] | 1980 | |
| 1981 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1982 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 1983 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 1984 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1985 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 1986 | /* These either have to go through ACPI video, or |
| 1987 | * act like in the IBM ThinkPads, so don't ever |
| 1988 | * enable them by default */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 1989 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 1990 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1991 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1992 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
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_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 1995 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1996 | |
| 1997 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 1998 | * react to it and reprograms the built-in *extra* mixer. |
| 1999 | * Never map it to control another mixer by default. |
| 2000 | * |
| 2001 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 2002 | * these over the regular keyboard, so these are no-ops, |
| 2003 | * but there are still weird bugs re. MUTE, so do not |
| 2004 | * change unless you get test reports from all Lenovo |
| 2005 | * models. May cause the BIOS to interfere with the |
| 2006 | * HDA mixer. |
| 2007 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2008 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2009 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2010 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2011 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2012 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
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 | /* (assignments unknown, please report if found) */ |
| 2015 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2016 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2017 | }; |
| 2018 | |
| 2019 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) |
| 2020 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) |
| 2021 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) |
| 2022 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2023 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2024 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2025 | int hkeyv; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2026 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2027 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); |
| 2028 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2029 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2030 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 2031 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2032 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2033 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2034 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2035 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2036 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2037 | mutex_init(&hotkey_thread_mutex); |
| 2038 | mutex_init(&hotkey_thread_data_mutex); |
| 2039 | #endif |
| 2040 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2041 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2042 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2043 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2044 | vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2045 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2046 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2047 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2048 | hotkey_dev_attributes = create_attr_set(13, NULL); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2049 | if (!hotkey_dev_attributes) |
| 2050 | return -ENOMEM; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2051 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 2052 | hotkey_attributes, |
| 2053 | ARRAY_SIZE(hotkey_attributes)); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2054 | if (res) |
| 2055 | return res; |
| 2056 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2057 | /* 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] | 2058 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 2059 | for HKEY interface version 0x100 */ |
| 2060 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 2061 | if ((hkeyv >> 8) != 1) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2062 | printk(TPACPI_ERR "unknown version of the " |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2063 | "HKEY interface: 0x%x\n", hkeyv); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2064 | printk(TPACPI_ERR "please report this to %s\n", |
| 2065 | TPACPI_MAIL); |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2066 | } else { |
| 2067 | /* |
| 2068 | * MHKV 0x100 in A31, R40, R40e, |
| 2069 | * T4x, X31, and later |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2070 | */ |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2071 | tp_features.hotkey_mask = 1; |
| 2072 | } |
| 2073 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2074 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2075 | vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2076 | str_supported(tp_features.hotkey_mask)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2077 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2078 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2079 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2080 | "MHKA", "qd")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2081 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2082 | "missing MHKA handler, " |
| 2083 | "please report this to %s\n", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2084 | TPACPI_MAIL); |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2085 | /* FN+F12, FN+F4, FN+F3 */ |
| 2086 | hotkey_all_mask = 0x080cU; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2087 | } |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2088 | } |
| 2089 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2090 | /* hotkey_source_mask *must* be zero for |
| 2091 | * the first hotkey_mask_get */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2092 | res = hotkey_status_get(&hotkey_orig_status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2093 | if (!res && tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2094 | res = hotkey_mask_get(); |
| 2095 | hotkey_orig_mask = hotkey_mask; |
| 2096 | if (!res) { |
| 2097 | res = add_many_to_attr_set( |
| 2098 | hotkey_dev_attributes, |
| 2099 | hotkey_mask_attributes, |
| 2100 | ARRAY_SIZE(hotkey_mask_attributes)); |
| 2101 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2102 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2103 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2104 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2105 | if (tp_features.hotkey_mask) { |
| 2106 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 2107 | & ~hotkey_all_mask; |
| 2108 | } else { |
| 2109 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK; |
| 2110 | } |
| 2111 | |
| 2112 | vdbg_printk(TPACPI_DBG_INIT, |
| 2113 | "hotkey source mask 0x%08x, polling freq %d\n", |
| 2114 | hotkey_source_mask, hotkey_poll_freq); |
| 2115 | #endif |
| 2116 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2117 | /* Not all thinkpads have a hardware radio switch */ |
| 2118 | if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 2119 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2120 | printk(TPACPI_INFO |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2121 | "radio switch found; radios are %s\n", |
| 2122 | enabled(status, 0)); |
| 2123 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2124 | &dev_attr_hotkey_radio_sw.attr); |
| 2125 | } |
| 2126 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2127 | /* For X41t, X60t, X61t Tablets... */ |
| 2128 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 2129 | tp_features.hotkey_tablet = 1; |
| 2130 | printk(TPACPI_INFO |
| 2131 | "possible tablet mode switch found; " |
| 2132 | "ThinkPad in %s mode\n", |
| 2133 | (status & TP_HOTKEY_TABLET_MASK)? |
| 2134 | "tablet" : "laptop"); |
| 2135 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2136 | &dev_attr_hotkey_tablet_mode.attr); |
| 2137 | } |
| 2138 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2139 | if (!res) |
| 2140 | res = register_attr_set_with_sysfs( |
| 2141 | hotkey_dev_attributes, |
| 2142 | &tpacpi_pdev->dev.kobj); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2143 | if (res) |
| 2144 | return res; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2145 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2146 | /* Set up key map */ |
| 2147 | |
| 2148 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 2149 | GFP_KERNEL); |
| 2150 | if (!hotkey_keycode_map) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2151 | printk(TPACPI_ERR |
| 2152 | "failed to allocate memory for key map\n"); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2153 | return -ENOMEM; |
| 2154 | } |
| 2155 | |
| 2156 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
| 2157 | dbg_printk(TPACPI_DBG_INIT, |
| 2158 | "using Lenovo default hot key map\n"); |
| 2159 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, |
| 2160 | TPACPI_HOTKEY_MAP_SIZE); |
| 2161 | } else { |
| 2162 | dbg_printk(TPACPI_DBG_INIT, |
| 2163 | "using IBM default hot key map\n"); |
| 2164 | memcpy(hotkey_keycode_map, &ibm_keycode_map, |
| 2165 | TPACPI_HOTKEY_MAP_SIZE); |
| 2166 | } |
| 2167 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2168 | set_bit(EV_KEY, tpacpi_inputdev->evbit); |
| 2169 | set_bit(EV_MSC, tpacpi_inputdev->evbit); |
| 2170 | set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2171 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 2172 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 2173 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 2174 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2175 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
| 2176 | set_bit(hotkey_keycode_map[i], |
| 2177 | tpacpi_inputdev->keybit); |
| 2178 | } else { |
| 2179 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 2180 | hotkey_reserved_mask |= 1 << i; |
| 2181 | } |
| 2182 | } |
| 2183 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2184 | if (tp_features.hotkey_wlsw) { |
| 2185 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2186 | set_bit(SW_RADIO, tpacpi_inputdev->swbit); |
| 2187 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2188 | if (tp_features.hotkey_tablet) { |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2189 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2190 | set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit); |
| 2191 | } |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2192 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 2193 | /* Do not issue duplicate brightness change events to |
| 2194 | * userspace */ |
| 2195 | if (!tp_features.bright_acpimode) |
| 2196 | /* update bright_acpimode... */ |
| 2197 | tpacpi_check_std_acpi_brightness_support(); |
| 2198 | |
| 2199 | if (tp_features.bright_acpimode) { |
| 2200 | printk(TPACPI_INFO |
| 2201 | "This ThinkPad has standard ACPI backlight " |
| 2202 | "brightness control, supported by the ACPI " |
| 2203 | "video driver\n"); |
| 2204 | printk(TPACPI_NOTICE |
| 2205 | "Disabling thinkpad-acpi brightness events " |
| 2206 | "by default...\n"); |
| 2207 | |
| 2208 | /* The hotkey_reserved_mask change below is not |
| 2209 | * necessary while the keys are at KEY_RESERVED in the |
| 2210 | * default map, but better safe than sorry, leave it |
| 2211 | * here as a marker of what we have to do, especially |
| 2212 | * when we finally become able to set this at runtime |
| 2213 | * on response to X.org requests */ |
| 2214 | hotkey_reserved_mask |= |
| 2215 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 2216 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
| 2217 | } |
| 2218 | |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2219 | dbg_printk(TPACPI_DBG_INIT, |
| 2220 | "enabling hot key handling\n"); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2221 | res = hotkey_status_set(1); |
| 2222 | if (res) |
| 2223 | return res; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2224 | res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask) |
| 2225 | & ~hotkey_reserved_mask) |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2226 | | hotkey_orig_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2227 | if (res < 0 && res != -ENXIO) |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2228 | return res; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2229 | |
| 2230 | dbg_printk(TPACPI_DBG_INIT, |
| 2231 | "legacy hot key reporting over procfs %s\n", |
| 2232 | (hotkey_report_mode < 2) ? |
| 2233 | "enabled" : "disabled"); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2234 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2235 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 2236 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 2237 | |
| 2238 | hotkey_poll_setup_safe(1); |
Henrique de Moraes Holschuh | 7526696 | 2008-02-16 02:17:53 -0200 | [diff] [blame] | 2239 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2240 | tpacpi_input_send_tabletsw(); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2241 | } |
| 2242 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2243 | return (tp_features.hotkey)? 0 : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | static void hotkey_exit(void) |
| 2247 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2248 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2249 | hotkey_poll_stop_sync(); |
| 2250 | #endif |
| 2251 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2252 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2253 | dbg_printk(TPACPI_DBG_EXIT, |
| 2254 | "restoring original hot key mask\n"); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2255 | /* no short-circuit boolean operator below! */ |
| 2256 | if ((hotkey_mask_set(hotkey_orig_mask) | |
| 2257 | hotkey_status_set(hotkey_orig_status)) != 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2258 | printk(TPACPI_ERR |
| 2259 | "failed to restore hot key mask " |
| 2260 | "to BIOS defaults\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2261 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2262 | |
| 2263 | if (hotkey_dev_attributes) { |
| 2264 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 2265 | hotkey_dev_attributes = NULL; |
| 2266 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 2270 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2271 | u32 hkey; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2272 | unsigned int scancode; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2273 | int send_acpi_ev; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2274 | int ignore_acpi_ev; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2275 | int unk_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2276 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2277 | if (event != 0x80) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2278 | printk(TPACPI_ERR |
| 2279 | "unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2280 | /* 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] | 2281 | acpi_bus_generate_netlink_event( |
| 2282 | ibm->acpi->device->pnp.device_class, |
| 2283 | ibm->acpi->device->dev.bus_id, |
| 2284 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2285 | return; |
| 2286 | } |
| 2287 | |
| 2288 | while (1) { |
| 2289 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2290 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2291 | return; |
| 2292 | } |
| 2293 | |
| 2294 | if (hkey == 0) { |
| 2295 | /* queue empty */ |
| 2296 | return; |
| 2297 | } |
| 2298 | |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2299 | send_acpi_ev = 1; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2300 | ignore_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2301 | unk_ev = 0; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2302 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2303 | switch (hkey >> 12) { |
| 2304 | case 1: |
| 2305 | /* 0x1000-0x1FFF: key presses */ |
| 2306 | scancode = hkey & 0xfff; |
| 2307 | if (scancode > 0 && scancode < 0x21) { |
| 2308 | scancode--; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2309 | if (!(hotkey_source_mask & (1 << scancode))) { |
| 2310 | tpacpi_input_send_key(scancode); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2311 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2312 | } else { |
| 2313 | ignore_acpi_ev = 1; |
| 2314 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2315 | } else { |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2316 | unk_ev = 1; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2317 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2318 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2319 | case 2: |
| 2320 | /* Wakeup reason */ |
| 2321 | switch (hkey) { |
| 2322 | case 0x2304: /* suspend, undock */ |
| 2323 | case 0x2404: /* hibernation, undock */ |
| 2324 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 2325 | ignore_acpi_ev = 1; |
| 2326 | break; |
| 2327 | case 0x2305: /* suspend, bay eject */ |
| 2328 | case 0x2405: /* hibernation, bay eject */ |
| 2329 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 2330 | ignore_acpi_ev = 1; |
| 2331 | break; |
| 2332 | default: |
| 2333 | unk_ev = 1; |
| 2334 | } |
| 2335 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
| 2336 | printk(TPACPI_INFO |
| 2337 | "woke up due to a hot-unplug " |
| 2338 | "request...\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2339 | hotkey_wakeup_reason_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2340 | } |
| 2341 | break; |
| 2342 | case 3: |
| 2343 | /* bay-related wakeups */ |
| 2344 | if (hkey == 0x3003) { |
| 2345 | hotkey_autosleep_ack = 1; |
| 2346 | printk(TPACPI_INFO |
| 2347 | "bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2348 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2349 | } else { |
| 2350 | unk_ev = 1; |
| 2351 | } |
| 2352 | break; |
| 2353 | case 4: |
| 2354 | /* dock-related wakeups */ |
| 2355 | if (hkey == 0x4003) { |
| 2356 | hotkey_autosleep_ack = 1; |
| 2357 | printk(TPACPI_INFO |
| 2358 | "undocked\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2359 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2360 | } else { |
| 2361 | unk_ev = 1; |
| 2362 | } |
| 2363 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2364 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2365 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2366 | switch (hkey) { |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2367 | case 0x5010: /* Lenovo new BIOS: brightness changed */ |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2368 | case 0x500b: /* X61t: tablet pen inserted into bay */ |
| 2369 | case 0x500c: /* X61t: tablet pen removed from bay */ |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2370 | break; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2371 | case 0x5009: /* X41t-X61t: swivel up (tablet mode) */ |
| 2372 | case 0x500a: /* X41t-X61t: swivel down (normal mode) */ |
| 2373 | tpacpi_input_send_tabletsw(); |
| 2374 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2375 | send_acpi_ev = 0; |
| 2376 | break; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2377 | case 0x5001: |
| 2378 | case 0x5002: |
| 2379 | /* LID switch events. Do not propagate */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2380 | ignore_acpi_ev = 1; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2381 | break; |
| 2382 | default: |
| 2383 | unk_ev = 1; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2384 | } |
| 2385 | break; |
| 2386 | case 7: |
| 2387 | /* 0x7000-0x7FFF: misc */ |
| 2388 | if (tp_features.hotkey_wlsw && hkey == 0x7000) { |
| 2389 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2390 | hotkey_radio_sw_notify_change(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2391 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2392 | break; |
| 2393 | } |
| 2394 | /* fallthrough to default */ |
| 2395 | default: |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2396 | unk_ev = 1; |
| 2397 | } |
| 2398 | if (unk_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2399 | printk(TPACPI_NOTICE |
| 2400 | "unhandled HKEY event 0x%04x\n", hkey); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2401 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2402 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2403 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2404 | if (!ignore_acpi_ev && |
| 2405 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 2406 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 2407 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2408 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2409 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2410 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2411 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2412 | acpi_bus_generate_netlink_event( |
| 2413 | ibm->acpi->device->pnp.device_class, |
| 2414 | ibm->acpi->device->dev.bus_id, |
| 2415 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2416 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2417 | } |
| 2418 | } |
| 2419 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2420 | static void hotkey_suspend(pm_message_t state) |
| 2421 | { |
| 2422 | /* Do these on suspend, we get the events on early resume! */ |
| 2423 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 2424 | hotkey_autosleep_ack = 0; |
| 2425 | } |
| 2426 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2427 | static void hotkey_resume(void) |
| 2428 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2429 | if (hotkey_mask_get()) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2430 | printk(TPACPI_ERR |
| 2431 | "error while trying to read hot key mask " |
| 2432 | "from firmware\n"); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2433 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2434 | hotkey_radio_sw_notify_change(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2435 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2436 | hotkey_wakeup_reason_notify_change(); |
| 2437 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2438 | hotkey_poll_setup_safe(0); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2439 | } |
| 2440 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2441 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2442 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2444 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | int len = 0; |
| 2446 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2447 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2448 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 2449 | return len; |
| 2450 | } |
| 2451 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 2452 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2453 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2454 | res = hotkey_status_get(&status); |
| 2455 | if (!res) |
| 2456 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2457 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2458 | if (res) |
| 2459 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | |
| 2461 | 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] | 2462 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2463 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | len += sprintf(p + len, |
| 2465 | "commands:\tenable, disable, reset, <mask>\n"); |
| 2466 | } else { |
| 2467 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 2468 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 2469 | } |
| 2470 | |
| 2471 | return len; |
| 2472 | } |
| 2473 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2474 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2476 | int res, status; |
| 2477 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2480 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | return -ENODEV; |
| 2482 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 2483 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2484 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2485 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2486 | status = -1; |
| 2487 | mask = hotkey_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2488 | |
| 2489 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | while ((cmd = next_cmd(&buf))) { |
| 2491 | if (strlencmp(cmd, "enable") == 0) { |
| 2492 | status = 1; |
| 2493 | } else if (strlencmp(cmd, "disable") == 0) { |
| 2494 | status = 0; |
| 2495 | } else if (strlencmp(cmd, "reset") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2496 | status = hotkey_orig_status; |
| 2497 | mask = hotkey_orig_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 2499 | /* mask set */ |
| 2500 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 2501 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2502 | } else { |
| 2503 | res = -EINVAL; |
| 2504 | goto errexit; |
| 2505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2507 | if (status != -1) |
| 2508 | res = hotkey_status_set(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2510 | if (!res && mask != hotkey_mask) |
| 2511 | res = hotkey_mask_set(mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2513 | errexit: |
| 2514 | mutex_unlock(&hotkey_mutex); |
| 2515 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2518 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2519 | {TPACPI_ACPI_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2520 | {"", 0}, |
| 2521 | }; |
| 2522 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2523 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2524 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2525 | .notify = hotkey_notify, |
| 2526 | .handle = &hkey_handle, |
| 2527 | .type = ACPI_DEVICE_NOTIFY, |
| 2528 | }; |
| 2529 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2530 | static struct ibm_struct hotkey_driver_data = { |
| 2531 | .name = "hotkey", |
| 2532 | .read = hotkey_read, |
| 2533 | .write = hotkey_write, |
| 2534 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2535 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2536 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2537 | .acpi = &ibm_hotkey_acpidriver, |
| 2538 | }; |
| 2539 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2540 | /************************************************************************* |
| 2541 | * Bluetooth subdriver |
| 2542 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2544 | enum { |
| 2545 | /* ACPI GBDC/SBDC bits */ |
| 2546 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 2547 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
| 2548 | TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */ |
| 2549 | }; |
| 2550 | |
| 2551 | static int bluetooth_get_radiosw(void); |
| 2552 | static int bluetooth_set_radiosw(int radio_on); |
| 2553 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2554 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 2555 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 2556 | struct device_attribute *attr, |
| 2557 | char *buf) |
| 2558 | { |
| 2559 | int status; |
| 2560 | |
| 2561 | status = bluetooth_get_radiosw(); |
| 2562 | if (status < 0) |
| 2563 | return status; |
| 2564 | |
| 2565 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); |
| 2566 | } |
| 2567 | |
| 2568 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 2569 | struct device_attribute *attr, |
| 2570 | const char *buf, size_t count) |
| 2571 | { |
| 2572 | unsigned long t; |
| 2573 | int res; |
| 2574 | |
| 2575 | if (parse_strtoul(buf, 1, &t)) |
| 2576 | return -EINVAL; |
| 2577 | |
| 2578 | res = bluetooth_set_radiosw(t); |
| 2579 | |
| 2580 | return (res) ? res : count; |
| 2581 | } |
| 2582 | |
| 2583 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2584 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2585 | bluetooth_enable_show, bluetooth_enable_store); |
| 2586 | |
| 2587 | /* --------------------------------------------------------------------- */ |
| 2588 | |
| 2589 | static struct attribute *bluetooth_attributes[] = { |
| 2590 | &dev_attr_bluetooth_enable.attr, |
| 2591 | NULL |
| 2592 | }; |
| 2593 | |
| 2594 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2595 | .attrs = bluetooth_attributes, |
| 2596 | }; |
| 2597 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2598 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2600 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2601 | int status = 0; |
| 2602 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2603 | vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n"); |
| 2604 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2605 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2606 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2607 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 2608 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2609 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2610 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2612 | vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n", |
| 2613 | str_supported(tp_features.bluetooth), |
| 2614 | status); |
| 2615 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2616 | if (tp_features.bluetooth) { |
| 2617 | if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 2618 | /* no bluetooth hardware present in system */ |
| 2619 | tp_features.bluetooth = 0; |
| 2620 | dbg_printk(TPACPI_DBG_INIT, |
| 2621 | "bluetooth hardware not installed\n"); |
| 2622 | } else { |
| 2623 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2624 | &bluetooth_attr_group); |
| 2625 | if (res) |
| 2626 | return res; |
| 2627 | } |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2628 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2629 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2630 | return (tp_features.bluetooth)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | } |
| 2632 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2633 | static void bluetooth_exit(void) |
| 2634 | { |
| 2635 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2636 | &bluetooth_attr_group); |
| 2637 | } |
| 2638 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2639 | static int bluetooth_get_radiosw(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | { |
| 2641 | int status; |
| 2642 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2643 | if (!tp_features.bluetooth) |
| 2644 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2646 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 2647 | return -EIO; |
| 2648 | |
| 2649 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0); |
| 2650 | } |
| 2651 | |
| 2652 | static int bluetooth_set_radiosw(int radio_on) |
| 2653 | { |
| 2654 | int status; |
| 2655 | |
| 2656 | if (!tp_features.bluetooth) |
| 2657 | return -ENODEV; |
| 2658 | |
| 2659 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 2660 | return -EIO; |
| 2661 | if (radio_on) |
| 2662 | status |= TP_ACPI_BLUETOOTH_RADIOSSW; |
| 2663 | else |
| 2664 | status &= ~TP_ACPI_BLUETOOTH_RADIOSSW; |
| 2665 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 2666 | return -EIO; |
| 2667 | |
| 2668 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2671 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2672 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | { |
| 2674 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2675 | int status = bluetooth_get_radiosw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2677 | if (!tp_features.bluetooth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2680 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2681 | (status)? "enabled" : "disabled"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 2683 | } |
| 2684 | |
| 2685 | return len; |
| 2686 | } |
| 2687 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2688 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2692 | if (!tp_features.bluetooth) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2693 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | |
| 2695 | while ((cmd = next_cmd(&buf))) { |
| 2696 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2697 | bluetooth_set_radiosw(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2699 | bluetooth_set_radiosw(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | } else |
| 2701 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | return 0; |
| 2705 | } |
| 2706 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2707 | static struct ibm_struct bluetooth_driver_data = { |
| 2708 | .name = "bluetooth", |
| 2709 | .read = bluetooth_read, |
| 2710 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2711 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2712 | }; |
| 2713 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2714 | /************************************************************************* |
| 2715 | * Wan subdriver |
| 2716 | */ |
| 2717 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2718 | enum { |
| 2719 | /* ACPI GWAN/SWAN bits */ |
| 2720 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 2721 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
| 2722 | TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */ |
| 2723 | }; |
| 2724 | |
| 2725 | static int wan_get_radiosw(void); |
| 2726 | static int wan_set_radiosw(int radio_on); |
| 2727 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2728 | /* sysfs wan enable ---------------------------------------------------- */ |
| 2729 | static ssize_t wan_enable_show(struct device *dev, |
| 2730 | struct device_attribute *attr, |
| 2731 | char *buf) |
| 2732 | { |
| 2733 | int status; |
| 2734 | |
| 2735 | status = wan_get_radiosw(); |
| 2736 | if (status < 0) |
| 2737 | return status; |
| 2738 | |
| 2739 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); |
| 2740 | } |
| 2741 | |
| 2742 | static ssize_t wan_enable_store(struct device *dev, |
| 2743 | struct device_attribute *attr, |
| 2744 | const char *buf, size_t count) |
| 2745 | { |
| 2746 | unsigned long t; |
| 2747 | int res; |
| 2748 | |
| 2749 | if (parse_strtoul(buf, 1, &t)) |
| 2750 | return -EINVAL; |
| 2751 | |
| 2752 | res = wan_set_radiosw(t); |
| 2753 | |
| 2754 | return (res) ? res : count; |
| 2755 | } |
| 2756 | |
| 2757 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2758 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2759 | wan_enable_show, wan_enable_store); |
| 2760 | |
| 2761 | /* --------------------------------------------------------------------- */ |
| 2762 | |
| 2763 | static struct attribute *wan_attributes[] = { |
| 2764 | &dev_attr_wan_enable.attr, |
| 2765 | NULL |
| 2766 | }; |
| 2767 | |
| 2768 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2769 | .attrs = wan_attributes, |
| 2770 | }; |
| 2771 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2772 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2773 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2774 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2775 | int status = 0; |
| 2776 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2777 | vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n"); |
| 2778 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2779 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2780 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2781 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2782 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2783 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2784 | vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n", |
| 2785 | str_supported(tp_features.wan), |
| 2786 | status); |
| 2787 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2788 | if (tp_features.wan) { |
| 2789 | if (!(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 2790 | /* no wan hardware present in system */ |
| 2791 | tp_features.wan = 0; |
| 2792 | dbg_printk(TPACPI_DBG_INIT, |
| 2793 | "wan hardware not installed\n"); |
| 2794 | } else { |
| 2795 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2796 | &wan_attr_group); |
| 2797 | if (res) |
| 2798 | return res; |
| 2799 | } |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2800 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2801 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2802 | return (tp_features.wan)? 0 : 1; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2803 | } |
| 2804 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2805 | static void wan_exit(void) |
| 2806 | { |
| 2807 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2808 | &wan_attr_group); |
| 2809 | } |
| 2810 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2811 | static int wan_get_radiosw(void) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2812 | { |
| 2813 | int status; |
| 2814 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2815 | if (!tp_features.wan) |
| 2816 | return -ENODEV; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2817 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2818 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 2819 | return -EIO; |
| 2820 | |
| 2821 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0); |
| 2822 | } |
| 2823 | |
| 2824 | static int wan_set_radiosw(int radio_on) |
| 2825 | { |
| 2826 | int status; |
| 2827 | |
| 2828 | if (!tp_features.wan) |
| 2829 | return -ENODEV; |
| 2830 | |
| 2831 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 2832 | return -EIO; |
| 2833 | if (radio_on) |
| 2834 | status |= TP_ACPI_WANCARD_RADIOSSW; |
| 2835 | else |
| 2836 | status &= ~TP_ACPI_WANCARD_RADIOSSW; |
| 2837 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 2838 | return -EIO; |
| 2839 | |
| 2840 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2841 | } |
| 2842 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2843 | /* procfs -------------------------------------------------------------- */ |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2844 | static int wan_read(char *p) |
| 2845 | { |
| 2846 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2847 | int status = wan_get_radiosw(); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2848 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2849 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2850 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2851 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2852 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2853 | (status)? "enabled" : "disabled"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2854 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 2855 | } |
| 2856 | |
| 2857 | return len; |
| 2858 | } |
| 2859 | |
| 2860 | static int wan_write(char *buf) |
| 2861 | { |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2862 | char *cmd; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2863 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2864 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2865 | return -ENODEV; |
| 2866 | |
| 2867 | while ((cmd = next_cmd(&buf))) { |
| 2868 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2869 | wan_set_radiosw(1); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2870 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2871 | wan_set_radiosw(0); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2872 | } else |
| 2873 | return -EINVAL; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2874 | } |
| 2875 | |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2876 | return 0; |
| 2877 | } |
| 2878 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2879 | static struct ibm_struct wan_driver_data = { |
| 2880 | .name = "wan", |
| 2881 | .read = wan_read, |
| 2882 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2883 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 2884 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2885 | }; |
| 2886 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2887 | /************************************************************************* |
| 2888 | * Video subdriver |
| 2889 | */ |
| 2890 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 2891 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 2892 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2893 | enum video_access_mode { |
| 2894 | TPACPI_VIDEO_NONE = 0, |
| 2895 | TPACPI_VIDEO_570, /* 570 */ |
| 2896 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 2897 | TPACPI_VIDEO_NEW, /* all others */ |
| 2898 | }; |
| 2899 | |
| 2900 | enum { /* video status flags, based on VIDEO_570 */ |
| 2901 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 2902 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 2903 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 2904 | }; |
| 2905 | |
| 2906 | enum { /* TPACPI_VIDEO_570 constants */ |
| 2907 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 2908 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 2909 | * video_status_flags */ |
| 2910 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 2911 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 2912 | }; |
| 2913 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 2914 | static enum video_access_mode video_supported; |
| 2915 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2916 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2917 | static int video_autosw_get(void); |
| 2918 | static int video_autosw_set(int enable); |
| 2919 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2920 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2921 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2922 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2924 | int ivga; |
| 2925 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2926 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 2927 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2928 | TPACPI_ACPIHANDLE_INIT(vid); |
| 2929 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2930 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2931 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 2932 | /* G41, assume IVGA doesn't change */ |
| 2933 | vid_handle = vid2_handle; |
| 2934 | |
| 2935 | if (!vid_handle) |
| 2936 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2937 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2938 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 2939 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2940 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2941 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 2942 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2943 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2944 | else |
| 2945 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2946 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2948 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 2949 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 2950 | video_supported); |
| 2951 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2952 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | } |
| 2954 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2955 | static void video_exit(void) |
| 2956 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2957 | dbg_printk(TPACPI_DBG_EXIT, |
| 2958 | "restoring original video autoswitch mode\n"); |
| 2959 | if (video_autosw_set(video_orig_autosw)) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2960 | printk(TPACPI_ERR "error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2961 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2962 | } |
| 2963 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2964 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | { |
| 2966 | int status = 0; |
| 2967 | int i; |
| 2968 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2969 | switch (video_supported) { |
| 2970 | case TPACPI_VIDEO_570: |
| 2971 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 2972 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 2973 | return -EIO; |
| 2974 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 2975 | break; |
| 2976 | case TPACPI_VIDEO_770: |
| 2977 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 2978 | return -EIO; |
| 2979 | if (i) |
| 2980 | status |= TP_ACPI_VIDEO_S_LCD; |
| 2981 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 2982 | return -EIO; |
| 2983 | if (i) |
| 2984 | status |= TP_ACPI_VIDEO_S_CRT; |
| 2985 | break; |
| 2986 | case TPACPI_VIDEO_NEW: |
| 2987 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 2988 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 2989 | return -EIO; |
| 2990 | if (i) |
| 2991 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2993 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 2994 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 2995 | return -EIO; |
| 2996 | if (i) |
| 2997 | status |= TP_ACPI_VIDEO_S_LCD; |
| 2998 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 2999 | return -EIO; |
| 3000 | if (i) |
| 3001 | status |= TP_ACPI_VIDEO_S_DVI; |
| 3002 | break; |
| 3003 | default: |
| 3004 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3005 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | |
| 3007 | return status; |
| 3008 | } |
| 3009 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3010 | static int video_outputsw_set(int status) |
| 3011 | { |
| 3012 | int autosw; |
| 3013 | int res = 0; |
| 3014 | |
| 3015 | switch (video_supported) { |
| 3016 | case TPACPI_VIDEO_570: |
| 3017 | res = acpi_evalf(NULL, NULL, |
| 3018 | "\\_SB.PHS2", "vdd", |
| 3019 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 3020 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 3021 | break; |
| 3022 | case TPACPI_VIDEO_770: |
| 3023 | autosw = video_autosw_get(); |
| 3024 | if (autosw < 0) |
| 3025 | return autosw; |
| 3026 | |
| 3027 | res = video_autosw_set(1); |
| 3028 | if (res) |
| 3029 | return res; |
| 3030 | res = acpi_evalf(vid_handle, NULL, |
| 3031 | "ASWT", "vdd", status * 0x100, 0); |
| 3032 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3033 | printk(TPACPI_ERR |
| 3034 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3035 | return -EIO; |
| 3036 | } |
| 3037 | break; |
| 3038 | case TPACPI_VIDEO_NEW: |
| 3039 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3040 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3041 | break; |
| 3042 | default: |
| 3043 | return -ENOSYS; |
| 3044 | } |
| 3045 | |
| 3046 | return (res)? 0 : -EIO; |
| 3047 | } |
| 3048 | |
| 3049 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3051 | int autosw = 0; |
| 3052 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3053 | switch (video_supported) { |
| 3054 | case TPACPI_VIDEO_570: |
| 3055 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 3056 | return -EIO; |
| 3057 | break; |
| 3058 | case TPACPI_VIDEO_770: |
| 3059 | case TPACPI_VIDEO_NEW: |
| 3060 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 3061 | return -EIO; |
| 3062 | break; |
| 3063 | default: |
| 3064 | return -ENOSYS; |
| 3065 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3066 | |
| 3067 | return autosw & 1; |
| 3068 | } |
| 3069 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3070 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3071 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3072 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3073 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3074 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3075 | } |
| 3076 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3077 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3078 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3079 | int autosw = video_autosw_get(); |
| 3080 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3081 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3082 | if (autosw < 0) |
| 3083 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3084 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3085 | switch (video_supported) { |
| 3086 | case TPACPI_VIDEO_570: |
| 3087 | res = video_autosw_set(1); |
| 3088 | if (res) |
| 3089 | return res; |
| 3090 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 3091 | break; |
| 3092 | case TPACPI_VIDEO_770: |
| 3093 | case TPACPI_VIDEO_NEW: |
| 3094 | res = video_autosw_set(1); |
| 3095 | if (res) |
| 3096 | return res; |
| 3097 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 3098 | break; |
| 3099 | default: |
| 3100 | return -ENOSYS; |
| 3101 | } |
| 3102 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3103 | printk(TPACPI_ERR |
| 3104 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3105 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3106 | } |
| 3107 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3108 | return (res)? 0 : -EIO; |
| 3109 | } |
| 3110 | |
| 3111 | static int video_expand_toggle(void) |
| 3112 | { |
| 3113 | switch (video_supported) { |
| 3114 | case TPACPI_VIDEO_570: |
| 3115 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 3116 | 0 : -EIO; |
| 3117 | case TPACPI_VIDEO_770: |
| 3118 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 3119 | 0 : -EIO; |
| 3120 | case TPACPI_VIDEO_NEW: |
| 3121 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 3122 | 0 : -EIO; |
| 3123 | default: |
| 3124 | return -ENOSYS; |
| 3125 | } |
| 3126 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3127 | } |
| 3128 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3129 | static int video_read(char *p) |
| 3130 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3131 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3132 | int len = 0; |
| 3133 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3134 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3135 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3136 | return len; |
| 3137 | } |
| 3138 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3139 | status = video_outputsw_get(); |
| 3140 | if (status < 0) |
| 3141 | return status; |
| 3142 | |
| 3143 | autosw = video_autosw_get(); |
| 3144 | if (autosw < 0) |
| 3145 | return autosw; |
| 3146 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3147 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3148 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 3149 | 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] | 3150 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3151 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 3152 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 3153 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 3154 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3155 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3156 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 3157 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 3158 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 3159 | |
| 3160 | return len; |
| 3161 | } |
| 3162 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3163 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | { |
| 3165 | char *cmd; |
| 3166 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3167 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3169 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3170 | return -ENODEV; |
| 3171 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3172 | enable = 0; |
| 3173 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | |
| 3175 | while ((cmd = next_cmd(&buf))) { |
| 3176 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3177 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3179 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3181 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3183 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3184 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3185 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3186 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3187 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3188 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3189 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3191 | res = video_autosw_set(1); |
| 3192 | if (res) |
| 3193 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3195 | res = video_autosw_set(0); |
| 3196 | if (res) |
| 3197 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3199 | res = video_outputsw_cycle(); |
| 3200 | if (res) |
| 3201 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3203 | res = video_expand_toggle(); |
| 3204 | if (res) |
| 3205 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | } else |
| 3207 | return -EINVAL; |
| 3208 | } |
| 3209 | |
| 3210 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3211 | status = video_outputsw_get(); |
| 3212 | if (status < 0) |
| 3213 | return status; |
| 3214 | res = video_outputsw_set((status & ~disable) | enable); |
| 3215 | if (res) |
| 3216 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | return 0; |
| 3220 | } |
| 3221 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3222 | static struct ibm_struct video_driver_data = { |
| 3223 | .name = "video", |
| 3224 | .read = video_read, |
| 3225 | .write = video_write, |
| 3226 | .exit = video_exit, |
| 3227 | }; |
| 3228 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 3229 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 3230 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3231 | /************************************************************************* |
| 3232 | * Light (thinklight) subdriver |
| 3233 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3235 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 3236 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3237 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3238 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3240 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 3241 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3242 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 3243 | TPACPI_ACPIHANDLE_INIT(lght); |
| 3244 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3245 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3246 | /* 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] | 3247 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3248 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3249 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3250 | /* light status not supported on |
| 3251 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3252 | tp_features.light_status = |
| 3253 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3255 | vdbg_printk(TPACPI_DBG_INIT, "light is %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3256 | str_supported(tp_features.light)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3257 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3258 | return (tp_features.light)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3261 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | { |
| 3263 | int len = 0; |
| 3264 | int status = 0; |
| 3265 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3266 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3267 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3268 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3269 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 3270 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 3271 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 3273 | return -EIO; |
| 3274 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3275 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 3276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | |
| 3278 | return len; |
| 3279 | } |
| 3280 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3281 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | { |
| 3283 | int cmos_cmd, lght_cmd; |
| 3284 | char *cmd; |
| 3285 | int success; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3286 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3287 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3288 | return -ENODEV; |
| 3289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | while ((cmd = next_cmd(&buf))) { |
| 3291 | if (strlencmp(cmd, "on") == 0) { |
| 3292 | cmos_cmd = 0x0c; |
| 3293 | lght_cmd = 1; |
| 3294 | } else if (strlencmp(cmd, "off") == 0) { |
| 3295 | cmos_cmd = 0x0d; |
| 3296 | lght_cmd = 0; |
| 3297 | } else |
| 3298 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | success = cmos_handle ? |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3301 | acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) : |
| 3302 | acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | if (!success) |
| 3304 | return -EIO; |
| 3305 | } |
| 3306 | |
| 3307 | return 0; |
| 3308 | } |
| 3309 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3310 | static struct ibm_struct light_driver_data = { |
| 3311 | .name = "light", |
| 3312 | .read = light_read, |
| 3313 | .write = light_write, |
| 3314 | }; |
| 3315 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3316 | /************************************************************************* |
| 3317 | * Dock subdriver |
| 3318 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3320 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3321 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3322 | static void dock_notify(struct ibm_struct *ibm, u32 event); |
| 3323 | static int dock_read(char *p); |
| 3324 | static int dock_write(char *buf); |
| 3325 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3326 | TPACPI_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3327 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ |
| 3328 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ |
| 3329 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
| 3330 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
| 3331 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3332 | /* 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] | 3333 | TPACPI_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3334 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3335 | static const struct acpi_device_id ibm_pci_device_ids[] = { |
| 3336 | {PCI_ROOT_HID_STRING, 0}, |
| 3337 | {"", 0}, |
| 3338 | }; |
| 3339 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3340 | static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = { |
| 3341 | { |
| 3342 | .notify = dock_notify, |
| 3343 | .handle = &dock_handle, |
| 3344 | .type = ACPI_SYSTEM_NOTIFY, |
| 3345 | }, |
| 3346 | { |
Henrique de Moraes Holschuh | 996fba0 | 2007-07-18 23:45:40 -0300 | [diff] [blame] | 3347 | /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING. |
| 3348 | * We just use it to get notifications of dock hotplug |
| 3349 | * in very old thinkpads */ |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3350 | .hid = ibm_pci_device_ids, |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3351 | .notify = dock_notify, |
| 3352 | .handle = &pci_handle, |
| 3353 | .type = ACPI_SYSTEM_NOTIFY, |
| 3354 | }, |
| 3355 | }; |
| 3356 | |
| 3357 | static struct ibm_struct dock_driver_data[2] = { |
| 3358 | { |
| 3359 | .name = "dock", |
| 3360 | .read = dock_read, |
| 3361 | .write = dock_write, |
| 3362 | .acpi = &ibm_dock_acpidriver[0], |
| 3363 | }, |
| 3364 | { |
| 3365 | .name = "dock", |
| 3366 | .acpi = &ibm_dock_acpidriver[1], |
| 3367 | }, |
| 3368 | }; |
| 3369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | #define dock_docked() (_sta(dock_handle) & 1) |
| 3371 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3372 | static int __init dock_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3373 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3374 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n"); |
| 3375 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3376 | TPACPI_ACPIHANDLE_INIT(dock); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3377 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3378 | vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n", |
| 3379 | str_supported(dock_handle != NULL)); |
| 3380 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3381 | return (dock_handle)? 0 : 1; |
| 3382 | } |
| 3383 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3384 | static int __init dock_init2(struct ibm_init_struct *iibm) |
| 3385 | { |
| 3386 | int dock2_needed; |
| 3387 | |
| 3388 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n"); |
| 3389 | |
| 3390 | if (dock_driver_data[0].flags.acpi_driver_registered && |
| 3391 | dock_driver_data[0].flags.acpi_notify_installed) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3392 | TPACPI_ACPIHANDLE_INIT(pci); |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3393 | dock2_needed = (pci_handle != NULL); |
| 3394 | vdbg_printk(TPACPI_DBG_INIT, |
| 3395 | "dock PCI handler for the TP 570 is %s\n", |
| 3396 | str_supported(dock2_needed)); |
| 3397 | } else { |
| 3398 | vdbg_printk(TPACPI_DBG_INIT, |
| 3399 | "dock subdriver part 2 not required\n"); |
| 3400 | dock2_needed = 0; |
| 3401 | } |
| 3402 | |
| 3403 | return (dock2_needed)? 0 : 1; |
| 3404 | } |
| 3405 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3406 | static void dock_notify(struct ibm_struct *ibm, u32 event) |
| 3407 | { |
| 3408 | int docked = dock_docked(); |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3409 | int pci = ibm->acpi->hid && ibm->acpi->device && |
| 3410 | acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3411 | int data; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3412 | |
| 3413 | if (event == 1 && !pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3414 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3415 | else if (event == 1 && pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3416 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3417 | else if (event == 3 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3418 | data = 1; /* button */ |
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 = 2; /* undock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3421 | else if (event == 0 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3422 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3423 | else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3424 | printk(TPACPI_ERR "unknown dock event %d, status %d\n", |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3425 | event, _sta(dock_handle)); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3426 | data = 0; /* unknown */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3427 | } |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 3428 | acpi_bus_generate_proc_event(ibm->acpi->device, event, data); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3429 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 3430 | ibm->acpi->device->dev.bus_id, |
| 3431 | event, data); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3432 | } |
| 3433 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3434 | static int dock_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | { |
| 3436 | int len = 0; |
| 3437 | int docked = dock_docked(); |
| 3438 | |
| 3439 | if (!dock_handle) |
| 3440 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3441 | else if (!docked) |
| 3442 | len += sprintf(p + len, "status:\t\tundocked\n"); |
| 3443 | else { |
| 3444 | len += sprintf(p + len, "status:\t\tdocked\n"); |
| 3445 | len += sprintf(p + len, "commands:\tdock, undock\n"); |
| 3446 | } |
| 3447 | |
| 3448 | return len; |
| 3449 | } |
| 3450 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3451 | static int dock_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | { |
| 3453 | char *cmd; |
| 3454 | |
| 3455 | if (!dock_docked()) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3456 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | |
| 3458 | while ((cmd = next_cmd(&buf))) { |
| 3459 | if (strlencmp(cmd, "undock") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3460 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || |
| 3461 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | return -EIO; |
| 3463 | } else if (strlencmp(cmd, "dock") == 0) { |
| 3464 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) |
| 3465 | return -EIO; |
| 3466 | } else |
| 3467 | return -EINVAL; |
| 3468 | } |
| 3469 | |
| 3470 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3471 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3473 | #endif /* CONFIG_THINKPAD_ACPI_DOCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3475 | /************************************************************************* |
| 3476 | * Bay subdriver |
| 3477 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3479 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3480 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3481 | TPACPI_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3482 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
| 3483 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ |
| 3484 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
| 3485 | ); /* A21e, R30, R31 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3486 | 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] | 3487 | "_EJ0", /* all others */ |
| 3488 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3489 | 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] | 3490 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ |
| 3491 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3492 | TPACPI_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3493 | "_EJ0", /* 770x */ |
| 3494 | ); /* all others */ |
| 3495 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3496 | static int __init bay_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3498 | vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n"); |
| 3499 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3500 | TPACPI_ACPIHANDLE_INIT(bay); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3501 | if (bay_handle) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3502 | TPACPI_ACPIHANDLE_INIT(bay_ej); |
| 3503 | TPACPI_ACPIHANDLE_INIT(bay2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3504 | if (bay2_handle) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3505 | TPACPI_ACPIHANDLE_INIT(bay2_ej); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3506 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3507 | tp_features.bay_status = bay_handle && |
| 3508 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); |
| 3509 | tp_features.bay_status2 = bay2_handle && |
| 3510 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3511 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3512 | tp_features.bay_eject = bay_handle && bay_ej_handle && |
| 3513 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); |
| 3514 | tp_features.bay_eject2 = bay2_handle && bay2_ej_handle && |
| 3515 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3517 | vdbg_printk(TPACPI_DBG_INIT, |
| 3518 | "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] | 3519 | str_supported(tp_features.bay_status), |
| 3520 | str_supported(tp_features.bay_eject), |
| 3521 | str_supported(tp_features.bay_status2), |
| 3522 | str_supported(tp_features.bay_eject2)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3523 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3524 | return (tp_features.bay_status || tp_features.bay_eject || |
| 3525 | tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3528 | static void bay_notify(struct ibm_struct *ibm, u32 event) |
| 3529 | { |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 3530 | acpi_bus_generate_proc_event(ibm->acpi->device, event, 0); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3531 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 3532 | ibm->acpi->device->dev.bus_id, |
| 3533 | event, 0); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3534 | } |
| 3535 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3536 | #define bay_occupied(b) (_sta(b##_handle) & 1) |
| 3537 | |
| 3538 | static int bay_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | { |
| 3540 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3541 | int occupied = bay_occupied(bay); |
| 3542 | int occupied2 = bay_occupied(bay2); |
| 3543 | int eject, eject2; |
| 3544 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3545 | len += sprintf(p + len, "status:\t\t%s\n", |
| 3546 | tp_features.bay_status ? |
| 3547 | (occupied ? "occupied" : "unoccupied") : |
| 3548 | "not supported"); |
| 3549 | if (tp_features.bay_status2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3550 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? |
| 3551 | "occupied" : "unoccupied"); |
| 3552 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3553 | eject = tp_features.bay_eject && occupied; |
| 3554 | eject2 = tp_features.bay_eject2 && occupied2; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3555 | |
| 3556 | if (eject && eject2) |
| 3557 | len += sprintf(p + len, "commands:\teject, eject2\n"); |
| 3558 | else if (eject) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | len += sprintf(p + len, "commands:\teject\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3560 | else if (eject2) |
| 3561 | len += sprintf(p + len, "commands:\teject2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | |
| 3563 | return len; |
| 3564 | } |
| 3565 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3566 | static int bay_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | { |
| 3568 | char *cmd; |
| 3569 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3570 | if (!tp_features.bay_eject && !tp_features.bay_eject2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3571 | return -ENODEV; |
| 3572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3574 | if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3575 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) |
| 3576 | return -EIO; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3577 | } else if (tp_features.bay_eject2 && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3578 | strlencmp(cmd, "eject2") == 0) { |
| 3579 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | return -EIO; |
| 3581 | } else |
| 3582 | return -EINVAL; |
| 3583 | } |
| 3584 | |
| 3585 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3586 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3587 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3588 | static struct tp_acpi_drv_struct ibm_bay_acpidriver = { |
| 3589 | .notify = bay_notify, |
| 3590 | .handle = &bay_handle, |
| 3591 | .type = ACPI_SYSTEM_NOTIFY, |
| 3592 | }; |
| 3593 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3594 | static struct ibm_struct bay_driver_data = { |
| 3595 | .name = "bay", |
| 3596 | .read = bay_read, |
| 3597 | .write = bay_write, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3598 | .acpi = &ibm_bay_acpidriver, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3599 | }; |
| 3600 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3601 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3603 | /************************************************************************* |
| 3604 | * CMOS subdriver |
| 3605 | */ |
| 3606 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3607 | /* sysfs cmos_command -------------------------------------------------- */ |
| 3608 | static ssize_t cmos_command_store(struct device *dev, |
| 3609 | struct device_attribute *attr, |
| 3610 | const char *buf, size_t count) |
| 3611 | { |
| 3612 | unsigned long cmos_cmd; |
| 3613 | int res; |
| 3614 | |
| 3615 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 3616 | return -EINVAL; |
| 3617 | |
| 3618 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 3619 | return (res)? res : count; |
| 3620 | } |
| 3621 | |
| 3622 | static struct device_attribute dev_attr_cmos_command = |
| 3623 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 3624 | |
| 3625 | /* --------------------------------------------------------------------- */ |
| 3626 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3627 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3628 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3629 | int res; |
| 3630 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3631 | vdbg_printk(TPACPI_DBG_INIT, |
| 3632 | "initializing cmos commands subdriver\n"); |
| 3633 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3634 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3635 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3636 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 3637 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3638 | |
| 3639 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 3640 | if (res) |
| 3641 | return res; |
| 3642 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3643 | return (cmos_handle)? 0 : 1; |
| 3644 | } |
| 3645 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3646 | static void cmos_exit(void) |
| 3647 | { |
| 3648 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 3649 | } |
| 3650 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3651 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | { |
| 3653 | int len = 0; |
| 3654 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3655 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 3656 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | if (!cmos_handle) |
| 3658 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3659 | else { |
| 3660 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3661 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | return len; |
| 3665 | } |
| 3666 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3667 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | { |
| 3669 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 3670 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | |
| 3672 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3673 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 3674 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | /* cmos_cmd set */ |
| 3676 | } else |
| 3677 | return -EINVAL; |
| 3678 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 3679 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 3680 | if (res) |
| 3681 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3685 | } |
| 3686 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3687 | static struct ibm_struct cmos_driver_data = { |
| 3688 | .name = "cmos", |
| 3689 | .read = cmos_read, |
| 3690 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3691 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3692 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3693 | |
| 3694 | /************************************************************************* |
| 3695 | * LED subdriver |
| 3696 | */ |
| 3697 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3698 | enum led_access_mode { |
| 3699 | TPACPI_LED_NONE = 0, |
| 3700 | TPACPI_LED_570, /* 570 */ |
| 3701 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 3702 | TPACPI_LED_NEW, /* all others */ |
| 3703 | }; |
| 3704 | |
| 3705 | enum { /* For TPACPI_LED_OLD */ |
| 3706 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 3707 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 3708 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 3709 | }; |
| 3710 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 3711 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3712 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3713 | TPACPI_HANDLE(led, ec, "SLED", /* 570 */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3714 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */ |
| 3715 | /* T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3716 | "LED", /* all others */ |
| 3717 | ); /* R30, R31 */ |
| 3718 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3719 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3720 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3721 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 3722 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3723 | TPACPI_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3724 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3725 | if (!led_handle) |
| 3726 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3727 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3728 | else if (strlencmp(led_path, "SLED") == 0) |
| 3729 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3730 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3731 | else if (strlencmp(led_path, "SYSL") == 0) |
| 3732 | /* 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] | 3733 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3734 | else |
| 3735 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3736 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3737 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3738 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 3739 | str_supported(led_supported), led_supported); |
| 3740 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3741 | return (led_supported != TPACPI_LED_NONE)? 0 : 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking")) |
| 3745 | |
| 3746 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | { |
| 3748 | int len = 0; |
| 3749 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3750 | if (!led_supported) { |
| 3751 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3752 | return len; |
| 3753 | } |
| 3754 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3755 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3756 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3757 | /* 570 */ |
| 3758 | int i, status; |
| 3759 | for (i = 0; i < 8; i++) { |
| 3760 | if (!acpi_evalf(ec_handle, |
| 3761 | &status, "GLED", "dd", 1 << i)) |
| 3762 | return -EIO; |
| 3763 | len += sprintf(p + len, "%d:\t\t%s\n", |
| 3764 | i, led_status(status)); |
| 3765 | } |
| 3766 | } |
| 3767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | len += sprintf(p + len, "commands:\t" |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3769 | "<led> on, <led> off, <led> blink (<led> is 0-7)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | |
| 3771 | return len; |
| 3772 | } |
| 3773 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3774 | /* off, on, blink */ |
| 3775 | static const int led_sled_arg1[] = { 0, 1, 3 }; |
| 3776 | static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */ |
| 3777 | static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */ |
| 3778 | static const int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
| 3779 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3780 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | { |
| 3782 | char *cmd; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3783 | int led, ind, ret; |
| 3784 | |
| 3785 | if (!led_supported) |
| 3786 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | |
| 3788 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3789 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | return -EINVAL; |
| 3791 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3792 | if (strstr(cmd, "off")) { |
| 3793 | ind = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | } else if (strstr(cmd, "on")) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3795 | ind = 1; |
| 3796 | } else if (strstr(cmd, "blink")) { |
| 3797 | ind = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | } else |
| 3799 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3800 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3801 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3802 | /* 570 */ |
| 3803 | led = 1 << led; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3805 | led, led_sled_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | return -EIO; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3807 | } else if (led_supported == TPACPI_LED_OLD) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3808 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
| 3809 | led = 1 << led; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3810 | ret = ec_write(TPACPI_LED_EC_HLMS, led); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3811 | if (ret >= 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3812 | ret = ec_write(TPACPI_LED_EC_HLBL, |
| 3813 | led * led_exp_hlbl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3814 | if (ret >= 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3815 | ret = ec_write(TPACPI_LED_EC_HLCL, |
| 3816 | led * led_exp_hlcl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3817 | if (ret < 0) |
| 3818 | return ret; |
| 3819 | } else { |
| 3820 | /* all others */ |
| 3821 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 3822 | led, led_led_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3824 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3828 | } |
| 3829 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3830 | static struct ibm_struct led_driver_data = { |
| 3831 | .name = "led", |
| 3832 | .read = led_read, |
| 3833 | .write = led_write, |
| 3834 | }; |
| 3835 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3836 | /************************************************************************* |
| 3837 | * Beep subdriver |
| 3838 | */ |
| 3839 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3840 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3841 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3842 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3843 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3844 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 3845 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3846 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3847 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3848 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 3849 | str_supported(beep_handle != NULL)); |
| 3850 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3851 | return (beep_handle)? 0 : 1; |
| 3852 | } |
| 3853 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3854 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | { |
| 3856 | int len = 0; |
| 3857 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3858 | if (!beep_handle) |
| 3859 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3860 | else { |
| 3861 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3862 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 3863 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | |
| 3865 | return len; |
| 3866 | } |
| 3867 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3868 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | { |
| 3870 | char *cmd; |
| 3871 | int beep_cmd; |
| 3872 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3873 | if (!beep_handle) |
| 3874 | return -ENODEV; |
| 3875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3877 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 3878 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | /* beep_cmd set */ |
| 3880 | } else |
| 3881 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3882 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | return -EIO; |
| 3884 | } |
| 3885 | |
| 3886 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3887 | } |
| 3888 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3889 | static struct ibm_struct beep_driver_data = { |
| 3890 | .name = "beep", |
| 3891 | .read = beep_read, |
| 3892 | .write = beep_write, |
| 3893 | }; |
| 3894 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3895 | /************************************************************************* |
| 3896 | * Thermal subdriver |
| 3897 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3898 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3899 | enum thermal_access_mode { |
| 3900 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 3901 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 3902 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 3903 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 3904 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 3905 | }; |
| 3906 | |
| 3907 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 3908 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 3909 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 3910 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
| 3911 | }; |
| 3912 | |
| 3913 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 3914 | struct ibm_thermal_sensors_struct { |
| 3915 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 3916 | }; |
| 3917 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 3918 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3919 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 3920 | /* idx is zero-based */ |
| 3921 | static int thermal_get_sensor(int idx, s32 *value) |
| 3922 | { |
| 3923 | int t; |
| 3924 | s8 tmp; |
| 3925 | char tmpi[5]; |
| 3926 | |
| 3927 | t = TP_EC_THERMAL_TMP0; |
| 3928 | |
| 3929 | switch (thermal_read_mode) { |
| 3930 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 3931 | case TPACPI_THERMAL_TPEC_16: |
| 3932 | if (idx >= 8 && idx <= 15) { |
| 3933 | t = TP_EC_THERMAL_TMP8; |
| 3934 | idx -= 8; |
| 3935 | } |
| 3936 | /* fallthrough */ |
| 3937 | #endif |
| 3938 | case TPACPI_THERMAL_TPEC_8: |
| 3939 | if (idx <= 7) { |
| 3940 | if (!acpi_ec_read(t + idx, &tmp)) |
| 3941 | return -EIO; |
| 3942 | *value = tmp * 1000; |
| 3943 | return 0; |
| 3944 | } |
| 3945 | break; |
| 3946 | |
| 3947 | case TPACPI_THERMAL_ACPI_UPDT: |
| 3948 | if (idx <= 7) { |
| 3949 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 3950 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 3951 | return -EIO; |
| 3952 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 3953 | return -EIO; |
| 3954 | *value = (t - 2732) * 100; |
| 3955 | return 0; |
| 3956 | } |
| 3957 | break; |
| 3958 | |
| 3959 | case TPACPI_THERMAL_ACPI_TMP07: |
| 3960 | if (idx <= 7) { |
| 3961 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 3962 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 3963 | return -EIO; |
| 3964 | if (t > 127 || t < -127) |
| 3965 | t = TP_EC_THERMAL_TMP_NA; |
| 3966 | *value = t * 1000; |
| 3967 | return 0; |
| 3968 | } |
| 3969 | break; |
| 3970 | |
| 3971 | case TPACPI_THERMAL_NONE: |
| 3972 | default: |
| 3973 | return -ENOSYS; |
| 3974 | } |
| 3975 | |
| 3976 | return -EINVAL; |
| 3977 | } |
| 3978 | |
| 3979 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 3980 | { |
| 3981 | int res, i; |
| 3982 | int n; |
| 3983 | |
| 3984 | n = 8; |
| 3985 | i = 0; |
| 3986 | |
| 3987 | if (!s) |
| 3988 | return -EINVAL; |
| 3989 | |
| 3990 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 3991 | n = 16; |
| 3992 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3993 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 3994 | res = thermal_get_sensor(i, &s->temp[i]); |
| 3995 | if (res) |
| 3996 | return res; |
| 3997 | } |
| 3998 | |
| 3999 | return n; |
| 4000 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4001 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4002 | /* sysfs temp##_input -------------------------------------------------- */ |
| 4003 | |
| 4004 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 4005 | struct device_attribute *attr, |
| 4006 | char *buf) |
| 4007 | { |
| 4008 | struct sensor_device_attribute *sensor_attr = |
| 4009 | to_sensor_dev_attr(attr); |
| 4010 | int idx = sensor_attr->index; |
| 4011 | s32 value; |
| 4012 | int res; |
| 4013 | |
| 4014 | res = thermal_get_sensor(idx, &value); |
| 4015 | if (res) |
| 4016 | return res; |
| 4017 | if (value == TP_EC_THERMAL_TMP_NA * 1000) |
| 4018 | return -ENXIO; |
| 4019 | |
| 4020 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 4021 | } |
| 4022 | |
| 4023 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4024 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 4025 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4026 | |
| 4027 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 4028 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 4029 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 4030 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 4031 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 4032 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 4033 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 4034 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 4035 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 4036 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 4037 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 4038 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 4039 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 4040 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 4041 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 4042 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 4043 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 4044 | }; |
| 4045 | |
| 4046 | #define THERMAL_ATTRS(X) \ |
| 4047 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 4048 | |
| 4049 | static struct attribute *thermal_temp_input_attr[] = { |
| 4050 | THERMAL_ATTRS(8), |
| 4051 | THERMAL_ATTRS(9), |
| 4052 | THERMAL_ATTRS(10), |
| 4053 | THERMAL_ATTRS(11), |
| 4054 | THERMAL_ATTRS(12), |
| 4055 | THERMAL_ATTRS(13), |
| 4056 | THERMAL_ATTRS(14), |
| 4057 | THERMAL_ATTRS(15), |
| 4058 | THERMAL_ATTRS(0), |
| 4059 | THERMAL_ATTRS(1), |
| 4060 | THERMAL_ATTRS(2), |
| 4061 | THERMAL_ATTRS(3), |
| 4062 | THERMAL_ATTRS(4), |
| 4063 | THERMAL_ATTRS(5), |
| 4064 | THERMAL_ATTRS(6), |
| 4065 | THERMAL_ATTRS(7), |
| 4066 | NULL |
| 4067 | }; |
| 4068 | |
| 4069 | static const struct attribute_group thermal_temp_input16_group = { |
| 4070 | .attrs = thermal_temp_input_attr |
| 4071 | }; |
| 4072 | |
| 4073 | static const struct attribute_group thermal_temp_input8_group = { |
| 4074 | .attrs = &thermal_temp_input_attr[8] |
| 4075 | }; |
| 4076 | |
| 4077 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 4078 | #undef THERMAL_ATTRS |
| 4079 | |
| 4080 | /* --------------------------------------------------------------------- */ |
| 4081 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4082 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4083 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4084 | u8 t, ta1, ta2; |
| 4085 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4086 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4087 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4088 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4089 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 4090 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4091 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4092 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 4093 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4094 | /* |
| 4095 | * Direct EC access mode: sensors at registers |
| 4096 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 4097 | * non-implemented, thermal sensors return 0x80 when |
| 4098 | * not available |
| 4099 | */ |
| 4100 | |
| 4101 | ta1 = ta2 = 0; |
| 4102 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4103 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4104 | ta1 |= t; |
| 4105 | } else { |
| 4106 | ta1 = 0; |
| 4107 | break; |
| 4108 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4109 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4110 | ta2 |= t; |
| 4111 | } else { |
| 4112 | ta1 = 0; |
| 4113 | break; |
| 4114 | } |
| 4115 | } |
| 4116 | if (ta1 == 0) { |
| 4117 | /* This is sheer paranoia, but we handle it anyway */ |
| 4118 | if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4119 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4120 | "ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4121 | "falling back to ACPI TMPx access " |
| 4122 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4123 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4124 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4125 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4126 | "ThinkPad ACPI EC access misbehaving, " |
| 4127 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4128 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4129 | } |
| 4130 | } else { |
| 4131 | thermal_read_mode = |
| 4132 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4133 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4134 | } |
| 4135 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4136 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 4137 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4138 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4139 | } else { |
| 4140 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4141 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4142 | } |
| 4143 | } else { |
| 4144 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4145 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4146 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4147 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4148 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 4149 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 4150 | thermal_read_mode); |
| 4151 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4152 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4153 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4154 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4155 | &thermal_temp_input16_group); |
| 4156 | if (res) |
| 4157 | return res; |
| 4158 | break; |
| 4159 | case TPACPI_THERMAL_TPEC_8: |
| 4160 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4161 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4162 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4163 | &thermal_temp_input8_group); |
| 4164 | if (res) |
| 4165 | return res; |
| 4166 | break; |
| 4167 | case TPACPI_THERMAL_NONE: |
| 4168 | default: |
| 4169 | return 1; |
| 4170 | } |
| 4171 | |
| 4172 | return 0; |
| 4173 | } |
| 4174 | |
| 4175 | static void thermal_exit(void) |
| 4176 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4177 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4178 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4179 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4180 | &thermal_temp_input16_group); |
| 4181 | break; |
| 4182 | case TPACPI_THERMAL_TPEC_8: |
| 4183 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4184 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4185 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4186 | &thermal_temp_input16_group); |
| 4187 | break; |
| 4188 | case TPACPI_THERMAL_NONE: |
| 4189 | default: |
| 4190 | break; |
| 4191 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | static int thermal_read(char *p) |
| 4195 | { |
| 4196 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4197 | int n, i; |
| 4198 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4199 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4200 | n = thermal_get_sensors(&t); |
| 4201 | if (unlikely(n < 0)) |
| 4202 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4203 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4204 | len += sprintf(p + len, "temperatures:\t"); |
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 | if (n > 0) { |
| 4207 | for (i = 0; i < (n - 1); i++) |
| 4208 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 4209 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 4210 | } else |
| 4211 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4212 | |
| 4213 | return len; |
| 4214 | } |
| 4215 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4216 | static struct ibm_struct thermal_driver_data = { |
| 4217 | .name = "thermal", |
| 4218 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4219 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4220 | }; |
| 4221 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4222 | /************************************************************************* |
| 4223 | * EC Dump subdriver |
| 4224 | */ |
| 4225 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4226 | static u8 ecdump_regs[256]; |
| 4227 | |
| 4228 | static int ecdump_read(char *p) |
| 4229 | { |
| 4230 | int len = 0; |
| 4231 | int i, j; |
| 4232 | u8 v; |
| 4233 | |
| 4234 | len += sprintf(p + len, "EC " |
| 4235 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 4236 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 4237 | for (i = 0; i < 256; i += 16) { |
| 4238 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 4239 | for (j = 0; j < 16; j++) { |
| 4240 | if (!acpi_ec_read(i + j, &v)) |
| 4241 | break; |
| 4242 | if (v != ecdump_regs[i + j]) |
| 4243 | len += sprintf(p + len, " *%02x", v); |
| 4244 | else |
| 4245 | len += sprintf(p + len, " %02x", v); |
| 4246 | ecdump_regs[i + j] = v; |
| 4247 | } |
| 4248 | len += sprintf(p + len, "\n"); |
| 4249 | if (j != 16) |
| 4250 | break; |
| 4251 | } |
| 4252 | |
| 4253 | /* These are way too dangerous to advertise openly... */ |
| 4254 | #if 0 |
| 4255 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 4256 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 4257 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 4258 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 4259 | #endif |
| 4260 | return len; |
| 4261 | } |
| 4262 | |
| 4263 | static int ecdump_write(char *buf) |
| 4264 | { |
| 4265 | char *cmd; |
| 4266 | int i, v; |
| 4267 | |
| 4268 | while ((cmd = next_cmd(&buf))) { |
| 4269 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 4270 | /* i and v set */ |
| 4271 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 4272 | /* i and v set */ |
| 4273 | } else |
| 4274 | return -EINVAL; |
| 4275 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 4276 | if (!acpi_ec_write(i, v)) |
| 4277 | return -EIO; |
| 4278 | } else |
| 4279 | return -EINVAL; |
| 4280 | } |
| 4281 | |
| 4282 | return 0; |
| 4283 | } |
| 4284 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4285 | static struct ibm_struct ecdump_driver_data = { |
| 4286 | .name = "ecdump", |
| 4287 | .read = ecdump_read, |
| 4288 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 4289 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4290 | }; |
| 4291 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4292 | /************************************************************************* |
| 4293 | * Backlight/brightness subdriver |
| 4294 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 4295 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4296 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 4297 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4298 | enum { |
| 4299 | TP_EC_BACKLIGHT = 0x31, |
| 4300 | |
| 4301 | /* TP_EC_BACKLIGHT bitmasks */ |
| 4302 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 4303 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 4304 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 4305 | }; |
| 4306 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 4307 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4308 | static int brightness_mode; |
| 4309 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 4310 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4311 | static struct mutex brightness_mutex; |
| 4312 | |
| 4313 | /* |
| 4314 | * ThinkPads can read brightness from two places: EC 0x31, or |
| 4315 | * CMOS NVRAM byte 0x5E, bits 0-3. |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4316 | * |
| 4317 | * EC 0x31 has the following layout |
| 4318 | * Bit 7: unknown function |
| 4319 | * Bit 6: unknown function |
| 4320 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 4321 | * Bit 4: must be set to zero to avoid problems |
| 4322 | * Bit 3-0: backlight brightness level |
| 4323 | * |
| 4324 | * 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] | 4325 | */ |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4326 | static int brightness_get_raw(int *status) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4327 | { |
| 4328 | u8 lec = 0, lcmos = 0, level = 0; |
| 4329 | |
| 4330 | if (brightness_mode & 1) { |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4331 | if (!acpi_ec_read(TP_EC_BACKLIGHT, &lec)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4332 | return -EIO; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4333 | level = lec & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4334 | }; |
| 4335 | if (brightness_mode & 2) { |
| 4336 | lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 4337 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 4338 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 4339 | lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07; |
| 4340 | level = lcmos; |
| 4341 | } |
| 4342 | |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 4343 | if (brightness_mode == 3) { |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4344 | *status = lec; /* Prefer EC, CMOS is just a backing store */ |
| 4345 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 4346 | if (lec == lcmos) |
| 4347 | tp_warned.bright_cmos_ec_unsync = 0; |
| 4348 | else { |
| 4349 | if (!tp_warned.bright_cmos_ec_unsync) { |
| 4350 | printk(TPACPI_ERR |
| 4351 | "CMOS NVRAM (%u) and EC (%u) do not " |
| 4352 | "agree on display brightness level\n", |
| 4353 | (unsigned int) lcmos, |
| 4354 | (unsigned int) lec); |
| 4355 | tp_warned.bright_cmos_ec_unsync = 1; |
| 4356 | } |
| 4357 | return -EIO; |
| 4358 | } |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4359 | } else { |
| 4360 | *status = level; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4361 | } |
| 4362 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4363 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
| 4367 | static int brightness_set(int value) |
| 4368 | { |
| 4369 | int cmos_cmd, inc, i, res; |
| 4370 | int current_value; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4371 | int command_bits; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4372 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4373 | if (value > ((tp_features.bright_16levels)? 15 : 7) || |
| 4374 | value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4375 | return -EINVAL; |
| 4376 | |
| 4377 | res = mutex_lock_interruptible(&brightness_mutex); |
| 4378 | if (res < 0) |
| 4379 | return res; |
| 4380 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4381 | res = brightness_get_raw(¤t_value); |
| 4382 | if (res < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4383 | goto errout; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4384 | |
| 4385 | command_bits = current_value & TP_EC_BACKLIGHT_CMDMSK; |
| 4386 | current_value &= TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4387 | |
| 4388 | cmos_cmd = value > current_value ? |
| 4389 | TP_CMOS_BRIGHTNESS_UP : |
| 4390 | TP_CMOS_BRIGHTNESS_DOWN; |
| 4391 | inc = (value > current_value)? 1 : -1; |
| 4392 | |
| 4393 | res = 0; |
| 4394 | for (i = current_value; i != value; i += inc) { |
| 4395 | if ((brightness_mode & 2) && |
| 4396 | issue_thinkpad_cmos_command(cmos_cmd)) { |
| 4397 | res = -EIO; |
| 4398 | goto errout; |
| 4399 | } |
| 4400 | if ((brightness_mode & 1) && |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4401 | !acpi_ec_write(TP_EC_BACKLIGHT, |
| 4402 | (i + inc) | command_bits)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4403 | res = -EIO; |
| 4404 | goto errout;; |
| 4405 | } |
| 4406 | } |
| 4407 | |
| 4408 | errout: |
| 4409 | mutex_unlock(&brightness_mutex); |
| 4410 | return res; |
| 4411 | } |
| 4412 | |
| 4413 | /* sysfs backlight class ----------------------------------------------- */ |
| 4414 | |
| 4415 | static int brightness_update_status(struct backlight_device *bd) |
| 4416 | { |
| 4417 | /* it is the backlight class's job (caller) to handle |
| 4418 | * EINTR and other errors properly */ |
| 4419 | return brightness_set( |
| 4420 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 4421 | bd->props.power == FB_BLANK_UNBLANK) ? |
| 4422 | bd->props.brightness : 0); |
| 4423 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 4424 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4425 | static int brightness_get(struct backlight_device *bd) |
| 4426 | { |
| 4427 | int status, res; |
| 4428 | |
| 4429 | res = brightness_get_raw(&status); |
| 4430 | if (res < 0) |
| 4431 | return 0; /* FIXME: teach backlight about error handling */ |
| 4432 | |
| 4433 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 4434 | } |
| 4435 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 4436 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4437 | .get_brightness = brightness_get, |
| 4438 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4439 | }; |
| 4440 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4441 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4442 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4443 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4444 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4445 | int b; |
| 4446 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4447 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 4448 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4449 | mutex_init(&brightness_mutex); |
| 4450 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 4451 | /* |
| 4452 | * We always attempt to detect acpi support, so as to switch |
| 4453 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 4454 | * going to publish a backlight interface |
| 4455 | */ |
| 4456 | b = tpacpi_check_std_acpi_brightness_support(); |
| 4457 | if (b > 0) { |
| 4458 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
| 4459 | printk(TPACPI_NOTICE |
| 4460 | "Lenovo BIOS switched to ACPI backlight " |
| 4461 | "control mode\n"); |
| 4462 | } |
| 4463 | if (brightness_enable > 1) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4464 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4465 | "standard ACPI backlight interface " |
| 4466 | "available, not loading native one...\n"); |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 4467 | return 1; |
| 4468 | } |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 4469 | } |
| 4470 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 4471 | if (!brightness_enable) { |
| 4472 | dbg_printk(TPACPI_DBG_INIT, |
| 4473 | "brightness support disabled by " |
| 4474 | "module parameter\n"); |
| 4475 | return 1; |
| 4476 | } |
| 4477 | |
| 4478 | if (b > 16) { |
| 4479 | printk(TPACPI_ERR |
| 4480 | "Unsupported brightness interface, " |
| 4481 | "please contact %s\n", TPACPI_MAIL); |
| 4482 | return 1; |
| 4483 | } |
| 4484 | if (b == 16) |
| 4485 | tp_features.bright_16levels = 1; |
| 4486 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4487 | if (!brightness_mode) { |
| 4488 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) |
| 4489 | brightness_mode = 2; |
| 4490 | else |
| 4491 | brightness_mode = 3; |
| 4492 | |
| 4493 | dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n", |
| 4494 | brightness_mode); |
| 4495 | } |
| 4496 | |
| 4497 | if (brightness_mode > 3) |
| 4498 | return -EINVAL; |
| 4499 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4500 | if (brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4501 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4502 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4503 | if (tp_features.bright_16levels) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4504 | printk(TPACPI_INFO |
| 4505 | "detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4506 | |
Henrique de Moraes Holschuh | 7d5a015 | 2007-04-24 11:48:20 -0300 | [diff] [blame] | 4507 | ibm_backlight_device = backlight_device_register( |
| 4508 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
| 4509 | &ibm_backlight_data); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4510 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4511 | printk(TPACPI_ERR "Could not register backlight device\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4512 | return PTR_ERR(ibm_backlight_device); |
| 4513 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4514 | vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4515 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4516 | ibm_backlight_device->props.max_brightness = |
| 4517 | (tp_features.bright_16levels)? 15 : 7; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame^] | 4518 | ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4519 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 4520 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4521 | return 0; |
| 4522 | } |
| 4523 | |
| 4524 | static void brightness_exit(void) |
| 4525 | { |
| 4526 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4527 | vdbg_printk(TPACPI_DBG_EXIT, |
| 4528 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4529 | backlight_device_unregister(ibm_backlight_device); |
| 4530 | ibm_backlight_device = NULL; |
| 4531 | } |
| 4532 | } |
| 4533 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4534 | static int brightness_read(char *p) |
| 4535 | { |
| 4536 | int len = 0; |
| 4537 | int level; |
| 4538 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4539 | level = brightness_get(NULL); |
| 4540 | if (level < 0) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4541 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 4542 | } else { |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4543 | len += sprintf(p + len, "level:\t\t%d\n", level); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4544 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 4545 | len += sprintf(p + len, "commands:\tlevel <level>" |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4546 | " (<level> is 0-%d)\n", |
| 4547 | (tp_features.bright_16levels) ? 15 : 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | return len; |
| 4551 | } |
| 4552 | |
| 4553 | static int brightness_write(char *buf) |
| 4554 | { |
| 4555 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4556 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4557 | char *cmd; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4558 | int max_level = (tp_features.bright_16levels) ? 15 : 7; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4559 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4560 | level = brightness_get(NULL); |
| 4561 | if (level < 0) |
| 4562 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4563 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4564 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4565 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4566 | if (level < max_level) |
| 4567 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4568 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4569 | if (level > 0) |
| 4570 | level--; |
| 4571 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
| 4572 | level >= 0 && level <= max_level) { |
| 4573 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4574 | } else |
| 4575 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4576 | } |
| 4577 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4578 | /* |
| 4579 | * Now we know what the final level should be, so we try to set it. |
| 4580 | * Doing it this way makes the syscall restartable in case of EINTR |
| 4581 | */ |
| 4582 | rc = brightness_set(level); |
| 4583 | return (rc == -EINTR)? ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4584 | } |
| 4585 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4586 | static struct ibm_struct brightness_driver_data = { |
| 4587 | .name = "brightness", |
| 4588 | .read = brightness_read, |
| 4589 | .write = brightness_write, |
| 4590 | .exit = brightness_exit, |
| 4591 | }; |
| 4592 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4593 | /************************************************************************* |
| 4594 | * Volume subdriver |
| 4595 | */ |
| 4596 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4597 | static int volume_offset = 0x30; |
| 4598 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4599 | static int volume_read(char *p) |
| 4600 | { |
| 4601 | int len = 0; |
| 4602 | u8 level; |
| 4603 | |
| 4604 | if (!acpi_ec_read(volume_offset, &level)) { |
| 4605 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 4606 | } else { |
| 4607 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 4608 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 4609 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 4610 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 4611 | " (<level> is 0-15)\n"); |
| 4612 | } |
| 4613 | |
| 4614 | return len; |
| 4615 | } |
| 4616 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4617 | static int volume_write(char *buf) |
| 4618 | { |
| 4619 | int cmos_cmd, inc, i; |
| 4620 | u8 level, mute; |
| 4621 | int new_level, new_mute; |
| 4622 | char *cmd; |
| 4623 | |
| 4624 | while ((cmd = next_cmd(&buf))) { |
| 4625 | if (!acpi_ec_read(volume_offset, &level)) |
| 4626 | return -EIO; |
| 4627 | new_mute = mute = level & 0x40; |
| 4628 | new_level = level = level & 0xf; |
| 4629 | |
| 4630 | if (strlencmp(cmd, "up") == 0) { |
| 4631 | if (mute) |
| 4632 | new_mute = 0; |
| 4633 | else |
| 4634 | new_level = level == 15 ? 15 : level + 1; |
| 4635 | } else if (strlencmp(cmd, "down") == 0) { |
| 4636 | if (mute) |
| 4637 | new_mute = 0; |
| 4638 | else |
| 4639 | new_level = level == 0 ? 0 : level - 1; |
| 4640 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 4641 | new_level >= 0 && new_level <= 15) { |
| 4642 | /* new_level set */ |
| 4643 | } else if (strlencmp(cmd, "mute") == 0) { |
| 4644 | new_mute = 0x40; |
| 4645 | } else |
| 4646 | return -EINVAL; |
| 4647 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4648 | if (new_level != level) { |
| 4649 | /* mute doesn't change */ |
| 4650 | |
| 4651 | cmos_cmd = (new_level > level) ? |
| 4652 | TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4653 | inc = new_level > level ? 1 : -1; |
| 4654 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4655 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4656 | !acpi_ec_write(volume_offset, level))) |
| 4657 | return -EIO; |
| 4658 | |
| 4659 | for (i = level; i != new_level; i += inc) |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4660 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4661 | !acpi_ec_write(volume_offset, i + inc)) |
| 4662 | return -EIO; |
| 4663 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4664 | if (mute && |
| 4665 | (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
| 4666 | !acpi_ec_write(volume_offset, new_level + mute))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4667 | return -EIO; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4668 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4669 | } |
| 4670 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4671 | if (new_mute != mute) { |
| 4672 | /* level doesn't change */ |
| 4673 | |
| 4674 | cmos_cmd = (new_mute) ? |
| 4675 | TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4676 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4677 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4678 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 4679 | return -EIO; |
| 4680 | } |
| 4681 | } |
| 4682 | |
| 4683 | return 0; |
| 4684 | } |
| 4685 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4686 | static struct ibm_struct volume_driver_data = { |
| 4687 | .name = "volume", |
| 4688 | .read = volume_read, |
| 4689 | .write = volume_write, |
| 4690 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4691 | |
| 4692 | /************************************************************************* |
| 4693 | * Fan subdriver |
| 4694 | */ |
| 4695 | |
| 4696 | /* |
| 4697 | * FAN ACCESS MODES |
| 4698 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4699 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4700 | * ACPI GFAN method: returns fan level |
| 4701 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4702 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4703 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4704 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4705 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4706 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 4707 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4708 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 4709 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4710 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4711 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4712 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 4713 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4714 | * |
| 4715 | * Fan speed changes of any sort (including those caused by the |
| 4716 | * disengaged mode) are usually done slowly by the firmware as the |
| 4717 | * maximum ammount of fan duty cycle change per second seems to be |
| 4718 | * limited. |
| 4719 | * |
| 4720 | * Reading is not available if GFAN exists. |
| 4721 | * Writing is not available if SFAN exists. |
| 4722 | * |
| 4723 | * Bits |
| 4724 | * 7 automatic mode engaged; |
| 4725 | * (default operation mode of the ThinkPad) |
| 4726 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4727 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4728 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4729 | * the tachometer while the fan controller ramps up |
| 4730 | * the speed (which can take up to a few *minutes*). |
| 4731 | * Speeds up fan to 100% duty-cycle, which is far above |
| 4732 | * the standard RPM levels. It is not impossible that |
| 4733 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4734 | * 5-3 unused in some models. Extra bits for fan level |
| 4735 | * in others, but still useless as all values above |
| 4736 | * 7 map to the same speed as level 7 in these models. |
| 4737 | * 2-0 fan level (0..7 usually) |
| 4738 | * 0x00 = stop |
| 4739 | * 0x07 = max (set when temperatures critical) |
| 4740 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4741 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4742 | * |
| 4743 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 4744 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 4745 | * does so, its initial value is meaningless (0x07). |
| 4746 | * |
| 4747 | * For firmware bugs, refer to: |
| 4748 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 4749 | * |
| 4750 | * ---- |
| 4751 | * |
| 4752 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 4753 | * Main fan tachometer reading (in RPM) |
| 4754 | * |
| 4755 | * This register is present on all ThinkPads with a new-style EC, and |
| 4756 | * it is known not to be present on the A21m/e, and T22, as there is |
| 4757 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 4758 | * ThinkPads from this same time period (and earlier) probably lack the |
| 4759 | * tachometer as well. |
| 4760 | * |
| 4761 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare |
| 4762 | * was never fixed by IBM to report the EC firmware version string |
| 4763 | * probably support the tachometer (like the early X models), so |
| 4764 | * detecting it is quite hard. We need more data to know for sure. |
| 4765 | * |
| 4766 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 4767 | * might result. |
| 4768 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4769 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 4770 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4771 | * |
| 4772 | * For firmware bugs, refer to: |
| 4773 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 4774 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4775 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4776 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 4777 | * |
| 4778 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 4779 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 4780 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 4781 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 4782 | * |
| 4783 | * The speeds are stored on handles |
| 4784 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 4785 | * |
| 4786 | * There are three default speed sets, acessible as handles: |
| 4787 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 4788 | * |
| 4789 | * ACPI DSDT switches which set is in use depending on various |
| 4790 | * factors. |
| 4791 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4792 | * 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] | 4793 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 4794 | * but the ACPI tables just mention level 7. |
| 4795 | */ |
| 4796 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4797 | enum { /* Fan control constants */ |
| 4798 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 4799 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 4800 | * 0x84 must be read before 0x85 */ |
| 4801 | |
| 4802 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 4803 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 4804 | |
| 4805 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 4806 | }; |
| 4807 | |
| 4808 | enum fan_status_access_mode { |
| 4809 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 4810 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 4811 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 4812 | }; |
| 4813 | |
| 4814 | enum fan_control_access_mode { |
| 4815 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 4816 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 4817 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 4818 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 4819 | }; |
| 4820 | |
| 4821 | enum fan_control_commands { |
| 4822 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 4823 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 4824 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 4825 | * and also watchdog cmd */ |
| 4826 | }; |
| 4827 | |
| 4828 | static int fan_control_allowed; |
| 4829 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 4830 | static enum fan_status_access_mode fan_status_access_mode; |
| 4831 | static enum fan_control_access_mode fan_control_access_mode; |
| 4832 | static enum fan_control_commands fan_control_commands; |
| 4833 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 4834 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 4835 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 4836 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4837 | |
| 4838 | static struct mutex fan_mutex; |
| 4839 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4840 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 4841 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 4842 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4843 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 4844 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4845 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 4846 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4847 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4848 | "JFNS", /* 770x-JL */ |
| 4849 | ); /* all others */ |
| 4850 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 4851 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4852 | * Call with fan_mutex held |
| 4853 | */ |
| 4854 | static void fan_update_desired_level(u8 status) |
| 4855 | { |
| 4856 | if ((status & |
| 4857 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 4858 | if (status > 7) |
| 4859 | fan_control_desired_level = 7; |
| 4860 | else |
| 4861 | fan_control_desired_level = status; |
| 4862 | } |
| 4863 | } |
| 4864 | |
| 4865 | static int fan_get_status(u8 *status) |
| 4866 | { |
| 4867 | u8 s; |
| 4868 | |
| 4869 | /* TODO: |
| 4870 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 4871 | |
| 4872 | switch (fan_status_access_mode) { |
| 4873 | case TPACPI_FAN_RD_ACPI_GFAN: |
| 4874 | /* 570, 600e/x, 770e, 770x */ |
| 4875 | |
| 4876 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
| 4877 | return -EIO; |
| 4878 | |
| 4879 | if (likely(status)) |
| 4880 | *status = s & 0x07; |
| 4881 | |
| 4882 | break; |
| 4883 | |
| 4884 | case TPACPI_FAN_RD_TPEC: |
| 4885 | /* all except 570, 600e/x, 770e, 770x */ |
| 4886 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 4887 | return -EIO; |
| 4888 | |
| 4889 | if (likely(status)) |
| 4890 | *status = s; |
| 4891 | |
| 4892 | break; |
| 4893 | |
| 4894 | default: |
| 4895 | return -ENXIO; |
| 4896 | } |
| 4897 | |
| 4898 | return 0; |
| 4899 | } |
| 4900 | |
| 4901 | static int fan_get_status_safe(u8 *status) |
| 4902 | { |
| 4903 | int rc; |
| 4904 | u8 s; |
| 4905 | |
| 4906 | if (mutex_lock_interruptible(&fan_mutex)) |
| 4907 | return -ERESTARTSYS; |
| 4908 | rc = fan_get_status(&s); |
| 4909 | if (!rc) |
| 4910 | fan_update_desired_level(s); |
| 4911 | mutex_unlock(&fan_mutex); |
| 4912 | |
| 4913 | if (status) |
| 4914 | *status = s; |
| 4915 | |
| 4916 | return rc; |
| 4917 | } |
| 4918 | |
| 4919 | static int fan_get_speed(unsigned int *speed) |
| 4920 | { |
| 4921 | u8 hi, lo; |
| 4922 | |
| 4923 | switch (fan_status_access_mode) { |
| 4924 | case TPACPI_FAN_RD_TPEC: |
| 4925 | /* all except 570, 600e/x, 770e, 770x */ |
| 4926 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 4927 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 4928 | return -EIO; |
| 4929 | |
| 4930 | if (likely(speed)) |
| 4931 | *speed = (hi << 8) | lo; |
| 4932 | |
| 4933 | break; |
| 4934 | |
| 4935 | default: |
| 4936 | return -ENXIO; |
| 4937 | } |
| 4938 | |
| 4939 | return 0; |
| 4940 | } |
| 4941 | |
| 4942 | static int fan_set_level(int level) |
| 4943 | { |
| 4944 | if (!fan_control_allowed) |
| 4945 | return -EPERM; |
| 4946 | |
| 4947 | switch (fan_control_access_mode) { |
| 4948 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 4949 | if (level >= 0 && level <= 7) { |
| 4950 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 4951 | return -EIO; |
| 4952 | } else |
| 4953 | return -EINVAL; |
| 4954 | break; |
| 4955 | |
| 4956 | case TPACPI_FAN_WR_ACPI_FANS: |
| 4957 | case TPACPI_FAN_WR_TPEC: |
| 4958 | if ((level != TP_EC_FAN_AUTO) && |
| 4959 | (level != TP_EC_FAN_FULLSPEED) && |
| 4960 | ((level < 0) || (level > 7))) |
| 4961 | return -EINVAL; |
| 4962 | |
| 4963 | /* safety net should the EC not support AUTO |
| 4964 | * or FULLSPEED mode bits and just ignore them */ |
| 4965 | if (level & TP_EC_FAN_FULLSPEED) |
| 4966 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 4967 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4968 | level |= 4; /* safety min speed 4 */ |
| 4969 | |
| 4970 | if (!acpi_ec_write(fan_status_offset, level)) |
| 4971 | return -EIO; |
| 4972 | else |
| 4973 | tp_features.fan_ctrl_status_undef = 0; |
| 4974 | break; |
| 4975 | |
| 4976 | default: |
| 4977 | return -ENXIO; |
| 4978 | } |
| 4979 | return 0; |
| 4980 | } |
| 4981 | |
| 4982 | static int fan_set_level_safe(int level) |
| 4983 | { |
| 4984 | int rc; |
| 4985 | |
| 4986 | if (!fan_control_allowed) |
| 4987 | return -EPERM; |
| 4988 | |
| 4989 | if (mutex_lock_interruptible(&fan_mutex)) |
| 4990 | return -ERESTARTSYS; |
| 4991 | |
| 4992 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 4993 | level = fan_control_desired_level; |
| 4994 | |
| 4995 | rc = fan_set_level(level); |
| 4996 | if (!rc) |
| 4997 | fan_update_desired_level(level); |
| 4998 | |
| 4999 | mutex_unlock(&fan_mutex); |
| 5000 | return rc; |
| 5001 | } |
| 5002 | |
| 5003 | static int fan_set_enable(void) |
| 5004 | { |
| 5005 | u8 s; |
| 5006 | int rc; |
| 5007 | |
| 5008 | if (!fan_control_allowed) |
| 5009 | return -EPERM; |
| 5010 | |
| 5011 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5012 | return -ERESTARTSYS; |
| 5013 | |
| 5014 | switch (fan_control_access_mode) { |
| 5015 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5016 | case TPACPI_FAN_WR_TPEC: |
| 5017 | rc = fan_get_status(&s); |
| 5018 | if (rc < 0) |
| 5019 | break; |
| 5020 | |
| 5021 | /* Don't go out of emergency fan mode */ |
| 5022 | if (s != 7) { |
| 5023 | s &= 0x07; |
| 5024 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 5025 | } |
| 5026 | |
| 5027 | if (!acpi_ec_write(fan_status_offset, s)) |
| 5028 | rc = -EIO; |
| 5029 | else { |
| 5030 | tp_features.fan_ctrl_status_undef = 0; |
| 5031 | rc = 0; |
| 5032 | } |
| 5033 | break; |
| 5034 | |
| 5035 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 5036 | rc = fan_get_status(&s); |
| 5037 | if (rc < 0) |
| 5038 | break; |
| 5039 | |
| 5040 | s &= 0x07; |
| 5041 | |
| 5042 | /* Set fan to at least level 4 */ |
| 5043 | s |= 4; |
| 5044 | |
| 5045 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5046 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5047 | else |
| 5048 | rc = 0; |
| 5049 | break; |
| 5050 | |
| 5051 | default: |
| 5052 | rc = -ENXIO; |
| 5053 | } |
| 5054 | |
| 5055 | mutex_unlock(&fan_mutex); |
| 5056 | return rc; |
| 5057 | } |
| 5058 | |
| 5059 | static int fan_set_disable(void) |
| 5060 | { |
| 5061 | int rc; |
| 5062 | |
| 5063 | if (!fan_control_allowed) |
| 5064 | return -EPERM; |
| 5065 | |
| 5066 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5067 | return -ERESTARTSYS; |
| 5068 | |
| 5069 | rc = 0; |
| 5070 | switch (fan_control_access_mode) { |
| 5071 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5072 | case TPACPI_FAN_WR_TPEC: |
| 5073 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 5074 | rc = -EIO; |
| 5075 | else { |
| 5076 | fan_control_desired_level = 0; |
| 5077 | tp_features.fan_ctrl_status_undef = 0; |
| 5078 | } |
| 5079 | break; |
| 5080 | |
| 5081 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 5082 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 5083 | rc = -EIO; |
| 5084 | else |
| 5085 | fan_control_desired_level = 0; |
| 5086 | break; |
| 5087 | |
| 5088 | default: |
| 5089 | rc = -ENXIO; |
| 5090 | } |
| 5091 | |
| 5092 | |
| 5093 | mutex_unlock(&fan_mutex); |
| 5094 | return rc; |
| 5095 | } |
| 5096 | |
| 5097 | static int fan_set_speed(int speed) |
| 5098 | { |
| 5099 | int rc; |
| 5100 | |
| 5101 | if (!fan_control_allowed) |
| 5102 | return -EPERM; |
| 5103 | |
| 5104 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5105 | return -ERESTARTSYS; |
| 5106 | |
| 5107 | rc = 0; |
| 5108 | switch (fan_control_access_mode) { |
| 5109 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5110 | if (speed >= 0 && speed <= 65535) { |
| 5111 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 5112 | speed, speed, speed)) |
| 5113 | rc = -EIO; |
| 5114 | } else |
| 5115 | rc = -EINVAL; |
| 5116 | break; |
| 5117 | |
| 5118 | default: |
| 5119 | rc = -ENXIO; |
| 5120 | } |
| 5121 | |
| 5122 | mutex_unlock(&fan_mutex); |
| 5123 | return rc; |
| 5124 | } |
| 5125 | |
| 5126 | static void fan_watchdog_reset(void) |
| 5127 | { |
| 5128 | static int fan_watchdog_active; |
| 5129 | |
| 5130 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 5131 | return; |
| 5132 | |
| 5133 | if (fan_watchdog_active) |
| 5134 | cancel_delayed_work(&fan_watchdog_task); |
| 5135 | |
| 5136 | if (fan_watchdog_maxinterval > 0 && |
| 5137 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
| 5138 | fan_watchdog_active = 1; |
| 5139 | if (!schedule_delayed_work(&fan_watchdog_task, |
| 5140 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 5141 | * 1000))) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5142 | printk(TPACPI_ERR |
| 5143 | "failed to schedule the fan watchdog, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5144 | "watchdog will not trigger\n"); |
| 5145 | } |
| 5146 | } else |
| 5147 | fan_watchdog_active = 0; |
| 5148 | } |
| 5149 | |
| 5150 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 5151 | { |
| 5152 | int rc; |
| 5153 | |
| 5154 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 5155 | return; |
| 5156 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5157 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5158 | rc = fan_set_enable(); |
| 5159 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5160 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5161 | "will try again later...\n", -rc); |
| 5162 | /* reschedule for later */ |
| 5163 | fan_watchdog_reset(); |
| 5164 | } |
| 5165 | } |
| 5166 | |
| 5167 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5168 | * SYSFS fan layout: hwmon compatible (device) |
| 5169 | * |
| 5170 | * pwm*_enable: |
| 5171 | * 0: "disengaged" mode |
| 5172 | * 1: manual mode |
| 5173 | * 2: native EC "auto" mode (recommended, hardware default) |
| 5174 | * |
| 5175 | * pwm*: set speed in manual mode, ignored otherwise. |
| 5176 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 5177 | * interpolation. |
| 5178 | * |
| 5179 | * fan*_input: tachometer reading, RPM |
| 5180 | * |
| 5181 | * |
| 5182 | * SYSFS fan layout: extensions |
| 5183 | * |
| 5184 | * fan_watchdog (driver): |
| 5185 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 5186 | */ |
| 5187 | |
| 5188 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 5189 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 5190 | struct device_attribute *attr, |
| 5191 | char *buf) |
| 5192 | { |
| 5193 | int res, mode; |
| 5194 | u8 status; |
| 5195 | |
| 5196 | res = fan_get_status_safe(&status); |
| 5197 | if (res) |
| 5198 | return res; |
| 5199 | |
| 5200 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 5201 | if (status != fan_control_initial_status) { |
| 5202 | tp_features.fan_ctrl_status_undef = 0; |
| 5203 | } else { |
| 5204 | /* Return most likely status. In fact, it |
| 5205 | * might be the only possible status */ |
| 5206 | status = TP_EC_FAN_AUTO; |
| 5207 | } |
| 5208 | } |
| 5209 | |
| 5210 | if (status & TP_EC_FAN_FULLSPEED) { |
| 5211 | mode = 0; |
| 5212 | } else if (status & TP_EC_FAN_AUTO) { |
| 5213 | mode = 2; |
| 5214 | } else |
| 5215 | mode = 1; |
| 5216 | |
| 5217 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 5218 | } |
| 5219 | |
| 5220 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 5221 | struct device_attribute *attr, |
| 5222 | const char *buf, size_t count) |
| 5223 | { |
| 5224 | unsigned long t; |
| 5225 | int res, level; |
| 5226 | |
| 5227 | if (parse_strtoul(buf, 2, &t)) |
| 5228 | return -EINVAL; |
| 5229 | |
| 5230 | switch (t) { |
| 5231 | case 0: |
| 5232 | level = TP_EC_FAN_FULLSPEED; |
| 5233 | break; |
| 5234 | case 1: |
| 5235 | level = TPACPI_FAN_LAST_LEVEL; |
| 5236 | break; |
| 5237 | case 2: |
| 5238 | level = TP_EC_FAN_AUTO; |
| 5239 | break; |
| 5240 | case 3: |
| 5241 | /* reserved for software-controlled auto mode */ |
| 5242 | return -ENOSYS; |
| 5243 | default: |
| 5244 | return -EINVAL; |
| 5245 | } |
| 5246 | |
| 5247 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 5248 | if (res == -ENXIO) |
| 5249 | return -EINVAL; |
| 5250 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5251 | return res; |
| 5252 | |
| 5253 | fan_watchdog_reset(); |
| 5254 | |
| 5255 | return count; |
| 5256 | } |
| 5257 | |
| 5258 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 5259 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 5260 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 5261 | |
| 5262 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 5263 | static ssize_t fan_pwm1_show(struct device *dev, |
| 5264 | struct device_attribute *attr, |
| 5265 | char *buf) |
| 5266 | { |
| 5267 | int res; |
| 5268 | u8 status; |
| 5269 | |
| 5270 | res = fan_get_status_safe(&status); |
| 5271 | if (res) |
| 5272 | return res; |
| 5273 | |
| 5274 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 5275 | if (status != fan_control_initial_status) { |
| 5276 | tp_features.fan_ctrl_status_undef = 0; |
| 5277 | } else { |
| 5278 | status = TP_EC_FAN_AUTO; |
| 5279 | } |
| 5280 | } |
| 5281 | |
| 5282 | if ((status & |
| 5283 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 5284 | status = fan_control_desired_level; |
| 5285 | |
| 5286 | if (status > 7) |
| 5287 | status = 7; |
| 5288 | |
| 5289 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 5290 | } |
| 5291 | |
| 5292 | static ssize_t fan_pwm1_store(struct device *dev, |
| 5293 | struct device_attribute *attr, |
| 5294 | const char *buf, size_t count) |
| 5295 | { |
| 5296 | unsigned long s; |
| 5297 | int rc; |
| 5298 | u8 status, newlevel; |
| 5299 | |
| 5300 | if (parse_strtoul(buf, 255, &s)) |
| 5301 | return -EINVAL; |
| 5302 | |
| 5303 | /* scale down from 0-255 to 0-7 */ |
| 5304 | newlevel = (s >> 5) & 0x07; |
| 5305 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 5306 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5307 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5308 | |
| 5309 | rc = fan_get_status(&status); |
| 5310 | if (!rc && (status & |
| 5311 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 5312 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 5313 | if (rc == -ENXIO) |
| 5314 | rc = -EINVAL; |
| 5315 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5316 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 5317 | fan_watchdog_reset(); |
| 5318 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | mutex_unlock(&fan_mutex); |
| 5322 | return (rc)? rc : count; |
| 5323 | } |
| 5324 | |
| 5325 | static struct device_attribute dev_attr_fan_pwm1 = |
| 5326 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 5327 | fan_pwm1_show, fan_pwm1_store); |
| 5328 | |
| 5329 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 5330 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 5331 | struct device_attribute *attr, |
| 5332 | char *buf) |
| 5333 | { |
| 5334 | int res; |
| 5335 | unsigned int speed; |
| 5336 | |
| 5337 | res = fan_get_speed(&speed); |
| 5338 | if (res < 0) |
| 5339 | return res; |
| 5340 | |
| 5341 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 5342 | } |
| 5343 | |
| 5344 | static struct device_attribute dev_attr_fan_fan1_input = |
| 5345 | __ATTR(fan1_input, S_IRUGO, |
| 5346 | fan_fan1_input_show, NULL); |
| 5347 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5348 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5349 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 5350 | char *buf) |
| 5351 | { |
| 5352 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 5353 | } |
| 5354 | |
| 5355 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 5356 | const char *buf, size_t count) |
| 5357 | { |
| 5358 | unsigned long t; |
| 5359 | |
| 5360 | if (parse_strtoul(buf, 120, &t)) |
| 5361 | return -EINVAL; |
| 5362 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5363 | if (!fan_control_allowed) |
| 5364 | return -EPERM; |
| 5365 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5366 | fan_watchdog_maxinterval = t; |
| 5367 | fan_watchdog_reset(); |
| 5368 | |
| 5369 | return count; |
| 5370 | } |
| 5371 | |
| 5372 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 5373 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 5374 | |
| 5375 | /* --------------------------------------------------------------------- */ |
| 5376 | static struct attribute *fan_attributes[] = { |
| 5377 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 5378 | &dev_attr_fan_fan1_input.attr, |
| 5379 | NULL |
| 5380 | }; |
| 5381 | |
| 5382 | static const struct attribute_group fan_attr_group = { |
| 5383 | .attrs = fan_attributes, |
| 5384 | }; |
| 5385 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5386 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5387 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5388 | int rc; |
| 5389 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5390 | vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n"); |
| 5391 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5392 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5393 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 5394 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5395 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5396 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5397 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5398 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5399 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5400 | TPACPI_ACPIHANDLE_INIT(fans); |
| 5401 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 5402 | TPACPI_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5403 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5404 | if (gfan_handle) { |
| 5405 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5406 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5407 | } else { |
| 5408 | /* all other ThinkPads: note that even old-style |
| 5409 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5410 | if (likely(acpi_ec_read(fan_status_offset, |
| 5411 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5412 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5413 | |
| 5414 | /* In some ThinkPads, neither the EC nor the ACPI |
| 5415 | * DSDT initialize the fan status, and it ends up |
| 5416 | * being set to 0x07 when it *could* be either |
| 5417 | * 0x07 or 0x80. |
| 5418 | * |
| 5419 | * Enable for TP-1Y (T43), TP-78 (R51e), |
| 5420 | * TP-76 (R52), TP-70 (T43, R52), which are known |
| 5421 | * to be buggy. */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5422 | if (fan_control_initial_status == 0x07) { |
| 5423 | switch (thinkpad_id.ec_model) { |
| 5424 | case 0x5931: /* TP-1Y */ |
| 5425 | case 0x3837: /* TP-78 */ |
| 5426 | case 0x3637: /* TP-76 */ |
| 5427 | case 0x3037: /* TP-70 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5428 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5429 | "fan_init: initial fan status " |
| 5430 | "is unknown, assuming it is " |
| 5431 | "in auto mode\n"); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5432 | tp_features.fan_ctrl_status_undef = 1; |
| 5433 | ;; |
| 5434 | } |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5435 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5436 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5437 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5438 | "ThinkPad ACPI EC access misbehaving, " |
| 5439 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5440 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5441 | } |
| 5442 | } |
| 5443 | |
| 5444 | if (sfan_handle) { |
| 5445 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5446 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5447 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5448 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5449 | } else { |
| 5450 | if (!gfan_handle) { |
| 5451 | /* gfan without sfan means no fan control */ |
| 5452 | /* all other models implement TP EC 0x2f control */ |
| 5453 | |
| 5454 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5455 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5456 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5457 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5458 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5459 | TPACPI_FAN_CMD_SPEED | |
| 5460 | TPACPI_FAN_CMD_LEVEL | |
| 5461 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5462 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5463 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5464 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5465 | TPACPI_FAN_CMD_LEVEL | |
| 5466 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5467 | } |
| 5468 | } |
| 5469 | } |
| 5470 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5471 | vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n", |
| 5472 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 5473 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 5474 | fan_status_access_mode, fan_control_access_mode); |
| 5475 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5476 | /* fan control master switch */ |
| 5477 | if (!fan_control_allowed) { |
| 5478 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 5479 | fan_control_commands = 0; |
| 5480 | dbg_printk(TPACPI_DBG_INIT, |
| 5481 | "fan control features disabled by parameter\n"); |
| 5482 | } |
| 5483 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5484 | /* update fan_control_desired_level */ |
| 5485 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 5486 | fan_get_status_safe(NULL); |
| 5487 | |
| 5488 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 5489 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5490 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5491 | &fan_attr_group); |
| 5492 | if (!(rc < 0)) |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5493 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5494 | &driver_attr_fan_watchdog); |
| 5495 | if (rc < 0) |
| 5496 | return rc; |
| 5497 | return 0; |
| 5498 | } else |
| 5499 | return 1; |
| 5500 | } |
| 5501 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5502 | static void fan_exit(void) |
| 5503 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5504 | vdbg_printk(TPACPI_DBG_EXIT, |
| 5505 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5506 | |
| 5507 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5508 | 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] | 5509 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 5510 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5511 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5512 | cancel_delayed_work(&fan_watchdog_task); |
| 5513 | flush_scheduled_work(); |
| 5514 | } |
| 5515 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5516 | static int fan_read(char *p) |
| 5517 | { |
| 5518 | int len = 0; |
| 5519 | int rc; |
| 5520 | u8 status; |
| 5521 | unsigned int speed = 0; |
| 5522 | |
| 5523 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5524 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5525 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5526 | rc = fan_get_status_safe(&status); |
| 5527 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5528 | return rc; |
| 5529 | |
| 5530 | len += sprintf(p + len, "status:\t\t%s\n" |
| 5531 | "level:\t\t%d\n", |
| 5532 | (status != 0) ? "enabled" : "disabled", status); |
| 5533 | break; |
| 5534 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5535 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5536 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5537 | rc = fan_get_status_safe(&status); |
| 5538 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5539 | return rc; |
| 5540 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5541 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5542 | if (status != fan_control_initial_status) |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5543 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5544 | else |
| 5545 | /* Return most likely status. In fact, it |
| 5546 | * might be the only possible status */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5547 | status = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5548 | } |
| 5549 | |
| 5550 | len += sprintf(p + len, "status:\t\t%s\n", |
| 5551 | (status != 0) ? "enabled" : "disabled"); |
| 5552 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5553 | rc = fan_get_speed(&speed); |
| 5554 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5555 | return rc; |
| 5556 | |
| 5557 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 5558 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5559 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5560 | /* Disengaged mode takes precedence */ |
| 5561 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5562 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5563 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 5564 | else |
| 5565 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 5566 | break; |
| 5567 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5568 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5569 | default: |
| 5570 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5571 | } |
| 5572 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5573 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5574 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 5575 | |
| 5576 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5577 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5578 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 5579 | break; |
| 5580 | |
| 5581 | default: |
| 5582 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5583 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5584 | break; |
| 5585 | } |
| 5586 | } |
| 5587 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5588 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5589 | len += sprintf(p + len, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5590 | "commands:\twatchdog <timeout> (<timeout> " |
| 5591 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5592 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5593 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5594 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 5595 | " (<speed> is 0-65535)\n"); |
| 5596 | |
| 5597 | return len; |
| 5598 | } |
| 5599 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5600 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 5601 | { |
| 5602 | int level; |
| 5603 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5604 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5605 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5606 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5607 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5608 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5609 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5610 | return 0; |
| 5611 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5612 | *rc = fan_set_level_safe(level); |
| 5613 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5614 | printk(TPACPI_ERR "level command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5615 | "access mode %d", fan_control_access_mode); |
| 5616 | |
| 5617 | return 1; |
| 5618 | } |
| 5619 | |
| 5620 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 5621 | { |
| 5622 | if (strlencmp(cmd, "enable") != 0) |
| 5623 | return 0; |
| 5624 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5625 | *rc = fan_set_enable(); |
| 5626 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5627 | printk(TPACPI_ERR "enable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5628 | "access mode %d", fan_control_access_mode); |
| 5629 | |
| 5630 | return 1; |
| 5631 | } |
| 5632 | |
| 5633 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 5634 | { |
| 5635 | if (strlencmp(cmd, "disable") != 0) |
| 5636 | return 0; |
| 5637 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5638 | *rc = fan_set_disable(); |
| 5639 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5640 | printk(TPACPI_ERR "disable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5641 | "access mode %d", fan_control_access_mode); |
| 5642 | |
| 5643 | return 1; |
| 5644 | } |
| 5645 | |
| 5646 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 5647 | { |
| 5648 | int speed; |
| 5649 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5650 | /* TODO: |
| 5651 | * Support speed <low> <medium> <high> ? */ |
| 5652 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5653 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 5654 | return 0; |
| 5655 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5656 | *rc = fan_set_speed(speed); |
| 5657 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5658 | printk(TPACPI_ERR "speed command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5659 | "access mode %d", fan_control_access_mode); |
| 5660 | |
| 5661 | return 1; |
| 5662 | } |
| 5663 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5664 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 5665 | { |
| 5666 | int interval; |
| 5667 | |
| 5668 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 5669 | return 0; |
| 5670 | |
| 5671 | if (interval < 0 || interval > 120) |
| 5672 | *rc = -EINVAL; |
| 5673 | else |
| 5674 | fan_watchdog_maxinterval = interval; |
| 5675 | |
| 5676 | return 1; |
| 5677 | } |
| 5678 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5679 | static int fan_write(char *buf) |
| 5680 | { |
| 5681 | char *cmd; |
| 5682 | int rc = 0; |
| 5683 | |
| 5684 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5685 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5686 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5687 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5688 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5689 | fan_write_cmd_disable(cmd, &rc) || |
| 5690 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5691 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5692 | fan_write_cmd_speed(cmd, &rc)) |
| 5693 | ) |
| 5694 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5695 | else if (!rc) |
| 5696 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5697 | } |
| 5698 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5699 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5700 | } |
| 5701 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5702 | static struct ibm_struct fan_driver_data = { |
| 5703 | .name = "fan", |
| 5704 | .read = fan_read, |
| 5705 | .write = fan_write, |
| 5706 | .exit = fan_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5707 | }; |
| 5708 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5709 | /**************************************************************************** |
| 5710 | **************************************************************************** |
| 5711 | * |
| 5712 | * Infrastructure |
| 5713 | * |
| 5714 | **************************************************************************** |
| 5715 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5716 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5717 | /* sysfs name ---------------------------------------------------------- */ |
| 5718 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 5719 | struct device_attribute *attr, |
| 5720 | char *buf) |
| 5721 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5722 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 5726 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 5727 | |
| 5728 | /* --------------------------------------------------------------------- */ |
| 5729 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5730 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5731 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5732 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5733 | /* |
| 5734 | * Module and infrastructure proble, init and exit handling |
| 5735 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5736 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5737 | static int force_load; |
| 5738 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5739 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5740 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5741 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5742 | static char text_unsupported[] __initdata = "not 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 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5745 | } |
| 5746 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 5747 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5748 | static void ibm_exit(struct ibm_struct *ibm) |
| 5749 | { |
| 5750 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 5751 | |
| 5752 | list_del_init(&ibm->all_drivers); |
| 5753 | |
| 5754 | if (ibm->flags.acpi_notify_installed) { |
| 5755 | dbg_printk(TPACPI_DBG_EXIT, |
| 5756 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 5757 | BUG_ON(!ibm->acpi); |
| 5758 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 5759 | ibm->acpi->type, |
| 5760 | dispatch_acpi_notify); |
| 5761 | ibm->flags.acpi_notify_installed = 0; |
| 5762 | ibm->flags.acpi_notify_installed = 0; |
| 5763 | } |
| 5764 | |
| 5765 | if (ibm->flags.proc_created) { |
| 5766 | dbg_printk(TPACPI_DBG_EXIT, |
| 5767 | "%s: remove_proc_entry\n", ibm->name); |
| 5768 | remove_proc_entry(ibm->name, proc_dir); |
| 5769 | ibm->flags.proc_created = 0; |
| 5770 | } |
| 5771 | |
| 5772 | if (ibm->flags.acpi_driver_registered) { |
| 5773 | dbg_printk(TPACPI_DBG_EXIT, |
| 5774 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 5775 | BUG_ON(!ibm->acpi); |
| 5776 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 5777 | kfree(ibm->acpi->driver); |
| 5778 | ibm->acpi->driver = NULL; |
| 5779 | ibm->flags.acpi_driver_registered = 0; |
| 5780 | } |
| 5781 | |
| 5782 | if (ibm->flags.init_called && ibm->exit) { |
| 5783 | ibm->exit(); |
| 5784 | ibm->flags.init_called = 0; |
| 5785 | } |
| 5786 | |
| 5787 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 5788 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5789 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5790 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5791 | { |
| 5792 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5793 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | struct proc_dir_entry *entry; |
| 5795 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5796 | BUG_ON(ibm == NULL); |
| 5797 | |
| 5798 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 5799 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5800 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5801 | return 0; |
| 5802 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5803 | dbg_printk(TPACPI_DBG_INIT, |
| 5804 | "probing for %s\n", ibm->name); |
| 5805 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5806 | if (iibm->init) { |
| 5807 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5808 | if (ret > 0) |
| 5809 | return 0; /* probe failed */ |
| 5810 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5811 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5812 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5813 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5814 | } |
| 5815 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5816 | if (ibm->acpi) { |
| 5817 | if (ibm->acpi->hid) { |
| 5818 | ret = register_tpacpi_subdriver(ibm); |
| 5819 | if (ret) |
| 5820 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5821 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5822 | |
| 5823 | if (ibm->acpi->notify) { |
| 5824 | ret = setup_acpi_notify(ibm); |
| 5825 | if (ret == -ENODEV) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5826 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5827 | ibm->name); |
| 5828 | ret = 0; |
| 5829 | goto err_out; |
| 5830 | } |
| 5831 | if (ret < 0) |
| 5832 | goto err_out; |
| 5833 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5834 | } |
| 5835 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5836 | dbg_printk(TPACPI_DBG_INIT, |
| 5837 | "%s installed\n", ibm->name); |
| 5838 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5839 | if (ibm->read) { |
| 5840 | entry = create_proc_entry(ibm->name, |
| 5841 | S_IFREG | S_IRUGO | S_IWUSR, |
| 5842 | proc_dir); |
| 5843 | if (!entry) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5844 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5845 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5846 | ret = -ENODEV; |
| 5847 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5848 | } |
| 5849 | entry->owner = THIS_MODULE; |
| 5850 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5851 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5852 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5853 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5854 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5855 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5856 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5857 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 5858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5859 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5860 | |
| 5861 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5862 | dbg_printk(TPACPI_DBG_INIT, |
| 5863 | "%s: at error exit path with result %d\n", |
| 5864 | ibm->name, ret); |
| 5865 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5866 | ibm_exit(ibm); |
| 5867 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5870 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5871 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5872 | 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] | 5873 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 5874 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5875 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5876 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5877 | if (!tp) |
| 5878 | return; |
| 5879 | |
| 5880 | memset(tp, 0, sizeof(*tp)); |
| 5881 | |
| 5882 | if (dmi_name_in_vendors("IBM")) |
| 5883 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 5884 | else if (dmi_name_in_vendors("LENOVO")) |
| 5885 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 5886 | else |
| 5887 | return; |
| 5888 | |
| 5889 | tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION), |
| 5890 | GFP_KERNEL); |
| 5891 | if (!tp->bios_version_str) |
| 5892 | return; |
| 5893 | tp->bios_model = tp->bios_version_str[0] |
| 5894 | | (tp->bios_version_str[1] << 8); |
| 5895 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5896 | /* |
| 5897 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 5898 | * X32 or newer, all Z series; Some models must have an |
| 5899 | * up-to-date BIOS or they will not be detected. |
| 5900 | * |
| 5901 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 5902 | */ |
| 5903 | 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] | 5904 | if (sscanf(dev->name, |
| 5905 | "IBM ThinkPad Embedded Controller -[%17c", |
| 5906 | ec_fw_string) == 1) { |
| 5907 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 5908 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5909 | |
| 5910 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
| 5911 | tp->ec_model = ec_fw_string[0] |
| 5912 | | (ec_fw_string[1] << 8); |
| 5913 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5914 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5915 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5916 | |
| 5917 | tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION), |
| 5918 | GFP_KERNEL); |
| 5919 | if (strnicmp(tp->model_str, "ThinkPad", 8) != 0) { |
| 5920 | kfree(tp->model_str); |
| 5921 | tp->model_str = NULL; |
| 5922 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 5923 | |
| 5924 | tp->nummodel_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_NAME), |
| 5925 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5926 | } |
| 5927 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5928 | static int __init probe_for_thinkpad(void) |
| 5929 | { |
| 5930 | int is_thinkpad; |
| 5931 | |
| 5932 | if (acpi_disabled) |
| 5933 | return -ENODEV; |
| 5934 | |
| 5935 | /* |
| 5936 | * Non-ancient models have better DMI tagging, but very old models |
| 5937 | * don't. |
| 5938 | */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5939 | is_thinkpad = (thinkpad_id.model_str != NULL); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5940 | |
| 5941 | /* 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] | 5942 | TPACPI_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5943 | if (!ec_handle) { |
| 5944 | if (is_thinkpad) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5945 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5946 | "Not yet supported ThinkPad detected!\n"); |
| 5947 | return -ENODEV; |
| 5948 | } |
| 5949 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 5950 | /* |
| 5951 | * Risks a regression on very old machines, but reduces potential |
| 5952 | * false positives a damn great deal |
| 5953 | */ |
| 5954 | if (!is_thinkpad) |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5955 | is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 5956 | |
| 5957 | if (!is_thinkpad && !force_load) |
| 5958 | return -ENODEV; |
| 5959 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5960 | return 0; |
| 5961 | } |
| 5962 | |
| 5963 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5964 | /* Module init, exit, parameters */ |
| 5965 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5966 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 5967 | { |
| 5968 | .init = thinkpad_acpi_driver_init, |
| 5969 | .data = &thinkpad_acpi_driver_data, |
| 5970 | }, |
| 5971 | { |
| 5972 | .init = hotkey_init, |
| 5973 | .data = &hotkey_driver_data, |
| 5974 | }, |
| 5975 | { |
| 5976 | .init = bluetooth_init, |
| 5977 | .data = &bluetooth_driver_data, |
| 5978 | }, |
| 5979 | { |
| 5980 | .init = wan_init, |
| 5981 | .data = &wan_driver_data, |
| 5982 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 5983 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5984 | { |
| 5985 | .init = video_init, |
| 5986 | .data = &video_driver_data, |
| 5987 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 5988 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5989 | { |
| 5990 | .init = light_init, |
| 5991 | .data = &light_driver_data, |
| 5992 | }, |
| 5993 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
| 5994 | { |
| 5995 | .init = dock_init, |
| 5996 | .data = &dock_driver_data[0], |
| 5997 | }, |
| 5998 | { |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 5999 | .init = dock_init2, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6000 | .data = &dock_driver_data[1], |
| 6001 | }, |
| 6002 | #endif |
| 6003 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 6004 | { |
| 6005 | .init = bay_init, |
| 6006 | .data = &bay_driver_data, |
| 6007 | }, |
| 6008 | #endif |
| 6009 | { |
| 6010 | .init = cmos_init, |
| 6011 | .data = &cmos_driver_data, |
| 6012 | }, |
| 6013 | { |
| 6014 | .init = led_init, |
| 6015 | .data = &led_driver_data, |
| 6016 | }, |
| 6017 | { |
| 6018 | .init = beep_init, |
| 6019 | .data = &beep_driver_data, |
| 6020 | }, |
| 6021 | { |
| 6022 | .init = thermal_init, |
| 6023 | .data = &thermal_driver_data, |
| 6024 | }, |
| 6025 | { |
| 6026 | .data = &ecdump_driver_data, |
| 6027 | }, |
| 6028 | { |
| 6029 | .init = brightness_init, |
| 6030 | .data = &brightness_driver_data, |
| 6031 | }, |
| 6032 | { |
| 6033 | .data = &volume_driver_data, |
| 6034 | }, |
| 6035 | { |
| 6036 | .init = fan_init, |
| 6037 | .data = &fan_driver_data, |
| 6038 | }, |
| 6039 | }; |
| 6040 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6041 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 6042 | { |
| 6043 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6044 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6045 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 6046 | if (!kp || !kp->name || !val) |
| 6047 | return -EINVAL; |
| 6048 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6049 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 6050 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 6051 | WARN_ON(ibm == NULL); |
| 6052 | |
| 6053 | if (!ibm || !ibm->name) |
| 6054 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6055 | |
| 6056 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 6057 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6058 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6059 | strcpy(ibms_init[i].param, val); |
| 6060 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6061 | return 0; |
| 6062 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6063 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6064 | |
| 6065 | return -EINVAL; |
| 6066 | } |
| 6067 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6068 | module_param(experimental, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6069 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6070 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6071 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 6072 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6073 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 6074 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 6075 | module_param(force_load, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6076 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6077 | "Attempts to load the driver even on a " |
| 6078 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 6079 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 6080 | module_param_named(fan_control, fan_control_allowed, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6081 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6082 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 6083 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6084 | module_param_named(brightness_mode, brightness_mode, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6085 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6086 | "Selects brightness control strategy: " |
| 6087 | "0=auto, 1=EC, 2=CMOS, 3=both"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6088 | |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6089 | module_param(brightness_enable, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6090 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6091 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6092 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6093 | module_param(hotkey_report_mode, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6094 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6095 | "used for backwards compatibility with userspace, " |
| 6096 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6097 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6098 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6099 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 6100 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6101 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6102 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6103 | TPACPI_PARAM(hotkey); |
| 6104 | TPACPI_PARAM(bluetooth); |
| 6105 | TPACPI_PARAM(video); |
| 6106 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6107 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6108 | TPACPI_PARAM(dock); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6109 | #endif |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6110 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6111 | TPACPI_PARAM(bay); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6112 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6113 | TPACPI_PARAM(cmos); |
| 6114 | TPACPI_PARAM(led); |
| 6115 | TPACPI_PARAM(beep); |
| 6116 | TPACPI_PARAM(ecdump); |
| 6117 | TPACPI_PARAM(brightness); |
| 6118 | TPACPI_PARAM(volume); |
| 6119 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6120 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6121 | static void thinkpad_acpi_module_exit(void) |
| 6122 | { |
| 6123 | struct ibm_struct *ibm, *itmp; |
| 6124 | |
| 6125 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 6126 | |
| 6127 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 6128 | &tpacpi_all_drivers, |
| 6129 | all_drivers) { |
| 6130 | ibm_exit(ibm); |
| 6131 | } |
| 6132 | |
| 6133 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 6134 | |
| 6135 | if (tpacpi_inputdev) { |
| 6136 | if (tp_features.input_device_registered) |
| 6137 | input_unregister_device(tpacpi_inputdev); |
| 6138 | else |
| 6139 | input_free_device(tpacpi_inputdev); |
| 6140 | } |
| 6141 | |
| 6142 | if (tpacpi_hwmon) |
| 6143 | hwmon_device_unregister(tpacpi_hwmon); |
| 6144 | |
| 6145 | if (tp_features.sensors_pdev_attrs_registered) |
| 6146 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 6147 | &dev_attr_thinkpad_acpi_pdev_name); |
| 6148 | if (tpacpi_sensors_pdev) |
| 6149 | platform_device_unregister(tpacpi_sensors_pdev); |
| 6150 | if (tpacpi_pdev) |
| 6151 | platform_device_unregister(tpacpi_pdev); |
| 6152 | |
| 6153 | if (tp_features.sensors_pdrv_attrs_registered) |
| 6154 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 6155 | if (tp_features.platform_drv_attrs_registered) |
| 6156 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 6157 | |
| 6158 | if (tp_features.sensors_pdrv_registered) |
| 6159 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 6160 | |
| 6161 | if (tp_features.platform_drv_registered) |
| 6162 | platform_driver_unregister(&tpacpi_pdriver); |
| 6163 | |
| 6164 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6165 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6166 | |
| 6167 | kfree(thinkpad_id.bios_version_str); |
| 6168 | kfree(thinkpad_id.ec_version_str); |
| 6169 | kfree(thinkpad_id.model_str); |
| 6170 | } |
| 6171 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6172 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6173 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6174 | { |
| 6175 | int ret, i; |
| 6176 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6177 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 6178 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6179 | /* Parameter checking */ |
| 6180 | if (hotkey_report_mode > 2) |
| 6181 | return -EINVAL; |
| 6182 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6183 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6184 | |
| 6185 | get_thinkpad_model_data(&thinkpad_id); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6186 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6187 | if (ret) { |
| 6188 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6189 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6191 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6192 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6193 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6194 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 6195 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6196 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6197 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6198 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6199 | printk(TPACPI_ERR |
| 6200 | "unable to create proc dir " TPACPI_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6201 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6202 | return -ENODEV; |
| 6203 | } |
| 6204 | proc_dir->owner = THIS_MODULE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6205 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6206 | ret = platform_driver_register(&tpacpi_pdriver); |
| 6207 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6208 | printk(TPACPI_ERR |
| 6209 | "unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6210 | thinkpad_acpi_module_exit(); |
| 6211 | return ret; |
| 6212 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 6213 | tp_features.platform_drv_registered = 1; |
| 6214 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6215 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 6216 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6217 | printk(TPACPI_ERR |
| 6218 | "unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6219 | thinkpad_acpi_module_exit(); |
| 6220 | return ret; |
| 6221 | } |
| 6222 | tp_features.sensors_pdrv_registered = 1; |
| 6223 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6224 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6225 | if (!ret) { |
| 6226 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6227 | ret = tpacpi_create_driver_attributes( |
| 6228 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6229 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6230 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6231 | printk(TPACPI_ERR |
| 6232 | "unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6233 | thinkpad_acpi_module_exit(); |
| 6234 | return ret; |
| 6235 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6236 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6237 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6238 | |
| 6239 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6240 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6241 | NULL, 0); |
| 6242 | if (IS_ERR(tpacpi_pdev)) { |
| 6243 | ret = PTR_ERR(tpacpi_pdev); |
| 6244 | tpacpi_pdev = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6245 | printk(TPACPI_ERR "unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6246 | thinkpad_acpi_module_exit(); |
| 6247 | return ret; |
| 6248 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6249 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6250 | TPACPI_HWMON_DRVR_NAME, |
| 6251 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6252 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 6253 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 6254 | tpacpi_sensors_pdev = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6255 | printk(TPACPI_ERR |
| 6256 | "unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6257 | thinkpad_acpi_module_exit(); |
| 6258 | return ret; |
| 6259 | } |
| 6260 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 6261 | &dev_attr_thinkpad_acpi_pdev_name); |
| 6262 | if (ret) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6263 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6264 | "unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6265 | thinkpad_acpi_module_exit(); |
| 6266 | return ret; |
| 6267 | } |
| 6268 | tp_features.sensors_pdev_attrs_registered = 1; |
| 6269 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6270 | if (IS_ERR(tpacpi_hwmon)) { |
| 6271 | ret = PTR_ERR(tpacpi_hwmon); |
| 6272 | tpacpi_hwmon = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6273 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6274 | thinkpad_acpi_module_exit(); |
| 6275 | return ret; |
| 6276 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 6277 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6278 | tpacpi_inputdev = input_allocate_device(); |
| 6279 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6280 | printk(TPACPI_ERR "unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6281 | thinkpad_acpi_module_exit(); |
| 6282 | return -ENOMEM; |
| 6283 | } else { |
| 6284 | /* Prepare input device, but don't register */ |
| 6285 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6286 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6287 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 6288 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
| 6289 | thinkpad_id.vendor : |
| 6290 | PCI_VENDOR_ID_IBM; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6291 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 6292 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
| 6293 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6294 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 6295 | ret = ibm_init(&ibms_init[i]); |
| 6296 | if (ret >= 0 && *ibms_init[i].param) |
| 6297 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6299 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6300 | return ret; |
| 6301 | } |
| 6302 | } |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6303 | ret = input_register_device(tpacpi_inputdev); |
| 6304 | if (ret < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6305 | printk(TPACPI_ERR "unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6306 | thinkpad_acpi_module_exit(); |
| 6307 | return ret; |
| 6308 | } else { |
| 6309 | tp_features.input_device_registered = 1; |
| 6310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6311 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6312 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6313 | return 0; |
| 6314 | } |
| 6315 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6316 | /* Please remove this in year 2009 */ |
| 6317 | MODULE_ALIAS("ibm_acpi"); |
| 6318 | |
| 6319 | /* |
| 6320 | * DMI matching for module autoloading |
| 6321 | * |
| 6322 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 6323 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 6324 | * |
| 6325 | * Only models listed in thinkwiki will be supported, so add yours |
| 6326 | * if it is not there yet. |
| 6327 | */ |
| 6328 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
| 6329 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW") |
| 6330 | |
| 6331 | /* Non-ancient thinkpads */ |
| 6332 | MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*"); |
| 6333 | MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*"); |
| 6334 | |
| 6335 | /* Ancient thinkpad BIOSes have to be identified by |
| 6336 | * BIOS type or model number, and there are far less |
| 6337 | * BIOS types than model numbers... */ |
| 6338 | IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]"); |
| 6339 | IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]"); |
| 6340 | IBM_BIOS_MODULE_ALIAS("K[U,X-Z]"); |
| 6341 | |
| 6342 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6343 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 6344 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6345 | MODULE_LICENSE("GPL"); |
| 6346 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6347 | module_init(thinkpad_acpi_module_init); |
| 6348 | module_exit(thinkpad_acpi_module_exit); |