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 | a62bc91 | 2007-03-23 17:33:58 -0300 | [diff] [blame] | 6 | * Copyright (C) 2006-2007 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 | 50efd83 | 2008-01-08 13:02:42 -0200 | [diff] [blame] | 24 | #define IBM_VERSION "0.18" |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 25 | #define TPACPI_SYSFS_VERSION 0x020101 |
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 | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 29 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
| 30 | * drivers/misc. |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 31 | * |
| 32 | * 2006-11-22 0.13 new maintainer |
| 33 | * changelog now lives in git commit history, and will |
| 34 | * not be updated further in-file. |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 35 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 36 | * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels |
| 37 | * 2005-03-17 0.11 support for 600e, 770x |
| 38 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
| 39 | * support for 770e, G41 |
| 40 | * G40 and G41 don't have a thinklight |
| 41 | * temperatures no longer experimental |
| 42 | * experimental brightness control |
| 43 | * experimental volume control |
| 44 | * experimental fan enable/disable |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 45 | * 2005-01-16 0.10 fix module loading on R30, R31 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 46 | * 2005-01-16 0.9 support for 570, R30, R31 |
| 47 | * ultrabay support on A22p, A3x |
| 48 | * limit arg for cmos, led, beep, drop experimental status |
| 49 | * more capable led control on A21e, A22p, T20-22, X20 |
| 50 | * experimental temperatures and fan speed |
| 51 | * experimental embedded controller register dump |
| 52 | * mark more functions as __init, drop incorrect __exit |
| 53 | * use MODULE_VERSION |
| 54 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
| 55 | * fix parameter passing on module loading |
| 56 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
| 57 | * thanks to Jim Radford <radford@blackbean.org> |
| 58 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
| 59 | * thanks to Chris Wright <chrisw@osdl.org> |
| 60 | * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20 |
| 61 | * fix led control on A21e |
| 62 | * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20 |
| 64 | * proc file format changed |
| 65 | * video_switch command |
| 66 | * experimental cmos control |
| 67 | * experimental led control |
| 68 | * experimental acpi sounds |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 69 | * 2004-09-16 0.4 support for module parameters |
| 70 | * hotkey mask can be prefixed by 0x |
| 71 | * video output switching |
| 72 | * video expansion control |
| 73 | * ultrabay eject support |
| 74 | * removed lcd brightness/on/off control, didn't work |
| 75 | * 2004-08-17 0.3 support for R40 |
| 76 | * lcd off, brightness control |
| 77 | * thinklight on/off |
| 78 | * 2004-08-14 0.2 support for T series, X20 |
| 79 | * bluetooth enable/disable |
| 80 | * hotkey events disabled by default |
| 81 | * removed fan control, currently useless |
| 82 | * 2004-08-09 0.1 initial release, support for X series |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | */ |
| 84 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame^] | 85 | /* ==================================================== BEGIN HEADER */ |
| 86 | |
| 87 | #include <linux/kernel.h> |
| 88 | #include <linux/module.h> |
| 89 | #include <linux/init.h> |
| 90 | #include <linux/types.h> |
| 91 | #include <linux/string.h> |
| 92 | #include <linux/list.h> |
| 93 | #include <linux/mutex.h> |
| 94 | #include <linux/kthread.h> |
| 95 | #include <linux/freezer.h> |
| 96 | #include <linux/delay.h> |
| 97 | |
| 98 | #include <linux/nvram.h> |
| 99 | #include <linux/proc_fs.h> |
| 100 | #include <linux/sysfs.h> |
| 101 | #include <linux/backlight.h> |
| 102 | #include <linux/fb.h> |
| 103 | #include <linux/platform_device.h> |
| 104 | #include <linux/hwmon.h> |
| 105 | #include <linux/hwmon-sysfs.h> |
| 106 | #include <linux/input.h> |
| 107 | #include <asm/uaccess.h> |
| 108 | |
| 109 | #include <linux/dmi.h> |
| 110 | #include <linux/jiffies.h> |
| 111 | #include <linux/workqueue.h> |
| 112 | |
| 113 | #include <acpi/acpi_drivers.h> |
| 114 | #include <acpi/acnamesp.h> |
| 115 | |
| 116 | #include <linux/pci_ids.h> |
| 117 | |
| 118 | /**************************************************************************** |
| 119 | * Main driver |
| 120 | */ |
| 121 | |
| 122 | #define IBM_NAME "thinkpad" |
| 123 | #define IBM_DESC "ThinkPad ACPI Extras" |
| 124 | #define IBM_FILE IBM_NAME "_acpi" |
| 125 | #define IBM_URL "http://ibm-acpi.sf.net/" |
| 126 | #define IBM_MAIL "ibm-acpi-devel@lists.sourceforge.net" |
| 127 | |
| 128 | #define IBM_PROC_DIR "ibm" |
| 129 | #define IBM_ACPI_EVENT_PREFIX "ibm" |
| 130 | #define IBM_DRVR_NAME IBM_FILE |
| 131 | #define IBM_HWMON_DRVR_NAME IBM_NAME "_hwmon" |
| 132 | |
| 133 | #define IBM_LOG IBM_FILE ": " |
| 134 | #define IBM_ERR KERN_ERR IBM_LOG |
| 135 | #define IBM_NOTICE KERN_NOTICE IBM_LOG |
| 136 | #define IBM_INFO KERN_INFO IBM_LOG |
| 137 | #define IBM_DEBUG KERN_DEBUG IBM_LOG |
| 138 | |
| 139 | #define IBM_MAX_ACPI_ARGS 3 |
| 140 | |
| 141 | /* ThinkPad CMOS commands */ |
| 142 | #define TP_CMOS_VOLUME_DOWN 0 |
| 143 | #define TP_CMOS_VOLUME_UP 1 |
| 144 | #define TP_CMOS_VOLUME_MUTE 2 |
| 145 | #define TP_CMOS_BRIGHTNESS_UP 4 |
| 146 | #define TP_CMOS_BRIGHTNESS_DOWN 5 |
| 147 | |
| 148 | /* NVRAM Addresses */ |
| 149 | enum tp_nvram_addr { |
| 150 | TP_NVRAM_ADDR_HK2 = 0x57, |
| 151 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, |
| 152 | TP_NVRAM_ADDR_VIDEO = 0x59, |
| 153 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, |
| 154 | TP_NVRAM_ADDR_MIXER = 0x60, |
| 155 | }; |
| 156 | |
| 157 | /* NVRAM bit masks */ |
| 158 | enum { |
| 159 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, |
| 160 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, |
| 161 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, |
| 162 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, |
| 163 | TP_NVRAM_MASK_THINKLIGHT = 0x10, |
| 164 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, |
| 165 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, |
| 166 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, |
| 167 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, |
| 168 | TP_NVRAM_MASK_MUTE = 0x40, |
| 169 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, |
| 170 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, |
| 171 | TP_NVRAM_POS_LEVEL_VOLUME = 0, |
| 172 | }; |
| 173 | |
| 174 | #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 175 | #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 176 | #define strlencmp(a,b) (strncmp((a), (b), strlen(b))) |
| 177 | |
| 178 | /* Debugging */ |
| 179 | #define TPACPI_DBG_ALL 0xffff |
| 180 | #define TPACPI_DBG_ALL 0xffff |
| 181 | #define TPACPI_DBG_INIT 0x0001 |
| 182 | #define TPACPI_DBG_EXIT 0x0002 |
| 183 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 184 | do { if (dbg_level & a_dbg_level) \ |
| 185 | printk(IBM_DEBUG "%s: " format, __func__ , ## arg); } while (0) |
| 186 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 187 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 188 | dbg_printk(a_dbg_level, format, ## arg) |
| 189 | static const char *str_supported(int is_supported); |
| 190 | #else |
| 191 | #define vdbg_printk(a_dbg_level, format, arg...) |
| 192 | #endif |
| 193 | |
| 194 | /* Input IDs */ |
| 195 | #define TPACPI_HKEY_INPUT_VENDOR PCI_VENDOR_ID_IBM |
| 196 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ |
| 197 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 |
| 198 | |
| 199 | /* ACPI HIDs */ |
| 200 | #define IBM_HKEY_HID "IBM0068" |
| 201 | |
| 202 | /* ACPI helpers */ |
| 203 | static int __must_check acpi_evalf(acpi_handle handle, |
| 204 | void *res, char *method, char *fmt, ...); |
| 205 | static int __must_check acpi_ec_read(int i, u8 * p); |
| 206 | static int __must_check acpi_ec_write(int i, u8 v); |
| 207 | static int __must_check _sta(acpi_handle handle); |
| 208 | |
| 209 | /* ACPI handles */ |
| 210 | static acpi_handle root_handle; /* root namespace */ |
| 211 | static acpi_handle ec_handle; /* EC */ |
| 212 | static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */ |
| 213 | static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */ |
| 214 | |
| 215 | static void drv_acpi_handle_init(char *name, |
| 216 | acpi_handle *handle, acpi_handle parent, |
| 217 | char **paths, int num_paths, char **path); |
| 218 | #define IBM_ACPIHANDLE_INIT(object) \ |
| 219 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
| 220 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
| 221 | |
| 222 | /* ThinkPad ACPI helpers */ |
| 223 | static int issue_thinkpad_cmos_command(int cmos_cmd); |
| 224 | |
| 225 | /* procfs support */ |
| 226 | static struct proc_dir_entry *proc_dir; |
| 227 | |
| 228 | /* procfs helpers */ |
| 229 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 230 | int count, int *eof, void *data); |
| 231 | static int dispatch_procfs_write(struct file *file, |
| 232 | const char __user * userbuf, |
| 233 | unsigned long count, void *data); |
| 234 | static char *next_cmd(char **cmds); |
| 235 | |
| 236 | /* sysfs support */ |
| 237 | struct attribute_set { |
| 238 | unsigned int members, max_members; |
| 239 | struct attribute_group group; |
| 240 | }; |
| 241 | |
| 242 | static struct attribute_set *create_attr_set(unsigned int max_members, |
| 243 | const char* name); |
| 244 | #define destroy_attr_set(_set) \ |
| 245 | kfree(_set); |
| 246 | static int add_to_attr_set(struct attribute_set* s, struct attribute *attr); |
| 247 | static int add_many_to_attr_set(struct attribute_set* s, |
| 248 | struct attribute **attr, |
| 249 | unsigned int count); |
| 250 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 251 | sysfs_create_group(_kobj, &_attr_set->group) |
| 252 | static void delete_attr_set(struct attribute_set* s, struct kobject *kobj); |
| 253 | |
| 254 | static int parse_strtoul(const char *buf, unsigned long max, |
| 255 | unsigned long *value); |
| 256 | |
| 257 | /* Device model */ |
| 258 | static struct platform_device *tpacpi_pdev; |
| 259 | static struct platform_device *tpacpi_sensors_pdev; |
| 260 | static struct device *tpacpi_hwmon; |
| 261 | static struct platform_driver tpacpi_pdriver; |
| 262 | static struct input_dev *tpacpi_inputdev; |
| 263 | static int tpacpi_create_driver_attributes(struct device_driver *drv); |
| 264 | static void tpacpi_remove_driver_attributes(struct device_driver *drv); |
| 265 | |
| 266 | /* Module */ |
| 267 | static int experimental; |
| 268 | static u32 dbg_level; |
| 269 | static int force_load; |
| 270 | static unsigned int hotkey_report_mode; |
| 271 | |
| 272 | static int thinkpad_acpi_module_init(void); |
| 273 | static void thinkpad_acpi_module_exit(void); |
| 274 | |
| 275 | |
| 276 | /**************************************************************************** |
| 277 | * Subdrivers |
| 278 | */ |
| 279 | |
| 280 | struct ibm_struct; |
| 281 | |
| 282 | struct tp_acpi_drv_struct { |
| 283 | const struct acpi_device_id *hid; |
| 284 | struct acpi_driver *driver; |
| 285 | |
| 286 | void (*notify) (struct ibm_struct *, u32); |
| 287 | acpi_handle *handle; |
| 288 | u32 type; |
| 289 | struct acpi_device *device; |
| 290 | }; |
| 291 | |
| 292 | struct ibm_struct { |
| 293 | char *name; |
| 294 | |
| 295 | int (*read) (char *); |
| 296 | int (*write) (char *); |
| 297 | void (*exit) (void); |
| 298 | void (*resume) (void); |
| 299 | |
| 300 | struct list_head all_drivers; |
| 301 | |
| 302 | struct tp_acpi_drv_struct *acpi; |
| 303 | |
| 304 | struct { |
| 305 | u8 acpi_driver_registered:1; |
| 306 | u8 acpi_notify_installed:1; |
| 307 | u8 proc_created:1; |
| 308 | u8 init_called:1; |
| 309 | u8 experimental:1; |
| 310 | } flags; |
| 311 | }; |
| 312 | |
| 313 | struct ibm_init_struct { |
| 314 | char param[32]; |
| 315 | |
| 316 | int (*init) (struct ibm_init_struct *); |
| 317 | struct ibm_struct *data; |
| 318 | }; |
| 319 | |
| 320 | static struct { |
| 321 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 322 | u32 bay_status:1; |
| 323 | u32 bay_eject:1; |
| 324 | u32 bay_status2:1; |
| 325 | u32 bay_eject2:1; |
| 326 | #endif |
| 327 | u32 bluetooth:1; |
| 328 | u32 hotkey:1; |
| 329 | u32 hotkey_mask:1; |
| 330 | u32 hotkey_wlsw:1; |
| 331 | u32 light:1; |
| 332 | u32 light_status:1; |
| 333 | u32 bright_16levels:1; |
| 334 | u32 wan:1; |
| 335 | u32 fan_ctrl_status_undef:1; |
| 336 | u32 input_device_registered:1; |
| 337 | u32 platform_drv_registered:1; |
| 338 | u32 platform_drv_attrs_registered:1; |
| 339 | u32 sensors_pdrv_registered:1; |
| 340 | u32 sensors_pdrv_attrs_registered:1; |
| 341 | u32 sensors_pdev_attrs_registered:1; |
| 342 | u32 hotkey_poll_active:1; |
| 343 | } tp_features; |
| 344 | |
| 345 | struct thinkpad_id_data { |
| 346 | unsigned int vendor; /* ThinkPad vendor: |
| 347 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 348 | |
| 349 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 350 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 351 | |
| 352 | u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */ |
| 353 | u16 ec_model; |
| 354 | |
| 355 | char *model_str; |
| 356 | }; |
| 357 | |
| 358 | static struct thinkpad_id_data thinkpad_id; |
| 359 | |
| 360 | static struct list_head tpacpi_all_drivers; |
| 361 | |
| 362 | static struct ibm_init_struct ibms_init[]; |
| 363 | static int set_ibm_param(const char *val, struct kernel_param *kp); |
| 364 | static int ibm_init(struct ibm_init_struct *iibm); |
| 365 | static void ibm_exit(struct ibm_struct *ibm); |
| 366 | |
| 367 | |
| 368 | /* |
| 369 | * procfs master subdriver |
| 370 | */ |
| 371 | static int thinkpad_acpi_driver_init(struct ibm_init_struct *iibm); |
| 372 | static int thinkpad_acpi_driver_read(char *p); |
| 373 | |
| 374 | |
| 375 | /* |
| 376 | * Bay subdriver |
| 377 | */ |
| 378 | |
| 379 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 380 | static acpi_handle bay_handle, bay_ej_handle; |
| 381 | static acpi_handle bay2_handle, bay2_ej_handle; |
| 382 | |
| 383 | static int bay_init(struct ibm_init_struct *iibm); |
| 384 | static void bay_notify(struct ibm_struct *ibm, u32 event); |
| 385 | static int bay_read(char *p); |
| 386 | static int bay_write(char *buf); |
| 387 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
| 388 | |
| 389 | |
| 390 | /* |
| 391 | * Beep subdriver |
| 392 | */ |
| 393 | |
| 394 | static acpi_handle beep_handle; |
| 395 | |
| 396 | static int beep_read(char *p); |
| 397 | static int beep_write(char *buf); |
| 398 | |
| 399 | |
| 400 | /* |
| 401 | * Bluetooth subdriver |
| 402 | */ |
| 403 | |
| 404 | enum { |
| 405 | /* ACPI GBDC/SBDC bits */ |
| 406 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 407 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
| 408 | TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */ |
| 409 | }; |
| 410 | |
| 411 | static int bluetooth_init(struct ibm_init_struct *iibm); |
| 412 | static int bluetooth_get_radiosw(void); |
| 413 | static int bluetooth_set_radiosw(int radio_on); |
| 414 | static int bluetooth_read(char *p); |
| 415 | static int bluetooth_write(char *buf); |
| 416 | |
| 417 | |
| 418 | /* |
| 419 | * Brightness (backlight) subdriver |
| 420 | */ |
| 421 | |
| 422 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 423 | |
| 424 | static struct backlight_device *ibm_backlight_device; |
| 425 | static int brightness_offset = 0x31; |
| 426 | static int brightness_mode; |
| 427 | static unsigned int brightness_enable; /* 0 = no, 1 = yes, 2 = auto */ |
| 428 | |
| 429 | static int brightness_init(struct ibm_init_struct *iibm); |
| 430 | static void brightness_exit(void); |
| 431 | static int brightness_get(struct backlight_device *bd); |
| 432 | static int brightness_set(int value); |
| 433 | static int brightness_update_status(struct backlight_device *bd); |
| 434 | static int brightness_read(char *p); |
| 435 | static int brightness_write(char *buf); |
| 436 | |
| 437 | |
| 438 | /* |
| 439 | * CMOS subdriver |
| 440 | */ |
| 441 | |
| 442 | static int cmos_read(char *p); |
| 443 | static int cmos_write(char *buf); |
| 444 | |
| 445 | |
| 446 | /* |
| 447 | * Dock subdriver |
| 448 | */ |
| 449 | |
| 450 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
| 451 | static acpi_handle pci_handle; |
| 452 | static acpi_handle dock_handle; |
| 453 | |
| 454 | static void dock_notify(struct ibm_struct *ibm, u32 event); |
| 455 | static int dock_read(char *p); |
| 456 | static int dock_write(char *buf); |
| 457 | #endif /* CONFIG_THINKPAD_ACPI_DOCK */ |
| 458 | |
| 459 | |
| 460 | /* |
| 461 | * EC dump subdriver |
| 462 | */ |
| 463 | |
| 464 | static int ecdump_read(char *p) ; |
| 465 | static int ecdump_write(char *buf); |
| 466 | |
| 467 | |
| 468 | /* |
| 469 | * Fan subdriver |
| 470 | */ |
| 471 | |
| 472 | enum { /* Fan control constants */ |
| 473 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 474 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 475 | * 0x84 must be read before 0x85 */ |
| 476 | |
| 477 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 478 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 479 | |
| 480 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 481 | }; |
| 482 | |
| 483 | enum fan_status_access_mode { |
| 484 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 485 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 486 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 487 | }; |
| 488 | |
| 489 | enum fan_control_access_mode { |
| 490 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 491 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 492 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 493 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 494 | }; |
| 495 | |
| 496 | enum fan_control_commands { |
| 497 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 498 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 499 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 500 | * and also watchdog cmd */ |
| 501 | }; |
| 502 | |
| 503 | static int fan_control_allowed; |
| 504 | |
| 505 | static enum fan_status_access_mode fan_status_access_mode; |
| 506 | static enum fan_control_access_mode fan_control_access_mode; |
| 507 | static enum fan_control_commands fan_control_commands; |
| 508 | static u8 fan_control_initial_status; |
| 509 | static u8 fan_control_desired_level; |
| 510 | static int fan_watchdog_maxinterval; |
| 511 | |
| 512 | static struct mutex fan_mutex; |
| 513 | |
| 514 | static acpi_handle fans_handle, gfan_handle, sfan_handle; |
| 515 | |
| 516 | static int fan_init(struct ibm_init_struct *iibm); |
| 517 | static void fan_exit(void); |
| 518 | static int fan_get_status(u8 *status); |
| 519 | static int fan_get_status_safe(u8 *status); |
| 520 | static int fan_get_speed(unsigned int *speed); |
| 521 | static void fan_update_desired_level(u8 status); |
| 522 | static void fan_watchdog_fire(struct work_struct *ignored); |
| 523 | static void fan_watchdog_reset(void); |
| 524 | static int fan_set_level(int level); |
| 525 | static int fan_set_level_safe(int level); |
| 526 | static int fan_set_enable(void); |
| 527 | static int fan_set_disable(void); |
| 528 | static int fan_set_speed(int speed); |
| 529 | static int fan_read(char *p); |
| 530 | static int fan_write(char *buf); |
| 531 | static int fan_write_cmd_level(const char *cmd, int *rc); |
| 532 | static int fan_write_cmd_enable(const char *cmd, int *rc); |
| 533 | static int fan_write_cmd_disable(const char *cmd, int *rc); |
| 534 | static int fan_write_cmd_speed(const char *cmd, int *rc); |
| 535 | static int fan_write_cmd_watchdog(const char *cmd, int *rc); |
| 536 | |
| 537 | |
| 538 | /* |
| 539 | * Hotkey subdriver |
| 540 | */ |
| 541 | |
| 542 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 543 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 544 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 545 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 546 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 547 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 548 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 549 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 550 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 551 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 552 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 553 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 554 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 555 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 556 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 557 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 558 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 559 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 560 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 561 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 562 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 563 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 564 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 565 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 566 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 567 | }; |
| 568 | |
| 569 | static int hotkey_orig_status; |
| 570 | static u32 hotkey_orig_mask; |
| 571 | |
| 572 | static struct mutex hotkey_mutex; |
| 573 | |
| 574 | static int hotkey_init(struct ibm_init_struct *iibm); |
| 575 | static void hotkey_exit(void); |
| 576 | static void hotkey_notify(struct ibm_struct *ibm, u32 event); |
| 577 | static int hotkey_read(char *p); |
| 578 | static int hotkey_write(char *buf); |
| 579 | |
| 580 | |
| 581 | /* |
| 582 | * LED subdriver |
| 583 | */ |
| 584 | |
| 585 | enum led_access_mode { |
| 586 | TPACPI_LED_NONE = 0, |
| 587 | TPACPI_LED_570, /* 570 */ |
| 588 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 589 | TPACPI_LED_NEW, /* all others */ |
| 590 | }; |
| 591 | |
| 592 | enum { /* For TPACPI_LED_OLD */ |
| 593 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 594 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 595 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 596 | }; |
| 597 | |
| 598 | static enum led_access_mode led_supported; |
| 599 | static acpi_handle led_handle; |
| 600 | |
| 601 | static int led_init(struct ibm_init_struct *iibm); |
| 602 | static int led_read(char *p); |
| 603 | static int led_write(char *buf); |
| 604 | |
| 605 | /* |
| 606 | * Light (thinklight) subdriver |
| 607 | */ |
| 608 | |
| 609 | static acpi_handle lght_handle, ledb_handle; |
| 610 | |
| 611 | static int light_init(struct ibm_init_struct *iibm); |
| 612 | static int light_read(char *p); |
| 613 | static int light_write(char *buf); |
| 614 | |
| 615 | |
| 616 | /* |
| 617 | * Thermal subdriver |
| 618 | */ |
| 619 | |
| 620 | enum thermal_access_mode { |
| 621 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 622 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 623 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 624 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 625 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 626 | }; |
| 627 | |
| 628 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 629 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 630 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 631 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
| 632 | }; |
| 633 | |
| 634 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 635 | struct ibm_thermal_sensors_struct { |
| 636 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 637 | }; |
| 638 | |
| 639 | static enum thermal_access_mode thermal_read_mode; |
| 640 | |
| 641 | static int thermal_init(struct ibm_init_struct *iibm); |
| 642 | static int thermal_get_sensor(int idx, s32 *value); |
| 643 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s); |
| 644 | static int thermal_read(char *p); |
| 645 | |
| 646 | |
| 647 | /* |
| 648 | * Video subdriver |
| 649 | */ |
| 650 | |
| 651 | enum video_access_mode { |
| 652 | TPACPI_VIDEO_NONE = 0, |
| 653 | TPACPI_VIDEO_570, /* 570 */ |
| 654 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 655 | TPACPI_VIDEO_NEW, /* all others */ |
| 656 | }; |
| 657 | |
| 658 | enum { /* video status flags, based on VIDEO_570 */ |
| 659 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 660 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 661 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 662 | }; |
| 663 | |
| 664 | enum { /* TPACPI_VIDEO_570 constants */ |
| 665 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 666 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 667 | * video_status_flags */ |
| 668 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 669 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 670 | }; |
| 671 | |
| 672 | static enum video_access_mode video_supported; |
| 673 | static int video_orig_autosw; |
| 674 | static acpi_handle vid_handle, vid2_handle; |
| 675 | |
| 676 | static int video_init(struct ibm_init_struct *iibm); |
| 677 | static void video_exit(void); |
| 678 | static int video_outputsw_get(void); |
| 679 | static int video_outputsw_set(int status); |
| 680 | static int video_autosw_get(void); |
| 681 | static int video_autosw_set(int enable); |
| 682 | static int video_outputsw_cycle(void); |
| 683 | static int video_expand_toggle(void); |
| 684 | static int video_read(char *p); |
| 685 | static int video_write(char *buf); |
| 686 | |
| 687 | |
| 688 | /* |
| 689 | * Volume subdriver |
| 690 | */ |
| 691 | |
| 692 | static int volume_offset = 0x30; |
| 693 | |
| 694 | static int volume_read(char *p); |
| 695 | static int volume_write(char *buf); |
| 696 | |
| 697 | |
| 698 | /* |
| 699 | * Wan subdriver |
| 700 | */ |
| 701 | |
| 702 | enum { |
| 703 | /* ACPI GWAN/SWAN bits */ |
| 704 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 705 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
| 706 | TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */ |
| 707 | }; |
| 708 | |
| 709 | static int wan_init(struct ibm_init_struct *iibm); |
| 710 | static int wan_get_radiosw(void); |
| 711 | static int wan_set_radiosw(int radio_on); |
| 712 | static int wan_read(char *p); |
| 713 | static int wan_write(char *buf); |
| 714 | |
| 715 | /* ==================================================== END HEADER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 717 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 718 | MODULE_DESCRIPTION(IBM_DESC); |
| 719 | MODULE_VERSION(IBM_VERSION); |
| 720 | MODULE_LICENSE("GPL"); |
| 721 | |
Henrique de Moraes Holschuh | d903ac5 | 2007-03-29 01:58:42 -0300 | [diff] [blame] | 722 | /* Please remove this in year 2009 */ |
| 723 | MODULE_ALIAS("ibm_acpi"); |
| 724 | |
Henrique de Moraes Holschuh | b964b43 | 2007-07-18 23:45:26 -0300 | [diff] [blame] | 725 | /* |
| 726 | * DMI matching for module autoloading |
| 727 | * |
| 728 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 729 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 730 | * |
| 731 | * Only models listed in thinkwiki will be supported, so add yours |
| 732 | * if it is not there yet. |
| 733 | */ |
| 734 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
| 735 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW") |
| 736 | |
| 737 | /* Non-ancient thinkpads */ |
| 738 | MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*"); |
| 739 | MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*"); |
| 740 | |
| 741 | /* Ancient thinkpad BIOSes have to be identified by |
| 742 | * BIOS type or model number, and there are far less |
| 743 | * BIOS types than model numbers... */ |
| 744 | IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]"); |
| 745 | IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]"); |
| 746 | IBM_BIOS_MODULE_ALIAS("K[U,X-Z]"); |
| 747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | #define __unused __attribute__ ((unused)) |
| 749 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 750 | static enum { |
| 751 | TPACPI_LIFE_INIT = 0, |
| 752 | TPACPI_LIFE_RUNNING, |
| 753 | TPACPI_LIFE_EXITING, |
| 754 | } tpacpi_lifecycle; |
| 755 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 756 | /**************************************************************************** |
| 757 | **************************************************************************** |
| 758 | * |
| 759 | * ACPI Helpers and device model |
| 760 | * |
| 761 | **************************************************************************** |
| 762 | ****************************************************************************/ |
| 763 | |
| 764 | /************************************************************************* |
| 765 | * ACPI basic handles |
| 766 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 768 | static acpi_handle root_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
| 770 | #define IBM_HANDLE(object, parent, paths...) \ |
| 771 | static acpi_handle object##_handle; \ |
| 772 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 773 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | static char *object##_paths[] = { paths } |
| 775 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 776 | IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
| 777 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 778 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 779 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 780 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 781 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 782 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 783 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 785 | IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 786 | IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 788 | |
| 789 | /************************************************************************* |
| 790 | * Misc ACPI handles |
| 791 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 793 | IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */ |
| 794 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 795 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 796 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 797 | |
| 798 | IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
| 799 | "^HKEY", /* R30, R31 */ |
| 800 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 801 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 802 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 803 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 804 | /************************************************************************* |
| 805 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 806 | */ |
| 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | static int acpi_evalf(acpi_handle handle, |
| 809 | void *res, char *method, char *fmt, ...) |
| 810 | { |
| 811 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 812 | struct acpi_object_list params; |
| 813 | union acpi_object in_objs[IBM_MAX_ACPI_ARGS]; |
| 814 | struct acpi_buffer result, *resultp; |
| 815 | union acpi_object out_obj; |
| 816 | acpi_status status; |
| 817 | va_list ap; |
| 818 | char res_type; |
| 819 | int success; |
| 820 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
| 822 | if (!*fmt) { |
| 823 | printk(IBM_ERR "acpi_evalf() called with empty format\n"); |
| 824 | return 0; |
| 825 | } |
| 826 | |
| 827 | if (*fmt == 'q') { |
| 828 | quiet = 1; |
| 829 | fmt++; |
| 830 | } else |
| 831 | quiet = 0; |
| 832 | |
| 833 | res_type = *(fmt++); |
| 834 | |
| 835 | params.count = 0; |
| 836 | params.pointer = &in_objs[0]; |
| 837 | |
| 838 | va_start(ap, fmt); |
| 839 | while (*fmt) { |
| 840 | char c = *(fmt++); |
| 841 | switch (c) { |
| 842 | case 'd': /* int */ |
| 843 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 844 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 845 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 846 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | default: |
| 848 | printk(IBM_ERR "acpi_evalf() called " |
| 849 | "with invalid format character '%c'\n", c); |
| 850 | return 0; |
| 851 | } |
| 852 | } |
| 853 | va_end(ap); |
| 854 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 855 | if (res_type != 'v') { |
| 856 | result.length = sizeof(out_obj); |
| 857 | result.pointer = &out_obj; |
| 858 | resultp = &result; |
| 859 | } else |
| 860 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 862 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 865 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | if (res) |
| 867 | *(int *)res = out_obj.integer.value; |
| 868 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 869 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 870 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | success = status == AE_OK; |
| 872 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 873 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | default: |
| 875 | printk(IBM_ERR "acpi_evalf() called " |
| 876 | "with invalid format character '%c'\n", res_type); |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | if (!success && !quiet) |
| 881 | printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
| 882 | method, fmt0, status); |
| 883 | |
| 884 | return success; |
| 885 | } |
| 886 | |
| 887 | static void __unused acpi_print_int(acpi_handle handle, char *method) |
| 888 | { |
| 889 | int i; |
| 890 | |
| 891 | if (acpi_evalf(handle, &i, method, "d")) |
| 892 | printk(IBM_INFO "%s = 0x%x\n", method, i); |
| 893 | else |
| 894 | printk(IBM_ERR "error calling %s\n", method); |
| 895 | } |
| 896 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 897 | static int acpi_ec_read(int i, u8 * p) |
| 898 | { |
| 899 | int v; |
| 900 | |
| 901 | if (ecrd_handle) { |
| 902 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 903 | return 0; |
| 904 | *p = v; |
| 905 | } else { |
| 906 | if (ec_read(i, p) < 0) |
| 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | return 1; |
| 911 | } |
| 912 | |
| 913 | static int acpi_ec_write(int i, u8 v) |
| 914 | { |
| 915 | if (ecwr_handle) { |
| 916 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 917 | return 0; |
| 918 | } else { |
| 919 | if (ec_write(i, v) < 0) |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | return 1; |
| 924 | } |
| 925 | |
| 926 | static int _sta(acpi_handle handle) |
| 927 | { |
| 928 | int status; |
| 929 | |
| 930 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) |
| 931 | status = 0; |
| 932 | |
| 933 | return status; |
| 934 | } |
| 935 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 936 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 937 | { |
| 938 | if (!cmos_handle) |
| 939 | return -ENXIO; |
| 940 | |
| 941 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 942 | return -EIO; |
| 943 | |
| 944 | return 0; |
| 945 | } |
| 946 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 947 | /************************************************************************* |
| 948 | * ACPI device model |
| 949 | */ |
| 950 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 951 | static void drv_acpi_handle_init(char *name, |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 952 | acpi_handle *handle, acpi_handle parent, |
| 953 | char **paths, int num_paths, char **path) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 954 | { |
| 955 | int i; |
| 956 | acpi_status status; |
| 957 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 958 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 959 | name); |
| 960 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 961 | for (i = 0; i < num_paths; i++) { |
| 962 | status = acpi_get_handle(parent, paths[i], handle); |
| 963 | if (ACPI_SUCCESS(status)) { |
| 964 | *path = paths[i]; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 965 | dbg_printk(TPACPI_DBG_INIT, |
| 966 | "Found ACPI handle %s for %s\n", |
| 967 | *path, name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 968 | return; |
| 969 | } |
| 970 | } |
| 971 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 972 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 973 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 974 | *handle = NULL; |
| 975 | } |
| 976 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 977 | 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] | 978 | { |
| 979 | struct ibm_struct *ibm = data; |
| 980 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 981 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 982 | return; |
| 983 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 984 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 985 | return; |
| 986 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 987 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 988 | } |
| 989 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 990 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 991 | { |
| 992 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 993 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 994 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 995 | BUG_ON(!ibm->acpi); |
| 996 | |
| 997 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 998 | return 0; |
| 999 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 1000 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1001 | "setting up ACPI notify for %s\n", ibm->name); |
| 1002 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 1003 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 1004 | if (rc < 0) { |
| 1005 | printk(IBM_ERR "acpi_bus_get_device(%s) failed: %d\n", |
| 1006 | ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1007 | return -ENODEV; |
| 1008 | } |
| 1009 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1010 | acpi_driver_data(ibm->acpi->device) = ibm; |
| 1011 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1012 | IBM_ACPI_EVENT_PREFIX, |
| 1013 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1014 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1015 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 1016 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1017 | if (ACPI_FAILURE(status)) { |
| 1018 | if (status == AE_ALREADY_EXISTS) { |
| 1019 | printk(IBM_NOTICE "another device driver is already handling %s events\n", |
| 1020 | ibm->name); |
| 1021 | } else { |
| 1022 | printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n", |
| 1023 | ibm->name, status); |
| 1024 | } |
| 1025 | return -ENODEV; |
| 1026 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1027 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1028 | return 0; |
| 1029 | } |
| 1030 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1031 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1032 | { |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 1036 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1037 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 1038 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1039 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1040 | dbg_printk(TPACPI_DBG_INIT, |
| 1041 | "registering %s as an ACPI driver\n", ibm->name); |
| 1042 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1043 | BUG_ON(!ibm->acpi); |
| 1044 | |
| 1045 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 1046 | if (!ibm->acpi->driver) { |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1047 | printk(IBM_ERR "kzalloc(ibm->driver) failed\n"); |
| 1048 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1049 | } |
| 1050 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1051 | sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name); |
| 1052 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 1053 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1054 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1055 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 1056 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 1057 | if (rc < 0) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1058 | printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 1059 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1060 | kfree(ibm->acpi->driver); |
| 1061 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 1062 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1063 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1064 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 1065 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | /**************************************************************************** |
| 1070 | **************************************************************************** |
| 1071 | * |
| 1072 | * Procfs Helpers |
| 1073 | * |
| 1074 | **************************************************************************** |
| 1075 | ****************************************************************************/ |
| 1076 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1077 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 1078 | int count, int *eof, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1079 | { |
| 1080 | struct ibm_struct *ibm = data; |
| 1081 | int len; |
| 1082 | |
| 1083 | if (!ibm || !ibm->read) |
| 1084 | return -EINVAL; |
| 1085 | |
| 1086 | len = ibm->read(page); |
| 1087 | if (len < 0) |
| 1088 | return len; |
| 1089 | |
| 1090 | if (len <= off + count) |
| 1091 | *eof = 1; |
| 1092 | *start = page + off; |
| 1093 | len -= off; |
| 1094 | if (len > count) |
| 1095 | len = count; |
| 1096 | if (len < 0) |
| 1097 | len = 0; |
| 1098 | |
| 1099 | return len; |
| 1100 | } |
| 1101 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1102 | static int dispatch_procfs_write(struct file *file, |
| 1103 | const char __user * userbuf, |
| 1104 | unsigned long count, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1105 | { |
| 1106 | struct ibm_struct *ibm = data; |
| 1107 | char *kernbuf; |
| 1108 | int ret; |
| 1109 | |
| 1110 | if (!ibm || !ibm->write) |
| 1111 | return -EINVAL; |
| 1112 | |
| 1113 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 1114 | if (!kernbuf) |
| 1115 | return -ENOMEM; |
| 1116 | |
| 1117 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 1118 | kfree(kernbuf); |
| 1119 | return -EFAULT; |
| 1120 | } |
| 1121 | |
| 1122 | kernbuf[count] = 0; |
| 1123 | strcat(kernbuf, ","); |
| 1124 | ret = ibm->write(kernbuf); |
| 1125 | if (ret == 0) |
| 1126 | ret = count; |
| 1127 | |
| 1128 | kfree(kernbuf); |
| 1129 | |
| 1130 | return ret; |
| 1131 | } |
| 1132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | static char *next_cmd(char **cmds) |
| 1134 | { |
| 1135 | char *start = *cmds; |
| 1136 | char *end; |
| 1137 | |
| 1138 | while ((end = strchr(start, ',')) && end == start) |
| 1139 | start = end + 1; |
| 1140 | |
| 1141 | if (!end) |
| 1142 | return NULL; |
| 1143 | |
| 1144 | *end = 0; |
| 1145 | *cmds = end + 1; |
| 1146 | return start; |
| 1147 | } |
| 1148 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1149 | |
| 1150 | /**************************************************************************** |
| 1151 | **************************************************************************** |
| 1152 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 1153 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1154 | * |
| 1155 | **************************************************************************** |
| 1156 | ****************************************************************************/ |
| 1157 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 1158 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 1159 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1160 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 1161 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 1162 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1163 | |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 1164 | |
| 1165 | static int tpacpi_resume_handler(struct platform_device *pdev) |
| 1166 | { |
| 1167 | struct ibm_struct *ibm, *itmp; |
| 1168 | |
| 1169 | list_for_each_entry_safe(ibm, itmp, |
| 1170 | &tpacpi_all_drivers, |
| 1171 | all_drivers) { |
| 1172 | if (ibm->resume) |
| 1173 | (ibm->resume)(); |
| 1174 | } |
| 1175 | |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1179 | static struct platform_driver tpacpi_pdriver = { |
| 1180 | .driver = { |
| 1181 | .name = IBM_DRVR_NAME, |
| 1182 | .owner = THIS_MODULE, |
| 1183 | }, |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 1184 | .resume = tpacpi_resume_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1185 | }; |
| 1186 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 1187 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 1188 | .driver = { |
| 1189 | .name = IBM_HWMON_DRVR_NAME, |
| 1190 | .owner = THIS_MODULE, |
| 1191 | }, |
| 1192 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1193 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 1194 | /************************************************************************* |
| 1195 | * thinkpad-acpi driver attributes |
| 1196 | */ |
| 1197 | |
| 1198 | /* interface_version --------------------------------------------------- */ |
| 1199 | static ssize_t tpacpi_driver_interface_version_show( |
| 1200 | struct device_driver *drv, |
| 1201 | char *buf) |
| 1202 | { |
| 1203 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 1204 | } |
| 1205 | |
| 1206 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 1207 | tpacpi_driver_interface_version_show, NULL); |
| 1208 | |
| 1209 | /* debug_level --------------------------------------------------------- */ |
| 1210 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 1211 | char *buf) |
| 1212 | { |
| 1213 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 1214 | } |
| 1215 | |
| 1216 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 1217 | const char *buf, size_t count) |
| 1218 | { |
| 1219 | unsigned long t; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 1220 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1221 | if (parse_strtoul(buf, 0xffff, &t)) |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 1222 | return -EINVAL; |
| 1223 | |
| 1224 | dbg_level = t; |
| 1225 | |
| 1226 | return count; |
| 1227 | } |
| 1228 | |
| 1229 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1230 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 1231 | |
| 1232 | /* version ------------------------------------------------------------- */ |
| 1233 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 1234 | char *buf) |
| 1235 | { |
| 1236 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", IBM_DESC, IBM_VERSION); |
| 1237 | } |
| 1238 | |
| 1239 | static DRIVER_ATTR(version, S_IRUGO, |
| 1240 | tpacpi_driver_version_show, NULL); |
| 1241 | |
| 1242 | /* --------------------------------------------------------------------- */ |
| 1243 | |
| 1244 | static struct driver_attribute* tpacpi_driver_attributes[] = { |
| 1245 | &driver_attr_debug_level, &driver_attr_version, |
| 1246 | &driver_attr_interface_version, |
| 1247 | }; |
| 1248 | |
| 1249 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 1250 | { |
| 1251 | int i, res; |
| 1252 | |
| 1253 | i = 0; |
| 1254 | res = 0; |
| 1255 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 1256 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 1257 | i++; |
| 1258 | } |
| 1259 | |
| 1260 | return res; |
| 1261 | } |
| 1262 | |
| 1263 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 1264 | { |
| 1265 | int i; |
| 1266 | |
| 1267 | for(i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
| 1268 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
| 1269 | } |
| 1270 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1271 | /************************************************************************* |
| 1272 | * sysfs support helpers |
| 1273 | */ |
| 1274 | |
| 1275 | struct attribute_set_obj { |
| 1276 | struct attribute_set s; |
| 1277 | struct attribute *a; |
| 1278 | } __attribute__((packed)); |
| 1279 | |
| 1280 | static struct attribute_set *create_attr_set(unsigned int max_members, |
| 1281 | const char* name) |
| 1282 | { |
| 1283 | struct attribute_set_obj *sobj; |
| 1284 | |
| 1285 | if (max_members == 0) |
| 1286 | return NULL; |
| 1287 | |
| 1288 | /* Allocates space for implicit NULL at the end too */ |
| 1289 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 1290 | max_members * sizeof(struct attribute *), |
| 1291 | GFP_KERNEL); |
| 1292 | if (!sobj) |
| 1293 | return NULL; |
| 1294 | sobj->s.max_members = max_members; |
| 1295 | sobj->s.group.attrs = &sobj->a; |
| 1296 | sobj->s.group.name = name; |
| 1297 | |
| 1298 | return &sobj->s; |
| 1299 | } |
| 1300 | |
| 1301 | /* not multi-threaded safe, use it in a single thread per set */ |
| 1302 | static int add_to_attr_set(struct attribute_set* s, struct attribute *attr) |
| 1303 | { |
| 1304 | if (!s || !attr) |
| 1305 | return -EINVAL; |
| 1306 | |
| 1307 | if (s->members >= s->max_members) |
| 1308 | return -ENOMEM; |
| 1309 | |
| 1310 | s->group.attrs[s->members] = attr; |
| 1311 | s->members++; |
| 1312 | |
| 1313 | return 0; |
| 1314 | } |
| 1315 | |
| 1316 | static int add_many_to_attr_set(struct attribute_set* s, |
| 1317 | struct attribute **attr, |
| 1318 | unsigned int count) |
| 1319 | { |
| 1320 | int i, res; |
| 1321 | |
| 1322 | for (i = 0; i < count; i++) { |
| 1323 | res = add_to_attr_set(s, attr[i]); |
| 1324 | if (res) |
| 1325 | return res; |
| 1326 | } |
| 1327 | |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
| 1331 | static void delete_attr_set(struct attribute_set* s, struct kobject *kobj) |
| 1332 | { |
| 1333 | sysfs_remove_group(kobj, &s->group); |
| 1334 | destroy_attr_set(s); |
| 1335 | } |
| 1336 | |
| 1337 | static int parse_strtoul(const char *buf, |
| 1338 | unsigned long max, unsigned long *value) |
| 1339 | { |
| 1340 | char *endp; |
| 1341 | |
Henrique de Moraes Holschuh | 32afbf0 | 2007-10-08 10:12:56 -0300 | [diff] [blame] | 1342 | while (*buf && isspace(*buf)) |
| 1343 | buf++; |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 1344 | *value = simple_strtoul(buf, &endp, 0); |
| 1345 | while (*endp && isspace(*endp)) |
| 1346 | endp++; |
| 1347 | if (*endp || *value > max) |
| 1348 | return -EINVAL; |
| 1349 | |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 1353 | /**************************************************************************** |
| 1354 | **************************************************************************** |
| 1355 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1356 | * Subdrivers |
| 1357 | * |
| 1358 | **************************************************************************** |
| 1359 | ****************************************************************************/ |
| 1360 | |
| 1361 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 1362 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1363 | */ |
| 1364 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1365 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | { |
| 1367 | printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); |
| 1368 | printk(IBM_INFO "%s\n", IBM_URL); |
| 1369 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1370 | printk(IBM_INFO "ThinkPad BIOS %s, EC %s\n", |
| 1371 | (thinkpad_id.bios_version_str) ? |
| 1372 | thinkpad_id.bios_version_str : "unknown", |
| 1373 | (thinkpad_id.ec_version_str) ? |
| 1374 | thinkpad_id.ec_version_str : "unknown"); |
| 1375 | |
| 1376 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
| 1377 | printk(IBM_INFO "%s %s\n", |
| 1378 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 1379 | "IBM" : ((thinkpad_id.vendor == |
| 1380 | PCI_VENDOR_ID_LENOVO) ? |
| 1381 | "Lenovo" : "Unknown vendor"), |
| 1382 | thinkpad_id.model_str); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 1383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | return 0; |
| 1385 | } |
| 1386 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1387 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | { |
| 1389 | int len = 0; |
| 1390 | |
| 1391 | len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC); |
| 1392 | len += sprintf(p + len, "version:\t%s\n", IBM_VERSION); |
| 1393 | |
| 1394 | return len; |
| 1395 | } |
| 1396 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1397 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1398 | .name = "driver", |
| 1399 | .read = thinkpad_acpi_driver_read, |
| 1400 | }; |
| 1401 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1402 | /************************************************************************* |
| 1403 | * Hotkey subdriver |
| 1404 | */ |
| 1405 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1406 | enum { /* Keys available through NVRAM polling */ |
| 1407 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1408 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1409 | }; |
| 1410 | |
| 1411 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1412 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1413 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1414 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1415 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1416 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1417 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1418 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1419 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1420 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1421 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1422 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1423 | }; |
| 1424 | |
| 1425 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1426 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1427 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1428 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1429 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1430 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1431 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1432 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1433 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1434 | TP_ACPI_HKEY_MUTE_MASK, |
| 1435 | }; |
| 1436 | |
| 1437 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1438 | struct tp_nvram_state { |
| 1439 | u16 thinkpad_toggle:1; |
| 1440 | u16 zoom_toggle:1; |
| 1441 | u16 display_toggle:1; |
| 1442 | u16 thinklight_toggle:1; |
| 1443 | u16 hibernate_toggle:1; |
| 1444 | u16 displayexp_toggle:1; |
| 1445 | u16 display_state:1; |
| 1446 | u16 brightness_toggle:1; |
| 1447 | u16 volume_toggle:1; |
| 1448 | u16 mute:1; |
| 1449 | |
| 1450 | u8 brightness_level; |
| 1451 | u8 volume_level; |
| 1452 | }; |
| 1453 | |
| 1454 | static struct task_struct *tpacpi_hotkey_task; |
| 1455 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 1456 | static int hotkey_poll_freq = 10; /* Hz */ |
| 1457 | static struct mutex hotkey_thread_mutex; |
| 1458 | static struct mutex hotkey_thread_data_mutex; |
| 1459 | static unsigned int hotkey_config_change; |
| 1460 | |
| 1461 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1462 | |
| 1463 | #define hotkey_source_mask 0U |
| 1464 | |
| 1465 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1466 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1467 | static int hotkey_orig_status; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1468 | static u32 hotkey_orig_mask; |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1469 | static u32 hotkey_all_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1470 | static u32 hotkey_reserved_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1471 | static u32 hotkey_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1472 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1473 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1474 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 1475 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1476 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1477 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1478 | #define HOTKEY_CONFIG_CRITICAL_START \ |
| 1479 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 1480 | hotkey_config_change++; |
| 1481 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 1482 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1483 | #else |
| 1484 | #define HOTKEY_CONFIG_CRITICAL_START |
| 1485 | #define HOTKEY_CONFIG_CRITICAL_END |
| 1486 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1487 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1488 | static int hotkey_get_wlsw(int *status) |
| 1489 | { |
| 1490 | if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) |
| 1491 | return -EIO; |
| 1492 | return 0; |
| 1493 | } |
| 1494 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1495 | /* |
| 1496 | * Call with hotkey_mutex held |
| 1497 | */ |
| 1498 | static int hotkey_mask_get(void) |
| 1499 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1500 | u32 m = 0; |
| 1501 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1502 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1503 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1504 | return -EIO; |
| 1505 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1506 | hotkey_mask = m | (hotkey_source_mask & hotkey_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1507 | |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
| 1511 | /* |
| 1512 | * Call with hotkey_mutex held |
| 1513 | */ |
| 1514 | static int hotkey_mask_set(u32 mask) |
| 1515 | { |
| 1516 | int i; |
| 1517 | int rc = 0; |
| 1518 | |
| 1519 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1520 | HOTKEY_CONFIG_CRITICAL_START |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1521 | for (i = 0; i < 32; i++) { |
| 1522 | u32 m = 1 << i; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1523 | /* enable in firmware mask only keys not in NVRAM |
| 1524 | * mode, but enable the key in the cached hotkey_mask |
| 1525 | * regardless of mode, or the key will end up |
| 1526 | * disabled by hotkey_mask_get() */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1527 | if (!acpi_evalf(hkey_handle, |
| 1528 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1529 | !!((mask & ~hotkey_source_mask) & m))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1530 | rc = -EIO; |
| 1531 | break; |
| 1532 | } else { |
| 1533 | hotkey_mask = (hotkey_mask & ~m) | (mask & m); |
| 1534 | } |
| 1535 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1536 | HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1537 | |
| 1538 | /* hotkey_mask_get must be called unconditionally below */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1539 | if (!hotkey_mask_get() && !rc && |
| 1540 | (hotkey_mask & ~hotkey_source_mask) != |
| 1541 | (mask & ~hotkey_source_mask)) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1542 | printk(IBM_NOTICE |
| 1543 | "requested hot key mask 0x%08x, but " |
| 1544 | "firmware forced it to 0x%08x\n", |
| 1545 | mask, hotkey_mask); |
| 1546 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1547 | } else { |
| 1548 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1549 | HOTKEY_CONFIG_CRITICAL_START |
| 1550 | hotkey_mask = mask & hotkey_source_mask; |
| 1551 | HOTKEY_CONFIG_CRITICAL_END |
| 1552 | hotkey_mask_get(); |
| 1553 | if (hotkey_mask != mask) { |
| 1554 | printk(IBM_NOTICE |
| 1555 | "requested hot key mask 0x%08x, " |
| 1556 | "forced to 0x%08x (NVRAM poll mask is " |
| 1557 | "0x%08x): no firmware mask support\n", |
| 1558 | mask, hotkey_mask, hotkey_source_mask); |
| 1559 | } |
| 1560 | #else |
| 1561 | hotkey_mask_get(); |
| 1562 | rc = -ENXIO; |
| 1563 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | return rc; |
| 1567 | } |
| 1568 | |
| 1569 | static int hotkey_status_get(int *status) |
| 1570 | { |
| 1571 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 1572 | return -EIO; |
| 1573 | |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
| 1577 | static int hotkey_status_set(int status) |
| 1578 | { |
| 1579 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) |
| 1580 | return -EIO; |
| 1581 | |
| 1582 | return 0; |
| 1583 | } |
| 1584 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1585 | static void tpacpi_input_send_radiosw(void) |
| 1586 | { |
| 1587 | int wlsw; |
| 1588 | |
| 1589 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1590 | |
| 1591 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { |
| 1592 | input_report_switch(tpacpi_inputdev, |
| 1593 | SW_RADIO, !!wlsw); |
| 1594 | input_sync(tpacpi_inputdev); |
| 1595 | } |
| 1596 | |
| 1597 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1598 | } |
| 1599 | |
| 1600 | static void tpacpi_input_send_key(unsigned int scancode) |
| 1601 | { |
| 1602 | unsigned int keycode; |
| 1603 | |
| 1604 | keycode = hotkey_keycode_map[scancode]; |
| 1605 | |
| 1606 | if (keycode != KEY_RESERVED) { |
| 1607 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1608 | |
| 1609 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 1610 | if (keycode == KEY_UNKNOWN) |
| 1611 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1612 | scancode); |
| 1613 | input_sync(tpacpi_inputdev); |
| 1614 | |
| 1615 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 1616 | if (keycode == KEY_UNKNOWN) |
| 1617 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1618 | scancode); |
| 1619 | input_sync(tpacpi_inputdev); |
| 1620 | |
| 1621 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1622 | } |
| 1623 | } |
| 1624 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1625 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1626 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 1627 | |
| 1628 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 1629 | { |
| 1630 | tpacpi_input_send_key(scancode); |
| 1631 | if (hotkey_report_mode < 2) { |
| 1632 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
| 1633 | 0x80, 0x1001 + scancode); |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m) |
| 1638 | { |
| 1639 | u8 d; |
| 1640 | |
| 1641 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 1642 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 1643 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 1644 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 1645 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 1646 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 1647 | } |
| 1648 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 1649 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 1650 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 1651 | } |
| 1652 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 1653 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 1654 | n->displayexp_toggle = |
| 1655 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 1656 | } |
| 1657 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 1658 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 1659 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 1660 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 1661 | n->brightness_toggle = |
| 1662 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 1663 | } |
| 1664 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 1665 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 1666 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 1667 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 1668 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 1669 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
| 1674 | do { if ((mask & (1 << __scancode)) && oldn->__member != newn->__member) \ |
| 1675 | tpacpi_hotkey_send_key(__scancode); } while (0) |
| 1676 | |
| 1677 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
| 1678 | do { if (mask & (1 << __scancode)) \ |
| 1679 | tpacpi_hotkey_send_key(__scancode); } while (0) |
| 1680 | |
| 1681 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
| 1682 | struct tp_nvram_state *newn, |
| 1683 | u32 mask) |
| 1684 | { |
| 1685 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 1686 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 1687 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 1688 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 1689 | |
| 1690 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 1691 | |
| 1692 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 1693 | |
| 1694 | /* handle volume */ |
| 1695 | if (oldn->volume_toggle != newn->volume_toggle) { |
| 1696 | if (oldn->mute != newn->mute) { |
| 1697 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1698 | } |
| 1699 | if (oldn->volume_level > newn->volume_level) { |
| 1700 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1701 | } else if (oldn->volume_level < newn->volume_level) { |
| 1702 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1703 | } else if (oldn->mute == newn->mute) { |
| 1704 | /* repeated key presses that didn't change state */ |
| 1705 | if (newn->mute) { |
| 1706 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1707 | } else if (newn->volume_level != 0) { |
| 1708 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1709 | } else { |
| 1710 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1711 | } |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | /* handle brightness */ |
| 1716 | if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 1717 | if (oldn->brightness_level < newn->brightness_level) { |
| 1718 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1719 | } else if (oldn->brightness_level > newn->brightness_level) { |
| 1720 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1721 | } else { |
| 1722 | /* repeated key presses that didn't change state */ |
| 1723 | if (newn->brightness_level != 0) { |
| 1724 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1725 | } else { |
| 1726 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1727 | } |
| 1728 | } |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | #undef TPACPI_COMPARE_KEY |
| 1733 | #undef TPACPI_MAY_SEND_KEY |
| 1734 | |
| 1735 | static int hotkey_kthread(void *data) |
| 1736 | { |
| 1737 | struct tp_nvram_state s[2]; |
| 1738 | u32 mask; |
| 1739 | unsigned int si, so; |
| 1740 | unsigned long t; |
| 1741 | unsigned int change_detector, must_reset; |
| 1742 | |
| 1743 | mutex_lock(&hotkey_thread_mutex); |
| 1744 | |
| 1745 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 1746 | goto exit; |
| 1747 | |
| 1748 | set_freezable(); |
| 1749 | |
| 1750 | so = 0; |
| 1751 | si = 1; |
| 1752 | t = 0; |
| 1753 | |
| 1754 | /* Initial state for compares */ |
| 1755 | mutex_lock(&hotkey_thread_data_mutex); |
| 1756 | change_detector = hotkey_config_change; |
| 1757 | mask = hotkey_source_mask & hotkey_mask; |
| 1758 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1759 | hotkey_read_nvram(&s[so], mask); |
| 1760 | |
| 1761 | while (!kthread_should_stop() && hotkey_poll_freq) { |
| 1762 | if (t == 0) |
| 1763 | t = 1000/hotkey_poll_freq; |
| 1764 | t = msleep_interruptible(t); |
| 1765 | if (unlikely(kthread_should_stop())) |
| 1766 | break; |
| 1767 | must_reset = try_to_freeze(); |
| 1768 | if (t > 0 && !must_reset) |
| 1769 | continue; |
| 1770 | |
| 1771 | mutex_lock(&hotkey_thread_data_mutex); |
| 1772 | if (must_reset || hotkey_config_change != change_detector) { |
| 1773 | /* forget old state on thaw or config change */ |
| 1774 | si = so; |
| 1775 | t = 0; |
| 1776 | change_detector = hotkey_config_change; |
| 1777 | } |
| 1778 | mask = hotkey_source_mask & hotkey_mask; |
| 1779 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1780 | |
| 1781 | if (likely(mask)) { |
| 1782 | hotkey_read_nvram(&s[si], mask); |
| 1783 | if (likely(si != so)) { |
| 1784 | hotkey_compare_and_issue_event(&s[so], &s[si], |
| 1785 | mask); |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | so = si; |
| 1790 | si ^= 1; |
| 1791 | } |
| 1792 | |
| 1793 | exit: |
| 1794 | mutex_unlock(&hotkey_thread_mutex); |
| 1795 | return 0; |
| 1796 | } |
| 1797 | |
| 1798 | static void hotkey_poll_stop_sync(void) |
| 1799 | { |
| 1800 | if (tpacpi_hotkey_task) { |
| 1801 | if (frozen(tpacpi_hotkey_task) || |
| 1802 | freezing(tpacpi_hotkey_task)) |
| 1803 | thaw_process(tpacpi_hotkey_task); |
| 1804 | |
| 1805 | kthread_stop(tpacpi_hotkey_task); |
| 1806 | tpacpi_hotkey_task = NULL; |
| 1807 | mutex_lock(&hotkey_thread_mutex); |
| 1808 | /* at this point, the thread did exit */ |
| 1809 | mutex_unlock(&hotkey_thread_mutex); |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | /* call with hotkey_mutex held */ |
| 1814 | static void hotkey_poll_setup(int may_warn) |
| 1815 | { |
| 1816 | if ((hotkey_source_mask & hotkey_mask) != 0 && |
| 1817 | hotkey_poll_freq > 0 && |
| 1818 | (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { |
| 1819 | if (!tpacpi_hotkey_task) { |
| 1820 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
| 1821 | NULL, IBM_FILE "d"); |
| 1822 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 1823 | tpacpi_hotkey_task = NULL; |
| 1824 | printk(IBM_ERR "could not create kernel thread " |
| 1825 | "for hotkey polling\n"); |
| 1826 | } |
| 1827 | } |
| 1828 | } else { |
| 1829 | hotkey_poll_stop_sync(); |
| 1830 | if (may_warn && |
| 1831 | hotkey_source_mask != 0 && hotkey_poll_freq == 0) { |
| 1832 | printk(IBM_NOTICE "hot keys 0x%08x require polling, " |
| 1833 | "which is currently disabled\n", |
| 1834 | hotkey_source_mask); |
| 1835 | } |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | static void hotkey_poll_setup_safe(int may_warn) |
| 1840 | { |
| 1841 | mutex_lock(&hotkey_mutex); |
| 1842 | hotkey_poll_setup(may_warn); |
| 1843 | mutex_unlock(&hotkey_mutex); |
| 1844 | } |
| 1845 | |
| 1846 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 1847 | { |
| 1848 | switch (tpacpi_lifecycle) { |
| 1849 | case TPACPI_LIFE_INIT: |
| 1850 | /* |
| 1851 | * hotkey_init will call hotkey_poll_setup_safe |
| 1852 | * at the appropriate moment |
| 1853 | */ |
| 1854 | return 0; |
| 1855 | case TPACPI_LIFE_EXITING: |
| 1856 | return -EBUSY; |
| 1857 | case TPACPI_LIFE_RUNNING: |
| 1858 | hotkey_poll_setup_safe(0); |
| 1859 | return 0; |
| 1860 | } |
| 1861 | |
| 1862 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 1863 | BUG(); |
| 1864 | return -EBUSY; |
| 1865 | } |
| 1866 | |
| 1867 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 1868 | { |
| 1869 | /* disable hotkey polling when possible */ |
| 1870 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING) |
| 1871 | hotkey_poll_setup_safe(0); |
| 1872 | } |
| 1873 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1874 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1875 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 1876 | static ssize_t hotkey_enable_show(struct device *dev, |
| 1877 | struct device_attribute *attr, |
| 1878 | char *buf) |
| 1879 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1880 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1881 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1882 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1883 | if (res) |
| 1884 | return res; |
| 1885 | |
| 1886 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 1887 | } |
| 1888 | |
| 1889 | static ssize_t hotkey_enable_store(struct device *dev, |
| 1890 | struct device_attribute *attr, |
| 1891 | const char *buf, size_t count) |
| 1892 | { |
| 1893 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1894 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1895 | |
| 1896 | if (parse_strtoul(buf, 1, &t)) |
| 1897 | return -EINVAL; |
| 1898 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1899 | res = hotkey_status_set(t); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1900 | |
| 1901 | return (res) ? res : count; |
| 1902 | } |
| 1903 | |
| 1904 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1905 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1906 | hotkey_enable_show, hotkey_enable_store); |
| 1907 | |
| 1908 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 1909 | static ssize_t hotkey_mask_show(struct device *dev, |
| 1910 | struct device_attribute *attr, |
| 1911 | char *buf) |
| 1912 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1913 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1914 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1915 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1916 | return -ERESTARTSYS; |
| 1917 | res = hotkey_mask_get(); |
| 1918 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1919 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1920 | return (res)? |
| 1921 | res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | static ssize_t hotkey_mask_store(struct device *dev, |
| 1925 | struct device_attribute *attr, |
| 1926 | const char *buf, size_t count) |
| 1927 | { |
| 1928 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1929 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1930 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1931 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1932 | return -EINVAL; |
| 1933 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1934 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1935 | return -ERESTARTSYS; |
| 1936 | |
| 1937 | res = hotkey_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1938 | |
| 1939 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1940 | hotkey_poll_setup(1); |
| 1941 | #endif |
| 1942 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1943 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1944 | |
| 1945 | return (res) ? res : count; |
| 1946 | } |
| 1947 | |
| 1948 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1949 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1950 | hotkey_mask_show, hotkey_mask_store); |
| 1951 | |
| 1952 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 1953 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 1954 | struct device_attribute *attr, |
| 1955 | char *buf) |
| 1956 | { |
| 1957 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status); |
| 1958 | } |
| 1959 | |
| 1960 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1961 | __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] | 1962 | |
| 1963 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 1964 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 1965 | struct device_attribute *attr, |
| 1966 | char *buf) |
| 1967 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1968 | 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] | 1969 | } |
| 1970 | |
| 1971 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1972 | __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] | 1973 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1974 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 1975 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 1976 | struct device_attribute *attr, |
| 1977 | char *buf) |
| 1978 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1979 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 1980 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 1984 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 1985 | |
| 1986 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 1987 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 1988 | struct device_attribute *attr, |
| 1989 | char *buf) |
| 1990 | { |
| 1991 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1992 | (hotkey_all_mask | hotkey_source_mask) |
| 1993 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 1997 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 1998 | hotkey_recommended_mask_show, NULL); |
| 1999 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2000 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2001 | |
| 2002 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 2003 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 2004 | struct device_attribute *attr, |
| 2005 | char *buf) |
| 2006 | { |
| 2007 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 2008 | } |
| 2009 | |
| 2010 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 2011 | struct device_attribute *attr, |
| 2012 | const char *buf, size_t count) |
| 2013 | { |
| 2014 | unsigned long t; |
| 2015 | |
| 2016 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 2017 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 2018 | return -EINVAL; |
| 2019 | |
| 2020 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2021 | return -ERESTARTSYS; |
| 2022 | |
| 2023 | HOTKEY_CONFIG_CRITICAL_START |
| 2024 | hotkey_source_mask = t; |
| 2025 | HOTKEY_CONFIG_CRITICAL_END |
| 2026 | |
| 2027 | hotkey_poll_setup(1); |
| 2028 | |
| 2029 | mutex_unlock(&hotkey_mutex); |
| 2030 | |
| 2031 | return count; |
| 2032 | } |
| 2033 | |
| 2034 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 2035 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 2036 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 2037 | |
| 2038 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 2039 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 2040 | struct device_attribute *attr, |
| 2041 | char *buf) |
| 2042 | { |
| 2043 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 2044 | } |
| 2045 | |
| 2046 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 2047 | struct device_attribute *attr, |
| 2048 | const char *buf, size_t count) |
| 2049 | { |
| 2050 | unsigned long t; |
| 2051 | |
| 2052 | if (parse_strtoul(buf, 25, &t)) |
| 2053 | return -EINVAL; |
| 2054 | |
| 2055 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2056 | return -ERESTARTSYS; |
| 2057 | |
| 2058 | hotkey_poll_freq = t; |
| 2059 | |
| 2060 | hotkey_poll_setup(1); |
| 2061 | mutex_unlock(&hotkey_mutex); |
| 2062 | |
| 2063 | return count; |
| 2064 | } |
| 2065 | |
| 2066 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 2067 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 2068 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 2069 | |
| 2070 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 2071 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2072 | /* sysfs hotkey radio_sw ----------------------------------------------- */ |
| 2073 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 2074 | struct device_attribute *attr, |
| 2075 | char *buf) |
| 2076 | { |
| 2077 | int res, s; |
| 2078 | res = hotkey_get_wlsw(&s); |
| 2079 | if (res < 0) |
| 2080 | return res; |
| 2081 | |
| 2082 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 2083 | } |
| 2084 | |
| 2085 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 2086 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 2087 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2088 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 2089 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 2090 | struct device_attribute *attr, |
| 2091 | char *buf) |
| 2092 | { |
| 2093 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 2094 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 2095 | } |
| 2096 | |
| 2097 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 2098 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 2099 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2100 | /* --------------------------------------------------------------------- */ |
| 2101 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2102 | static struct attribute *hotkey_attributes[] __initdata = { |
| 2103 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2104 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2105 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2106 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2107 | &dev_attr_hotkey_mask.attr, |
| 2108 | &dev_attr_hotkey_all_mask.attr, |
| 2109 | &dev_attr_hotkey_recommended_mask.attr, |
| 2110 | &dev_attr_hotkey_source_mask.attr, |
| 2111 | &dev_attr_hotkey_poll_freq.attr, |
| 2112 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2113 | }; |
| 2114 | |
| 2115 | static struct attribute *hotkey_mask_attributes[] __initdata = { |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2116 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2117 | #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2118 | &dev_attr_hotkey_mask.attr, |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2119 | &dev_attr_hotkey_all_mask.attr, |
| 2120 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2121 | #endif |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2122 | }; |
| 2123 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2124 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2125 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2126 | /* Requirements for changing the default keymaps: |
| 2127 | * |
| 2128 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 2129 | * good reasons. Do not change them unless you have deep |
| 2130 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 2131 | * the various ThinkPad models. The driver behaves |
| 2132 | * differently for KEY_RESERVED: such keys have their |
| 2133 | * hot key mask *unset* in mask_recommended, and also |
| 2134 | * in the initial hot key mask programmed into the |
| 2135 | * firmware at driver load time, which means the firm- |
| 2136 | * ware may react very differently if you change them to |
| 2137 | * something else; |
| 2138 | * |
| 2139 | * 2. You must be subscribed to the linux-thinkpad and |
| 2140 | * ibm-acpi-devel mailing lists, and you should read the |
| 2141 | * list archives since 2007 if you want to change the |
| 2142 | * keymaps. This requirement exists so that you will |
| 2143 | * know the past history of problems with the thinkpad- |
| 2144 | * acpi driver keymaps, and also that you will be |
| 2145 | * listening to any bug reports; |
| 2146 | * |
| 2147 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 2148 | * for merging, *ever*. Send them to the linux-acpi |
| 2149 | * mailinglist for comments. Merging is to be done only |
| 2150 | * through acpi-test and the ACPI maintainer. |
| 2151 | * |
| 2152 | * If the above is too much to ask, don't change the keymap. |
| 2153 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 2154 | */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2155 | static u16 ibm_keycode_map[] __initdata = { |
| 2156 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 2157 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
| 2158 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 2159 | 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] | 2160 | |
| 2161 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2162 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 2163 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 2164 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2165 | |
| 2166 | /* brightness: firmware always reacts to them, unless |
| 2167 | * X.org did some tricks in the radeon BIOS scratch |
| 2168 | * registers of *some* models */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2169 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2170 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2171 | |
| 2172 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2173 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2174 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2175 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 2176 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2177 | |
| 2178 | /* Volume: firmware always react to it and reprograms |
| 2179 | * the built-in *extra* mixer. Never map it to control |
| 2180 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2181 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2182 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2183 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2184 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2185 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2186 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2187 | /* (assignments unknown, please report if found) */ |
| 2188 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2189 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2190 | }; |
| 2191 | static u16 lenovo_keycode_map[] __initdata = { |
| 2192 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 2193 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
| 2194 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 2195 | 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] | 2196 | |
| 2197 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2198 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 2199 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 2200 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2201 | |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 2202 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 2203 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2204 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2205 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2206 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2207 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 2208 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2209 | |
| 2210 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 2211 | * react to it and reprograms the built-in *extra* mixer. |
| 2212 | * Never map it to control another mixer by default. |
| 2213 | * |
| 2214 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 2215 | * these over the regular keyboard, so these are no-ops, |
| 2216 | * but there are still weird bugs re. MUTE, so do not |
| 2217 | * change unless you get test reports from all Lenovo |
| 2218 | * models. May cause the BIOS to interfere with the |
| 2219 | * HDA mixer. |
| 2220 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2221 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2222 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2223 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2224 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2225 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2226 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2227 | /* (assignments unknown, please report if found) */ |
| 2228 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2229 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2230 | }; |
| 2231 | |
| 2232 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) |
| 2233 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) |
| 2234 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) |
| 2235 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2236 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2237 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2238 | int hkeyv; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2239 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2240 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); |
| 2241 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2242 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2243 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 2244 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2245 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2246 | IBM_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2247 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2248 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2249 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2250 | mutex_init(&hotkey_thread_mutex); |
| 2251 | mutex_init(&hotkey_thread_data_mutex); |
| 2252 | #endif |
| 2253 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2254 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2255 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2256 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2257 | vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2258 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2259 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2260 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2261 | hotkey_dev_attributes = create_attr_set(10, NULL); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2262 | if (!hotkey_dev_attributes) |
| 2263 | return -ENOMEM; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2264 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 2265 | hotkey_attributes, |
| 2266 | ARRAY_SIZE(hotkey_attributes)); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2267 | if (res) |
| 2268 | return res; |
| 2269 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2270 | /* 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] | 2271 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 2272 | for HKEY interface version 0x100 */ |
| 2273 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 2274 | if ((hkeyv >> 8) != 1) { |
| 2275 | printk(IBM_ERR "unknown version of the " |
| 2276 | "HKEY interface: 0x%x\n", hkeyv); |
| 2277 | printk(IBM_ERR "please report this to %s\n", |
| 2278 | IBM_MAIL); |
| 2279 | } else { |
| 2280 | /* |
| 2281 | * MHKV 0x100 in A31, R40, R40e, |
| 2282 | * T4x, X31, and later |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2283 | */ |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2284 | tp_features.hotkey_mask = 1; |
| 2285 | } |
| 2286 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2287 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2288 | vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2289 | str_supported(tp_features.hotkey_mask)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2290 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2291 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2292 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2293 | "MHKA", "qd")) { |
| 2294 | printk(IBM_ERR |
| 2295 | "missing MHKA handler, " |
| 2296 | "please report this to %s\n", |
| 2297 | IBM_MAIL); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2298 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2299 | } |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2300 | } |
| 2301 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2302 | /* hotkey_source_mask *must* be zero for |
| 2303 | * the first hotkey_mask_get */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2304 | res = hotkey_status_get(&hotkey_orig_status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2305 | if (!res && tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2306 | res = hotkey_mask_get(); |
| 2307 | hotkey_orig_mask = hotkey_mask; |
| 2308 | if (!res) { |
| 2309 | res = add_many_to_attr_set( |
| 2310 | hotkey_dev_attributes, |
| 2311 | hotkey_mask_attributes, |
| 2312 | ARRAY_SIZE(hotkey_mask_attributes)); |
| 2313 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2314 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2315 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2316 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2317 | if (tp_features.hotkey_mask) { |
| 2318 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 2319 | & ~hotkey_all_mask; |
| 2320 | } else { |
| 2321 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK; |
| 2322 | } |
| 2323 | |
| 2324 | vdbg_printk(TPACPI_DBG_INIT, |
| 2325 | "hotkey source mask 0x%08x, polling freq %d\n", |
| 2326 | hotkey_source_mask, hotkey_poll_freq); |
| 2327 | #endif |
| 2328 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2329 | /* Not all thinkpads have a hardware radio switch */ |
| 2330 | if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 2331 | tp_features.hotkey_wlsw = 1; |
| 2332 | printk(IBM_INFO |
| 2333 | "radio switch found; radios are %s\n", |
| 2334 | enabled(status, 0)); |
| 2335 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2336 | &dev_attr_hotkey_radio_sw.attr); |
| 2337 | } |
| 2338 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2339 | if (!res) |
| 2340 | res = register_attr_set_with_sysfs( |
| 2341 | hotkey_dev_attributes, |
| 2342 | &tpacpi_pdev->dev.kobj); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2343 | if (res) |
| 2344 | return res; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2345 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2346 | /* Set up key map */ |
| 2347 | |
| 2348 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 2349 | GFP_KERNEL); |
| 2350 | if (!hotkey_keycode_map) { |
| 2351 | printk(IBM_ERR "failed to allocate memory for key map\n"); |
| 2352 | return -ENOMEM; |
| 2353 | } |
| 2354 | |
| 2355 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
| 2356 | dbg_printk(TPACPI_DBG_INIT, |
| 2357 | "using Lenovo default hot key map\n"); |
| 2358 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, |
| 2359 | TPACPI_HOTKEY_MAP_SIZE); |
| 2360 | } else { |
| 2361 | dbg_printk(TPACPI_DBG_INIT, |
| 2362 | "using IBM default hot key map\n"); |
| 2363 | memcpy(hotkey_keycode_map, &ibm_keycode_map, |
| 2364 | TPACPI_HOTKEY_MAP_SIZE); |
| 2365 | } |
| 2366 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2367 | set_bit(EV_KEY, tpacpi_inputdev->evbit); |
| 2368 | set_bit(EV_MSC, tpacpi_inputdev->evbit); |
| 2369 | set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2370 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 2371 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 2372 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 2373 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2374 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
| 2375 | set_bit(hotkey_keycode_map[i], |
| 2376 | tpacpi_inputdev->keybit); |
| 2377 | } else { |
| 2378 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 2379 | hotkey_reserved_mask |= 1 << i; |
| 2380 | } |
| 2381 | } |
| 2382 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2383 | if (tp_features.hotkey_wlsw) { |
| 2384 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2385 | set_bit(SW_RADIO, tpacpi_inputdev->swbit); |
| 2386 | } |
| 2387 | |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2388 | dbg_printk(TPACPI_DBG_INIT, |
| 2389 | "enabling hot key handling\n"); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2390 | res = hotkey_status_set(1); |
| 2391 | if (res) |
| 2392 | return res; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2393 | res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask) |
| 2394 | & ~hotkey_reserved_mask) |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2395 | | hotkey_orig_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2396 | if (res < 0 && res != -ENXIO) |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2397 | return res; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2398 | |
| 2399 | dbg_printk(TPACPI_DBG_INIT, |
| 2400 | "legacy hot key reporting over procfs %s\n", |
| 2401 | (hotkey_report_mode < 2) ? |
| 2402 | "enabled" : "disabled"); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2403 | |
| 2404 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2405 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 2406 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 2407 | |
| 2408 | hotkey_poll_setup_safe(1); |
| 2409 | #endif |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2410 | } |
| 2411 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2412 | return (tp_features.hotkey)? 0 : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | static void hotkey_exit(void) |
| 2416 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2417 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2418 | hotkey_poll_stop_sync(); |
| 2419 | #endif |
| 2420 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2421 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2422 | dbg_printk(TPACPI_DBG_EXIT, "restoring original hot key mask\n"); |
| 2423 | /* no short-circuit boolean operator below! */ |
| 2424 | if ((hotkey_mask_set(hotkey_orig_mask) | |
| 2425 | hotkey_status_set(hotkey_orig_status)) != 0) |
| 2426 | printk(IBM_ERR "failed to restore hot key mask to BIOS defaults\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2427 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2428 | |
| 2429 | if (hotkey_dev_attributes) { |
| 2430 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 2431 | hotkey_dev_attributes = NULL; |
| 2432 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 2436 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2437 | u32 hkey; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2438 | unsigned int scancode; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2439 | int send_acpi_ev; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2440 | int ignore_acpi_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2441 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2442 | if (event != 0x80) { |
| 2443 | printk(IBM_ERR "unknown HKEY notification event %d\n", event); |
| 2444 | /* forward it to userspace, maybe it knows how to handle it */ |
| 2445 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 2446 | ibm->acpi->device->dev.bus_id, |
| 2447 | event, 0); |
| 2448 | return; |
| 2449 | } |
| 2450 | |
| 2451 | while (1) { |
| 2452 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
| 2453 | printk(IBM_ERR "failed to retrieve HKEY event\n"); |
| 2454 | return; |
| 2455 | } |
| 2456 | |
| 2457 | if (hkey == 0) { |
| 2458 | /* queue empty */ |
| 2459 | return; |
| 2460 | } |
| 2461 | |
| 2462 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2463 | ignore_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2464 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2465 | switch (hkey >> 12) { |
| 2466 | case 1: |
| 2467 | /* 0x1000-0x1FFF: key presses */ |
| 2468 | scancode = hkey & 0xfff; |
| 2469 | if (scancode > 0 && scancode < 0x21) { |
| 2470 | scancode--; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2471 | if (!(hotkey_source_mask & (1 << scancode))) { |
| 2472 | tpacpi_input_send_key(scancode); |
| 2473 | } else { |
| 2474 | ignore_acpi_ev = 1; |
| 2475 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2476 | } else { |
| 2477 | printk(IBM_ERR |
| 2478 | "hotkey 0x%04x out of range for keyboard map\n", |
| 2479 | hkey); |
| 2480 | send_acpi_ev = 1; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2481 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2482 | break; |
| 2483 | case 5: |
| 2484 | /* 0x5000-0x5FFF: LID */ |
| 2485 | /* we don't handle it through this path, just |
| 2486 | * eat up known LID events */ |
| 2487 | if (hkey != 0x5001 && hkey != 0x5002) { |
| 2488 | printk(IBM_ERR |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2489 | "unknown LID-related HKEY event: 0x%04x\n", |
| 2490 | hkey); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2491 | send_acpi_ev = 1; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2492 | } else { |
| 2493 | ignore_acpi_ev = 1; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2494 | } |
| 2495 | break; |
| 2496 | case 7: |
| 2497 | /* 0x7000-0x7FFF: misc */ |
| 2498 | if (tp_features.hotkey_wlsw && hkey == 0x7000) { |
| 2499 | tpacpi_input_send_radiosw(); |
| 2500 | break; |
| 2501 | } |
| 2502 | /* fallthrough to default */ |
| 2503 | default: |
| 2504 | /* case 2: dock-related */ |
| 2505 | /* 0x2305 - T43 waking up due to bay lever eject while aslept */ |
| 2506 | /* case 3: ultra-bay related. maybe bay in dock? */ |
| 2507 | /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */ |
| 2508 | printk(IBM_NOTICE "unhandled HKEY event 0x%04x\n", hkey); |
| 2509 | send_acpi_ev = 1; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2510 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2511 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2512 | /* Legacy events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2513 | if (!ignore_acpi_ev && (send_acpi_ev || hotkey_report_mode < 2)) { |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2514 | acpi_bus_generate_proc_event(ibm->acpi->device, event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2515 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2516 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2517 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2518 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2519 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 2520 | ibm->acpi->device->dev.bus_id, |
| 2521 | event, hkey); |
| 2522 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2523 | } |
| 2524 | } |
| 2525 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2526 | static void hotkey_resume(void) |
| 2527 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2528 | if (hotkey_mask_get()) |
| 2529 | printk(IBM_ERR "error while trying to read hot key mask from firmware\n"); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2530 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2531 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2532 | hotkey_poll_setup_safe(0); |
| 2533 | #endif |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2534 | } |
| 2535 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2536 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2537 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2539 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | int len = 0; |
| 2541 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2542 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2543 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 2544 | return len; |
| 2545 | } |
| 2546 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 2547 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2548 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2549 | res = hotkey_status_get(&status); |
| 2550 | if (!res) |
| 2551 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2552 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2553 | if (res) |
| 2554 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | |
| 2556 | 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] | 2557 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2558 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | len += sprintf(p + len, |
| 2560 | "commands:\tenable, disable, reset, <mask>\n"); |
| 2561 | } else { |
| 2562 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 2563 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 2564 | } |
| 2565 | |
| 2566 | return len; |
| 2567 | } |
| 2568 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2569 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2571 | int res, status; |
| 2572 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2575 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | return -ENODEV; |
| 2577 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 2578 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2579 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2580 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2581 | status = -1; |
| 2582 | mask = hotkey_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2583 | |
| 2584 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | while ((cmd = next_cmd(&buf))) { |
| 2586 | if (strlencmp(cmd, "enable") == 0) { |
| 2587 | status = 1; |
| 2588 | } else if (strlencmp(cmd, "disable") == 0) { |
| 2589 | status = 0; |
| 2590 | } else if (strlencmp(cmd, "reset") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2591 | status = hotkey_orig_status; |
| 2592 | mask = hotkey_orig_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 2594 | /* mask set */ |
| 2595 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 2596 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2597 | } else { |
| 2598 | res = -EINVAL; |
| 2599 | goto errexit; |
| 2600 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2602 | if (status != -1) |
| 2603 | res = hotkey_status_set(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2605 | if (!res && mask != hotkey_mask) |
| 2606 | res = hotkey_mask_set(mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2608 | errexit: |
| 2609 | mutex_unlock(&hotkey_mutex); |
| 2610 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2611 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2613 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
| 2614 | {IBM_HKEY_HID, 0}, |
| 2615 | {"", 0}, |
| 2616 | }; |
| 2617 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2618 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2619 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2620 | .notify = hotkey_notify, |
| 2621 | .handle = &hkey_handle, |
| 2622 | .type = ACPI_DEVICE_NOTIFY, |
| 2623 | }; |
| 2624 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2625 | static struct ibm_struct hotkey_driver_data = { |
| 2626 | .name = "hotkey", |
| 2627 | .read = hotkey_read, |
| 2628 | .write = hotkey_write, |
| 2629 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2630 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2631 | .acpi = &ibm_hotkey_acpidriver, |
| 2632 | }; |
| 2633 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2634 | /************************************************************************* |
| 2635 | * Bluetooth subdriver |
| 2636 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2638 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 2639 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 2640 | struct device_attribute *attr, |
| 2641 | char *buf) |
| 2642 | { |
| 2643 | int status; |
| 2644 | |
| 2645 | status = bluetooth_get_radiosw(); |
| 2646 | if (status < 0) |
| 2647 | return status; |
| 2648 | |
| 2649 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); |
| 2650 | } |
| 2651 | |
| 2652 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 2653 | struct device_attribute *attr, |
| 2654 | const char *buf, size_t count) |
| 2655 | { |
| 2656 | unsigned long t; |
| 2657 | int res; |
| 2658 | |
| 2659 | if (parse_strtoul(buf, 1, &t)) |
| 2660 | return -EINVAL; |
| 2661 | |
| 2662 | res = bluetooth_set_radiosw(t); |
| 2663 | |
| 2664 | return (res) ? res : count; |
| 2665 | } |
| 2666 | |
| 2667 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2668 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2669 | bluetooth_enable_show, bluetooth_enable_store); |
| 2670 | |
| 2671 | /* --------------------------------------------------------------------- */ |
| 2672 | |
| 2673 | static struct attribute *bluetooth_attributes[] = { |
| 2674 | &dev_attr_bluetooth_enable.attr, |
| 2675 | NULL |
| 2676 | }; |
| 2677 | |
| 2678 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2679 | .attrs = bluetooth_attributes, |
| 2680 | }; |
| 2681 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2682 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2684 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2685 | int status = 0; |
| 2686 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2687 | vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n"); |
| 2688 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2689 | IBM_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2690 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2691 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 2692 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2693 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2694 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2696 | vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n", |
| 2697 | str_supported(tp_features.bluetooth), |
| 2698 | status); |
| 2699 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2700 | if (tp_features.bluetooth) { |
| 2701 | if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 2702 | /* no bluetooth hardware present in system */ |
| 2703 | tp_features.bluetooth = 0; |
| 2704 | dbg_printk(TPACPI_DBG_INIT, |
| 2705 | "bluetooth hardware not installed\n"); |
| 2706 | } else { |
| 2707 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2708 | &bluetooth_attr_group); |
| 2709 | if (res) |
| 2710 | return res; |
| 2711 | } |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2712 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2713 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2714 | return (tp_features.bluetooth)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | } |
| 2716 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2717 | static void bluetooth_exit(void) |
| 2718 | { |
| 2719 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2720 | &bluetooth_attr_group); |
| 2721 | } |
| 2722 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2723 | static int bluetooth_get_radiosw(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | { |
| 2725 | int status; |
| 2726 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2727 | if (!tp_features.bluetooth) |
| 2728 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2730 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 2731 | return -EIO; |
| 2732 | |
| 2733 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0); |
| 2734 | } |
| 2735 | |
| 2736 | static int bluetooth_set_radiosw(int radio_on) |
| 2737 | { |
| 2738 | int status; |
| 2739 | |
| 2740 | if (!tp_features.bluetooth) |
| 2741 | return -ENODEV; |
| 2742 | |
| 2743 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 2744 | return -EIO; |
| 2745 | if (radio_on) |
| 2746 | status |= TP_ACPI_BLUETOOTH_RADIOSSW; |
| 2747 | else |
| 2748 | status &= ~TP_ACPI_BLUETOOTH_RADIOSSW; |
| 2749 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 2750 | return -EIO; |
| 2751 | |
| 2752 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | } |
| 2754 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2755 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2756 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | { |
| 2758 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2759 | int status = bluetooth_get_radiosw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2761 | if (!tp_features.bluetooth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2764 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2765 | (status)? "enabled" : "disabled"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 2767 | } |
| 2768 | |
| 2769 | return len; |
| 2770 | } |
| 2771 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2772 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2776 | if (!tp_features.bluetooth) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2777 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | |
| 2779 | while ((cmd = next_cmd(&buf))) { |
| 2780 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2781 | bluetooth_set_radiosw(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2783 | bluetooth_set_radiosw(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | } else |
| 2785 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | return 0; |
| 2789 | } |
| 2790 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2791 | static struct ibm_struct bluetooth_driver_data = { |
| 2792 | .name = "bluetooth", |
| 2793 | .read = bluetooth_read, |
| 2794 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2795 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2796 | }; |
| 2797 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2798 | /************************************************************************* |
| 2799 | * Wan subdriver |
| 2800 | */ |
| 2801 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2802 | /* sysfs wan enable ---------------------------------------------------- */ |
| 2803 | static ssize_t wan_enable_show(struct device *dev, |
| 2804 | struct device_attribute *attr, |
| 2805 | char *buf) |
| 2806 | { |
| 2807 | int status; |
| 2808 | |
| 2809 | status = wan_get_radiosw(); |
| 2810 | if (status < 0) |
| 2811 | return status; |
| 2812 | |
| 2813 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); |
| 2814 | } |
| 2815 | |
| 2816 | static ssize_t wan_enable_store(struct device *dev, |
| 2817 | struct device_attribute *attr, |
| 2818 | const char *buf, size_t count) |
| 2819 | { |
| 2820 | unsigned long t; |
| 2821 | int res; |
| 2822 | |
| 2823 | if (parse_strtoul(buf, 1, &t)) |
| 2824 | return -EINVAL; |
| 2825 | |
| 2826 | res = wan_set_radiosw(t); |
| 2827 | |
| 2828 | return (res) ? res : count; |
| 2829 | } |
| 2830 | |
| 2831 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2832 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2833 | wan_enable_show, wan_enable_store); |
| 2834 | |
| 2835 | /* --------------------------------------------------------------------- */ |
| 2836 | |
| 2837 | static struct attribute *wan_attributes[] = { |
| 2838 | &dev_attr_wan_enable.attr, |
| 2839 | NULL |
| 2840 | }; |
| 2841 | |
| 2842 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2843 | .attrs = wan_attributes, |
| 2844 | }; |
| 2845 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2846 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2847 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2848 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2849 | int status = 0; |
| 2850 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2851 | vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n"); |
| 2852 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2853 | IBM_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2854 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2855 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2856 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2857 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2858 | vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n", |
| 2859 | str_supported(tp_features.wan), |
| 2860 | status); |
| 2861 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2862 | if (tp_features.wan) { |
| 2863 | if (!(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 2864 | /* no wan hardware present in system */ |
| 2865 | tp_features.wan = 0; |
| 2866 | dbg_printk(TPACPI_DBG_INIT, |
| 2867 | "wan hardware not installed\n"); |
| 2868 | } else { |
| 2869 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2870 | &wan_attr_group); |
| 2871 | if (res) |
| 2872 | return res; |
| 2873 | } |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2874 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2875 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2876 | return (tp_features.wan)? 0 : 1; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2877 | } |
| 2878 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2879 | static void wan_exit(void) |
| 2880 | { |
| 2881 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2882 | &wan_attr_group); |
| 2883 | } |
| 2884 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2885 | static int wan_get_radiosw(void) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2886 | { |
| 2887 | int status; |
| 2888 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2889 | if (!tp_features.wan) |
| 2890 | return -ENODEV; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2891 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2892 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 2893 | return -EIO; |
| 2894 | |
| 2895 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0); |
| 2896 | } |
| 2897 | |
| 2898 | static int wan_set_radiosw(int radio_on) |
| 2899 | { |
| 2900 | int status; |
| 2901 | |
| 2902 | if (!tp_features.wan) |
| 2903 | return -ENODEV; |
| 2904 | |
| 2905 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 2906 | return -EIO; |
| 2907 | if (radio_on) |
| 2908 | status |= TP_ACPI_WANCARD_RADIOSSW; |
| 2909 | else |
| 2910 | status &= ~TP_ACPI_WANCARD_RADIOSSW; |
| 2911 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 2912 | return -EIO; |
| 2913 | |
| 2914 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2915 | } |
| 2916 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2917 | /* procfs -------------------------------------------------------------- */ |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2918 | static int wan_read(char *p) |
| 2919 | { |
| 2920 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2921 | int status = wan_get_radiosw(); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2922 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2923 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2924 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2925 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2926 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2927 | (status)? "enabled" : "disabled"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2928 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 2929 | } |
| 2930 | |
| 2931 | return len; |
| 2932 | } |
| 2933 | |
| 2934 | static int wan_write(char *buf) |
| 2935 | { |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2936 | char *cmd; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2937 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2938 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2939 | return -ENODEV; |
| 2940 | |
| 2941 | while ((cmd = next_cmd(&buf))) { |
| 2942 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2943 | wan_set_radiosw(1); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2944 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2945 | wan_set_radiosw(0); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2946 | } else |
| 2947 | return -EINVAL; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2948 | } |
| 2949 | |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2950 | return 0; |
| 2951 | } |
| 2952 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2953 | static struct ibm_struct wan_driver_data = { |
| 2954 | .name = "wan", |
| 2955 | .read = wan_read, |
| 2956 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2957 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 2958 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2959 | }; |
| 2960 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2961 | /************************************************************************* |
| 2962 | * Video subdriver |
| 2963 | */ |
| 2964 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 2965 | static enum video_access_mode video_supported; |
| 2966 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2967 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2968 | IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 2969 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 2970 | "\\_SB.PCI0.VID0", /* 770e */ |
| 2971 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 2972 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 2973 | ); /* R30, R31 */ |
| 2974 | |
| 2975 | IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
| 2976 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2977 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2979 | int ivga; |
| 2980 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2981 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 2982 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2983 | IBM_ACPIHANDLE_INIT(vid); |
| 2984 | IBM_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2985 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2986 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 2987 | /* G41, assume IVGA doesn't change */ |
| 2988 | vid_handle = vid2_handle; |
| 2989 | |
| 2990 | if (!vid_handle) |
| 2991 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2992 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2993 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 2994 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2995 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2996 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 2997 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2998 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2999 | else |
| 3000 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3001 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3003 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 3004 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 3005 | video_supported); |
| 3006 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3007 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3010 | static void video_exit(void) |
| 3011 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3012 | dbg_printk(TPACPI_DBG_EXIT, |
| 3013 | "restoring original video autoswitch mode\n"); |
| 3014 | if (video_autosw_set(video_orig_autosw)) |
| 3015 | printk(IBM_ERR "error while trying to restore original " |
| 3016 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3017 | } |
| 3018 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3019 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | { |
| 3021 | int status = 0; |
| 3022 | int i; |
| 3023 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3024 | switch (video_supported) { |
| 3025 | case TPACPI_VIDEO_570: |
| 3026 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 3027 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 3028 | return -EIO; |
| 3029 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 3030 | break; |
| 3031 | case TPACPI_VIDEO_770: |
| 3032 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 3033 | return -EIO; |
| 3034 | if (i) |
| 3035 | status |= TP_ACPI_VIDEO_S_LCD; |
| 3036 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 3037 | return -EIO; |
| 3038 | if (i) |
| 3039 | status |= TP_ACPI_VIDEO_S_CRT; |
| 3040 | break; |
| 3041 | case TPACPI_VIDEO_NEW: |
| 3042 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 3043 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 3044 | return -EIO; |
| 3045 | if (i) |
| 3046 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3048 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 3049 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 3050 | return -EIO; |
| 3051 | if (i) |
| 3052 | status |= TP_ACPI_VIDEO_S_LCD; |
| 3053 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 3054 | return -EIO; |
| 3055 | if (i) |
| 3056 | status |= TP_ACPI_VIDEO_S_DVI; |
| 3057 | break; |
| 3058 | default: |
| 3059 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3060 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | |
| 3062 | return status; |
| 3063 | } |
| 3064 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3065 | static int video_outputsw_set(int status) |
| 3066 | { |
| 3067 | int autosw; |
| 3068 | int res = 0; |
| 3069 | |
| 3070 | switch (video_supported) { |
| 3071 | case TPACPI_VIDEO_570: |
| 3072 | res = acpi_evalf(NULL, NULL, |
| 3073 | "\\_SB.PHS2", "vdd", |
| 3074 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 3075 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 3076 | break; |
| 3077 | case TPACPI_VIDEO_770: |
| 3078 | autosw = video_autosw_get(); |
| 3079 | if (autosw < 0) |
| 3080 | return autosw; |
| 3081 | |
| 3082 | res = video_autosw_set(1); |
| 3083 | if (res) |
| 3084 | return res; |
| 3085 | res = acpi_evalf(vid_handle, NULL, |
| 3086 | "ASWT", "vdd", status * 0x100, 0); |
| 3087 | if (!autosw && video_autosw_set(autosw)) { |
| 3088 | printk(IBM_ERR "video auto-switch left enabled due to error\n"); |
| 3089 | return -EIO; |
| 3090 | } |
| 3091 | break; |
| 3092 | case TPACPI_VIDEO_NEW: |
| 3093 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
| 3094 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
| 3095 | break; |
| 3096 | default: |
| 3097 | return -ENOSYS; |
| 3098 | } |
| 3099 | |
| 3100 | return (res)? 0 : -EIO; |
| 3101 | } |
| 3102 | |
| 3103 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3105 | int autosw = 0; |
| 3106 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3107 | switch (video_supported) { |
| 3108 | case TPACPI_VIDEO_570: |
| 3109 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 3110 | return -EIO; |
| 3111 | break; |
| 3112 | case TPACPI_VIDEO_770: |
| 3113 | case TPACPI_VIDEO_NEW: |
| 3114 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 3115 | return -EIO; |
| 3116 | break; |
| 3117 | default: |
| 3118 | return -ENOSYS; |
| 3119 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3120 | |
| 3121 | return autosw & 1; |
| 3122 | } |
| 3123 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3124 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3125 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3126 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3127 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3128 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3129 | } |
| 3130 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3131 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3132 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3133 | int autosw = video_autosw_get(); |
| 3134 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3135 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3136 | if (autosw < 0) |
| 3137 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3138 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3139 | switch (video_supported) { |
| 3140 | case TPACPI_VIDEO_570: |
| 3141 | res = video_autosw_set(1); |
| 3142 | if (res) |
| 3143 | return res; |
| 3144 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 3145 | break; |
| 3146 | case TPACPI_VIDEO_770: |
| 3147 | case TPACPI_VIDEO_NEW: |
| 3148 | res = video_autosw_set(1); |
| 3149 | if (res) |
| 3150 | return res; |
| 3151 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 3152 | break; |
| 3153 | default: |
| 3154 | return -ENOSYS; |
| 3155 | } |
| 3156 | if (!autosw && video_autosw_set(autosw)) { |
| 3157 | printk(IBM_ERR "video auto-switch left enabled due to error\n"); |
| 3158 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3159 | } |
| 3160 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3161 | return (res)? 0 : -EIO; |
| 3162 | } |
| 3163 | |
| 3164 | static int video_expand_toggle(void) |
| 3165 | { |
| 3166 | switch (video_supported) { |
| 3167 | case TPACPI_VIDEO_570: |
| 3168 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 3169 | 0 : -EIO; |
| 3170 | case TPACPI_VIDEO_770: |
| 3171 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 3172 | 0 : -EIO; |
| 3173 | case TPACPI_VIDEO_NEW: |
| 3174 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 3175 | 0 : -EIO; |
| 3176 | default: |
| 3177 | return -ENOSYS; |
| 3178 | } |
| 3179 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3180 | } |
| 3181 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3182 | static int video_read(char *p) |
| 3183 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3184 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3185 | int len = 0; |
| 3186 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3187 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3188 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3189 | return len; |
| 3190 | } |
| 3191 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3192 | status = video_outputsw_get(); |
| 3193 | if (status < 0) |
| 3194 | return status; |
| 3195 | |
| 3196 | autosw = video_autosw_get(); |
| 3197 | if (autosw < 0) |
| 3198 | return autosw; |
| 3199 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3200 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3201 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 3202 | 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] | 3203 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3204 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 3205 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 3206 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 3207 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3208 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3209 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 3210 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 3211 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 3212 | |
| 3213 | return len; |
| 3214 | } |
| 3215 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3216 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | { |
| 3218 | char *cmd; |
| 3219 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3220 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3222 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3223 | return -ENODEV; |
| 3224 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3225 | enable = 0; |
| 3226 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | |
| 3228 | while ((cmd = next_cmd(&buf))) { |
| 3229 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3230 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3232 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3234 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3236 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3237 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3238 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3239 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3240 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3241 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3242 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3244 | res = video_autosw_set(1); |
| 3245 | if (res) |
| 3246 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3248 | res = video_autosw_set(0); |
| 3249 | if (res) |
| 3250 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3252 | res = video_outputsw_cycle(); |
| 3253 | if (res) |
| 3254 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3256 | res = video_expand_toggle(); |
| 3257 | if (res) |
| 3258 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | } else |
| 3260 | return -EINVAL; |
| 3261 | } |
| 3262 | |
| 3263 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3264 | status = video_outputsw_get(); |
| 3265 | if (status < 0) |
| 3266 | return status; |
| 3267 | res = video_outputsw_set((status & ~disable) | enable); |
| 3268 | if (res) |
| 3269 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | return 0; |
| 3273 | } |
| 3274 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3275 | static struct ibm_struct video_driver_data = { |
| 3276 | .name = "video", |
| 3277 | .read = video_read, |
| 3278 | .write = video_write, |
| 3279 | .exit = video_exit, |
| 3280 | }; |
| 3281 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3282 | /************************************************************************* |
| 3283 | * Light (thinklight) subdriver |
| 3284 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3286 | IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 3287 | IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
| 3288 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3289 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3291 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 3292 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3293 | IBM_ACPIHANDLE_INIT(ledb); |
| 3294 | IBM_ACPIHANDLE_INIT(lght); |
| 3295 | IBM_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3296 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3297 | /* 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] | 3298 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3299 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3300 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3301 | /* light status not supported on |
| 3302 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3303 | tp_features.light_status = |
| 3304 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3306 | vdbg_printk(TPACPI_DBG_INIT, "light is %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3307 | str_supported(tp_features.light)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3308 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3309 | return (tp_features.light)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3312 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | { |
| 3314 | int len = 0; |
| 3315 | int status = 0; |
| 3316 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3317 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3318 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3319 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3320 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 3321 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 3322 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 3324 | return -EIO; |
| 3325 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3326 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 3327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | |
| 3329 | return len; |
| 3330 | } |
| 3331 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3332 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | { |
| 3334 | int cmos_cmd, lght_cmd; |
| 3335 | char *cmd; |
| 3336 | int success; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3337 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3338 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3339 | return -ENODEV; |
| 3340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | while ((cmd = next_cmd(&buf))) { |
| 3342 | if (strlencmp(cmd, "on") == 0) { |
| 3343 | cmos_cmd = 0x0c; |
| 3344 | lght_cmd = 1; |
| 3345 | } else if (strlencmp(cmd, "off") == 0) { |
| 3346 | cmos_cmd = 0x0d; |
| 3347 | lght_cmd = 0; |
| 3348 | } else |
| 3349 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | success = cmos_handle ? |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3352 | acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) : |
| 3353 | acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | if (!success) |
| 3355 | return -EIO; |
| 3356 | } |
| 3357 | |
| 3358 | return 0; |
| 3359 | } |
| 3360 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3361 | static struct ibm_struct light_driver_data = { |
| 3362 | .name = "light", |
| 3363 | .read = light_read, |
| 3364 | .write = light_write, |
| 3365 | }; |
| 3366 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3367 | /************************************************************************* |
| 3368 | * Dock subdriver |
| 3369 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3371 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3372 | |
| 3373 | IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ |
| 3374 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ |
| 3375 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ |
| 3376 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
| 3377 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
| 3378 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3379 | /* don't list other alternatives as we install a notify handler on the 570 */ |
| 3380 | IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
| 3381 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3382 | static const struct acpi_device_id ibm_pci_device_ids[] = { |
| 3383 | {PCI_ROOT_HID_STRING, 0}, |
| 3384 | {"", 0}, |
| 3385 | }; |
| 3386 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3387 | static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = { |
| 3388 | { |
| 3389 | .notify = dock_notify, |
| 3390 | .handle = &dock_handle, |
| 3391 | .type = ACPI_SYSTEM_NOTIFY, |
| 3392 | }, |
| 3393 | { |
Henrique de Moraes Holschuh | 996fba0 | 2007-07-18 23:45:40 -0300 | [diff] [blame] | 3394 | /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING. |
| 3395 | * We just use it to get notifications of dock hotplug |
| 3396 | * in very old thinkpads */ |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3397 | .hid = ibm_pci_device_ids, |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3398 | .notify = dock_notify, |
| 3399 | .handle = &pci_handle, |
| 3400 | .type = ACPI_SYSTEM_NOTIFY, |
| 3401 | }, |
| 3402 | }; |
| 3403 | |
| 3404 | static struct ibm_struct dock_driver_data[2] = { |
| 3405 | { |
| 3406 | .name = "dock", |
| 3407 | .read = dock_read, |
| 3408 | .write = dock_write, |
| 3409 | .acpi = &ibm_dock_acpidriver[0], |
| 3410 | }, |
| 3411 | { |
| 3412 | .name = "dock", |
| 3413 | .acpi = &ibm_dock_acpidriver[1], |
| 3414 | }, |
| 3415 | }; |
| 3416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | #define dock_docked() (_sta(dock_handle) & 1) |
| 3418 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3419 | static int __init dock_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3420 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3421 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n"); |
| 3422 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3423 | IBM_ACPIHANDLE_INIT(dock); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3424 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3425 | vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n", |
| 3426 | str_supported(dock_handle != NULL)); |
| 3427 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3428 | return (dock_handle)? 0 : 1; |
| 3429 | } |
| 3430 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3431 | static int __init dock_init2(struct ibm_init_struct *iibm) |
| 3432 | { |
| 3433 | int dock2_needed; |
| 3434 | |
| 3435 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n"); |
| 3436 | |
| 3437 | if (dock_driver_data[0].flags.acpi_driver_registered && |
| 3438 | dock_driver_data[0].flags.acpi_notify_installed) { |
| 3439 | IBM_ACPIHANDLE_INIT(pci); |
| 3440 | dock2_needed = (pci_handle != NULL); |
| 3441 | vdbg_printk(TPACPI_DBG_INIT, |
| 3442 | "dock PCI handler for the TP 570 is %s\n", |
| 3443 | str_supported(dock2_needed)); |
| 3444 | } else { |
| 3445 | vdbg_printk(TPACPI_DBG_INIT, |
| 3446 | "dock subdriver part 2 not required\n"); |
| 3447 | dock2_needed = 0; |
| 3448 | } |
| 3449 | |
| 3450 | return (dock2_needed)? 0 : 1; |
| 3451 | } |
| 3452 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3453 | static void dock_notify(struct ibm_struct *ibm, u32 event) |
| 3454 | { |
| 3455 | int docked = dock_docked(); |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3456 | int pci = ibm->acpi->hid && ibm->acpi->device && |
| 3457 | acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3458 | int data; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3459 | |
| 3460 | if (event == 1 && !pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3461 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3462 | else if (event == 1 && pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3463 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3464 | else if (event == 3 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3465 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3466 | else if (event == 3 && !docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3467 | data = 2; /* undock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3468 | else if (event == 0 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3469 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3470 | else { |
| 3471 | printk(IBM_ERR "unknown dock event %d, status %d\n", |
| 3472 | event, _sta(dock_handle)); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3473 | data = 0; /* unknown */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3474 | } |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 3475 | acpi_bus_generate_proc_event(ibm->acpi->device, event, data); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3476 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 3477 | ibm->acpi->device->dev.bus_id, |
| 3478 | event, data); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3479 | } |
| 3480 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3481 | static int dock_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | { |
| 3483 | int len = 0; |
| 3484 | int docked = dock_docked(); |
| 3485 | |
| 3486 | if (!dock_handle) |
| 3487 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3488 | else if (!docked) |
| 3489 | len += sprintf(p + len, "status:\t\tundocked\n"); |
| 3490 | else { |
| 3491 | len += sprintf(p + len, "status:\t\tdocked\n"); |
| 3492 | len += sprintf(p + len, "commands:\tdock, undock\n"); |
| 3493 | } |
| 3494 | |
| 3495 | return len; |
| 3496 | } |
| 3497 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3498 | static int dock_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | { |
| 3500 | char *cmd; |
| 3501 | |
| 3502 | if (!dock_docked()) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3503 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | |
| 3505 | while ((cmd = next_cmd(&buf))) { |
| 3506 | if (strlencmp(cmd, "undock") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3507 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || |
| 3508 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | return -EIO; |
| 3510 | } else if (strlencmp(cmd, "dock") == 0) { |
| 3511 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) |
| 3512 | return -EIO; |
| 3513 | } else |
| 3514 | return -EINVAL; |
| 3515 | } |
| 3516 | |
| 3517 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3518 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3520 | #endif /* CONFIG_THINKPAD_ACPI_DOCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3522 | /************************************************************************* |
| 3523 | * Bay subdriver |
| 3524 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3526 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3527 | IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
| 3528 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
| 3529 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ |
| 3530 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
| 3531 | ); /* A21e, R30, R31 */ |
| 3532 | IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ |
| 3533 | "_EJ0", /* all others */ |
| 3534 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ |
| 3535 | IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ |
| 3536 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ |
| 3537 | ); /* all others */ |
| 3538 | IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
| 3539 | "_EJ0", /* 770x */ |
| 3540 | ); /* all others */ |
| 3541 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3542 | static int __init bay_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3544 | vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n"); |
| 3545 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3546 | IBM_ACPIHANDLE_INIT(bay); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3547 | if (bay_handle) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3548 | IBM_ACPIHANDLE_INIT(bay_ej); |
| 3549 | IBM_ACPIHANDLE_INIT(bay2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3550 | if (bay2_handle) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3551 | IBM_ACPIHANDLE_INIT(bay2_ej); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3552 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3553 | tp_features.bay_status = bay_handle && |
| 3554 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); |
| 3555 | tp_features.bay_status2 = bay2_handle && |
| 3556 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3557 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3558 | tp_features.bay_eject = bay_handle && bay_ej_handle && |
| 3559 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); |
| 3560 | tp_features.bay_eject2 = bay2_handle && bay2_ej_handle && |
| 3561 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3563 | vdbg_printk(TPACPI_DBG_INIT, |
| 3564 | "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] | 3565 | str_supported(tp_features.bay_status), |
| 3566 | str_supported(tp_features.bay_eject), |
| 3567 | str_supported(tp_features.bay_status2), |
| 3568 | str_supported(tp_features.bay_eject2)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3569 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3570 | return (tp_features.bay_status || tp_features.bay_eject || |
| 3571 | tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3574 | static void bay_notify(struct ibm_struct *ibm, u32 event) |
| 3575 | { |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 3576 | acpi_bus_generate_proc_event(ibm->acpi->device, event, 0); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3577 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 3578 | ibm->acpi->device->dev.bus_id, |
| 3579 | event, 0); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3580 | } |
| 3581 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3582 | #define bay_occupied(b) (_sta(b##_handle) & 1) |
| 3583 | |
| 3584 | static int bay_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | { |
| 3586 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3587 | int occupied = bay_occupied(bay); |
| 3588 | int occupied2 = bay_occupied(bay2); |
| 3589 | int eject, eject2; |
| 3590 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3591 | len += sprintf(p + len, "status:\t\t%s\n", |
| 3592 | tp_features.bay_status ? |
| 3593 | (occupied ? "occupied" : "unoccupied") : |
| 3594 | "not supported"); |
| 3595 | if (tp_features.bay_status2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3596 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? |
| 3597 | "occupied" : "unoccupied"); |
| 3598 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3599 | eject = tp_features.bay_eject && occupied; |
| 3600 | eject2 = tp_features.bay_eject2 && occupied2; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3601 | |
| 3602 | if (eject && eject2) |
| 3603 | len += sprintf(p + len, "commands:\teject, eject2\n"); |
| 3604 | else if (eject) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | len += sprintf(p + len, "commands:\teject\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3606 | else if (eject2) |
| 3607 | len += sprintf(p + len, "commands:\teject2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | |
| 3609 | return len; |
| 3610 | } |
| 3611 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3612 | static int bay_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | { |
| 3614 | char *cmd; |
| 3615 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3616 | if (!tp_features.bay_eject && !tp_features.bay_eject2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3617 | return -ENODEV; |
| 3618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3620 | if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3621 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) |
| 3622 | return -EIO; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3623 | } else if (tp_features.bay_eject2 && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3624 | strlencmp(cmd, "eject2") == 0) { |
| 3625 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | return -EIO; |
| 3627 | } else |
| 3628 | return -EINVAL; |
| 3629 | } |
| 3630 | |
| 3631 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3632 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3633 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3634 | static struct tp_acpi_drv_struct ibm_bay_acpidriver = { |
| 3635 | .notify = bay_notify, |
| 3636 | .handle = &bay_handle, |
| 3637 | .type = ACPI_SYSTEM_NOTIFY, |
| 3638 | }; |
| 3639 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3640 | static struct ibm_struct bay_driver_data = { |
| 3641 | .name = "bay", |
| 3642 | .read = bay_read, |
| 3643 | .write = bay_write, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3644 | .acpi = &ibm_bay_acpidriver, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3645 | }; |
| 3646 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3647 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3649 | /************************************************************************* |
| 3650 | * CMOS subdriver |
| 3651 | */ |
| 3652 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3653 | /* sysfs cmos_command -------------------------------------------------- */ |
| 3654 | static ssize_t cmos_command_store(struct device *dev, |
| 3655 | struct device_attribute *attr, |
| 3656 | const char *buf, size_t count) |
| 3657 | { |
| 3658 | unsigned long cmos_cmd; |
| 3659 | int res; |
| 3660 | |
| 3661 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 3662 | return -EINVAL; |
| 3663 | |
| 3664 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 3665 | return (res)? res : count; |
| 3666 | } |
| 3667 | |
| 3668 | static struct device_attribute dev_attr_cmos_command = |
| 3669 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 3670 | |
| 3671 | /* --------------------------------------------------------------------- */ |
| 3672 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3673 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3674 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3675 | int res; |
| 3676 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3677 | vdbg_printk(TPACPI_DBG_INIT, |
| 3678 | "initializing cmos commands subdriver\n"); |
| 3679 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3680 | IBM_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3681 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3682 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 3683 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3684 | |
| 3685 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 3686 | if (res) |
| 3687 | return res; |
| 3688 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3689 | return (cmos_handle)? 0 : 1; |
| 3690 | } |
| 3691 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3692 | static void cmos_exit(void) |
| 3693 | { |
| 3694 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 3695 | } |
| 3696 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3697 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | { |
| 3699 | int len = 0; |
| 3700 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3701 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 3702 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | if (!cmos_handle) |
| 3704 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3705 | else { |
| 3706 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3707 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | return len; |
| 3711 | } |
| 3712 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3713 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | { |
| 3715 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 3716 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | |
| 3718 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3719 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 3720 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | /* cmos_cmd set */ |
| 3722 | } else |
| 3723 | return -EINVAL; |
| 3724 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 3725 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 3726 | if (res) |
| 3727 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3731 | } |
| 3732 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3733 | static struct ibm_struct cmos_driver_data = { |
| 3734 | .name = "cmos", |
| 3735 | .read = cmos_read, |
| 3736 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3737 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3738 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3739 | |
| 3740 | /************************************************************************* |
| 3741 | * LED subdriver |
| 3742 | */ |
| 3743 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 3744 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3745 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3746 | IBM_HANDLE(led, ec, "SLED", /* 570 */ |
| 3747 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 3748 | "LED", /* all others */ |
| 3749 | ); /* R30, R31 */ |
| 3750 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3751 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3752 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3753 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 3754 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3755 | IBM_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3756 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3757 | if (!led_handle) |
| 3758 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3759 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3760 | else if (strlencmp(led_path, "SLED") == 0) |
| 3761 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3762 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3763 | else if (strlencmp(led_path, "SYSL") == 0) |
| 3764 | /* 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] | 3765 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3766 | else |
| 3767 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3768 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3769 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3770 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 3771 | str_supported(led_supported), led_supported); |
| 3772 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3773 | return (led_supported != TPACPI_LED_NONE)? 0 : 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking")) |
| 3777 | |
| 3778 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | { |
| 3780 | int len = 0; |
| 3781 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3782 | if (!led_supported) { |
| 3783 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3784 | return len; |
| 3785 | } |
| 3786 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3787 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3788 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3789 | /* 570 */ |
| 3790 | int i, status; |
| 3791 | for (i = 0; i < 8; i++) { |
| 3792 | if (!acpi_evalf(ec_handle, |
| 3793 | &status, "GLED", "dd", 1 << i)) |
| 3794 | return -EIO; |
| 3795 | len += sprintf(p + len, "%d:\t\t%s\n", |
| 3796 | i, led_status(status)); |
| 3797 | } |
| 3798 | } |
| 3799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | len += sprintf(p + len, "commands:\t" |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3801 | "<led> on, <led> off, <led> blink (<led> is 0-7)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | |
| 3803 | return len; |
| 3804 | } |
| 3805 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3806 | /* off, on, blink */ |
| 3807 | static const int led_sled_arg1[] = { 0, 1, 3 }; |
| 3808 | static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */ |
| 3809 | static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */ |
| 3810 | static const int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
| 3811 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3812 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | { |
| 3814 | char *cmd; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3815 | int led, ind, ret; |
| 3816 | |
| 3817 | if (!led_supported) |
| 3818 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | |
| 3820 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3821 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | return -EINVAL; |
| 3823 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3824 | if (strstr(cmd, "off")) { |
| 3825 | ind = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | } else if (strstr(cmd, "on")) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3827 | ind = 1; |
| 3828 | } else if (strstr(cmd, "blink")) { |
| 3829 | ind = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | } else |
| 3831 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3832 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3833 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3834 | /* 570 */ |
| 3835 | led = 1 << led; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3837 | led, led_sled_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | return -EIO; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3839 | } else if (led_supported == TPACPI_LED_OLD) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3840 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
| 3841 | led = 1 << led; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3842 | ret = ec_write(TPACPI_LED_EC_HLMS, led); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3843 | if (ret >= 0) |
| 3844 | ret = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3845 | ec_write(TPACPI_LED_EC_HLBL, |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 3846 | led * led_exp_hlbl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3847 | if (ret >= 0) |
| 3848 | ret = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3849 | ec_write(TPACPI_LED_EC_HLCL, |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 3850 | led * led_exp_hlcl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3851 | if (ret < 0) |
| 3852 | return ret; |
| 3853 | } else { |
| 3854 | /* all others */ |
| 3855 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 3856 | led, led_led_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3858 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3862 | } |
| 3863 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3864 | static struct ibm_struct led_driver_data = { |
| 3865 | .name = "led", |
| 3866 | .read = led_read, |
| 3867 | .write = led_write, |
| 3868 | }; |
| 3869 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3870 | /************************************************************************* |
| 3871 | * Beep subdriver |
| 3872 | */ |
| 3873 | |
| 3874 | IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
| 3875 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3876 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3877 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3878 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 3879 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3880 | IBM_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3881 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3882 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 3883 | str_supported(beep_handle != NULL)); |
| 3884 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3885 | return (beep_handle)? 0 : 1; |
| 3886 | } |
| 3887 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3888 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | { |
| 3890 | int len = 0; |
| 3891 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3892 | if (!beep_handle) |
| 3893 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3894 | else { |
| 3895 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3896 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 3897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | |
| 3899 | return len; |
| 3900 | } |
| 3901 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3902 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | { |
| 3904 | char *cmd; |
| 3905 | int beep_cmd; |
| 3906 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3907 | if (!beep_handle) |
| 3908 | return -ENODEV; |
| 3909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3911 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 3912 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | /* beep_cmd set */ |
| 3914 | } else |
| 3915 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3916 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | return -EIO; |
| 3918 | } |
| 3919 | |
| 3920 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3921 | } |
| 3922 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3923 | static struct ibm_struct beep_driver_data = { |
| 3924 | .name = "beep", |
| 3925 | .read = beep_read, |
| 3926 | .write = beep_write, |
| 3927 | }; |
| 3928 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3929 | /************************************************************************* |
| 3930 | * Thermal subdriver |
| 3931 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3932 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 3933 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3934 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 3935 | /* sysfs temp##_input -------------------------------------------------- */ |
| 3936 | |
| 3937 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 3938 | struct device_attribute *attr, |
| 3939 | char *buf) |
| 3940 | { |
| 3941 | struct sensor_device_attribute *sensor_attr = |
| 3942 | to_sensor_dev_attr(attr); |
| 3943 | int idx = sensor_attr->index; |
| 3944 | s32 value; |
| 3945 | int res; |
| 3946 | |
| 3947 | res = thermal_get_sensor(idx, &value); |
| 3948 | if (res) |
| 3949 | return res; |
| 3950 | if (value == TP_EC_THERMAL_TMP_NA * 1000) |
| 3951 | return -ENXIO; |
| 3952 | |
| 3953 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 3954 | } |
| 3955 | |
| 3956 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
| 3957 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB) |
| 3958 | |
| 3959 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 3960 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 3961 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 3962 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 3963 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 3964 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 3965 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 3966 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 3967 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 3968 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 3969 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 3970 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 3971 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 3972 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 3973 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 3974 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 3975 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 3976 | }; |
| 3977 | |
| 3978 | #define THERMAL_ATTRS(X) \ |
| 3979 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 3980 | |
| 3981 | static struct attribute *thermal_temp_input_attr[] = { |
| 3982 | THERMAL_ATTRS(8), |
| 3983 | THERMAL_ATTRS(9), |
| 3984 | THERMAL_ATTRS(10), |
| 3985 | THERMAL_ATTRS(11), |
| 3986 | THERMAL_ATTRS(12), |
| 3987 | THERMAL_ATTRS(13), |
| 3988 | THERMAL_ATTRS(14), |
| 3989 | THERMAL_ATTRS(15), |
| 3990 | THERMAL_ATTRS(0), |
| 3991 | THERMAL_ATTRS(1), |
| 3992 | THERMAL_ATTRS(2), |
| 3993 | THERMAL_ATTRS(3), |
| 3994 | THERMAL_ATTRS(4), |
| 3995 | THERMAL_ATTRS(5), |
| 3996 | THERMAL_ATTRS(6), |
| 3997 | THERMAL_ATTRS(7), |
| 3998 | NULL |
| 3999 | }; |
| 4000 | |
| 4001 | static const struct attribute_group thermal_temp_input16_group = { |
| 4002 | .attrs = thermal_temp_input_attr |
| 4003 | }; |
| 4004 | |
| 4005 | static const struct attribute_group thermal_temp_input8_group = { |
| 4006 | .attrs = &thermal_temp_input_attr[8] |
| 4007 | }; |
| 4008 | |
| 4009 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 4010 | #undef THERMAL_ATTRS |
| 4011 | |
| 4012 | /* --------------------------------------------------------------------- */ |
| 4013 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4014 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4015 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4016 | u8 t, ta1, ta2; |
| 4017 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4018 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4019 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4020 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4021 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 4022 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4023 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4024 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 4025 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4026 | /* |
| 4027 | * Direct EC access mode: sensors at registers |
| 4028 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 4029 | * non-implemented, thermal sensors return 0x80 when |
| 4030 | * not available |
| 4031 | */ |
| 4032 | |
| 4033 | ta1 = ta2 = 0; |
| 4034 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4035 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4036 | ta1 |= t; |
| 4037 | } else { |
| 4038 | ta1 = 0; |
| 4039 | break; |
| 4040 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4041 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4042 | ta2 |= t; |
| 4043 | } else { |
| 4044 | ta1 = 0; |
| 4045 | break; |
| 4046 | } |
| 4047 | } |
| 4048 | if (ta1 == 0) { |
| 4049 | /* This is sheer paranoia, but we handle it anyway */ |
| 4050 | if (acpi_tmp7) { |
| 4051 | printk(IBM_ERR |
| 4052 | "ThinkPad ACPI EC access misbehaving, " |
| 4053 | "falling back to ACPI TMPx access mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4054 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4055 | } else { |
| 4056 | printk(IBM_ERR |
| 4057 | "ThinkPad ACPI EC access misbehaving, " |
| 4058 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4059 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4060 | } |
| 4061 | } else { |
| 4062 | thermal_read_mode = |
| 4063 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4064 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4065 | } |
| 4066 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4067 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 4068 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4069 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4070 | } else { |
| 4071 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4072 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4073 | } |
| 4074 | } else { |
| 4075 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4076 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4077 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4078 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4079 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 4080 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 4081 | thermal_read_mode); |
| 4082 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4083 | switch(thermal_read_mode) { |
| 4084 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4085 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4086 | &thermal_temp_input16_group); |
| 4087 | if (res) |
| 4088 | return res; |
| 4089 | break; |
| 4090 | case TPACPI_THERMAL_TPEC_8: |
| 4091 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4092 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4093 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4094 | &thermal_temp_input8_group); |
| 4095 | if (res) |
| 4096 | return res; |
| 4097 | break; |
| 4098 | case TPACPI_THERMAL_NONE: |
| 4099 | default: |
| 4100 | return 1; |
| 4101 | } |
| 4102 | |
| 4103 | return 0; |
| 4104 | } |
| 4105 | |
| 4106 | static void thermal_exit(void) |
| 4107 | { |
| 4108 | switch(thermal_read_mode) { |
| 4109 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4110 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4111 | &thermal_temp_input16_group); |
| 4112 | break; |
| 4113 | case TPACPI_THERMAL_TPEC_8: |
| 4114 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4115 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4116 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4117 | &thermal_temp_input16_group); |
| 4118 | break; |
| 4119 | case TPACPI_THERMAL_NONE: |
| 4120 | default: |
| 4121 | break; |
| 4122 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4123 | } |
| 4124 | |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4125 | /* idx is zero-based */ |
| 4126 | static int thermal_get_sensor(int idx, s32 *value) |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4127 | { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4128 | int t; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4129 | s8 tmp; |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4130 | char tmpi[5]; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4131 | |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4132 | t = TP_EC_THERMAL_TMP0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4133 | |
| 4134 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4135 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 4136 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4137 | if (idx >= 8 && idx <= 15) { |
| 4138 | t = TP_EC_THERMAL_TMP8; |
| 4139 | idx -= 8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4140 | } |
| 4141 | /* fallthrough */ |
| 4142 | #endif |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4143 | case TPACPI_THERMAL_TPEC_8: |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4144 | if (idx <= 7) { |
| 4145 | if (!acpi_ec_read(t + idx, &tmp)) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4146 | return -EIO; |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4147 | *value = tmp * 1000; |
| 4148 | return 0; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4149 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4150 | break; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4151 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4152 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4153 | if (idx <= 7) { |
| 4154 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 4155 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 4156 | return -EIO; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4157 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 4158 | return -EIO; |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4159 | *value = (t - 2732) * 100; |
| 4160 | return 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4161 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4162 | break; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4163 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4164 | case TPACPI_THERMAL_ACPI_TMP07: |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4165 | if (idx <= 7) { |
| 4166 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4167 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 4168 | return -EIO; |
Henrique de Moraes Holschuh | a8fba3da | 2007-07-18 23:45:45 -0300 | [diff] [blame] | 4169 | if (t > 127 || t < -127) |
| 4170 | t = TP_EC_THERMAL_TMP_NA; |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4171 | *value = t * 1000; |
| 4172 | return 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4173 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4174 | break; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4175 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4176 | case TPACPI_THERMAL_NONE: |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4177 | default: |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4178 | return -ENOSYS; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4179 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4180 | |
| 4181 | return -EINVAL; |
| 4182 | } |
| 4183 | |
| 4184 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 4185 | { |
| 4186 | int res, i; |
| 4187 | int n; |
| 4188 | |
| 4189 | n = 8; |
| 4190 | i = 0; |
| 4191 | |
| 4192 | if (!s) |
| 4193 | return -EINVAL; |
| 4194 | |
| 4195 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 4196 | n = 16; |
| 4197 | |
| 4198 | for(i = 0 ; i < n; i++) { |
| 4199 | res = thermal_get_sensor(i, &s->temp[i]); |
| 4200 | if (res) |
| 4201 | return res; |
| 4202 | } |
| 4203 | |
| 4204 | return n; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4205 | } |
| 4206 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4207 | static int thermal_read(char *p) |
| 4208 | { |
| 4209 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4210 | int n, i; |
| 4211 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4212 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4213 | n = thermal_get_sensors(&t); |
| 4214 | if (unlikely(n < 0)) |
| 4215 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4216 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4217 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4218 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4219 | if (n > 0) { |
| 4220 | for (i = 0; i < (n - 1); i++) |
| 4221 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 4222 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 4223 | } else |
| 4224 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4225 | |
| 4226 | return len; |
| 4227 | } |
| 4228 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4229 | static struct ibm_struct thermal_driver_data = { |
| 4230 | .name = "thermal", |
| 4231 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4232 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4233 | }; |
| 4234 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4235 | /************************************************************************* |
| 4236 | * EC Dump subdriver |
| 4237 | */ |
| 4238 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4239 | static u8 ecdump_regs[256]; |
| 4240 | |
| 4241 | static int ecdump_read(char *p) |
| 4242 | { |
| 4243 | int len = 0; |
| 4244 | int i, j; |
| 4245 | u8 v; |
| 4246 | |
| 4247 | len += sprintf(p + len, "EC " |
| 4248 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 4249 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 4250 | for (i = 0; i < 256; i += 16) { |
| 4251 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 4252 | for (j = 0; j < 16; j++) { |
| 4253 | if (!acpi_ec_read(i + j, &v)) |
| 4254 | break; |
| 4255 | if (v != ecdump_regs[i + j]) |
| 4256 | len += sprintf(p + len, " *%02x", v); |
| 4257 | else |
| 4258 | len += sprintf(p + len, " %02x", v); |
| 4259 | ecdump_regs[i + j] = v; |
| 4260 | } |
| 4261 | len += sprintf(p + len, "\n"); |
| 4262 | if (j != 16) |
| 4263 | break; |
| 4264 | } |
| 4265 | |
| 4266 | /* These are way too dangerous to advertise openly... */ |
| 4267 | #if 0 |
| 4268 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 4269 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 4270 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 4271 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 4272 | #endif |
| 4273 | return len; |
| 4274 | } |
| 4275 | |
| 4276 | static int ecdump_write(char *buf) |
| 4277 | { |
| 4278 | char *cmd; |
| 4279 | int i, v; |
| 4280 | |
| 4281 | while ((cmd = next_cmd(&buf))) { |
| 4282 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 4283 | /* i and v set */ |
| 4284 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 4285 | /* i and v set */ |
| 4286 | } else |
| 4287 | return -EINVAL; |
| 4288 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 4289 | if (!acpi_ec_write(i, v)) |
| 4290 | return -EIO; |
| 4291 | } else |
| 4292 | return -EINVAL; |
| 4293 | } |
| 4294 | |
| 4295 | return 0; |
| 4296 | } |
| 4297 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4298 | static struct ibm_struct ecdump_driver_data = { |
| 4299 | .name = "ecdump", |
| 4300 | .read = ecdump_read, |
| 4301 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 4302 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4303 | }; |
| 4304 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4305 | /************************************************************************* |
| 4306 | * Backlight/brightness subdriver |
| 4307 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 4308 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 4309 | static struct backlight_device *ibm_backlight_device; |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 4310 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 4311 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4312 | .get_brightness = brightness_get, |
| 4313 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4314 | }; |
| 4315 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4316 | static struct mutex brightness_mutex; |
| 4317 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4318 | static int __init tpacpi_query_bcll_levels(acpi_handle handle) |
| 4319 | { |
| 4320 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 4321 | union acpi_object *obj; |
| 4322 | int rc; |
| 4323 | |
| 4324 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { |
| 4325 | obj = (union acpi_object *)buffer.pointer; |
| 4326 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
| 4327 | printk(IBM_ERR "Unknown BCLL data, " |
| 4328 | "please report this to %s\n", IBM_MAIL); |
| 4329 | rc = 0; |
| 4330 | } else { |
| 4331 | rc = obj->package.count; |
| 4332 | } |
| 4333 | } else { |
| 4334 | return 0; |
| 4335 | } |
| 4336 | |
| 4337 | kfree(buffer.pointer); |
| 4338 | return rc; |
| 4339 | } |
| 4340 | |
| 4341 | static acpi_status __init brightness_find_bcll(acpi_handle handle, u32 lvl, |
| 4342 | void *context, void **rv) |
| 4343 | { |
| 4344 | char name[ACPI_PATH_SEGMENT_LENGTH]; |
| 4345 | struct acpi_buffer buffer = { sizeof(name), &name }; |
| 4346 | |
| 4347 | if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && |
| 4348 | !strncmp("BCLL", name, sizeof(name) - 1)) { |
| 4349 | if (tpacpi_query_bcll_levels(handle) == 16) { |
| 4350 | *rv = handle; |
| 4351 | return AE_CTRL_TERMINATE; |
| 4352 | } else { |
| 4353 | return AE_OK; |
| 4354 | } |
| 4355 | } else { |
| 4356 | return AE_OK; |
| 4357 | } |
| 4358 | } |
| 4359 | |
| 4360 | static int __init brightness_check_levels(void) |
| 4361 | { |
| 4362 | int status; |
| 4363 | void *found_node = NULL; |
| 4364 | |
| 4365 | if (!vid_handle) { |
| 4366 | IBM_ACPIHANDLE_INIT(vid); |
| 4367 | } |
| 4368 | if (!vid_handle) |
| 4369 | return 0; |
| 4370 | |
| 4371 | /* Search for a BCLL package with 16 levels */ |
| 4372 | status = acpi_walk_namespace(ACPI_TYPE_PACKAGE, vid_handle, 3, |
| 4373 | brightness_find_bcll, NULL, &found_node); |
| 4374 | |
| 4375 | return (ACPI_SUCCESS(status) && found_node != NULL); |
| 4376 | } |
| 4377 | |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 4378 | static acpi_status __init brightness_find_bcl(acpi_handle handle, u32 lvl, |
| 4379 | void *context, void **rv) |
| 4380 | { |
| 4381 | char name[ACPI_PATH_SEGMENT_LENGTH]; |
| 4382 | struct acpi_buffer buffer = { sizeof(name), &name }; |
| 4383 | |
| 4384 | if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && |
| 4385 | !strncmp("_BCL", name, sizeof(name) - 1)) { |
| 4386 | *rv = handle; |
| 4387 | return AE_CTRL_TERMINATE; |
| 4388 | } else { |
| 4389 | return AE_OK; |
| 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | static int __init brightness_check_std_acpi_support(void) |
| 4394 | { |
| 4395 | int status; |
| 4396 | void *found_node = NULL; |
| 4397 | |
| 4398 | if (!vid_handle) { |
| 4399 | IBM_ACPIHANDLE_INIT(vid); |
| 4400 | } |
| 4401 | if (!vid_handle) |
| 4402 | return 0; |
| 4403 | |
| 4404 | /* Search for a _BCL method, but don't execute it */ |
| 4405 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, |
| 4406 | brightness_find_bcl, NULL, &found_node); |
| 4407 | |
| 4408 | return (ACPI_SUCCESS(status) && found_node != NULL); |
| 4409 | } |
| 4410 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4411 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4412 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4413 | int b; |
| 4414 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4415 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 4416 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4417 | mutex_init(&brightness_mutex); |
| 4418 | |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 4419 | if (!brightness_enable) { |
| 4420 | dbg_printk(TPACPI_DBG_INIT, |
| 4421 | "brightness support disabled by module parameter\n"); |
| 4422 | return 1; |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 4423 | } else if (brightness_enable > 1) { |
| 4424 | if (brightness_check_std_acpi_support()) { |
| 4425 | printk(IBM_NOTICE |
| 4426 | "standard ACPI backlight interface available, not loading native one...\n"); |
| 4427 | return 1; |
| 4428 | } |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 4429 | } |
| 4430 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4431 | if (!brightness_mode) { |
| 4432 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) |
| 4433 | brightness_mode = 2; |
| 4434 | else |
| 4435 | brightness_mode = 3; |
| 4436 | |
| 4437 | dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n", |
| 4438 | brightness_mode); |
| 4439 | } |
| 4440 | |
| 4441 | if (brightness_mode > 3) |
| 4442 | return -EINVAL; |
| 4443 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4444 | tp_features.bright_16levels = |
| 4445 | thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO && |
| 4446 | brightness_check_levels(); |
| 4447 | |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4448 | b = brightness_get(NULL); |
| 4449 | if (b < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4450 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4451 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4452 | if (tp_features.bright_16levels) |
| 4453 | printk(IBM_INFO "detected a 16-level brightness capable ThinkPad\n"); |
| 4454 | |
Henrique de Moraes Holschuh | 7d5a015 | 2007-04-24 11:48:20 -0300 | [diff] [blame] | 4455 | ibm_backlight_device = backlight_device_register( |
| 4456 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
| 4457 | &ibm_backlight_data); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4458 | if (IS_ERR(ibm_backlight_device)) { |
| 4459 | printk(IBM_ERR "Could not register backlight device\n"); |
| 4460 | return PTR_ERR(ibm_backlight_device); |
| 4461 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4462 | vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4463 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4464 | ibm_backlight_device->props.max_brightness = |
| 4465 | (tp_features.bright_16levels)? 15 : 7; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4466 | ibm_backlight_device->props.brightness = b; |
| 4467 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 4468 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4469 | return 0; |
| 4470 | } |
| 4471 | |
| 4472 | static void brightness_exit(void) |
| 4473 | { |
| 4474 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4475 | vdbg_printk(TPACPI_DBG_EXIT, |
| 4476 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4477 | backlight_device_unregister(ibm_backlight_device); |
| 4478 | ibm_backlight_device = NULL; |
| 4479 | } |
| 4480 | } |
| 4481 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4482 | static int brightness_update_status(struct backlight_device *bd) |
| 4483 | { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4484 | /* it is the backlight class's job (caller) to handle |
| 4485 | * EINTR and other errors properly */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4486 | return brightness_set( |
| 4487 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 4488 | bd->props.power == FB_BLANK_UNBLANK) ? |
| 4489 | bd->props.brightness : 0); |
| 4490 | } |
| 4491 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4492 | /* |
| 4493 | * ThinkPads can read brightness from two places: EC 0x31, or |
| 4494 | * CMOS NVRAM byte 0x5E, bits 0-3. |
| 4495 | */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4496 | static int brightness_get(struct backlight_device *bd) |
| 4497 | { |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4498 | u8 lec = 0, lcmos = 0, level = 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4499 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4500 | if (brightness_mode & 1) { |
| 4501 | if (!acpi_ec_read(brightness_offset, &lec)) |
| 4502 | return -EIO; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4503 | lec &= (tp_features.bright_16levels)? 0x0f : 0x07; |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4504 | level = lec; |
| 4505 | }; |
| 4506 | if (brightness_mode & 2) { |
| 4507 | lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 4508 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 4509 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4510 | lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07; |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4511 | level = lcmos; |
| 4512 | } |
| 4513 | |
| 4514 | if (brightness_mode == 3 && lec != lcmos) { |
| 4515 | printk(IBM_ERR |
| 4516 | "CMOS NVRAM (%u) and EC (%u) do not agree " |
| 4517 | "on display brightness level\n", |
| 4518 | (unsigned int) lcmos, |
| 4519 | (unsigned int) lec); |
| 4520 | return -EIO; |
| 4521 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4522 | |
| 4523 | return level; |
| 4524 | } |
| 4525 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4526 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4527 | static int brightness_set(int value) |
| 4528 | { |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4529 | int cmos_cmd, inc, i, res; |
| 4530 | int current_value; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4531 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4532 | if (value > ((tp_features.bright_16levels)? 15 : 7)) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4533 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4534 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4535 | res = mutex_lock_interruptible(&brightness_mutex); |
| 4536 | if (res < 0) |
| 4537 | return res; |
| 4538 | |
| 4539 | current_value = brightness_get(NULL); |
| 4540 | if (current_value < 0) { |
| 4541 | res = current_value; |
| 4542 | goto errout; |
| 4543 | } |
| 4544 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4545 | cmos_cmd = value > current_value ? |
| 4546 | TP_CMOS_BRIGHTNESS_UP : |
| 4547 | TP_CMOS_BRIGHTNESS_DOWN; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4548 | inc = (value > current_value)? 1 : -1; |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4549 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4550 | res = 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4551 | for (i = current_value; i != value; i += inc) { |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4552 | if ((brightness_mode & 2) && |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4553 | issue_thinkpad_cmos_command(cmos_cmd)) { |
| 4554 | res = -EIO; |
| 4555 | goto errout; |
| 4556 | } |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4557 | if ((brightness_mode & 1) && |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4558 | !acpi_ec_write(brightness_offset, i + inc)) { |
| 4559 | res = -EIO; |
| 4560 | goto errout;; |
| 4561 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4562 | } |
| 4563 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4564 | errout: |
| 4565 | mutex_unlock(&brightness_mutex); |
| 4566 | return res; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | static int brightness_read(char *p) |
| 4570 | { |
| 4571 | int len = 0; |
| 4572 | int level; |
| 4573 | |
| 4574 | if ((level = brightness_get(NULL)) < 0) { |
| 4575 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 4576 | } else { |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4577 | len += sprintf(p + len, "level:\t\t%d\n", level); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4578 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 4579 | len += sprintf(p + len, "commands:\tlevel <level>" |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4580 | " (<level> is 0-%d)\n", |
| 4581 | (tp_features.bright_16levels) ? 15 : 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4582 | } |
| 4583 | |
| 4584 | return len; |
| 4585 | } |
| 4586 | |
| 4587 | static int brightness_write(char *buf) |
| 4588 | { |
| 4589 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4590 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4591 | char *cmd; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4592 | int max_level = (tp_features.bright_16levels) ? 15 : 7; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4593 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4594 | level = brightness_get(NULL); |
| 4595 | if (level < 0) |
| 4596 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4597 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4598 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4599 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4600 | if (level < max_level) |
| 4601 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4602 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4603 | if (level > 0) |
| 4604 | level--; |
| 4605 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
| 4606 | level >= 0 && level <= max_level) { |
| 4607 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4608 | } else |
| 4609 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4610 | } |
| 4611 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4612 | /* |
| 4613 | * Now we know what the final level should be, so we try to set it. |
| 4614 | * Doing it this way makes the syscall restartable in case of EINTR |
| 4615 | */ |
| 4616 | rc = brightness_set(level); |
| 4617 | return (rc == -EINTR)? ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4618 | } |
| 4619 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4620 | static struct ibm_struct brightness_driver_data = { |
| 4621 | .name = "brightness", |
| 4622 | .read = brightness_read, |
| 4623 | .write = brightness_write, |
| 4624 | .exit = brightness_exit, |
| 4625 | }; |
| 4626 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4627 | /************************************************************************* |
| 4628 | * Volume subdriver |
| 4629 | */ |
| 4630 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4631 | static int volume_read(char *p) |
| 4632 | { |
| 4633 | int len = 0; |
| 4634 | u8 level; |
| 4635 | |
| 4636 | if (!acpi_ec_read(volume_offset, &level)) { |
| 4637 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 4638 | } else { |
| 4639 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 4640 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 4641 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 4642 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 4643 | " (<level> is 0-15)\n"); |
| 4644 | } |
| 4645 | |
| 4646 | return len; |
| 4647 | } |
| 4648 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4649 | static int volume_write(char *buf) |
| 4650 | { |
| 4651 | int cmos_cmd, inc, i; |
| 4652 | u8 level, mute; |
| 4653 | int new_level, new_mute; |
| 4654 | char *cmd; |
| 4655 | |
| 4656 | while ((cmd = next_cmd(&buf))) { |
| 4657 | if (!acpi_ec_read(volume_offset, &level)) |
| 4658 | return -EIO; |
| 4659 | new_mute = mute = level & 0x40; |
| 4660 | new_level = level = level & 0xf; |
| 4661 | |
| 4662 | if (strlencmp(cmd, "up") == 0) { |
| 4663 | if (mute) |
| 4664 | new_mute = 0; |
| 4665 | else |
| 4666 | new_level = level == 15 ? 15 : level + 1; |
| 4667 | } else if (strlencmp(cmd, "down") == 0) { |
| 4668 | if (mute) |
| 4669 | new_mute = 0; |
| 4670 | else |
| 4671 | new_level = level == 0 ? 0 : level - 1; |
| 4672 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 4673 | new_level >= 0 && new_level <= 15) { |
| 4674 | /* new_level set */ |
| 4675 | } else if (strlencmp(cmd, "mute") == 0) { |
| 4676 | new_mute = 0x40; |
| 4677 | } else |
| 4678 | return -EINVAL; |
| 4679 | |
| 4680 | if (new_level != level) { /* mute doesn't change */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4681 | cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4682 | inc = new_level > level ? 1 : -1; |
| 4683 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4684 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4685 | !acpi_ec_write(volume_offset, level))) |
| 4686 | return -EIO; |
| 4687 | |
| 4688 | for (i = level; i != new_level; i += inc) |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4689 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4690 | !acpi_ec_write(volume_offset, i + inc)) |
| 4691 | return -EIO; |
| 4692 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4693 | if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4694 | !acpi_ec_write(volume_offset, |
| 4695 | new_level + mute))) |
| 4696 | return -EIO; |
| 4697 | } |
| 4698 | |
| 4699 | if (new_mute != mute) { /* level doesn't change */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4700 | cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4701 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4702 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4703 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 4704 | return -EIO; |
| 4705 | } |
| 4706 | } |
| 4707 | |
| 4708 | return 0; |
| 4709 | } |
| 4710 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4711 | static struct ibm_struct volume_driver_data = { |
| 4712 | .name = "volume", |
| 4713 | .read = volume_read, |
| 4714 | .write = volume_write, |
| 4715 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4716 | |
| 4717 | /************************************************************************* |
| 4718 | * Fan subdriver |
| 4719 | */ |
| 4720 | |
| 4721 | /* |
| 4722 | * FAN ACCESS MODES |
| 4723 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4724 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4725 | * ACPI GFAN method: returns fan level |
| 4726 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4727 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4728 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4729 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4730 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4731 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 4732 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4733 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 4734 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4735 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4736 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4737 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 4738 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4739 | * |
| 4740 | * Fan speed changes of any sort (including those caused by the |
| 4741 | * disengaged mode) are usually done slowly by the firmware as the |
| 4742 | * maximum ammount of fan duty cycle change per second seems to be |
| 4743 | * limited. |
| 4744 | * |
| 4745 | * Reading is not available if GFAN exists. |
| 4746 | * Writing is not available if SFAN exists. |
| 4747 | * |
| 4748 | * Bits |
| 4749 | * 7 automatic mode engaged; |
| 4750 | * (default operation mode of the ThinkPad) |
| 4751 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4752 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4753 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4754 | * the tachometer while the fan controller ramps up |
| 4755 | * the speed (which can take up to a few *minutes*). |
| 4756 | * Speeds up fan to 100% duty-cycle, which is far above |
| 4757 | * the standard RPM levels. It is not impossible that |
| 4758 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4759 | * 5-3 unused in some models. Extra bits for fan level |
| 4760 | * in others, but still useless as all values above |
| 4761 | * 7 map to the same speed as level 7 in these models. |
| 4762 | * 2-0 fan level (0..7 usually) |
| 4763 | * 0x00 = stop |
| 4764 | * 0x07 = max (set when temperatures critical) |
| 4765 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4766 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4767 | * |
| 4768 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 4769 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 4770 | * does so, its initial value is meaningless (0x07). |
| 4771 | * |
| 4772 | * For firmware bugs, refer to: |
| 4773 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 4774 | * |
| 4775 | * ---- |
| 4776 | * |
| 4777 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 4778 | * Main fan tachometer reading (in RPM) |
| 4779 | * |
| 4780 | * This register is present on all ThinkPads with a new-style EC, and |
| 4781 | * it is known not to be present on the A21m/e, and T22, as there is |
| 4782 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 4783 | * ThinkPads from this same time period (and earlier) probably lack the |
| 4784 | * tachometer as well. |
| 4785 | * |
| 4786 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare |
| 4787 | * was never fixed by IBM to report the EC firmware version string |
| 4788 | * probably support the tachometer (like the early X models), so |
| 4789 | * detecting it is quite hard. We need more data to know for sure. |
| 4790 | * |
| 4791 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 4792 | * might result. |
| 4793 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4794 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 4795 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4796 | * |
| 4797 | * For firmware bugs, refer to: |
| 4798 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 4799 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4800 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4801 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 4802 | * |
| 4803 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 4804 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 4805 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 4806 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 4807 | * |
| 4808 | * The speeds are stored on handles |
| 4809 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 4810 | * |
| 4811 | * There are three default speed sets, acessible as handles: |
| 4812 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 4813 | * |
| 4814 | * ACPI DSDT switches which set is in use depending on various |
| 4815 | * factors. |
| 4816 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4817 | * 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] | 4818 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 4819 | * but the ACPI tables just mention level 7. |
| 4820 | */ |
| 4821 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 4822 | static enum fan_status_access_mode fan_status_access_mode; |
| 4823 | static enum fan_control_access_mode fan_control_access_mode; |
| 4824 | static enum fan_control_commands fan_control_commands; |
| 4825 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 4826 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 4827 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 4828 | |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 4829 | static void fan_watchdog_fire(struct work_struct *ignored); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 4830 | static int fan_watchdog_maxinterval; |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 4831 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 4832 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4833 | IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 4834 | IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ |
| 4835 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 4836 | ); /* all others */ |
| 4837 | IBM_HANDLE(sfan, ec, "SFAN", /* 570 */ |
| 4838 | "JFNS", /* 770x-JL */ |
| 4839 | ); /* all others */ |
| 4840 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 4841 | /* |
| 4842 | * SYSFS fan layout: hwmon compatible (device) |
| 4843 | * |
| 4844 | * pwm*_enable: |
| 4845 | * 0: "disengaged" mode |
| 4846 | * 1: manual mode |
| 4847 | * 2: native EC "auto" mode (recommended, hardware default) |
| 4848 | * |
| 4849 | * pwm*: set speed in manual mode, ignored otherwise. |
| 4850 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 4851 | * interpolation. |
| 4852 | * |
| 4853 | * fan*_input: tachometer reading, RPM |
| 4854 | * |
| 4855 | * |
| 4856 | * SYSFS fan layout: extensions |
| 4857 | * |
| 4858 | * fan_watchdog (driver): |
| 4859 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 4860 | */ |
| 4861 | |
| 4862 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 4863 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 4864 | struct device_attribute *attr, |
| 4865 | char *buf) |
| 4866 | { |
| 4867 | int res, mode; |
| 4868 | u8 status; |
| 4869 | |
| 4870 | res = fan_get_status_safe(&status); |
| 4871 | if (res) |
| 4872 | return res; |
| 4873 | |
| 4874 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 4875 | if (status != fan_control_initial_status) { |
| 4876 | tp_features.fan_ctrl_status_undef = 0; |
| 4877 | } else { |
| 4878 | /* Return most likely status. In fact, it |
| 4879 | * might be the only possible status */ |
| 4880 | status = TP_EC_FAN_AUTO; |
| 4881 | } |
| 4882 | } |
| 4883 | |
| 4884 | if (status & TP_EC_FAN_FULLSPEED) { |
| 4885 | mode = 0; |
| 4886 | } else if (status & TP_EC_FAN_AUTO) { |
| 4887 | mode = 2; |
| 4888 | } else |
| 4889 | mode = 1; |
| 4890 | |
| 4891 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 4892 | } |
| 4893 | |
| 4894 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 4895 | struct device_attribute *attr, |
| 4896 | const char *buf, size_t count) |
| 4897 | { |
| 4898 | unsigned long t; |
| 4899 | int res, level; |
| 4900 | |
| 4901 | if (parse_strtoul(buf, 2, &t)) |
| 4902 | return -EINVAL; |
| 4903 | |
| 4904 | switch (t) { |
| 4905 | case 0: |
| 4906 | level = TP_EC_FAN_FULLSPEED; |
| 4907 | break; |
| 4908 | case 1: |
| 4909 | level = TPACPI_FAN_LAST_LEVEL; |
| 4910 | break; |
| 4911 | case 2: |
| 4912 | level = TP_EC_FAN_AUTO; |
| 4913 | break; |
| 4914 | case 3: |
| 4915 | /* reserved for software-controlled auto mode */ |
| 4916 | return -ENOSYS; |
| 4917 | default: |
| 4918 | return -EINVAL; |
| 4919 | } |
| 4920 | |
| 4921 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 4922 | if (res == -ENXIO) |
| 4923 | return -EINVAL; |
| 4924 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 4925 | return res; |
| 4926 | |
| 4927 | fan_watchdog_reset(); |
| 4928 | |
| 4929 | return count; |
| 4930 | } |
| 4931 | |
| 4932 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 4933 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 4934 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 4935 | |
| 4936 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 4937 | static ssize_t fan_pwm1_show(struct device *dev, |
| 4938 | struct device_attribute *attr, |
| 4939 | char *buf) |
| 4940 | { |
| 4941 | int res; |
| 4942 | u8 status; |
| 4943 | |
| 4944 | res = fan_get_status_safe(&status); |
| 4945 | if (res) |
| 4946 | return res; |
| 4947 | |
| 4948 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 4949 | if (status != fan_control_initial_status) { |
| 4950 | tp_features.fan_ctrl_status_undef = 0; |
| 4951 | } else { |
| 4952 | status = TP_EC_FAN_AUTO; |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | if ((status & |
| 4957 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 4958 | status = fan_control_desired_level; |
| 4959 | |
| 4960 | if (status > 7) |
| 4961 | status = 7; |
| 4962 | |
| 4963 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 4964 | } |
| 4965 | |
| 4966 | static ssize_t fan_pwm1_store(struct device *dev, |
| 4967 | struct device_attribute *attr, |
| 4968 | const char *buf, size_t count) |
| 4969 | { |
| 4970 | unsigned long s; |
| 4971 | int rc; |
| 4972 | u8 status, newlevel; |
| 4973 | |
| 4974 | if (parse_strtoul(buf, 255, &s)) |
| 4975 | return -EINVAL; |
| 4976 | |
| 4977 | /* scale down from 0-255 to 0-7 */ |
| 4978 | newlevel = (s >> 5) & 0x07; |
| 4979 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 4980 | if (mutex_lock_interruptible(&fan_mutex)) |
| 4981 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 4982 | |
| 4983 | rc = fan_get_status(&status); |
| 4984 | if (!rc && (status & |
| 4985 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 4986 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 4987 | if (rc == -ENXIO) |
| 4988 | rc = -EINVAL; |
| 4989 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 4990 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 4991 | fan_watchdog_reset(); |
| 4992 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | mutex_unlock(&fan_mutex); |
| 4996 | return (rc)? rc : count; |
| 4997 | } |
| 4998 | |
| 4999 | static struct device_attribute dev_attr_fan_pwm1 = |
| 5000 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 5001 | fan_pwm1_show, fan_pwm1_store); |
| 5002 | |
| 5003 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 5004 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 5005 | struct device_attribute *attr, |
| 5006 | char *buf) |
| 5007 | { |
| 5008 | int res; |
| 5009 | unsigned int speed; |
| 5010 | |
| 5011 | res = fan_get_speed(&speed); |
| 5012 | if (res < 0) |
| 5013 | return res; |
| 5014 | |
| 5015 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 5016 | } |
| 5017 | |
| 5018 | static struct device_attribute dev_attr_fan_fan1_input = |
| 5019 | __ATTR(fan1_input, S_IRUGO, |
| 5020 | fan_fan1_input_show, NULL); |
| 5021 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5022 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5023 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 5024 | char *buf) |
| 5025 | { |
| 5026 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 5027 | } |
| 5028 | |
| 5029 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 5030 | const char *buf, size_t count) |
| 5031 | { |
| 5032 | unsigned long t; |
| 5033 | |
| 5034 | if (parse_strtoul(buf, 120, &t)) |
| 5035 | return -EINVAL; |
| 5036 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5037 | if (!fan_control_allowed) |
| 5038 | return -EPERM; |
| 5039 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5040 | fan_watchdog_maxinterval = t; |
| 5041 | fan_watchdog_reset(); |
| 5042 | |
| 5043 | return count; |
| 5044 | } |
| 5045 | |
| 5046 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 5047 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 5048 | |
| 5049 | /* --------------------------------------------------------------------- */ |
| 5050 | static struct attribute *fan_attributes[] = { |
| 5051 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 5052 | &dev_attr_fan_fan1_input.attr, |
| 5053 | NULL |
| 5054 | }; |
| 5055 | |
| 5056 | static const struct attribute_group fan_attr_group = { |
| 5057 | .attrs = fan_attributes, |
| 5058 | }; |
| 5059 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5060 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5061 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5062 | int rc; |
| 5063 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5064 | vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n"); |
| 5065 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5066 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5067 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 5068 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5069 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5070 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5071 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5072 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5073 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5074 | IBM_ACPIHANDLE_INIT(fans); |
| 5075 | IBM_ACPIHANDLE_INIT(gfan); |
| 5076 | IBM_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5077 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5078 | if (gfan_handle) { |
| 5079 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5080 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5081 | } else { |
| 5082 | /* all other ThinkPads: note that even old-style |
| 5083 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5084 | if (likely(acpi_ec_read(fan_status_offset, |
| 5085 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5086 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5087 | |
| 5088 | /* In some ThinkPads, neither the EC nor the ACPI |
| 5089 | * DSDT initialize the fan status, and it ends up |
| 5090 | * being set to 0x07 when it *could* be either |
| 5091 | * 0x07 or 0x80. |
| 5092 | * |
| 5093 | * Enable for TP-1Y (T43), TP-78 (R51e), |
| 5094 | * TP-76 (R52), TP-70 (T43, R52), which are known |
| 5095 | * to be buggy. */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5096 | if (fan_control_initial_status == 0x07) { |
| 5097 | switch (thinkpad_id.ec_model) { |
| 5098 | case 0x5931: /* TP-1Y */ |
| 5099 | case 0x3837: /* TP-78 */ |
| 5100 | case 0x3637: /* TP-76 */ |
| 5101 | case 0x3037: /* TP-70 */ |
| 5102 | printk(IBM_NOTICE |
| 5103 | "fan_init: initial fan status is " |
| 5104 | "unknown, assuming it is in auto " |
| 5105 | "mode\n"); |
| 5106 | tp_features.fan_ctrl_status_undef = 1; |
| 5107 | ;; |
| 5108 | } |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5109 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5110 | } else { |
| 5111 | printk(IBM_ERR |
| 5112 | "ThinkPad ACPI EC access misbehaving, " |
| 5113 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5114 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5115 | } |
| 5116 | } |
| 5117 | |
| 5118 | if (sfan_handle) { |
| 5119 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5120 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5121 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5122 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5123 | } else { |
| 5124 | if (!gfan_handle) { |
| 5125 | /* gfan without sfan means no fan control */ |
| 5126 | /* all other models implement TP EC 0x2f control */ |
| 5127 | |
| 5128 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5129 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5130 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5131 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5132 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5133 | TPACPI_FAN_CMD_SPEED | |
| 5134 | TPACPI_FAN_CMD_LEVEL | |
| 5135 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5136 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5137 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5138 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5139 | TPACPI_FAN_CMD_LEVEL | |
| 5140 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5141 | } |
| 5142 | } |
| 5143 | } |
| 5144 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5145 | vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n", |
| 5146 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 5147 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 5148 | fan_status_access_mode, fan_control_access_mode); |
| 5149 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5150 | /* fan control master switch */ |
| 5151 | if (!fan_control_allowed) { |
| 5152 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 5153 | fan_control_commands = 0; |
| 5154 | dbg_printk(TPACPI_DBG_INIT, |
| 5155 | "fan control features disabled by parameter\n"); |
| 5156 | } |
| 5157 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5158 | /* update fan_control_desired_level */ |
| 5159 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 5160 | fan_get_status_safe(NULL); |
| 5161 | |
| 5162 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 5163 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5164 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5165 | &fan_attr_group); |
| 5166 | if (!(rc < 0)) |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5167 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5168 | &driver_attr_fan_watchdog); |
| 5169 | if (rc < 0) |
| 5170 | return rc; |
| 5171 | return 0; |
| 5172 | } else |
| 5173 | return 1; |
| 5174 | } |
| 5175 | |
| 5176 | /* |
| 5177 | * Call with fan_mutex held |
| 5178 | */ |
| 5179 | static void fan_update_desired_level(u8 status) |
| 5180 | { |
| 5181 | if ((status & |
| 5182 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 5183 | if (status > 7) |
| 5184 | fan_control_desired_level = 7; |
| 5185 | else |
| 5186 | fan_control_desired_level = status; |
| 5187 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5188 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5189 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 5190 | static int fan_get_status(u8 *status) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5191 | { |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 5192 | u8 s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5193 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5194 | /* TODO: |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5195 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5196 | |
Henrique de Moraes Holschuh | 3ef8a60 | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 5197 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5198 | case TPACPI_FAN_RD_ACPI_GFAN: |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5199 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 5200 | |
| 5201 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5202 | return -EIO; |
| 5203 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 5204 | if (likely(status)) |
| 5205 | *status = s & 0x07; |
| 5206 | |
| 5207 | break; |
| 5208 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5209 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 5210 | /* all except 570, 600e/x, 770e, 770x */ |
| 5211 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 5212 | return -EIO; |
| 5213 | |
| 5214 | if (likely(status)) |
| 5215 | *status = s; |
| 5216 | |
| 5217 | break; |
| 5218 | |
| 5219 | default: |
| 5220 | return -ENXIO; |
| 5221 | } |
| 5222 | |
| 5223 | return 0; |
| 5224 | } |
| 5225 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5226 | static int fan_get_status_safe(u8 *status) |
| 5227 | { |
| 5228 | int rc; |
| 5229 | u8 s; |
| 5230 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 5231 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5232 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5233 | rc = fan_get_status(&s); |
| 5234 | if (!rc) |
| 5235 | fan_update_desired_level(s); |
| 5236 | mutex_unlock(&fan_mutex); |
| 5237 | |
| 5238 | if (status) |
| 5239 | *status = s; |
| 5240 | |
| 5241 | return rc; |
| 5242 | } |
| 5243 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5244 | static void fan_exit(void) |
| 5245 | { |
Henrique de Moraes Holschuh | 99fba3f | 2007-04-21 11:08:44 -0300 | [diff] [blame] | 5246 | vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5247 | |
| 5248 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5249 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group); |
| 5250 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5251 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5252 | cancel_delayed_work(&fan_watchdog_task); |
| 5253 | flush_scheduled_work(); |
| 5254 | } |
| 5255 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 5256 | static int fan_get_speed(unsigned int *speed) |
| 5257 | { |
| 5258 | u8 hi, lo; |
| 5259 | |
| 5260 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5261 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 5262 | /* all except 570, 600e/x, 770e, 770x */ |
| 5263 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 5264 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 5265 | return -EIO; |
| 5266 | |
| 5267 | if (likely(speed)) |
| 5268 | *speed = (hi << 8) | lo; |
| 5269 | |
| 5270 | break; |
| 5271 | |
| 5272 | default: |
| 5273 | return -ENXIO; |
| 5274 | } |
| 5275 | |
| 5276 | return 0; |
| 5277 | } |
| 5278 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5279 | static void fan_watchdog_fire(struct work_struct *ignored) |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5280 | { |
Henrique de Moraes Holschuh | 99fba3f | 2007-04-21 11:08:44 -0300 | [diff] [blame] | 5281 | int rc; |
| 5282 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 5283 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 5284 | return; |
| 5285 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5286 | printk(IBM_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | 99fba3f | 2007-04-21 11:08:44 -0300 | [diff] [blame] | 5287 | rc = fan_set_enable(); |
| 5288 | if (rc < 0) { |
| 5289 | printk(IBM_ERR "fan watchdog: error %d while enabling fan, " |
| 5290 | "will try again later...\n", -rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5291 | /* reschedule for later */ |
| 5292 | fan_watchdog_reset(); |
| 5293 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | static void fan_watchdog_reset(void) |
| 5297 | { |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5298 | static int fan_watchdog_active; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5299 | |
Henrique de Moraes Holschuh | 4985cd0 | 2007-04-27 22:00:10 -0300 | [diff] [blame] | 5300 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 5301 | return; |
| 5302 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5303 | if (fan_watchdog_active) |
| 5304 | cancel_delayed_work(&fan_watchdog_task); |
| 5305 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 5306 | if (fan_watchdog_maxinterval > 0 && |
| 5307 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5308 | fan_watchdog_active = 1; |
| 5309 | if (!schedule_delayed_work(&fan_watchdog_task, |
| 5310 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 5311 | * 1000))) { |
| 5312 | printk(IBM_ERR "failed to schedule the fan watchdog, " |
| 5313 | "watchdog will not trigger\n"); |
| 5314 | } |
| 5315 | } else |
| 5316 | fan_watchdog_active = 0; |
| 5317 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5318 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5319 | static int fan_set_level(int level) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5320 | { |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5321 | if (!fan_control_allowed) |
| 5322 | return -EPERM; |
| 5323 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5324 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5325 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5326 | if (level >= 0 && level <= 7) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5327 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5328 | return -EIO; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5329 | } else |
| 5330 | return -EINVAL; |
| 5331 | break; |
| 5332 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5333 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5334 | case TPACPI_FAN_WR_TPEC: |
| 5335 | if ((level != TP_EC_FAN_AUTO) && |
| 5336 | (level != TP_EC_FAN_FULLSPEED) && |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5337 | ((level < 0) || (level > 7))) |
| 5338 | return -EINVAL; |
| 5339 | |
Henrique de Moraes Holschuh | eaa7571 | 2007-04-24 11:48:18 -0300 | [diff] [blame] | 5340 | /* safety net should the EC not support AUTO |
| 5341 | * or FULLSPEED mode bits and just ignore them */ |
| 5342 | if (level & TP_EC_FAN_FULLSPEED) |
| 5343 | level |= 7; /* safety min speed 7 */ |
| 5344 | else if (level & TP_EC_FAN_FULLSPEED) |
| 5345 | level |= 4; /* safety min speed 4 */ |
| 5346 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5347 | if (!acpi_ec_write(fan_status_offset, level)) |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5348 | return -EIO; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5349 | else |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5350 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5351 | break; |
| 5352 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5353 | default: |
| 5354 | return -ENXIO; |
| 5355 | } |
| 5356 | return 0; |
| 5357 | } |
| 5358 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5359 | static int fan_set_level_safe(int level) |
| 5360 | { |
| 5361 | int rc; |
| 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 | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 5366 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5367 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5368 | |
| 5369 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 5370 | level = fan_control_desired_level; |
| 5371 | |
| 5372 | rc = fan_set_level(level); |
| 5373 | if (!rc) |
| 5374 | fan_update_desired_level(level); |
| 5375 | |
| 5376 | mutex_unlock(&fan_mutex); |
| 5377 | return rc; |
| 5378 | } |
| 5379 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5380 | static int fan_set_enable(void) |
| 5381 | { |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5382 | u8 s; |
| 5383 | int rc; |
| 5384 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5385 | if (!fan_control_allowed) |
| 5386 | return -EPERM; |
| 5387 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 5388 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5389 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5390 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5391 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5392 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5393 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5394 | rc = fan_get_status(&s); |
| 5395 | if (rc < 0) |
| 5396 | break; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5397 | |
| 5398 | /* Don't go out of emergency fan mode */ |
Henrique de Moraes Holschuh | eaa7571 | 2007-04-24 11:48:18 -0300 | [diff] [blame] | 5399 | if (s != 7) { |
| 5400 | s &= 0x07; |
| 5401 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 5402 | } |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5403 | |
| 5404 | if (!acpi_ec_write(fan_status_offset, s)) |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5405 | rc = -EIO; |
| 5406 | else { |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5407 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5408 | rc = 0; |
| 5409 | } |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5410 | break; |
| 5411 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5412 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5413 | rc = fan_get_status(&s); |
| 5414 | if (rc < 0) |
| 5415 | break; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5416 | |
| 5417 | s &= 0x07; |
| 5418 | |
| 5419 | /* Set fan to at least level 4 */ |
Henrique de Moraes Holschuh | eaa7571 | 2007-04-24 11:48:18 -0300 | [diff] [blame] | 5420 | s |= 4; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5421 | |
| 5422 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5423 | rc= -EIO; |
| 5424 | else |
| 5425 | rc = 0; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5426 | break; |
| 5427 | |
| 5428 | default: |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5429 | rc = -ENXIO; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5430 | } |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5431 | |
| 5432 | mutex_unlock(&fan_mutex); |
| 5433 | return rc; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5434 | } |
| 5435 | |
| 5436 | static int fan_set_disable(void) |
| 5437 | { |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5438 | int rc; |
| 5439 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5440 | if (!fan_control_allowed) |
| 5441 | return -EPERM; |
| 5442 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 5443 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5444 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5445 | |
| 5446 | rc = 0; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5447 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5448 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5449 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5450 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5451 | rc = -EIO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5452 | else { |
| 5453 | fan_control_desired_level = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5454 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5455 | } |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5456 | break; |
| 5457 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5458 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5459 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5460 | rc = -EIO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5461 | else |
| 5462 | fan_control_desired_level = 0; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5463 | break; |
| 5464 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5465 | default: |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5466 | rc = -ENXIO; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5467 | } |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5468 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5469 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5470 | mutex_unlock(&fan_mutex); |
| 5471 | return rc; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5472 | } |
| 5473 | |
| 5474 | static int fan_set_speed(int speed) |
| 5475 | { |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5476 | int rc; |
| 5477 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5478 | if (!fan_control_allowed) |
| 5479 | return -EPERM; |
| 5480 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 5481 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5482 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5483 | |
| 5484 | rc = 0; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5485 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5486 | case TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5487 | if (speed >= 0 && speed <= 65535) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5488 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 5489 | speed, speed, speed)) |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5490 | rc = -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5491 | } else |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5492 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5493 | break; |
| 5494 | |
| 5495 | default: |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5496 | rc = -ENXIO; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5497 | } |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5498 | |
| 5499 | mutex_unlock(&fan_mutex); |
| 5500 | return rc; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5501 | } |
| 5502 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5503 | static int fan_read(char *p) |
| 5504 | { |
| 5505 | int len = 0; |
| 5506 | int rc; |
| 5507 | u8 status; |
| 5508 | unsigned int speed = 0; |
| 5509 | |
| 5510 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5511 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5512 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5513 | if ((rc = fan_get_status_safe(&status)) < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5514 | return rc; |
| 5515 | |
| 5516 | len += sprintf(p + len, "status:\t\t%s\n" |
| 5517 | "level:\t\t%d\n", |
| 5518 | (status != 0) ? "enabled" : "disabled", status); |
| 5519 | break; |
| 5520 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5521 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5522 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5523 | if ((rc = fan_get_status_safe(&status)) < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5524 | return rc; |
| 5525 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5526 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5527 | if (status != fan_control_initial_status) |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5528 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5529 | else |
| 5530 | /* Return most likely status. In fact, it |
| 5531 | * might be the only possible status */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5532 | status = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | len += sprintf(p + len, "status:\t\t%s\n", |
| 5536 | (status != 0) ? "enabled" : "disabled"); |
| 5537 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5538 | if ((rc = fan_get_speed(&speed)) < 0) |
| 5539 | return rc; |
| 5540 | |
| 5541 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 5542 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5543 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5544 | /* Disengaged mode takes precedence */ |
| 5545 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5546 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5547 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 5548 | else |
| 5549 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 5550 | break; |
| 5551 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5552 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5553 | default: |
| 5554 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5555 | } |
| 5556 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5557 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5558 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 5559 | |
| 5560 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5561 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5562 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 5563 | break; |
| 5564 | |
| 5565 | default: |
| 5566 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5567 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5568 | break; |
| 5569 | } |
| 5570 | } |
| 5571 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5572 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5573 | len += sprintf(p + len, "commands:\tenable, disable\n" |
| 5574 | "commands:\twatchdog <timeout> (<timeout> is 0 (off), " |
| 5575 | "1-120 (seconds))\n"); |
| 5576 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5577 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5578 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 5579 | " (<speed> is 0-65535)\n"); |
| 5580 | |
| 5581 | return len; |
| 5582 | } |
| 5583 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5584 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 5585 | { |
| 5586 | int level; |
| 5587 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5588 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5589 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5590 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
| 5591 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5592 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5593 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5594 | return 0; |
| 5595 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5596 | if ((*rc = fan_set_level_safe(level)) == -ENXIO) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5597 | printk(IBM_ERR "level command accepted for unsupported " |
| 5598 | "access mode %d", fan_control_access_mode); |
| 5599 | |
| 5600 | return 1; |
| 5601 | } |
| 5602 | |
| 5603 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 5604 | { |
| 5605 | if (strlencmp(cmd, "enable") != 0) |
| 5606 | return 0; |
| 5607 | |
| 5608 | if ((*rc = fan_set_enable()) == -ENXIO) |
| 5609 | printk(IBM_ERR "enable command accepted for unsupported " |
| 5610 | "access mode %d", fan_control_access_mode); |
| 5611 | |
| 5612 | return 1; |
| 5613 | } |
| 5614 | |
| 5615 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 5616 | { |
| 5617 | if (strlencmp(cmd, "disable") != 0) |
| 5618 | return 0; |
| 5619 | |
| 5620 | if ((*rc = fan_set_disable()) == -ENXIO) |
| 5621 | printk(IBM_ERR "disable command accepted for unsupported " |
| 5622 | "access mode %d", fan_control_access_mode); |
| 5623 | |
| 5624 | return 1; |
| 5625 | } |
| 5626 | |
| 5627 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 5628 | { |
| 5629 | int speed; |
| 5630 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5631 | /* TODO: |
| 5632 | * Support speed <low> <medium> <high> ? */ |
| 5633 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5634 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 5635 | return 0; |
| 5636 | |
| 5637 | if ((*rc = fan_set_speed(speed)) == -ENXIO) |
| 5638 | printk(IBM_ERR "speed command accepted for unsupported " |
| 5639 | "access mode %d", fan_control_access_mode); |
| 5640 | |
| 5641 | return 1; |
| 5642 | } |
| 5643 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5644 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 5645 | { |
| 5646 | int interval; |
| 5647 | |
| 5648 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 5649 | return 0; |
| 5650 | |
| 5651 | if (interval < 0 || interval > 120) |
| 5652 | *rc = -EINVAL; |
| 5653 | else |
| 5654 | fan_watchdog_maxinterval = interval; |
| 5655 | |
| 5656 | return 1; |
| 5657 | } |
| 5658 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5659 | static int fan_write(char *buf) |
| 5660 | { |
| 5661 | char *cmd; |
| 5662 | int rc = 0; |
| 5663 | |
| 5664 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5665 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5666 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5667 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5668 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5669 | fan_write_cmd_disable(cmd, &rc) || |
| 5670 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5671 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5672 | fan_write_cmd_speed(cmd, &rc)) |
| 5673 | ) |
| 5674 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5675 | else if (!rc) |
| 5676 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5677 | } |
| 5678 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5679 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5680 | } |
| 5681 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5682 | static struct ibm_struct fan_driver_data = { |
| 5683 | .name = "fan", |
| 5684 | .read = fan_read, |
| 5685 | .write = fan_write, |
| 5686 | .exit = fan_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5687 | }; |
| 5688 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5689 | /**************************************************************************** |
| 5690 | **************************************************************************** |
| 5691 | * |
| 5692 | * Infrastructure |
| 5693 | * |
| 5694 | **************************************************************************** |
| 5695 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5696 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5697 | /* sysfs name ---------------------------------------------------------- */ |
| 5698 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 5699 | struct device_attribute *attr, |
| 5700 | char *buf) |
| 5701 | { |
| 5702 | return snprintf(buf, PAGE_SIZE, "%s\n", IBM_NAME); |
| 5703 | } |
| 5704 | |
| 5705 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 5706 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 5707 | |
| 5708 | /* --------------------------------------------------------------------- */ |
| 5709 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5710 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 5711 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5712 | |
| 5713 | /* Subdriver registry */ |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5714 | static LIST_HEAD(tpacpi_all_drivers); |
| 5715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5716 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5717 | /* |
| 5718 | * Module and infrastructure proble, init and exit handling |
| 5719 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5720 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5721 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5722 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5723 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5724 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5725 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5726 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5727 | } |
| 5728 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 5729 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5730 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5731 | { |
| 5732 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5733 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5734 | struct proc_dir_entry *entry; |
| 5735 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5736 | BUG_ON(ibm == NULL); |
| 5737 | |
| 5738 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 5739 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5740 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5741 | return 0; |
| 5742 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5743 | dbg_printk(TPACPI_DBG_INIT, |
| 5744 | "probing for %s\n", ibm->name); |
| 5745 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5746 | if (iibm->init) { |
| 5747 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5748 | if (ret > 0) |
| 5749 | return 0; /* probe failed */ |
| 5750 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5751 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5752 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5753 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5754 | } |
| 5755 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5756 | if (ibm->acpi) { |
| 5757 | if (ibm->acpi->hid) { |
| 5758 | ret = register_tpacpi_subdriver(ibm); |
| 5759 | if (ret) |
| 5760 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5761 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5762 | |
| 5763 | if (ibm->acpi->notify) { |
| 5764 | ret = setup_acpi_notify(ibm); |
| 5765 | if (ret == -ENODEV) { |
| 5766 | printk(IBM_NOTICE "disabling subdriver %s\n", |
| 5767 | ibm->name); |
| 5768 | ret = 0; |
| 5769 | goto err_out; |
| 5770 | } |
| 5771 | if (ret < 0) |
| 5772 | goto err_out; |
| 5773 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5774 | } |
| 5775 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5776 | dbg_printk(TPACPI_DBG_INIT, |
| 5777 | "%s installed\n", ibm->name); |
| 5778 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5779 | if (ibm->read) { |
| 5780 | entry = create_proc_entry(ibm->name, |
| 5781 | S_IFREG | S_IRUGO | S_IWUSR, |
| 5782 | proc_dir); |
| 5783 | if (!entry) { |
| 5784 | printk(IBM_ERR "unable to create proc entry %s\n", |
| 5785 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5786 | ret = -ENODEV; |
| 5787 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5788 | } |
| 5789 | entry->owner = THIS_MODULE; |
| 5790 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5791 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5792 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5793 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5794 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5795 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5796 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5797 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 5798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5799 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5800 | |
| 5801 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5802 | dbg_printk(TPACPI_DBG_INIT, |
| 5803 | "%s: at error exit path with result %d\n", |
| 5804 | ibm->name, ret); |
| 5805 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5806 | ibm_exit(ibm); |
| 5807 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | static void ibm_exit(struct ibm_struct *ibm) |
| 5811 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5812 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5813 | |
| 5814 | list_del_init(&ibm->all_drivers); |
| 5815 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5816 | if (ibm->flags.acpi_notify_installed) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5817 | dbg_printk(TPACPI_DBG_EXIT, |
| 5818 | "%s: acpi_remove_notify_handler\n", ibm->name); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5819 | BUG_ON(!ibm->acpi); |
| 5820 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 5821 | ibm->acpi->type, |
| 5822 | dispatch_acpi_notify); |
| 5823 | ibm->flags.acpi_notify_installed = 0; |
| 5824 | ibm->flags.acpi_notify_installed = 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5825 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5827 | if (ibm->flags.proc_created) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5828 | dbg_printk(TPACPI_DBG_EXIT, |
| 5829 | "%s: remove_proc_entry\n", ibm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5830 | remove_proc_entry(ibm->name, proc_dir); |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5831 | ibm->flags.proc_created = 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5832 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5834 | if (ibm->flags.acpi_driver_registered) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5835 | dbg_printk(TPACPI_DBG_EXIT, |
| 5836 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5837 | BUG_ON(!ibm->acpi); |
| 5838 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 5839 | kfree(ibm->acpi->driver); |
| 5840 | ibm->acpi->driver = NULL; |
| 5841 | ibm->flags.acpi_driver_registered = 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5842 | } |
| 5843 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5844 | if (ibm->flags.init_called && ibm->exit) { |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5845 | ibm->exit(); |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 5846 | ibm->flags.init_called = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5848 | |
| 5849 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5850 | } |
| 5851 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5852 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5854 | 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] | 5855 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 5856 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5857 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5858 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5859 | if (!tp) |
| 5860 | return; |
| 5861 | |
| 5862 | memset(tp, 0, sizeof(*tp)); |
| 5863 | |
| 5864 | if (dmi_name_in_vendors("IBM")) |
| 5865 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 5866 | else if (dmi_name_in_vendors("LENOVO")) |
| 5867 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 5868 | else |
| 5869 | return; |
| 5870 | |
| 5871 | tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION), |
| 5872 | GFP_KERNEL); |
| 5873 | if (!tp->bios_version_str) |
| 5874 | return; |
| 5875 | tp->bios_model = tp->bios_version_str[0] |
| 5876 | | (tp->bios_version_str[1] << 8); |
| 5877 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5878 | /* |
| 5879 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 5880 | * X32 or newer, all Z series; Some models must have an |
| 5881 | * up-to-date BIOS or they will not be detected. |
| 5882 | * |
| 5883 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 5884 | */ |
| 5885 | 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] | 5886 | if (sscanf(dev->name, |
| 5887 | "IBM ThinkPad Embedded Controller -[%17c", |
| 5888 | ec_fw_string) == 1) { |
| 5889 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 5890 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5891 | |
| 5892 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
| 5893 | tp->ec_model = ec_fw_string[0] |
| 5894 | | (ec_fw_string[1] << 8); |
| 5895 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5896 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 5897 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5898 | |
| 5899 | tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION), |
| 5900 | GFP_KERNEL); |
| 5901 | if (strnicmp(tp->model_str, "ThinkPad", 8) != 0) { |
| 5902 | kfree(tp->model_str); |
| 5903 | tp->model_str = NULL; |
| 5904 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5905 | } |
| 5906 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5907 | static int __init probe_for_thinkpad(void) |
| 5908 | { |
| 5909 | int is_thinkpad; |
| 5910 | |
| 5911 | if (acpi_disabled) |
| 5912 | return -ENODEV; |
| 5913 | |
| 5914 | /* |
| 5915 | * Non-ancient models have better DMI tagging, but very old models |
| 5916 | * don't. |
| 5917 | */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5918 | is_thinkpad = (thinkpad_id.model_str != NULL); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5919 | |
| 5920 | /* ec is required because many other handles are relative to it */ |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 5921 | IBM_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5922 | if (!ec_handle) { |
| 5923 | if (is_thinkpad) |
| 5924 | printk(IBM_ERR |
| 5925 | "Not yet supported ThinkPad detected!\n"); |
| 5926 | return -ENODEV; |
| 5927 | } |
| 5928 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 5929 | /* |
| 5930 | * Risks a regression on very old machines, but reduces potential |
| 5931 | * false positives a damn great deal |
| 5932 | */ |
| 5933 | if (!is_thinkpad) |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5934 | is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 5935 | |
| 5936 | if (!is_thinkpad && !force_load) |
| 5937 | return -ENODEV; |
| 5938 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5939 | return 0; |
| 5940 | } |
| 5941 | |
| 5942 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5943 | /* Module init, exit, parameters */ |
| 5944 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5945 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 5946 | { |
| 5947 | .init = thinkpad_acpi_driver_init, |
| 5948 | .data = &thinkpad_acpi_driver_data, |
| 5949 | }, |
| 5950 | { |
| 5951 | .init = hotkey_init, |
| 5952 | .data = &hotkey_driver_data, |
| 5953 | }, |
| 5954 | { |
| 5955 | .init = bluetooth_init, |
| 5956 | .data = &bluetooth_driver_data, |
| 5957 | }, |
| 5958 | { |
| 5959 | .init = wan_init, |
| 5960 | .data = &wan_driver_data, |
| 5961 | }, |
| 5962 | { |
| 5963 | .init = video_init, |
| 5964 | .data = &video_driver_data, |
| 5965 | }, |
| 5966 | { |
| 5967 | .init = light_init, |
| 5968 | .data = &light_driver_data, |
| 5969 | }, |
| 5970 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
| 5971 | { |
| 5972 | .init = dock_init, |
| 5973 | .data = &dock_driver_data[0], |
| 5974 | }, |
| 5975 | { |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 5976 | .init = dock_init2, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5977 | .data = &dock_driver_data[1], |
| 5978 | }, |
| 5979 | #endif |
| 5980 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 5981 | { |
| 5982 | .init = bay_init, |
| 5983 | .data = &bay_driver_data, |
| 5984 | }, |
| 5985 | #endif |
| 5986 | { |
| 5987 | .init = cmos_init, |
| 5988 | .data = &cmos_driver_data, |
| 5989 | }, |
| 5990 | { |
| 5991 | .init = led_init, |
| 5992 | .data = &led_driver_data, |
| 5993 | }, |
| 5994 | { |
| 5995 | .init = beep_init, |
| 5996 | .data = &beep_driver_data, |
| 5997 | }, |
| 5998 | { |
| 5999 | .init = thermal_init, |
| 6000 | .data = &thermal_driver_data, |
| 6001 | }, |
| 6002 | { |
| 6003 | .data = &ecdump_driver_data, |
| 6004 | }, |
| 6005 | { |
| 6006 | .init = brightness_init, |
| 6007 | .data = &brightness_driver_data, |
| 6008 | }, |
| 6009 | { |
| 6010 | .data = &volume_driver_data, |
| 6011 | }, |
| 6012 | { |
| 6013 | .init = fan_init, |
| 6014 | .data = &fan_driver_data, |
| 6015 | }, |
| 6016 | }; |
| 6017 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6018 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 6019 | { |
| 6020 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6021 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6022 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 6023 | if (!kp || !kp->name || !val) |
| 6024 | return -EINVAL; |
| 6025 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6026 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 6027 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 6028 | WARN_ON(ibm == NULL); |
| 6029 | |
| 6030 | if (!ibm || !ibm->name) |
| 6031 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6032 | |
| 6033 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 6034 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6035 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6036 | strcpy(ibms_init[i].param, val); |
| 6037 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6038 | return 0; |
| 6039 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6040 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6041 | |
| 6042 | return -EINVAL; |
| 6043 | } |
| 6044 | |
| 6045 | static int experimental; |
| 6046 | module_param(experimental, int, 0); |
| 6047 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 6048 | static u32 dbg_level; |
| 6049 | module_param_named(debug, dbg_level, uint, 0); |
| 6050 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 6051 | static int force_load; |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 6052 | module_param(force_load, bool, 0); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 6053 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 6054 | static int fan_control_allowed; |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 6055 | module_param_named(fan_control, fan_control_allowed, bool, 0); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 6056 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6057 | static int brightness_mode; |
| 6058 | module_param_named(brightness_mode, brightness_mode, int, 0); |
| 6059 | |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6060 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 6061 | module_param(brightness_enable, uint, 0); |
| 6062 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6063 | static unsigned int hotkey_report_mode; |
| 6064 | module_param(hotkey_report_mode, uint, 0); |
| 6065 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6066 | #define IBM_PARAM(feature) \ |
| 6067 | module_param_call(feature, set_ibm_param, NULL, NULL, 0) |
| 6068 | |
| 6069 | IBM_PARAM(hotkey); |
| 6070 | IBM_PARAM(bluetooth); |
| 6071 | IBM_PARAM(video); |
| 6072 | IBM_PARAM(light); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6073 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6074 | IBM_PARAM(dock); |
| 6075 | #endif |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6076 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6077 | IBM_PARAM(bay); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6078 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6079 | IBM_PARAM(cmos); |
| 6080 | IBM_PARAM(led); |
| 6081 | IBM_PARAM(beep); |
| 6082 | IBM_PARAM(ecdump); |
| 6083 | IBM_PARAM(brightness); |
| 6084 | IBM_PARAM(volume); |
| 6085 | IBM_PARAM(fan); |
| 6086 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6087 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6088 | { |
| 6089 | int ret, i; |
| 6090 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6091 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 6092 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6093 | /* Parameter checking */ |
| 6094 | if (hotkey_report_mode > 2) |
| 6095 | return -EINVAL; |
| 6096 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6097 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6098 | |
| 6099 | get_thinkpad_model_data(&thinkpad_id); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6100 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6101 | if (ret) { |
| 6102 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6103 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6105 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6106 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6107 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6108 | IBM_ACPIHANDLE_INIT(ecrd); |
| 6109 | IBM_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6110 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6111 | proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6112 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6113 | printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6114 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6115 | return -ENODEV; |
| 6116 | } |
| 6117 | proc_dir->owner = THIS_MODULE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6118 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6119 | ret = platform_driver_register(&tpacpi_pdriver); |
| 6120 | if (ret) { |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6121 | printk(IBM_ERR "unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6122 | thinkpad_acpi_module_exit(); |
| 6123 | return ret; |
| 6124 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 6125 | tp_features.platform_drv_registered = 1; |
| 6126 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6127 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 6128 | if (ret) { |
| 6129 | printk(IBM_ERR "unable to register hwmon platform driver\n"); |
| 6130 | thinkpad_acpi_module_exit(); |
| 6131 | return ret; |
| 6132 | } |
| 6133 | tp_features.sensors_pdrv_registered = 1; |
| 6134 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6135 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6136 | if (!ret) { |
| 6137 | tp_features.platform_drv_attrs_registered = 1; |
| 6138 | ret = tpacpi_create_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 6139 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6140 | if (ret) { |
| 6141 | printk(IBM_ERR "unable to create sysfs driver attributes\n"); |
| 6142 | thinkpad_acpi_module_exit(); |
| 6143 | return ret; |
| 6144 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6145 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6146 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6147 | |
| 6148 | /* Device initialization */ |
| 6149 | tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1, |
| 6150 | NULL, 0); |
| 6151 | if (IS_ERR(tpacpi_pdev)) { |
| 6152 | ret = PTR_ERR(tpacpi_pdev); |
| 6153 | tpacpi_pdev = NULL; |
| 6154 | printk(IBM_ERR "unable to register platform device\n"); |
| 6155 | thinkpad_acpi_module_exit(); |
| 6156 | return ret; |
| 6157 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6158 | tpacpi_sensors_pdev = platform_device_register_simple( |
| 6159 | IBM_HWMON_DRVR_NAME, |
| 6160 | -1, NULL, 0); |
| 6161 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 6162 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 6163 | tpacpi_sensors_pdev = NULL; |
| 6164 | printk(IBM_ERR "unable to register hwmon platform device\n"); |
| 6165 | thinkpad_acpi_module_exit(); |
| 6166 | return ret; |
| 6167 | } |
| 6168 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 6169 | &dev_attr_thinkpad_acpi_pdev_name); |
| 6170 | if (ret) { |
| 6171 | printk(IBM_ERR |
| 6172 | "unable to create sysfs hwmon device attributes\n"); |
| 6173 | thinkpad_acpi_module_exit(); |
| 6174 | return ret; |
| 6175 | } |
| 6176 | tp_features.sensors_pdev_attrs_registered = 1; |
| 6177 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6178 | if (IS_ERR(tpacpi_hwmon)) { |
| 6179 | ret = PTR_ERR(tpacpi_hwmon); |
| 6180 | tpacpi_hwmon = NULL; |
| 6181 | printk(IBM_ERR "unable to register hwmon device\n"); |
| 6182 | thinkpad_acpi_module_exit(); |
| 6183 | return ret; |
| 6184 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 6185 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6186 | tpacpi_inputdev = input_allocate_device(); |
| 6187 | if (!tpacpi_inputdev) { |
| 6188 | printk(IBM_ERR "unable to allocate input device\n"); |
| 6189 | thinkpad_acpi_module_exit(); |
| 6190 | return -ENOMEM; |
| 6191 | } else { |
| 6192 | /* Prepare input device, but don't register */ |
| 6193 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
| 6194 | tpacpi_inputdev->phys = IBM_DRVR_NAME "/input0"; |
| 6195 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 6196 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
| 6197 | thinkpad_id.vendor : |
| 6198 | PCI_VENDOR_ID_IBM; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6199 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 6200 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
| 6201 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6202 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 6203 | ret = ibm_init(&ibms_init[i]); |
| 6204 | if (ret >= 0 && *ibms_init[i].param) |
| 6205 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6206 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6207 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6208 | return ret; |
| 6209 | } |
| 6210 | } |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6211 | ret = input_register_device(tpacpi_inputdev); |
| 6212 | if (ret < 0) { |
| 6213 | printk(IBM_ERR "unable to register input device\n"); |
| 6214 | thinkpad_acpi_module_exit(); |
| 6215 | return ret; |
| 6216 | } else { |
| 6217 | tp_features.input_device_registered = 1; |
| 6218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6219 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6220 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6221 | return 0; |
| 6222 | } |
| 6223 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6224 | static void thinkpad_acpi_module_exit(void) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6225 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6226 | struct ibm_struct *ibm, *itmp; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6227 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6228 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 6229 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6230 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 6231 | &tpacpi_all_drivers, |
| 6232 | all_drivers) { |
| 6233 | ibm_exit(ibm); |
| 6234 | } |
| 6235 | |
| 6236 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6237 | |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6238 | if (tpacpi_inputdev) { |
| 6239 | if (tp_features.input_device_registered) |
| 6240 | input_unregister_device(tpacpi_inputdev); |
| 6241 | else |
| 6242 | input_free_device(tpacpi_inputdev); |
| 6243 | } |
| 6244 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6245 | if (tpacpi_hwmon) |
| 6246 | hwmon_device_unregister(tpacpi_hwmon); |
| 6247 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6248 | if (tp_features.sensors_pdev_attrs_registered) |
| 6249 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 6250 | &dev_attr_thinkpad_acpi_pdev_name); |
| 6251 | if (tpacpi_sensors_pdev) |
| 6252 | platform_device_unregister(tpacpi_sensors_pdev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6253 | if (tpacpi_pdev) |
| 6254 | platform_device_unregister(tpacpi_pdev); |
| 6255 | |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6256 | if (tp_features.sensors_pdrv_attrs_registered) |
| 6257 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 6258 | if (tp_features.platform_drv_attrs_registered) |
| 6259 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 6260 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6261 | if (tp_features.sensors_pdrv_registered) |
| 6262 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 6263 | |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 6264 | if (tp_features.platform_drv_registered) |
| 6265 | platform_driver_unregister(&tpacpi_pdriver); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6266 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6267 | if (proc_dir) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6268 | remove_proc_entry(IBM_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6269 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6270 | kfree(thinkpad_id.bios_version_str); |
| 6271 | kfree(thinkpad_id.ec_version_str); |
| 6272 | kfree(thinkpad_id.model_str); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6273 | } |
| 6274 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6275 | module_init(thinkpad_acpi_module_init); |
| 6276 | module_exit(thinkpad_acpi_module_exit); |