Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 2 | * thinkpad_acpi.c - ThinkPad ACPI Extras |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> |
Henrique de Moraes Holschuh | 6a2e293 | 2008-01-08 13:02:56 -0200 | [diff] [blame] | 6 | * Copyright (C) 2006-2008 Henrique de Moraes Holschuh <hmh@hmh.eng.br> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
Henrique de Moraes Holschuh | a62bc91 | 2007-03-23 17:33:58 -0300 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 21 | * 02110-1301, USA. |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 22 | */ |
| 23 | |
Henrique de Moraes Holschuh | 1cee5cc | 2008-01-08 13:02:57 -0200 | [diff] [blame] | 24 | #define TPACPI_VERSION "0.19" |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 25 | #define TPACPI_SYSFS_VERSION 0x020200 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 26 | |
| 27 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * Changelog: |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 29 | * 2007-10-20 changelog trimmed down |
| 30 | * |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 31 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
| 32 | * drivers/misc. |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 33 | * |
| 34 | * 2006-11-22 0.13 new maintainer |
| 35 | * changelog now lives in git commit history, and will |
| 36 | * not be updated further in-file. |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 37 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 38 | * 2005-03-17 0.11 support for 600e, 770x |
| 39 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
Henrique de Moraes Holschuh | 4b45cc0 | 2008-01-08 13:02:46 -0200 | [diff] [blame] | 40 | * |
| 41 | * 2005-01-16 0.9 use MODULE_VERSION |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 42 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
| 43 | * fix parameter passing on module loading |
| 44 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
| 45 | * thanks to Jim Radford <radford@blackbean.org> |
| 46 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
| 47 | * thanks to Chris Wright <chrisw@osdl.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | */ |
| 49 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 50 | #include <linux/kernel.h> |
| 51 | #include <linux/module.h> |
| 52 | #include <linux/init.h> |
| 53 | #include <linux/types.h> |
| 54 | #include <linux/string.h> |
| 55 | #include <linux/list.h> |
| 56 | #include <linux/mutex.h> |
| 57 | #include <linux/kthread.h> |
| 58 | #include <linux/freezer.h> |
| 59 | #include <linux/delay.h> |
| 60 | |
| 61 | #include <linux/nvram.h> |
| 62 | #include <linux/proc_fs.h> |
| 63 | #include <linux/sysfs.h> |
| 64 | #include <linux/backlight.h> |
| 65 | #include <linux/fb.h> |
| 66 | #include <linux/platform_device.h> |
| 67 | #include <linux/hwmon.h> |
| 68 | #include <linux/hwmon-sysfs.h> |
| 69 | #include <linux/input.h> |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 70 | #include <linux/leds.h> |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 71 | #include <asm/uaccess.h> |
| 72 | |
| 73 | #include <linux/dmi.h> |
| 74 | #include <linux/jiffies.h> |
| 75 | #include <linux/workqueue.h> |
| 76 | |
| 77 | #include <acpi/acpi_drivers.h> |
| 78 | #include <acpi/acnamesp.h> |
| 79 | |
| 80 | #include <linux/pci_ids.h> |
| 81 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 82 | |
| 83 | /* ThinkPad CMOS commands */ |
| 84 | #define TP_CMOS_VOLUME_DOWN 0 |
| 85 | #define TP_CMOS_VOLUME_UP 1 |
| 86 | #define TP_CMOS_VOLUME_MUTE 2 |
| 87 | #define TP_CMOS_BRIGHTNESS_UP 4 |
| 88 | #define TP_CMOS_BRIGHTNESS_DOWN 5 |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 89 | #define TP_CMOS_THINKLIGHT_ON 12 |
| 90 | #define TP_CMOS_THINKLIGHT_OFF 13 |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 91 | |
| 92 | /* NVRAM Addresses */ |
| 93 | enum tp_nvram_addr { |
| 94 | TP_NVRAM_ADDR_HK2 = 0x57, |
| 95 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, |
| 96 | TP_NVRAM_ADDR_VIDEO = 0x59, |
| 97 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, |
| 98 | TP_NVRAM_ADDR_MIXER = 0x60, |
| 99 | }; |
| 100 | |
| 101 | /* NVRAM bit masks */ |
| 102 | enum { |
| 103 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, |
| 104 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, |
| 105 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, |
| 106 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, |
| 107 | TP_NVRAM_MASK_THINKLIGHT = 0x10, |
| 108 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, |
| 109 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, |
| 110 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, |
| 111 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, |
| 112 | TP_NVRAM_MASK_MUTE = 0x40, |
| 113 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, |
| 114 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, |
| 115 | TP_NVRAM_POS_LEVEL_VOLUME = 0, |
| 116 | }; |
| 117 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 118 | /* ACPI HIDs */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 119 | #define TPACPI_ACPI_HKEY_HID "IBM0068" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 120 | |
| 121 | /* Input IDs */ |
| 122 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ |
| 123 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 |
| 124 | |
| 125 | |
| 126 | /**************************************************************************** |
| 127 | * Main driver |
| 128 | */ |
| 129 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 130 | #define TPACPI_NAME "thinkpad" |
| 131 | #define TPACPI_DESC "ThinkPad ACPI Extras" |
| 132 | #define TPACPI_FILE TPACPI_NAME "_acpi" |
| 133 | #define TPACPI_URL "http://ibm-acpi.sf.net/" |
| 134 | #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 135 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 136 | #define TPACPI_PROC_DIR "ibm" |
| 137 | #define TPACPI_ACPI_EVENT_PREFIX "ibm" |
| 138 | #define TPACPI_DRVR_NAME TPACPI_FILE |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 139 | #define TPACPI_DRVR_SHORTNAME "tpacpi" |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 140 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 141 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 142 | #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd" |
| 143 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 144 | #define TPACPI_MAX_ACPI_ARGS 3 |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 145 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 146 | /* Debugging */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 147 | #define TPACPI_LOG TPACPI_FILE ": " |
| 148 | #define TPACPI_ERR KERN_ERR TPACPI_LOG |
| 149 | #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG |
| 150 | #define TPACPI_INFO KERN_INFO TPACPI_LOG |
| 151 | #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 152 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 153 | #define TPACPI_DBG_ALL 0xffff |
| 154 | #define TPACPI_DBG_ALL 0xffff |
| 155 | #define TPACPI_DBG_INIT 0x0001 |
| 156 | #define TPACPI_DBG_EXIT 0x0002 |
| 157 | #define dbg_printk(a_dbg_level, format, arg...) \ |
| 158 | do { if (dbg_level & a_dbg_level) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 159 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ |
| 160 | } while (0) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 161 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
| 162 | #define vdbg_printk(a_dbg_level, format, arg...) \ |
| 163 | dbg_printk(a_dbg_level, format, ## arg) |
| 164 | static const char *str_supported(int is_supported); |
| 165 | #else |
| 166 | #define vdbg_printk(a_dbg_level, format, arg...) |
| 167 | #endif |
| 168 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 169 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
| 170 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
| 171 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 172 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 173 | |
| 174 | /**************************************************************************** |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 175 | * Driver-wide structs and misc. variables |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 176 | */ |
| 177 | |
| 178 | struct ibm_struct; |
| 179 | |
| 180 | struct tp_acpi_drv_struct { |
| 181 | const struct acpi_device_id *hid; |
| 182 | struct acpi_driver *driver; |
| 183 | |
| 184 | void (*notify) (struct ibm_struct *, u32); |
| 185 | acpi_handle *handle; |
| 186 | u32 type; |
| 187 | struct acpi_device *device; |
| 188 | }; |
| 189 | |
| 190 | struct ibm_struct { |
| 191 | char *name; |
| 192 | |
| 193 | int (*read) (char *); |
| 194 | int (*write) (char *); |
| 195 | void (*exit) (void); |
| 196 | void (*resume) (void); |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 197 | void (*suspend) (pm_message_t state); |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 198 | |
| 199 | struct list_head all_drivers; |
| 200 | |
| 201 | struct tp_acpi_drv_struct *acpi; |
| 202 | |
| 203 | struct { |
| 204 | u8 acpi_driver_registered:1; |
| 205 | u8 acpi_notify_installed:1; |
| 206 | u8 proc_created:1; |
| 207 | u8 init_called:1; |
| 208 | u8 experimental:1; |
| 209 | } flags; |
| 210 | }; |
| 211 | |
| 212 | struct ibm_init_struct { |
| 213 | char param[32]; |
| 214 | |
| 215 | int (*init) (struct ibm_init_struct *); |
| 216 | struct ibm_struct *data; |
| 217 | }; |
| 218 | |
| 219 | static struct { |
| 220 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 221 | u32 bay_status:1; |
| 222 | u32 bay_eject:1; |
| 223 | u32 bay_status2:1; |
| 224 | u32 bay_eject2:1; |
| 225 | #endif |
| 226 | u32 bluetooth:1; |
| 227 | u32 hotkey:1; |
| 228 | u32 hotkey_mask:1; |
| 229 | u32 hotkey_wlsw:1; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 230 | u32 hotkey_tablet:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 231 | u32 light:1; |
| 232 | u32 light_status:1; |
| 233 | u32 bright_16levels:1; |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 234 | u32 bright_acpimode:1; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 235 | u32 wan:1; |
| 236 | u32 fan_ctrl_status_undef:1; |
| 237 | u32 input_device_registered:1; |
| 238 | u32 platform_drv_registered:1; |
| 239 | u32 platform_drv_attrs_registered:1; |
| 240 | u32 sensors_pdrv_registered:1; |
| 241 | u32 sensors_pdrv_attrs_registered:1; |
| 242 | u32 sensors_pdev_attrs_registered:1; |
| 243 | u32 hotkey_poll_active:1; |
| 244 | } tp_features; |
| 245 | |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 246 | static struct { |
| 247 | u16 hotkey_mask_ff:1; |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 248 | u16 bright_cmos_ec_unsync:1; |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 249 | } tp_warned; |
| 250 | |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 251 | struct thinkpad_id_data { |
| 252 | unsigned int vendor; /* ThinkPad vendor: |
| 253 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ |
| 254 | |
| 255 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ |
| 256 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ |
| 257 | |
| 258 | u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */ |
| 259 | u16 ec_model; |
| 260 | |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 261 | char *model_str; /* ThinkPad T43 */ |
| 262 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 263 | }; |
Henrique de Moraes Holschuh | 0c78039 | 2008-01-08 13:02:43 -0200 | [diff] [blame] | 264 | static struct thinkpad_id_data thinkpad_id; |
| 265 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 266 | static enum { |
| 267 | TPACPI_LIFE_INIT = 0, |
| 268 | TPACPI_LIFE_RUNNING, |
| 269 | TPACPI_LIFE_EXITING, |
| 270 | } tpacpi_lifecycle; |
| 271 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 272 | static int experimental; |
| 273 | static u32 dbg_level; |
| 274 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 275 | /* Special LED class that can defer work */ |
| 276 | struct tpacpi_led_classdev { |
| 277 | struct led_classdev led_classdev; |
| 278 | struct work_struct work; |
| 279 | enum led_brightness new_brightness; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 280 | unsigned int led; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 281 | }; |
| 282 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 283 | /**************************************************************************** |
| 284 | **************************************************************************** |
| 285 | * |
| 286 | * ACPI Helpers and device model |
| 287 | * |
| 288 | **************************************************************************** |
| 289 | ****************************************************************************/ |
| 290 | |
| 291 | /************************************************************************* |
| 292 | * ACPI basic handles |
| 293 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 295 | static acpi_handle root_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 297 | #define TPACPI_HANDLE(object, parent, paths...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | static acpi_handle object##_handle; \ |
| 299 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 300 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | static char *object##_paths[] = { paths } |
| 302 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 303 | TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 304 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 305 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 306 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 307 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 308 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 309 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 310 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 312 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 313 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 315 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
| 316 | /* T4x, X31, X40 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 317 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 318 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 319 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 320 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 321 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 322 | "^HKEY", /* R30, R31 */ |
| 323 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 324 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 325 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 326 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 327 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 328 | "\\_SB.PCI0.VID0", /* 770e */ |
| 329 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 330 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 331 | ); /* R30, R31 */ |
| 332 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 333 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 334 | /************************************************************************* |
| 335 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 336 | */ |
| 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | static int acpi_evalf(acpi_handle handle, |
| 339 | void *res, char *method, char *fmt, ...) |
| 340 | { |
| 341 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 342 | struct acpi_object_list params; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 343 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 344 | struct acpi_buffer result, *resultp; |
| 345 | union acpi_object out_obj; |
| 346 | acpi_status status; |
| 347 | va_list ap; |
| 348 | char res_type; |
| 349 | int success; |
| 350 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
| 352 | if (!*fmt) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 353 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | if (*fmt == 'q') { |
| 358 | quiet = 1; |
| 359 | fmt++; |
| 360 | } else |
| 361 | quiet = 0; |
| 362 | |
| 363 | res_type = *(fmt++); |
| 364 | |
| 365 | params.count = 0; |
| 366 | params.pointer = &in_objs[0]; |
| 367 | |
| 368 | va_start(ap, fmt); |
| 369 | while (*fmt) { |
| 370 | char c = *(fmt++); |
| 371 | switch (c) { |
| 372 | case 'd': /* int */ |
| 373 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 374 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 375 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 376 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 378 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | "with invalid format character '%c'\n", c); |
| 380 | return 0; |
| 381 | } |
| 382 | } |
| 383 | va_end(ap); |
| 384 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 385 | if (res_type != 'v') { |
| 386 | result.length = sizeof(out_obj); |
| 387 | result.pointer = &out_obj; |
| 388 | resultp = &result; |
| 389 | } else |
| 390 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 392 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
| 394 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 395 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | if (res) |
| 397 | *(int *)res = out_obj.integer.value; |
| 398 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 399 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 400 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | success = status == AE_OK; |
| 402 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 403 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | default: |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 405 | printk(TPACPI_ERR "acpi_evalf() called " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | "with invalid format character '%c'\n", res_type); |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | if (!success && !quiet) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 411 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | method, fmt0, status); |
| 413 | |
| 414 | return success; |
| 415 | } |
| 416 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 417 | static int acpi_ec_read(int i, u8 *p) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 418 | { |
| 419 | int v; |
| 420 | |
| 421 | if (ecrd_handle) { |
| 422 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 423 | return 0; |
| 424 | *p = v; |
| 425 | } else { |
| 426 | if (ec_read(i, p) < 0) |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | return 1; |
| 431 | } |
| 432 | |
| 433 | static int acpi_ec_write(int i, u8 v) |
| 434 | { |
| 435 | if (ecwr_handle) { |
| 436 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 437 | return 0; |
| 438 | } else { |
| 439 | if (ec_write(i, v) < 0) |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | return 1; |
| 444 | } |
| 445 | |
Henrique de Moraes Holschuh | 013c40e | 2008-01-08 13:02:54 -0200 | [diff] [blame] | 446 | #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 447 | static int _sta(acpi_handle handle) |
| 448 | { |
| 449 | int status; |
| 450 | |
| 451 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) |
| 452 | status = 0; |
| 453 | |
| 454 | return status; |
| 455 | } |
Henrique de Moraes Holschuh | 013c40e | 2008-01-08 13:02:54 -0200 | [diff] [blame] | 456 | #endif |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 457 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 458 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 459 | { |
| 460 | if (!cmos_handle) |
| 461 | return -ENXIO; |
| 462 | |
| 463 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 464 | return -EIO; |
| 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 469 | /************************************************************************* |
| 470 | * ACPI device model |
| 471 | */ |
| 472 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 473 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
| 474 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 475 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
| 476 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 477 | static void drv_acpi_handle_init(char *name, |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 478 | acpi_handle *handle, acpi_handle parent, |
| 479 | char **paths, int num_paths, char **path) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 480 | { |
| 481 | int i; |
| 482 | acpi_status status; |
| 483 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 484 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
| 485 | name); |
| 486 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 487 | for (i = 0; i < num_paths; i++) { |
| 488 | status = acpi_get_handle(parent, paths[i], handle); |
| 489 | if (ACPI_SUCCESS(status)) { |
| 490 | *path = paths[i]; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 491 | dbg_printk(TPACPI_DBG_INIT, |
| 492 | "Found ACPI handle %s for %s\n", |
| 493 | *path, name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 494 | return; |
| 495 | } |
| 496 | } |
| 497 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 498 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
| 499 | name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 500 | *handle = NULL; |
| 501 | } |
| 502 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 503 | 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] | 504 | { |
| 505 | struct ibm_struct *ibm = data; |
| 506 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 507 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 508 | return; |
| 509 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 510 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 511 | return; |
| 512 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 513 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 514 | } |
| 515 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 516 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 517 | { |
| 518 | acpi_status status; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 519 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 520 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 521 | BUG_ON(!ibm->acpi); |
| 522 | |
| 523 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 524 | return 0; |
| 525 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 526 | vdbg_printk(TPACPI_DBG_INIT, |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 527 | "setting up ACPI notify for %s\n", ibm->name); |
| 528 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 529 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
| 530 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 531 | printk(TPACPI_ERR "acpi_bus_get_device(%s) failed: %d\n", |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 532 | ibm->name, rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 533 | return -ENODEV; |
| 534 | } |
| 535 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 536 | acpi_driver_data(ibm->acpi->device) = ibm; |
| 537 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 538 | TPACPI_ACPI_EVENT_PREFIX, |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 539 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 540 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 541 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 542 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 543 | if (ACPI_FAILURE(status)) { |
| 544 | if (status == AE_ALREADY_EXISTS) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 545 | printk(TPACPI_NOTICE |
| 546 | "another device driver is already " |
| 547 | "handling %s events\n", ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 548 | } else { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 549 | printk(TPACPI_ERR |
| 550 | "acpi_install_notify_handler(%s) failed: %d\n", |
| 551 | ibm->name, status); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 552 | } |
| 553 | return -ENODEV; |
| 554 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 555 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 556 | return 0; |
| 557 | } |
| 558 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 559 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 560 | { |
| 561 | return 0; |
| 562 | } |
| 563 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 564 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 565 | { |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 566 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 567 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 568 | dbg_printk(TPACPI_DBG_INIT, |
| 569 | "registering %s as an ACPI driver\n", ibm->name); |
| 570 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 571 | BUG_ON(!ibm->acpi); |
| 572 | |
| 573 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 574 | if (!ibm->acpi->driver) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 575 | printk(TPACPI_ERR "kzalloc(ibm->driver) failed\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 576 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 577 | } |
| 578 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 579 | sprintf(ibm->acpi->driver->name, "%s_%s", TPACPI_NAME, ibm->name); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 580 | ibm->acpi->driver->ids = ibm->acpi->hid; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 581 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 582 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 583 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 584 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
| 585 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 586 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 587 | ibm->name, rc); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 588 | kfree(ibm->acpi->driver); |
| 589 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 590 | } else if (!rc) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 591 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 592 | |
Henrique de Moraes Holschuh | 5ae930e | 2007-04-27 22:00:14 -0300 | [diff] [blame] | 593 | return rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | |
| 597 | /**************************************************************************** |
| 598 | **************************************************************************** |
| 599 | * |
| 600 | * Procfs Helpers |
| 601 | * |
| 602 | **************************************************************************** |
| 603 | ****************************************************************************/ |
| 604 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 605 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 606 | int count, int *eof, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 607 | { |
| 608 | struct ibm_struct *ibm = data; |
| 609 | int len; |
| 610 | |
| 611 | if (!ibm || !ibm->read) |
| 612 | return -EINVAL; |
| 613 | |
| 614 | len = ibm->read(page); |
| 615 | if (len < 0) |
| 616 | return len; |
| 617 | |
| 618 | if (len <= off + count) |
| 619 | *eof = 1; |
| 620 | *start = page + off; |
| 621 | len -= off; |
| 622 | if (len > count) |
| 623 | len = count; |
| 624 | if (len < 0) |
| 625 | len = 0; |
| 626 | |
| 627 | return len; |
| 628 | } |
| 629 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 630 | static int dispatch_procfs_write(struct file *file, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 631 | const char __user *userbuf, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 632 | unsigned long count, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 633 | { |
| 634 | struct ibm_struct *ibm = data; |
| 635 | char *kernbuf; |
| 636 | int ret; |
| 637 | |
| 638 | if (!ibm || !ibm->write) |
| 639 | return -EINVAL; |
| 640 | |
| 641 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 642 | if (!kernbuf) |
| 643 | return -ENOMEM; |
| 644 | |
| 645 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 646 | kfree(kernbuf); |
| 647 | return -EFAULT; |
| 648 | } |
| 649 | |
| 650 | kernbuf[count] = 0; |
| 651 | strcat(kernbuf, ","); |
| 652 | ret = ibm->write(kernbuf); |
| 653 | if (ret == 0) |
| 654 | ret = count; |
| 655 | |
| 656 | kfree(kernbuf); |
| 657 | |
| 658 | return ret; |
| 659 | } |
| 660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | static char *next_cmd(char **cmds) |
| 662 | { |
| 663 | char *start = *cmds; |
| 664 | char *end; |
| 665 | |
| 666 | while ((end = strchr(start, ',')) && end == start) |
| 667 | start = end + 1; |
| 668 | |
| 669 | if (!end) |
| 670 | return NULL; |
| 671 | |
| 672 | *end = 0; |
| 673 | *cmds = end + 1; |
| 674 | return start; |
| 675 | } |
| 676 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 677 | |
| 678 | /**************************************************************************** |
| 679 | **************************************************************************** |
| 680 | * |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 681 | * Device model: input, hwmon and platform |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 682 | * |
| 683 | **************************************************************************** |
| 684 | ****************************************************************************/ |
| 685 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 686 | static struct platform_device *tpacpi_pdev; |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 687 | static struct platform_device *tpacpi_sensors_pdev; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 688 | static struct device *tpacpi_hwmon; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 689 | static struct input_dev *tpacpi_inputdev; |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 690 | static struct mutex tpacpi_inputdev_send_mutex; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 691 | static LIST_HEAD(tpacpi_all_drivers); |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 692 | |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 693 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
| 694 | pm_message_t state) |
| 695 | { |
| 696 | struct ibm_struct *ibm, *itmp; |
| 697 | |
| 698 | list_for_each_entry_safe(ibm, itmp, |
| 699 | &tpacpi_all_drivers, |
| 700 | all_drivers) { |
| 701 | if (ibm->suspend) |
| 702 | (ibm->suspend)(state); |
| 703 | } |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 708 | static int tpacpi_resume_handler(struct platform_device *pdev) |
| 709 | { |
| 710 | struct ibm_struct *ibm, *itmp; |
| 711 | |
| 712 | list_for_each_entry_safe(ibm, itmp, |
| 713 | &tpacpi_all_drivers, |
| 714 | all_drivers) { |
| 715 | if (ibm->resume) |
| 716 | (ibm->resume)(); |
| 717 | } |
| 718 | |
| 719 | return 0; |
| 720 | } |
| 721 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 722 | static struct platform_driver tpacpi_pdriver = { |
| 723 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 724 | .name = TPACPI_DRVR_NAME, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 725 | .owner = THIS_MODULE, |
| 726 | }, |
Henrique de Moraes Holschuh | 083f176 | 2008-01-08 13:02:50 -0200 | [diff] [blame] | 727 | .suspend = tpacpi_suspend_handler, |
Henrique de Moraes Holschuh | e295e85 | 2007-07-18 23:45:37 -0300 | [diff] [blame] | 728 | .resume = tpacpi_resume_handler, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 729 | }; |
| 730 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 731 | static struct platform_driver tpacpi_hwmon_pdriver = { |
| 732 | .driver = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 733 | .name = TPACPI_HWMON_DRVR_NAME, |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 734 | .owner = THIS_MODULE, |
| 735 | }, |
| 736 | }; |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 737 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 738 | /************************************************************************* |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 739 | * sysfs support helpers |
| 740 | */ |
| 741 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 742 | struct attribute_set { |
| 743 | unsigned int members, max_members; |
| 744 | struct attribute_group group; |
| 745 | }; |
| 746 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 747 | struct attribute_set_obj { |
| 748 | struct attribute_set s; |
| 749 | struct attribute *a; |
| 750 | } __attribute__((packed)); |
| 751 | |
| 752 | static struct attribute_set *create_attr_set(unsigned int max_members, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 753 | const char *name) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 754 | { |
| 755 | struct attribute_set_obj *sobj; |
| 756 | |
| 757 | if (max_members == 0) |
| 758 | return NULL; |
| 759 | |
| 760 | /* Allocates space for implicit NULL at the end too */ |
| 761 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 762 | max_members * sizeof(struct attribute *), |
| 763 | GFP_KERNEL); |
| 764 | if (!sobj) |
| 765 | return NULL; |
| 766 | sobj->s.max_members = max_members; |
| 767 | sobj->s.group.attrs = &sobj->a; |
| 768 | sobj->s.group.name = name; |
| 769 | |
| 770 | return &sobj->s; |
| 771 | } |
| 772 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 773 | #define destroy_attr_set(_set) \ |
| 774 | kfree(_set); |
| 775 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 776 | /* not multi-threaded safe, use it in a single thread per set */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 777 | static int add_to_attr_set(struct attribute_set *s, struct attribute *attr) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 778 | { |
| 779 | if (!s || !attr) |
| 780 | return -EINVAL; |
| 781 | |
| 782 | if (s->members >= s->max_members) |
| 783 | return -ENOMEM; |
| 784 | |
| 785 | s->group.attrs[s->members] = attr; |
| 786 | s->members++; |
| 787 | |
| 788 | return 0; |
| 789 | } |
| 790 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 791 | static int add_many_to_attr_set(struct attribute_set *s, |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 792 | struct attribute **attr, |
| 793 | unsigned int count) |
| 794 | { |
| 795 | int i, res; |
| 796 | |
| 797 | for (i = 0; i < count; i++) { |
| 798 | res = add_to_attr_set(s, attr[i]); |
| 799 | if (res) |
| 800 | return res; |
| 801 | } |
| 802 | |
| 803 | return 0; |
| 804 | } |
| 805 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 806 | static void delete_attr_set(struct attribute_set *s, struct kobject *kobj) |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 807 | { |
| 808 | sysfs_remove_group(kobj, &s->group); |
| 809 | destroy_attr_set(s); |
| 810 | } |
| 811 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 812 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
| 813 | sysfs_create_group(_kobj, &_attr_set->group) |
| 814 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 815 | static int parse_strtoul(const char *buf, |
| 816 | unsigned long max, unsigned long *value) |
| 817 | { |
| 818 | char *endp; |
| 819 | |
Henrique de Moraes Holschuh | 32afbf0 | 2007-10-08 10:12:56 -0300 | [diff] [blame] | 820 | while (*buf && isspace(*buf)) |
| 821 | buf++; |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 822 | *value = simple_strtoul(buf, &endp, 0); |
| 823 | while (*endp && isspace(*endp)) |
| 824 | endp++; |
| 825 | if (*endp || *value > max) |
| 826 | return -EINVAL; |
| 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 831 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
| 832 | { |
| 833 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 834 | union acpi_object *obj; |
| 835 | int rc; |
| 836 | |
| 837 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { |
| 838 | obj = (union acpi_object *)buffer.pointer; |
| 839 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
| 840 | printk(TPACPI_ERR "Unknown _BCL data, " |
| 841 | "please report this to %s\n", TPACPI_MAIL); |
| 842 | rc = 0; |
| 843 | } else { |
| 844 | rc = obj->package.count; |
| 845 | } |
| 846 | } else { |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | kfree(buffer.pointer); |
| 851 | return rc; |
| 852 | } |
| 853 | |
| 854 | static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle, |
| 855 | u32 lvl, void *context, void **rv) |
| 856 | { |
| 857 | char name[ACPI_PATH_SEGMENT_LENGTH]; |
| 858 | struct acpi_buffer buffer = { sizeof(name), &name }; |
| 859 | |
| 860 | if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && |
| 861 | !strncmp("_BCL", name, sizeof(name) - 1)) { |
| 862 | BUG_ON(!rv || !*rv); |
| 863 | **(int **)rv = tpacpi_query_bcl_levels(handle); |
| 864 | return AE_CTRL_TERMINATE; |
| 865 | } else { |
| 866 | return AE_OK; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /* |
| 871 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map |
| 872 | */ |
| 873 | static int __init tpacpi_check_std_acpi_brightness_support(void) |
| 874 | { |
| 875 | int status; |
| 876 | int bcl_levels = 0; |
| 877 | void *bcl_ptr = &bcl_levels; |
| 878 | |
| 879 | if (!vid_handle) { |
| 880 | TPACPI_ACPIHANDLE_INIT(vid); |
| 881 | } |
| 882 | if (!vid_handle) |
| 883 | return 0; |
| 884 | |
| 885 | /* |
| 886 | * Search for a _BCL method, and execute it. This is safe on all |
| 887 | * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista |
| 888 | * BIOS in ACPI backlight control mode. We do NOT have to care |
| 889 | * about calling the _BCL method in an enabled video device, any |
| 890 | * will do for our purposes. |
| 891 | */ |
| 892 | |
| 893 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, |
| 894 | tpacpi_acpi_walk_find_bcl, NULL, |
| 895 | &bcl_ptr); |
| 896 | |
| 897 | if (ACPI_SUCCESS(status) && bcl_levels > 2) { |
| 898 | tp_features.bright_acpimode = 1; |
| 899 | return (bcl_levels - 2); |
| 900 | } |
| 901 | |
| 902 | return 0; |
| 903 | } |
| 904 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 905 | /************************************************************************* |
| 906 | * thinkpad-acpi driver attributes |
| 907 | */ |
| 908 | |
| 909 | /* interface_version --------------------------------------------------- */ |
| 910 | static ssize_t tpacpi_driver_interface_version_show( |
| 911 | struct device_driver *drv, |
| 912 | char *buf) |
| 913 | { |
| 914 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 915 | } |
| 916 | |
| 917 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 918 | tpacpi_driver_interface_version_show, NULL); |
| 919 | |
| 920 | /* debug_level --------------------------------------------------------- */ |
| 921 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 922 | char *buf) |
| 923 | { |
| 924 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 925 | } |
| 926 | |
| 927 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 928 | const char *buf, size_t count) |
| 929 | { |
| 930 | unsigned long t; |
| 931 | |
| 932 | if (parse_strtoul(buf, 0xffff, &t)) |
| 933 | return -EINVAL; |
| 934 | |
| 935 | dbg_level = t; |
| 936 | |
| 937 | return count; |
| 938 | } |
| 939 | |
| 940 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 941 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 942 | |
| 943 | /* version ------------------------------------------------------------- */ |
| 944 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 945 | char *buf) |
| 946 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 947 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
| 948 | TPACPI_DESC, TPACPI_VERSION); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | static DRIVER_ATTR(version, S_IRUGO, |
| 952 | tpacpi_driver_version_show, NULL); |
| 953 | |
| 954 | /* --------------------------------------------------------------------- */ |
| 955 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 956 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 957 | &driver_attr_debug_level, &driver_attr_version, |
| 958 | &driver_attr_interface_version, |
| 959 | }; |
| 960 | |
| 961 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 962 | { |
| 963 | int i, res; |
| 964 | |
| 965 | i = 0; |
| 966 | res = 0; |
| 967 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 968 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 969 | i++; |
| 970 | } |
| 971 | |
| 972 | return res; |
| 973 | } |
| 974 | |
| 975 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 976 | { |
| 977 | int i; |
| 978 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 979 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 980 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
| 981 | } |
| 982 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 983 | /**************************************************************************** |
| 984 | **************************************************************************** |
| 985 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 986 | * Subdrivers |
| 987 | * |
| 988 | **************************************************************************** |
| 989 | ****************************************************************************/ |
| 990 | |
| 991 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 992 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 993 | */ |
| 994 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 995 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 997 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
| 998 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1000 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1001 | (thinkpad_id.bios_version_str) ? |
| 1002 | thinkpad_id.bios_version_str : "unknown", |
| 1003 | (thinkpad_id.ec_version_str) ? |
| 1004 | thinkpad_id.ec_version_str : "unknown"); |
| 1005 | |
| 1006 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1007 | printk(TPACPI_INFO "%s %s, model %s\n", |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 1008 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
| 1009 | "IBM" : ((thinkpad_id.vendor == |
| 1010 | PCI_VENDOR_ID_LENOVO) ? |
| 1011 | "Lenovo" : "Unknown vendor"), |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 1012 | thinkpad_id.model_str, |
| 1013 | (thinkpad_id.nummodel_str) ? |
| 1014 | thinkpad_id.nummodel_str : "unknown"); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 1015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | return 0; |
| 1017 | } |
| 1018 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 1019 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | { |
| 1021 | int len = 0; |
| 1022 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1023 | len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); |
| 1024 | len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
| 1026 | return len; |
| 1027 | } |
| 1028 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1029 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 1030 | .name = "driver", |
| 1031 | .read = thinkpad_acpi_driver_read, |
| 1032 | }; |
| 1033 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1034 | /************************************************************************* |
| 1035 | * Hotkey subdriver |
| 1036 | */ |
| 1037 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1038 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
| 1039 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, |
| 1040 | TP_ACPI_HOTKEYSCAN_FNF2, |
| 1041 | TP_ACPI_HOTKEYSCAN_FNF3, |
| 1042 | TP_ACPI_HOTKEYSCAN_FNF4, |
| 1043 | TP_ACPI_HOTKEYSCAN_FNF5, |
| 1044 | TP_ACPI_HOTKEYSCAN_FNF6, |
| 1045 | TP_ACPI_HOTKEYSCAN_FNF7, |
| 1046 | TP_ACPI_HOTKEYSCAN_FNF8, |
| 1047 | TP_ACPI_HOTKEYSCAN_FNF9, |
| 1048 | TP_ACPI_HOTKEYSCAN_FNF10, |
| 1049 | TP_ACPI_HOTKEYSCAN_FNF11, |
| 1050 | TP_ACPI_HOTKEYSCAN_FNF12, |
| 1051 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, |
| 1052 | TP_ACPI_HOTKEYSCAN_FNINSERT, |
| 1053 | TP_ACPI_HOTKEYSCAN_FNDELETE, |
| 1054 | TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1055 | TP_ACPI_HOTKEYSCAN_FNEND, |
| 1056 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1057 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, |
| 1058 | TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1059 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1060 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1061 | TP_ACPI_HOTKEYSCAN_MUTE, |
| 1062 | TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1063 | }; |
| 1064 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1065 | enum { /* Keys available through NVRAM polling */ |
| 1066 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
| 1067 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, |
| 1068 | }; |
| 1069 | |
| 1070 | enum { /* Positions of some of the keys in hotkey masks */ |
| 1071 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, |
| 1072 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, |
| 1073 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, |
| 1074 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, |
| 1075 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, |
| 1076 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, |
| 1077 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, |
| 1078 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, |
| 1079 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, |
| 1080 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, |
| 1081 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, |
| 1082 | }; |
| 1083 | |
| 1084 | enum { /* NVRAM to ACPI HKEY group map */ |
| 1085 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | |
| 1086 | TP_ACPI_HKEY_ZOOM_MASK | |
| 1087 | TP_ACPI_HKEY_DISPSWTCH_MASK | |
| 1088 | TP_ACPI_HKEY_HIBERNATE_MASK, |
| 1089 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | |
| 1090 | TP_ACPI_HKEY_BRGHTDWN_MASK, |
| 1091 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | |
| 1092 | TP_ACPI_HKEY_VOLDWN_MASK | |
| 1093 | TP_ACPI_HKEY_MUTE_MASK, |
| 1094 | }; |
| 1095 | |
| 1096 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1097 | struct tp_nvram_state { |
| 1098 | u16 thinkpad_toggle:1; |
| 1099 | u16 zoom_toggle:1; |
| 1100 | u16 display_toggle:1; |
| 1101 | u16 thinklight_toggle:1; |
| 1102 | u16 hibernate_toggle:1; |
| 1103 | u16 displayexp_toggle:1; |
| 1104 | u16 display_state:1; |
| 1105 | u16 brightness_toggle:1; |
| 1106 | u16 volume_toggle:1; |
| 1107 | u16 mute:1; |
| 1108 | |
| 1109 | u8 brightness_level; |
| 1110 | u8 volume_level; |
| 1111 | }; |
| 1112 | |
| 1113 | static struct task_struct *tpacpi_hotkey_task; |
| 1114 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ |
| 1115 | static int hotkey_poll_freq = 10; /* Hz */ |
| 1116 | static struct mutex hotkey_thread_mutex; |
| 1117 | static struct mutex hotkey_thread_data_mutex; |
| 1118 | static unsigned int hotkey_config_change; |
| 1119 | |
| 1120 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1121 | |
| 1122 | #define hotkey_source_mask 0U |
| 1123 | |
| 1124 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1125 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 1126 | static struct mutex hotkey_mutex; |
| 1127 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1128 | static enum { /* Reasons for waking up */ |
| 1129 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ |
| 1130 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ |
| 1131 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ |
| 1132 | } hotkey_wakeup_reason; |
| 1133 | |
| 1134 | static int hotkey_autosleep_ack; |
| 1135 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1136 | static int hotkey_orig_status; |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1137 | static u32 hotkey_orig_mask; |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1138 | static u32 hotkey_all_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1139 | static u32 hotkey_reserved_mask; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1140 | static u32 hotkey_mask; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 1141 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 1142 | static unsigned int hotkey_report_mode; |
| 1143 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1144 | static u16 *hotkey_keycode_map; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1145 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 1146 | static struct attribute_set *hotkey_dev_attributes; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1147 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1148 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1149 | #define HOTKEY_CONFIG_CRITICAL_START \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1150 | do { \ |
| 1151 | mutex_lock(&hotkey_thread_data_mutex); \ |
| 1152 | hotkey_config_change++; \ |
| 1153 | } while (0); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1154 | #define HOTKEY_CONFIG_CRITICAL_END \ |
| 1155 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1156 | #else |
| 1157 | #define HOTKEY_CONFIG_CRITICAL_START |
| 1158 | #define HOTKEY_CONFIG_CRITICAL_END |
| 1159 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1160 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1161 | /* HKEY.MHKG() return bits */ |
| 1162 | #define TP_HOTKEY_TABLET_MASK (1 << 3) |
| 1163 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1164 | static int hotkey_get_wlsw(int *status) |
| 1165 | { |
| 1166 | if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) |
| 1167 | return -EIO; |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1171 | static int hotkey_get_tablet_mode(int *status) |
| 1172 | { |
| 1173 | int s; |
| 1174 | |
| 1175 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) |
| 1176 | return -EIO; |
| 1177 | |
Henrique de Moraes Holschuh | cee47f5 | 2008-03-04 14:29:21 -0800 | [diff] [blame] | 1178 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
| 1179 | return 0; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1180 | } |
| 1181 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1182 | /* |
| 1183 | * Call with hotkey_mutex held |
| 1184 | */ |
| 1185 | static int hotkey_mask_get(void) |
| 1186 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1187 | u32 m = 0; |
| 1188 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1189 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1190 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1191 | return -EIO; |
| 1192 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1193 | hotkey_mask = m | (hotkey_source_mask & hotkey_mask); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1194 | |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
| 1198 | /* |
| 1199 | * Call with hotkey_mutex held |
| 1200 | */ |
| 1201 | static int hotkey_mask_set(u32 mask) |
| 1202 | { |
| 1203 | int i; |
| 1204 | int rc = 0; |
| 1205 | |
| 1206 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 9288902 | 2008-04-26 01:02:18 -0300 | [diff] [blame] | 1207 | if (!tp_warned.hotkey_mask_ff && |
| 1208 | (mask == 0xffff || mask == 0xffffff || |
| 1209 | mask == 0xffffffff)) { |
| 1210 | tp_warned.hotkey_mask_ff = 1; |
| 1211 | printk(TPACPI_NOTICE |
| 1212 | "setting the hotkey mask to 0x%08x is likely " |
| 1213 | "not the best way to go about it\n", mask); |
| 1214 | printk(TPACPI_NOTICE |
| 1215 | "please consider using the driver defaults, " |
| 1216 | "and refer to up-to-date thinkpad-acpi " |
| 1217 | "documentation\n"); |
| 1218 | } |
| 1219 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1220 | HOTKEY_CONFIG_CRITICAL_START |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1221 | for (i = 0; i < 32; i++) { |
| 1222 | u32 m = 1 << i; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1223 | /* enable in firmware mask only keys not in NVRAM |
| 1224 | * mode, but enable the key in the cached hotkey_mask |
| 1225 | * regardless of mode, or the key will end up |
| 1226 | * disabled by hotkey_mask_get() */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1227 | if (!acpi_evalf(hkey_handle, |
| 1228 | NULL, "MHKM", "vdd", i + 1, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1229 | !!((mask & ~hotkey_source_mask) & m))) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1230 | rc = -EIO; |
| 1231 | break; |
| 1232 | } else { |
| 1233 | hotkey_mask = (hotkey_mask & ~m) | (mask & m); |
| 1234 | } |
| 1235 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1236 | HOTKEY_CONFIG_CRITICAL_END |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1237 | |
| 1238 | /* hotkey_mask_get must be called unconditionally below */ |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1239 | if (!hotkey_mask_get() && !rc && |
| 1240 | (hotkey_mask & ~hotkey_source_mask) != |
| 1241 | (mask & ~hotkey_source_mask)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1242 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1243 | "requested hot key mask 0x%08x, but " |
| 1244 | "firmware forced it to 0x%08x\n", |
| 1245 | mask, hotkey_mask); |
| 1246 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1247 | } else { |
| 1248 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1249 | HOTKEY_CONFIG_CRITICAL_START |
| 1250 | hotkey_mask = mask & hotkey_source_mask; |
| 1251 | HOTKEY_CONFIG_CRITICAL_END |
| 1252 | hotkey_mask_get(); |
| 1253 | if (hotkey_mask != mask) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 1254 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1255 | "requested hot key mask 0x%08x, " |
| 1256 | "forced to 0x%08x (NVRAM poll mask is " |
| 1257 | "0x%08x): no firmware mask support\n", |
| 1258 | mask, hotkey_mask, hotkey_source_mask); |
| 1259 | } |
| 1260 | #else |
| 1261 | hotkey_mask_get(); |
| 1262 | rc = -ENXIO; |
| 1263 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | return rc; |
| 1267 | } |
| 1268 | |
| 1269 | static int hotkey_status_get(int *status) |
| 1270 | { |
| 1271 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
| 1272 | return -EIO; |
| 1273 | |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
| 1277 | static int hotkey_status_set(int status) |
| 1278 | { |
| 1279 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) |
| 1280 | return -EIO; |
| 1281 | |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1285 | static void tpacpi_input_send_radiosw(void) |
| 1286 | { |
| 1287 | int wlsw; |
| 1288 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1289 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { |
Henrique de Moraes Holschuh | d147da7 | 2008-02-16 02:17:57 -0200 | [diff] [blame] | 1290 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1291 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1292 | input_report_switch(tpacpi_inputdev, |
| 1293 | SW_RADIO, !!wlsw); |
| 1294 | input_sync(tpacpi_inputdev); |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1295 | |
Henrique de Moraes Holschuh | d147da7 | 2008-02-16 02:17:57 -0200 | [diff] [blame] | 1296 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1297 | } |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1298 | } |
| 1299 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1300 | static void tpacpi_input_send_tabletsw(void) |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1301 | { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1302 | int state; |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1303 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1304 | if (tp_features.hotkey_tablet && |
| 1305 | !hotkey_get_tablet_mode(&state)) { |
| 1306 | mutex_lock(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1307 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1308 | input_report_switch(tpacpi_inputdev, |
| 1309 | SW_TABLET_MODE, !!state); |
| 1310 | input_sync(tpacpi_inputdev); |
| 1311 | |
| 1312 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1313 | } |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 1314 | } |
| 1315 | |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 1316 | static void tpacpi_input_send_key(unsigned int scancode) |
| 1317 | { |
| 1318 | unsigned int keycode; |
| 1319 | |
| 1320 | keycode = hotkey_keycode_map[scancode]; |
| 1321 | |
| 1322 | if (keycode != KEY_RESERVED) { |
| 1323 | mutex_lock(&tpacpi_inputdev_send_mutex); |
| 1324 | |
| 1325 | input_report_key(tpacpi_inputdev, keycode, 1); |
| 1326 | if (keycode == KEY_UNKNOWN) |
| 1327 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1328 | scancode); |
| 1329 | input_sync(tpacpi_inputdev); |
| 1330 | |
| 1331 | input_report_key(tpacpi_inputdev, keycode, 0); |
| 1332 | if (keycode == KEY_UNKNOWN) |
| 1333 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, |
| 1334 | scancode); |
| 1335 | input_sync(tpacpi_inputdev); |
| 1336 | |
| 1337 | mutex_unlock(&tpacpi_inputdev_send_mutex); |
| 1338 | } |
| 1339 | } |
| 1340 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1341 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1342 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; |
| 1343 | |
| 1344 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
| 1345 | { |
| 1346 | tpacpi_input_send_key(scancode); |
| 1347 | if (hotkey_report_mode < 2) { |
| 1348 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, |
| 1349 | 0x80, 0x1001 + scancode); |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m) |
| 1354 | { |
| 1355 | u8 d; |
| 1356 | |
| 1357 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { |
| 1358 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); |
| 1359 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); |
| 1360 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); |
| 1361 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); |
| 1362 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); |
| 1363 | } |
| 1364 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { |
| 1365 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); |
| 1366 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); |
| 1367 | } |
| 1368 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { |
| 1369 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); |
| 1370 | n->displayexp_toggle = |
| 1371 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); |
| 1372 | } |
| 1373 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { |
| 1374 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); |
| 1375 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 1376 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 1377 | n->brightness_toggle = |
| 1378 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); |
| 1379 | } |
| 1380 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { |
| 1381 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); |
| 1382 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) |
| 1383 | >> TP_NVRAM_POS_LEVEL_VOLUME; |
| 1384 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); |
| 1385 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1390 | do { \ |
| 1391 | if ((mask & (1 << __scancode)) && \ |
| 1392 | oldn->__member != newn->__member) \ |
| 1393 | tpacpi_hotkey_send_key(__scancode); \ |
| 1394 | } while (0) |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1395 | |
| 1396 | #define TPACPI_MAY_SEND_KEY(__scancode) \ |
| 1397 | do { if (mask & (1 << __scancode)) \ |
| 1398 | tpacpi_hotkey_send_key(__scancode); } while (0) |
| 1399 | |
| 1400 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1401 | struct tp_nvram_state *newn, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1402 | u32 mask) |
| 1403 | { |
| 1404 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
| 1405 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); |
| 1406 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); |
| 1407 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); |
| 1408 | |
| 1409 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); |
| 1410 | |
| 1411 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); |
| 1412 | |
| 1413 | /* handle volume */ |
| 1414 | if (oldn->volume_toggle != newn->volume_toggle) { |
| 1415 | if (oldn->mute != newn->mute) { |
| 1416 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1417 | } |
| 1418 | if (oldn->volume_level > newn->volume_level) { |
| 1419 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1420 | } else if (oldn->volume_level < newn->volume_level) { |
| 1421 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1422 | } else if (oldn->mute == newn->mute) { |
| 1423 | /* repeated key presses that didn't change state */ |
| 1424 | if (newn->mute) { |
| 1425 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
| 1426 | } else if (newn->volume_level != 0) { |
| 1427 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
| 1428 | } else { |
| 1429 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
| 1430 | } |
| 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | /* handle brightness */ |
| 1435 | if (oldn->brightness_toggle != newn->brightness_toggle) { |
| 1436 | if (oldn->brightness_level < newn->brightness_level) { |
| 1437 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1438 | } else if (oldn->brightness_level > newn->brightness_level) { |
| 1439 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1440 | } else { |
| 1441 | /* repeated key presses that didn't change state */ |
| 1442 | if (newn->brightness_level != 0) { |
| 1443 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); |
| 1444 | } else { |
| 1445 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
| 1446 | } |
| 1447 | } |
| 1448 | } |
| 1449 | } |
| 1450 | |
| 1451 | #undef TPACPI_COMPARE_KEY |
| 1452 | #undef TPACPI_MAY_SEND_KEY |
| 1453 | |
| 1454 | static int hotkey_kthread(void *data) |
| 1455 | { |
| 1456 | struct tp_nvram_state s[2]; |
| 1457 | u32 mask; |
| 1458 | unsigned int si, so; |
| 1459 | unsigned long t; |
| 1460 | unsigned int change_detector, must_reset; |
| 1461 | |
| 1462 | mutex_lock(&hotkey_thread_mutex); |
| 1463 | |
| 1464 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) |
| 1465 | goto exit; |
| 1466 | |
| 1467 | set_freezable(); |
| 1468 | |
| 1469 | so = 0; |
| 1470 | si = 1; |
| 1471 | t = 0; |
| 1472 | |
| 1473 | /* Initial state for compares */ |
| 1474 | mutex_lock(&hotkey_thread_data_mutex); |
| 1475 | change_detector = hotkey_config_change; |
| 1476 | mask = hotkey_source_mask & hotkey_mask; |
| 1477 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1478 | hotkey_read_nvram(&s[so], mask); |
| 1479 | |
| 1480 | while (!kthread_should_stop() && hotkey_poll_freq) { |
| 1481 | if (t == 0) |
| 1482 | t = 1000/hotkey_poll_freq; |
| 1483 | t = msleep_interruptible(t); |
| 1484 | if (unlikely(kthread_should_stop())) |
| 1485 | break; |
| 1486 | must_reset = try_to_freeze(); |
| 1487 | if (t > 0 && !must_reset) |
| 1488 | continue; |
| 1489 | |
| 1490 | mutex_lock(&hotkey_thread_data_mutex); |
| 1491 | if (must_reset || hotkey_config_change != change_detector) { |
| 1492 | /* forget old state on thaw or config change */ |
| 1493 | si = so; |
| 1494 | t = 0; |
| 1495 | change_detector = hotkey_config_change; |
| 1496 | } |
| 1497 | mask = hotkey_source_mask & hotkey_mask; |
| 1498 | mutex_unlock(&hotkey_thread_data_mutex); |
| 1499 | |
| 1500 | if (likely(mask)) { |
| 1501 | hotkey_read_nvram(&s[si], mask); |
| 1502 | if (likely(si != so)) { |
| 1503 | hotkey_compare_and_issue_event(&s[so], &s[si], |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1504 | mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | so = si; |
| 1509 | si ^= 1; |
| 1510 | } |
| 1511 | |
| 1512 | exit: |
| 1513 | mutex_unlock(&hotkey_thread_mutex); |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
| 1517 | static void hotkey_poll_stop_sync(void) |
| 1518 | { |
| 1519 | if (tpacpi_hotkey_task) { |
| 1520 | if (frozen(tpacpi_hotkey_task) || |
| 1521 | freezing(tpacpi_hotkey_task)) |
| 1522 | thaw_process(tpacpi_hotkey_task); |
| 1523 | |
| 1524 | kthread_stop(tpacpi_hotkey_task); |
| 1525 | tpacpi_hotkey_task = NULL; |
| 1526 | mutex_lock(&hotkey_thread_mutex); |
| 1527 | /* at this point, the thread did exit */ |
| 1528 | mutex_unlock(&hotkey_thread_mutex); |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | /* call with hotkey_mutex held */ |
| 1533 | static void hotkey_poll_setup(int may_warn) |
| 1534 | { |
| 1535 | if ((hotkey_source_mask & hotkey_mask) != 0 && |
| 1536 | hotkey_poll_freq > 0 && |
| 1537 | (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { |
| 1538 | if (!tpacpi_hotkey_task) { |
| 1539 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 1540 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1541 | if (IS_ERR(tpacpi_hotkey_task)) { |
| 1542 | tpacpi_hotkey_task = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1543 | printk(TPACPI_ERR |
| 1544 | "could not create kernel thread " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1545 | "for hotkey polling\n"); |
| 1546 | } |
| 1547 | } |
| 1548 | } else { |
| 1549 | hotkey_poll_stop_sync(); |
| 1550 | if (may_warn && |
| 1551 | hotkey_source_mask != 0 && hotkey_poll_freq == 0) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 1552 | printk(TPACPI_NOTICE |
| 1553 | "hot keys 0x%08x require polling, " |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1554 | "which is currently disabled\n", |
| 1555 | hotkey_source_mask); |
| 1556 | } |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | static void hotkey_poll_setup_safe(int may_warn) |
| 1561 | { |
| 1562 | mutex_lock(&hotkey_mutex); |
| 1563 | hotkey_poll_setup(may_warn); |
| 1564 | mutex_unlock(&hotkey_mutex); |
| 1565 | } |
| 1566 | |
Henrique de Moraes Holschuh | 1bc6b9c | 2008-02-16 02:17:52 -0200 | [diff] [blame] | 1567 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1568 | |
| 1569 | static void hotkey_poll_setup_safe(int __unused) |
| 1570 | { |
| 1571 | } |
| 1572 | |
| 1573 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1574 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1575 | static int hotkey_inputdev_open(struct input_dev *dev) |
| 1576 | { |
| 1577 | switch (tpacpi_lifecycle) { |
| 1578 | case TPACPI_LIFE_INIT: |
| 1579 | /* |
| 1580 | * hotkey_init will call hotkey_poll_setup_safe |
| 1581 | * at the appropriate moment |
| 1582 | */ |
| 1583 | return 0; |
| 1584 | case TPACPI_LIFE_EXITING: |
| 1585 | return -EBUSY; |
| 1586 | case TPACPI_LIFE_RUNNING: |
| 1587 | hotkey_poll_setup_safe(0); |
| 1588 | return 0; |
| 1589 | } |
| 1590 | |
| 1591 | /* Should only happen if tpacpi_lifecycle is corrupt */ |
| 1592 | BUG(); |
| 1593 | return -EBUSY; |
| 1594 | } |
| 1595 | |
| 1596 | static void hotkey_inputdev_close(struct input_dev *dev) |
| 1597 | { |
| 1598 | /* disable hotkey polling when possible */ |
| 1599 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING) |
| 1600 | hotkey_poll_setup_safe(0); |
| 1601 | } |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1602 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1603 | /* sysfs hotkey enable ------------------------------------------------- */ |
| 1604 | static ssize_t hotkey_enable_show(struct device *dev, |
| 1605 | struct device_attribute *attr, |
| 1606 | char *buf) |
| 1607 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1608 | int res, status; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1609 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1610 | res = hotkey_status_get(&status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1611 | if (res) |
| 1612 | return res; |
| 1613 | |
| 1614 | return snprintf(buf, PAGE_SIZE, "%d\n", status); |
| 1615 | } |
| 1616 | |
| 1617 | static ssize_t hotkey_enable_store(struct device *dev, |
| 1618 | struct device_attribute *attr, |
| 1619 | const char *buf, size_t count) |
| 1620 | { |
| 1621 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1622 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1623 | |
| 1624 | if (parse_strtoul(buf, 1, &t)) |
| 1625 | return -EINVAL; |
| 1626 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1627 | res = hotkey_status_set(t); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1628 | |
| 1629 | return (res) ? res : count; |
| 1630 | } |
| 1631 | |
| 1632 | static struct device_attribute dev_attr_hotkey_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1633 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1634 | hotkey_enable_show, hotkey_enable_store); |
| 1635 | |
| 1636 | /* sysfs hotkey mask --------------------------------------------------- */ |
| 1637 | static ssize_t hotkey_mask_show(struct device *dev, |
| 1638 | struct device_attribute *attr, |
| 1639 | char *buf) |
| 1640 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1641 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1642 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1643 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1644 | return -ERESTARTSYS; |
| 1645 | res = hotkey_mask_get(); |
| 1646 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1647 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1648 | return (res)? |
| 1649 | res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | static ssize_t hotkey_mask_store(struct device *dev, |
| 1653 | struct device_attribute *attr, |
| 1654 | const char *buf, size_t count) |
| 1655 | { |
| 1656 | unsigned long t; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1657 | int res; |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1658 | |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1659 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1660 | return -EINVAL; |
| 1661 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1662 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1663 | return -ERESTARTSYS; |
| 1664 | |
| 1665 | res = hotkey_mask_set(t); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1666 | |
| 1667 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1668 | hotkey_poll_setup(1); |
| 1669 | #endif |
| 1670 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 1671 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1672 | |
| 1673 | return (res) ? res : count; |
| 1674 | } |
| 1675 | |
| 1676 | static struct device_attribute dev_attr_hotkey_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1677 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1678 | hotkey_mask_show, hotkey_mask_store); |
| 1679 | |
| 1680 | /* sysfs hotkey bios_enabled ------------------------------------------- */ |
| 1681 | static ssize_t hotkey_bios_enabled_show(struct device *dev, |
| 1682 | struct device_attribute *attr, |
| 1683 | char *buf) |
| 1684 | { |
| 1685 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status); |
| 1686 | } |
| 1687 | |
| 1688 | static struct device_attribute dev_attr_hotkey_bios_enabled = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1689 | __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] | 1690 | |
| 1691 | /* sysfs hotkey bios_mask ---------------------------------------------- */ |
| 1692 | static ssize_t hotkey_bios_mask_show(struct device *dev, |
| 1693 | struct device_attribute *attr, |
| 1694 | char *buf) |
| 1695 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 1696 | 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] | 1697 | } |
| 1698 | |
| 1699 | static struct device_attribute dev_attr_hotkey_bios_mask = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 1700 | __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] | 1701 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1702 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
| 1703 | static ssize_t hotkey_all_mask_show(struct device *dev, |
| 1704 | struct device_attribute *attr, |
| 1705 | char *buf) |
| 1706 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1707 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
| 1708 | hotkey_all_mask | hotkey_source_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | static struct device_attribute dev_attr_hotkey_all_mask = |
| 1712 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); |
| 1713 | |
| 1714 | /* sysfs hotkey recommended_mask --------------------------------------- */ |
| 1715 | static ssize_t hotkey_recommended_mask_show(struct device *dev, |
| 1716 | struct device_attribute *attr, |
| 1717 | char *buf) |
| 1718 | { |
| 1719 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1720 | (hotkey_all_mask | hotkey_source_mask) |
| 1721 | & ~hotkey_reserved_mask); |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
| 1725 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
| 1726 | hotkey_recommended_mask_show, NULL); |
| 1727 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1728 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1729 | |
| 1730 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ |
| 1731 | static ssize_t hotkey_source_mask_show(struct device *dev, |
| 1732 | struct device_attribute *attr, |
| 1733 | char *buf) |
| 1734 | { |
| 1735 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); |
| 1736 | } |
| 1737 | |
| 1738 | static ssize_t hotkey_source_mask_store(struct device *dev, |
| 1739 | struct device_attribute *attr, |
| 1740 | const char *buf, size_t count) |
| 1741 | { |
| 1742 | unsigned long t; |
| 1743 | |
| 1744 | if (parse_strtoul(buf, 0xffffffffUL, &t) || |
| 1745 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) |
| 1746 | return -EINVAL; |
| 1747 | |
| 1748 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1749 | return -ERESTARTSYS; |
| 1750 | |
| 1751 | HOTKEY_CONFIG_CRITICAL_START |
| 1752 | hotkey_source_mask = t; |
| 1753 | HOTKEY_CONFIG_CRITICAL_END |
| 1754 | |
| 1755 | hotkey_poll_setup(1); |
| 1756 | |
| 1757 | mutex_unlock(&hotkey_mutex); |
| 1758 | |
| 1759 | return count; |
| 1760 | } |
| 1761 | |
| 1762 | static struct device_attribute dev_attr_hotkey_source_mask = |
| 1763 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, |
| 1764 | hotkey_source_mask_show, hotkey_source_mask_store); |
| 1765 | |
| 1766 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ |
| 1767 | static ssize_t hotkey_poll_freq_show(struct device *dev, |
| 1768 | struct device_attribute *attr, |
| 1769 | char *buf) |
| 1770 | { |
| 1771 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); |
| 1772 | } |
| 1773 | |
| 1774 | static ssize_t hotkey_poll_freq_store(struct device *dev, |
| 1775 | struct device_attribute *attr, |
| 1776 | const char *buf, size_t count) |
| 1777 | { |
| 1778 | unsigned long t; |
| 1779 | |
| 1780 | if (parse_strtoul(buf, 25, &t)) |
| 1781 | return -EINVAL; |
| 1782 | |
| 1783 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 1784 | return -ERESTARTSYS; |
| 1785 | |
| 1786 | hotkey_poll_freq = t; |
| 1787 | |
| 1788 | hotkey_poll_setup(1); |
| 1789 | mutex_unlock(&hotkey_mutex); |
| 1790 | |
| 1791 | return count; |
| 1792 | } |
| 1793 | |
| 1794 | static struct device_attribute dev_attr_hotkey_poll_freq = |
| 1795 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, |
| 1796 | hotkey_poll_freq_show, hotkey_poll_freq_store); |
| 1797 | |
| 1798 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
| 1799 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1800 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 1801 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
| 1802 | struct device_attribute *attr, |
| 1803 | char *buf) |
| 1804 | { |
| 1805 | int res, s; |
| 1806 | res = hotkey_get_wlsw(&s); |
| 1807 | if (res < 0) |
| 1808 | return res; |
| 1809 | |
| 1810 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 1811 | } |
| 1812 | |
| 1813 | static struct device_attribute dev_attr_hotkey_radio_sw = |
| 1814 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
| 1815 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1816 | static void hotkey_radio_sw_notify_change(void) |
| 1817 | { |
| 1818 | if (tp_features.hotkey_wlsw) |
| 1819 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1820 | "hotkey_radio_sw"); |
| 1821 | } |
| 1822 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 1823 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
| 1824 | static ssize_t hotkey_tablet_mode_show(struct device *dev, |
| 1825 | struct device_attribute *attr, |
| 1826 | char *buf) |
| 1827 | { |
| 1828 | int res, s; |
| 1829 | res = hotkey_get_tablet_mode(&s); |
| 1830 | if (res < 0) |
| 1831 | return res; |
| 1832 | |
| 1833 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); |
| 1834 | } |
| 1835 | |
| 1836 | static struct device_attribute dev_attr_hotkey_tablet_mode = |
| 1837 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); |
| 1838 | |
| 1839 | static void hotkey_tablet_mode_notify_change(void) |
| 1840 | { |
| 1841 | if (tp_features.hotkey_tablet) |
| 1842 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1843 | "hotkey_tablet_mode"); |
| 1844 | } |
| 1845 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1846 | /* sysfs hotkey report_mode -------------------------------------------- */ |
| 1847 | static ssize_t hotkey_report_mode_show(struct device *dev, |
| 1848 | struct device_attribute *attr, |
| 1849 | char *buf) |
| 1850 | { |
| 1851 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1852 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); |
| 1853 | } |
| 1854 | |
| 1855 | static struct device_attribute dev_attr_hotkey_report_mode = |
| 1856 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
| 1857 | |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1858 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1859 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
| 1860 | struct device_attribute *attr, |
| 1861 | char *buf) |
| 1862 | { |
| 1863 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); |
| 1864 | } |
| 1865 | |
| 1866 | static struct device_attribute dev_attr_hotkey_wakeup_reason = |
| 1867 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); |
| 1868 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 1869 | static void hotkey_wakeup_reason_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1870 | { |
| 1871 | if (tp_features.hotkey_mask) |
| 1872 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1873 | "wakeup_reason"); |
| 1874 | } |
| 1875 | |
| 1876 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1877 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
| 1878 | struct device_attribute *attr, |
| 1879 | char *buf) |
| 1880 | { |
| 1881 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); |
| 1882 | } |
| 1883 | |
| 1884 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = |
| 1885 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, |
| 1886 | hotkey_wakeup_hotunplug_complete_show, NULL); |
| 1887 | |
Adrian Bunk | 1d5a2b5 | 2008-02-13 23:30:06 +0200 | [diff] [blame] | 1888 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 1889 | { |
| 1890 | if (tp_features.hotkey_mask) |
| 1891 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
| 1892 | "wakeup_hotunplug_complete"); |
| 1893 | } |
| 1894 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1895 | /* --------------------------------------------------------------------- */ |
| 1896 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1897 | static struct attribute *hotkey_attributes[] __initdata = { |
| 1898 | &dev_attr_hotkey_enable.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1899 | &dev_attr_hotkey_bios_enabled.attr, |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1900 | &dev_attr_hotkey_report_mode.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1901 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1902 | &dev_attr_hotkey_mask.attr, |
| 1903 | &dev_attr_hotkey_all_mask.attr, |
| 1904 | &dev_attr_hotkey_recommended_mask.attr, |
| 1905 | &dev_attr_hotkey_source_mask.attr, |
| 1906 | &dev_attr_hotkey_poll_freq.attr, |
| 1907 | #endif |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 1908 | }; |
| 1909 | |
| 1910 | static struct attribute *hotkey_mask_attributes[] __initdata = { |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1911 | &dev_attr_hotkey_bios_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1912 | #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 1913 | &dev_attr_hotkey_mask.attr, |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 1914 | &dev_attr_hotkey_all_mask.attr, |
| 1915 | &dev_attr_hotkey_recommended_mask.attr, |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 1916 | #endif |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 1917 | &dev_attr_hotkey_wakeup_reason.attr, |
| 1918 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 1919 | }; |
| 1920 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1921 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1922 | { |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1923 | /* Requirements for changing the default keymaps: |
| 1924 | * |
| 1925 | * 1. Many of the keys are mapped to KEY_RESERVED for very |
| 1926 | * good reasons. Do not change them unless you have deep |
| 1927 | * knowledge on the IBM and Lenovo ThinkPad firmware for |
| 1928 | * the various ThinkPad models. The driver behaves |
| 1929 | * differently for KEY_RESERVED: such keys have their |
| 1930 | * hot key mask *unset* in mask_recommended, and also |
| 1931 | * in the initial hot key mask programmed into the |
| 1932 | * firmware at driver load time, which means the firm- |
| 1933 | * ware may react very differently if you change them to |
| 1934 | * something else; |
| 1935 | * |
| 1936 | * 2. You must be subscribed to the linux-thinkpad and |
| 1937 | * ibm-acpi-devel mailing lists, and you should read the |
| 1938 | * list archives since 2007 if you want to change the |
| 1939 | * keymaps. This requirement exists so that you will |
| 1940 | * know the past history of problems with the thinkpad- |
| 1941 | * acpi driver keymaps, and also that you will be |
| 1942 | * listening to any bug reports; |
| 1943 | * |
| 1944 | * 3. Do not send thinkpad-acpi specific patches directly to |
| 1945 | * for merging, *ever*. Send them to the linux-acpi |
| 1946 | * mailinglist for comments. Merging is to be done only |
| 1947 | * through acpi-test and the ACPI maintainer. |
| 1948 | * |
| 1949 | * If the above is too much to ask, don't change the keymap. |
| 1950 | * Ask the thinkpad-acpi maintainer to do it, instead. |
| 1951 | */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1952 | static u16 ibm_keycode_map[] __initdata = { |
| 1953 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 1954 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
| 1955 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 1956 | 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] | 1957 | |
| 1958 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1959 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 1960 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 1961 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1962 | |
| 1963 | /* brightness: firmware always reacts to them, unless |
| 1964 | * X.org did some tricks in the radeon BIOS scratch |
| 1965 | * registers of *some* models */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1966 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1967 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1968 | |
| 1969 | /* Thinklight: firmware always react to it */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1970 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1971 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1972 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 1973 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1974 | |
| 1975 | /* Volume: firmware always react to it and reprograms |
| 1976 | * the built-in *extra* mixer. Never map it to control |
| 1977 | * another mixer by default. */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 1978 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 1979 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 1980 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1981 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1982 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1983 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1984 | /* (assignments unknown, please report if found) */ |
| 1985 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 1986 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 1987 | }; |
| 1988 | static u16 lenovo_keycode_map[] __initdata = { |
| 1989 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
| 1990 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
| 1991 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
| 1992 | 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] | 1993 | |
| 1994 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 1995 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
| 1996 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
| 1997 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 1998 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 1999 | /* These either have to go through ACPI video, or |
| 2000 | * act like in the IBM ThinkPads, so don't ever |
| 2001 | * enable them by default */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 2002 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
Henrique de Moraes Holschuh | 56a185b | 2007-12-13 12:14:09 -0200 | [diff] [blame] | 2003 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2004 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2005 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2006 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2007 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
| 2008 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2009 | |
| 2010 | /* Volume: z60/z61, T60 (BIOS version?): firmware always |
| 2011 | * react to it and reprograms the built-in *extra* mixer. |
| 2012 | * Never map it to control another mixer by default. |
| 2013 | * |
| 2014 | * T60?, T61, R60?, R61: firmware and EC tries to send |
| 2015 | * these over the regular keyboard, so these are no-ops, |
| 2016 | * but there are still weird bugs re. MUTE, so do not |
| 2017 | * change unless you get test reports from all Lenovo |
| 2018 | * models. May cause the BIOS to interfere with the |
| 2019 | * HDA mixer. |
| 2020 | */ |
Henrique de Moraes Holschuh | e927c08 | 2007-10-30 17:46:19 -0200 | [diff] [blame] | 2021 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
| 2022 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
| 2023 | KEY_RESERVED, /* 0x16: MUTE */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2024 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2025 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
Henrique de Moraes Holschuh | 0f08914 | 2008-01-08 13:02:38 -0200 | [diff] [blame] | 2026 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2027 | /* (assignments unknown, please report if found) */ |
| 2028 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2029 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 2030 | }; |
| 2031 | |
| 2032 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) |
| 2033 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) |
| 2034 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) |
| 2035 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2036 | int res, i; |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2037 | int status; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2038 | int hkeyv; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2039 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2040 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); |
| 2041 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2042 | BUG_ON(!tpacpi_inputdev); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2043 | BUG_ON(tpacpi_inputdev->open != NULL || |
| 2044 | tpacpi_inputdev->close != NULL); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2045 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2046 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2047 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2048 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2049 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2050 | mutex_init(&hotkey_thread_mutex); |
| 2051 | mutex_init(&hotkey_thread_data_mutex); |
| 2052 | #endif |
| 2053 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2054 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2055 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2056 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2057 | vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2058 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2059 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2060 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2061 | hotkey_dev_attributes = create_attr_set(13, NULL); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2062 | if (!hotkey_dev_attributes) |
| 2063 | return -ENOMEM; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2064 | res = add_many_to_attr_set(hotkey_dev_attributes, |
| 2065 | hotkey_attributes, |
| 2066 | ARRAY_SIZE(hotkey_attributes)); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2067 | if (res) |
| 2068 | return res; |
| 2069 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2070 | /* 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] | 2071 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
| 2072 | for HKEY interface version 0x100 */ |
| 2073 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
| 2074 | if ((hkeyv >> 8) != 1) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2075 | printk(TPACPI_ERR "unknown version of the " |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2076 | "HKEY interface: 0x%x\n", hkeyv); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2077 | printk(TPACPI_ERR "please report this to %s\n", |
| 2078 | TPACPI_MAIL); |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2079 | } else { |
| 2080 | /* |
| 2081 | * MHKV 0x100 in A31, R40, R40e, |
| 2082 | * T4x, X31, and later |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2083 | */ |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2084 | tp_features.hotkey_mask = 1; |
| 2085 | } |
| 2086 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2087 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2088 | vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2089 | str_supported(tp_features.hotkey_mask)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2090 | |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2091 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2092 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2093 | "MHKA", "qd")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2094 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2095 | "missing MHKA handler, " |
| 2096 | "please report this to %s\n", |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2097 | TPACPI_MAIL); |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2098 | /* FN+F12, FN+F4, FN+F3 */ |
| 2099 | hotkey_all_mask = 0x080cU; |
Henrique de Moraes Holschuh | 1b6521d | 2007-09-23 11:39:03 -0300 | [diff] [blame] | 2100 | } |
Henrique de Moraes Holschuh | 9b010de | 2007-07-18 23:45:30 -0300 | [diff] [blame] | 2101 | } |
| 2102 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2103 | /* hotkey_source_mask *must* be zero for |
| 2104 | * the first hotkey_mask_get */ |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2105 | res = hotkey_status_get(&hotkey_orig_status); |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2106 | if (!res && tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2107 | res = hotkey_mask_get(); |
| 2108 | hotkey_orig_mask = hotkey_mask; |
| 2109 | if (!res) { |
| 2110 | res = add_many_to_attr_set( |
| 2111 | hotkey_dev_attributes, |
| 2112 | hotkey_mask_attributes, |
| 2113 | ARRAY_SIZE(hotkey_mask_attributes)); |
| 2114 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2115 | } |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2116 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2117 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2118 | if (tp_features.hotkey_mask) { |
| 2119 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
| 2120 | & ~hotkey_all_mask; |
| 2121 | } else { |
| 2122 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK; |
| 2123 | } |
| 2124 | |
| 2125 | vdbg_printk(TPACPI_DBG_INIT, |
| 2126 | "hotkey source mask 0x%08x, polling freq %d\n", |
| 2127 | hotkey_source_mask, hotkey_poll_freq); |
| 2128 | #endif |
| 2129 | |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2130 | /* Not all thinkpads have a hardware radio switch */ |
| 2131 | if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
| 2132 | tp_features.hotkey_wlsw = 1; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2133 | printk(TPACPI_INFO |
Henrique de Moraes Holschuh | 74941a6 | 2007-07-18 23:45:31 -0300 | [diff] [blame] | 2134 | "radio switch found; radios are %s\n", |
| 2135 | enabled(status, 0)); |
| 2136 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2137 | &dev_attr_hotkey_radio_sw.attr); |
| 2138 | } |
| 2139 | |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2140 | /* For X41t, X60t, X61t Tablets... */ |
| 2141 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { |
| 2142 | tp_features.hotkey_tablet = 1; |
| 2143 | printk(TPACPI_INFO |
| 2144 | "possible tablet mode switch found; " |
| 2145 | "ThinkPad in %s mode\n", |
| 2146 | (status & TP_HOTKEY_TABLET_MASK)? |
| 2147 | "tablet" : "laptop"); |
| 2148 | res = add_to_attr_set(hotkey_dev_attributes, |
| 2149 | &dev_attr_hotkey_tablet_mode.attr); |
| 2150 | } |
| 2151 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2152 | if (!res) |
| 2153 | res = register_attr_set_with_sysfs( |
| 2154 | hotkey_dev_attributes, |
| 2155 | &tpacpi_pdev->dev.kobj); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2156 | if (res) |
| 2157 | return res; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2158 | |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2159 | /* Set up key map */ |
| 2160 | |
| 2161 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
| 2162 | GFP_KERNEL); |
| 2163 | if (!hotkey_keycode_map) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2164 | printk(TPACPI_ERR |
| 2165 | "failed to allocate memory for key map\n"); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2166 | return -ENOMEM; |
| 2167 | } |
| 2168 | |
| 2169 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
| 2170 | dbg_printk(TPACPI_DBG_INIT, |
| 2171 | "using Lenovo default hot key map\n"); |
| 2172 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, |
| 2173 | TPACPI_HOTKEY_MAP_SIZE); |
| 2174 | } else { |
| 2175 | dbg_printk(TPACPI_DBG_INIT, |
| 2176 | "using IBM default hot key map\n"); |
| 2177 | memcpy(hotkey_keycode_map, &ibm_keycode_map, |
| 2178 | TPACPI_HOTKEY_MAP_SIZE); |
| 2179 | } |
| 2180 | |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2181 | set_bit(EV_KEY, tpacpi_inputdev->evbit); |
| 2182 | set_bit(EV_MSC, tpacpi_inputdev->evbit); |
| 2183 | set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 2184 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
| 2185 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; |
| 2186 | tpacpi_inputdev->keycode = hotkey_keycode_map; |
| 2187 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2188 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
| 2189 | set_bit(hotkey_keycode_map[i], |
| 2190 | tpacpi_inputdev->keybit); |
| 2191 | } else { |
| 2192 | if (i < sizeof(hotkey_reserved_mask)*8) |
| 2193 | hotkey_reserved_mask |= 1 << i; |
| 2194 | } |
| 2195 | } |
| 2196 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2197 | if (tp_features.hotkey_wlsw) { |
| 2198 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2199 | set_bit(SW_RADIO, tpacpi_inputdev->swbit); |
| 2200 | } |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2201 | if (tp_features.hotkey_tablet) { |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2202 | set_bit(EV_SW, tpacpi_inputdev->evbit); |
| 2203 | set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit); |
| 2204 | } |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2205 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 2206 | /* Do not issue duplicate brightness change events to |
| 2207 | * userspace */ |
| 2208 | if (!tp_features.bright_acpimode) |
| 2209 | /* update bright_acpimode... */ |
| 2210 | tpacpi_check_std_acpi_brightness_support(); |
| 2211 | |
| 2212 | if (tp_features.bright_acpimode) { |
| 2213 | printk(TPACPI_INFO |
| 2214 | "This ThinkPad has standard ACPI backlight " |
| 2215 | "brightness control, supported by the ACPI " |
| 2216 | "video driver\n"); |
| 2217 | printk(TPACPI_NOTICE |
| 2218 | "Disabling thinkpad-acpi brightness events " |
| 2219 | "by default...\n"); |
| 2220 | |
| 2221 | /* The hotkey_reserved_mask change below is not |
| 2222 | * necessary while the keys are at KEY_RESERVED in the |
| 2223 | * default map, but better safe than sorry, leave it |
| 2224 | * here as a marker of what we have to do, especially |
| 2225 | * when we finally become able to set this at runtime |
| 2226 | * on response to X.org requests */ |
| 2227 | hotkey_reserved_mask |= |
| 2228 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) |
| 2229 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); |
| 2230 | } |
| 2231 | |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2232 | dbg_printk(TPACPI_DBG_INIT, |
| 2233 | "enabling hot key handling\n"); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2234 | res = hotkey_status_set(1); |
| 2235 | if (res) |
| 2236 | return res; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2237 | res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask) |
| 2238 | & ~hotkey_reserved_mask) |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2239 | | hotkey_orig_mask); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2240 | if (res < 0 && res != -ENXIO) |
Henrique de Moraes Holschuh | 1a34376 | 2007-07-18 23:45:36 -0300 | [diff] [blame] | 2241 | return res; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2242 | |
| 2243 | dbg_printk(TPACPI_DBG_INIT, |
| 2244 | "legacy hot key reporting over procfs %s\n", |
| 2245 | (hotkey_report_mode < 2) ? |
| 2246 | "enabled" : "disabled"); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2247 | |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2248 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
| 2249 | tpacpi_inputdev->close = &hotkey_inputdev_close; |
| 2250 | |
| 2251 | hotkey_poll_setup_safe(1); |
Henrique de Moraes Holschuh | 7526696 | 2008-02-16 02:17:53 -0200 | [diff] [blame] | 2252 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2253 | tpacpi_input_send_tabletsw(); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2254 | } |
| 2255 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2256 | return (tp_features.hotkey)? 0 : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | static void hotkey_exit(void) |
| 2260 | { |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2261 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
| 2262 | hotkey_poll_stop_sync(); |
| 2263 | #endif |
| 2264 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2265 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2266 | dbg_printk(TPACPI_DBG_EXIT, |
| 2267 | "restoring original hot key mask\n"); |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2268 | /* no short-circuit boolean operator below! */ |
| 2269 | if ((hotkey_mask_set(hotkey_orig_mask) | |
| 2270 | hotkey_status_set(hotkey_orig_status)) != 0) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2271 | printk(TPACPI_ERR |
| 2272 | "failed to restore hot key mask " |
| 2273 | "to BIOS defaults\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2274 | } |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2275 | |
| 2276 | if (hotkey_dev_attributes) { |
| 2277 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
| 2278 | hotkey_dev_attributes = NULL; |
| 2279 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 2283 | { |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2284 | u32 hkey; |
Henrique de Moraes Holschuh | b7c8c20 | 2008-01-08 13:02:40 -0200 | [diff] [blame] | 2285 | unsigned int scancode; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2286 | int send_acpi_ev; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2287 | int ignore_acpi_ev; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2288 | int unk_ev; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2289 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2290 | if (event != 0x80) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2291 | printk(TPACPI_ERR |
| 2292 | "unknown HKEY notification event %d\n", event); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2293 | /* forward it to userspace, maybe it knows how to handle it */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2294 | acpi_bus_generate_netlink_event( |
| 2295 | ibm->acpi->device->pnp.device_class, |
| 2296 | ibm->acpi->device->dev.bus_id, |
| 2297 | event, 0); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2298 | return; |
| 2299 | } |
| 2300 | |
| 2301 | while (1) { |
| 2302 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2303 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2304 | return; |
| 2305 | } |
| 2306 | |
| 2307 | if (hkey == 0) { |
| 2308 | /* queue empty */ |
| 2309 | return; |
| 2310 | } |
| 2311 | |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2312 | send_acpi_ev = 1; |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2313 | ignore_acpi_ev = 0; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2314 | unk_ev = 0; |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2315 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2316 | switch (hkey >> 12) { |
| 2317 | case 1: |
| 2318 | /* 0x1000-0x1FFF: key presses */ |
| 2319 | scancode = hkey & 0xfff; |
| 2320 | if (scancode > 0 && scancode < 0x21) { |
| 2321 | scancode--; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2322 | if (!(hotkey_source_mask & (1 << scancode))) { |
| 2323 | tpacpi_input_send_key(scancode); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2324 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2325 | } else { |
| 2326 | ignore_acpi_ev = 1; |
| 2327 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2328 | } else { |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2329 | unk_ev = 1; |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2330 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2331 | break; |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2332 | case 2: |
| 2333 | /* Wakeup reason */ |
| 2334 | switch (hkey) { |
| 2335 | case 0x2304: /* suspend, undock */ |
| 2336 | case 0x2404: /* hibernation, undock */ |
| 2337 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
| 2338 | ignore_acpi_ev = 1; |
| 2339 | break; |
| 2340 | case 0x2305: /* suspend, bay eject */ |
| 2341 | case 0x2405: /* hibernation, bay eject */ |
| 2342 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
| 2343 | ignore_acpi_ev = 1; |
| 2344 | break; |
| 2345 | default: |
| 2346 | unk_ev = 1; |
| 2347 | } |
| 2348 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { |
| 2349 | printk(TPACPI_INFO |
| 2350 | "woke up due to a hot-unplug " |
| 2351 | "request...\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2352 | hotkey_wakeup_reason_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2353 | } |
| 2354 | break; |
| 2355 | case 3: |
| 2356 | /* bay-related wakeups */ |
| 2357 | if (hkey == 0x3003) { |
| 2358 | hotkey_autosleep_ack = 1; |
| 2359 | printk(TPACPI_INFO |
| 2360 | "bay ejected\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2361 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2362 | } else { |
| 2363 | unk_ev = 1; |
| 2364 | } |
| 2365 | break; |
| 2366 | case 4: |
| 2367 | /* dock-related wakeups */ |
| 2368 | if (hkey == 0x4003) { |
| 2369 | hotkey_autosleep_ack = 1; |
| 2370 | printk(TPACPI_INFO |
| 2371 | "undocked\n"); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2372 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2373 | } else { |
| 2374 | unk_ev = 1; |
| 2375 | } |
| 2376 | break; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2377 | case 5: |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2378 | /* 0x5000-0x5FFF: human interface helpers */ |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2379 | switch (hkey) { |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2380 | case 0x5010: /* Lenovo new BIOS: brightness changed */ |
Henrique de Moraes Holschuh | d1edb2b | 2008-01-08 13:02:53 -0200 | [diff] [blame] | 2381 | case 0x500b: /* X61t: tablet pen inserted into bay */ |
| 2382 | case 0x500c: /* X61t: tablet pen removed from bay */ |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2383 | break; |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2384 | case 0x5009: /* X41t-X61t: swivel up (tablet mode) */ |
| 2385 | case 0x500a: /* X41t-X61t: swivel down (normal mode) */ |
| 2386 | tpacpi_input_send_tabletsw(); |
| 2387 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | b3ec6f9 | 2008-02-16 02:17:55 -0200 | [diff] [blame] | 2388 | send_acpi_ev = 0; |
| 2389 | break; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2390 | case 0x5001: |
| 2391 | case 0x5002: |
| 2392 | /* LID switch events. Do not propagate */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2393 | ignore_acpi_ev = 1; |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2394 | break; |
| 2395 | default: |
| 2396 | unk_ev = 1; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2397 | } |
| 2398 | break; |
| 2399 | case 7: |
| 2400 | /* 0x7000-0x7FFF: misc */ |
| 2401 | if (tp_features.hotkey_wlsw && hkey == 0x7000) { |
| 2402 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2403 | hotkey_radio_sw_notify_change(); |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2404 | send_acpi_ev = 0; |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2405 | break; |
| 2406 | } |
| 2407 | /* fallthrough to default */ |
| 2408 | default: |
Henrique de Moraes Holschuh | 3b64b51 | 2008-01-08 13:02:51 -0200 | [diff] [blame] | 2409 | unk_ev = 1; |
| 2410 | } |
| 2411 | if (unk_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2412 | printk(TPACPI_NOTICE |
| 2413 | "unhandled HKEY event 0x%04x\n", hkey); |
Henrique de Moraes Holschuh | 6a38abb | 2007-07-18 23:45:35 -0300 | [diff] [blame] | 2414 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2415 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2416 | /* Legacy events */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2417 | if (!ignore_acpi_ev && |
| 2418 | (send_acpi_ev || hotkey_report_mode < 2)) { |
| 2419 | acpi_bus_generate_proc_event(ibm->acpi->device, |
| 2420 | event, hkey); |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2421 | } |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 2422 | |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2423 | /* netlink events */ |
Henrique de Moraes Holschuh | 3e5ce91 | 2007-09-23 11:39:05 -0300 | [diff] [blame] | 2424 | if (!ignore_acpi_ev && send_acpi_ev) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2425 | acpi_bus_generate_netlink_event( |
| 2426 | ibm->acpi->device->pnp.device_class, |
| 2427 | ibm->acpi->device->dev.bus_id, |
| 2428 | event, hkey); |
Henrique de Moraes Holschuh | 3eea123 | 2007-09-23 11:39:04 -0300 | [diff] [blame] | 2429 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2430 | } |
| 2431 | } |
| 2432 | |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2433 | static void hotkey_suspend(pm_message_t state) |
| 2434 | { |
| 2435 | /* Do these on suspend, we get the events on early resume! */ |
| 2436 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; |
| 2437 | hotkey_autosleep_ack = 0; |
| 2438 | } |
| 2439 | |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2440 | static void hotkey_resume(void) |
| 2441 | { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2442 | if (hotkey_mask_get()) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 2443 | printk(TPACPI_ERR |
| 2444 | "error while trying to read hot key mask " |
| 2445 | "from firmware\n"); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2446 | tpacpi_input_send_radiosw(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2447 | hotkey_radio_sw_notify_change(); |
Henrique de Moraes Holschuh | 6c231bd | 2008-02-16 02:17:58 -0200 | [diff] [blame] | 2448 | hotkey_tablet_mode_notify_change(); |
Henrique de Moraes Holschuh | 50ebec0 | 2008-01-08 13:02:55 -0200 | [diff] [blame] | 2449 | hotkey_wakeup_reason_notify_change(); |
| 2450 | hotkey_wakeup_hotunplug_complete_notify_change(); |
Henrique de Moraes Holschuh | 01e88f2 | 2008-01-08 13:02:41 -0200 | [diff] [blame] | 2451 | hotkey_poll_setup_safe(0); |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2452 | } |
| 2453 | |
Henrique de Moraes Holschuh | a041642 | 2007-04-27 22:00:16 -0300 | [diff] [blame] | 2454 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2455 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2457 | int res, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | int len = 0; |
| 2459 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2460 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2461 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 2462 | return len; |
| 2463 | } |
| 2464 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 2465 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2466 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2467 | res = hotkey_status_get(&status); |
| 2468 | if (!res) |
| 2469 | res = hotkey_mask_get(); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2470 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 2471 | if (res) |
| 2472 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | |
| 2474 | 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] | 2475 | if (tp_features.hotkey_mask) { |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2476 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | len += sprintf(p + len, |
| 2478 | "commands:\tenable, disable, reset, <mask>\n"); |
| 2479 | } else { |
| 2480 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 2481 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 2482 | } |
| 2483 | |
| 2484 | return len; |
| 2485 | } |
| 2486 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2487 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | { |
Henrique de Moraes Holschuh | ae92bd1 | 2007-07-18 23:45:29 -0300 | [diff] [blame] | 2489 | int res, status; |
| 2490 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2493 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | return -ENODEV; |
| 2495 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 2496 | if (mutex_lock_interruptible(&hotkey_mutex)) |
| 2497 | return -ERESTARTSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2498 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2499 | status = -1; |
| 2500 | mask = hotkey_mask; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2501 | |
| 2502 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | while ((cmd = next_cmd(&buf))) { |
| 2504 | if (strlencmp(cmd, "enable") == 0) { |
| 2505 | status = 1; |
| 2506 | } else if (strlencmp(cmd, "disable") == 0) { |
| 2507 | status = 0; |
| 2508 | } else if (strlencmp(cmd, "reset") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2509 | status = hotkey_orig_status; |
| 2510 | mask = hotkey_orig_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 2512 | /* mask set */ |
| 2513 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 2514 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2515 | } else { |
| 2516 | res = -EINVAL; |
| 2517 | goto errexit; |
| 2518 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | } |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2520 | if (status != -1) |
| 2521 | res = hotkey_status_set(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | |
Henrique de Moraes Holschuh | b2c985e | 2008-01-08 13:02:39 -0200 | [diff] [blame] | 2523 | if (!res && mask != hotkey_mask) |
| 2524 | res = hotkey_mask_set(mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2526 | errexit: |
| 2527 | mutex_unlock(&hotkey_mutex); |
| 2528 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2529 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2531 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2532 | {TPACPI_ACPI_HKEY_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2533 | {"", 0}, |
| 2534 | }; |
| 2535 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2536 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 2537 | .hid = ibm_htk_device_ids, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2538 | .notify = hotkey_notify, |
| 2539 | .handle = &hkey_handle, |
| 2540 | .type = ACPI_DEVICE_NOTIFY, |
| 2541 | }; |
| 2542 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2543 | static struct ibm_struct hotkey_driver_data = { |
| 2544 | .name = "hotkey", |
| 2545 | .read = hotkey_read, |
| 2546 | .write = hotkey_write, |
| 2547 | .exit = hotkey_exit, |
Henrique de Moraes Holschuh | 5c29d58 | 2007-07-18 23:45:38 -0300 | [diff] [blame] | 2548 | .resume = hotkey_resume, |
Henrique de Moraes Holschuh | a713b4d | 2008-01-08 13:02:52 -0200 | [diff] [blame] | 2549 | .suspend = hotkey_suspend, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2550 | .acpi = &ibm_hotkey_acpidriver, |
| 2551 | }; |
| 2552 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2553 | /************************************************************************* |
| 2554 | * Bluetooth subdriver |
| 2555 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2557 | enum { |
| 2558 | /* ACPI GBDC/SBDC bits */ |
| 2559 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ |
| 2560 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ |
| 2561 | TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */ |
| 2562 | }; |
| 2563 | |
| 2564 | static int bluetooth_get_radiosw(void); |
| 2565 | static int bluetooth_set_radiosw(int radio_on); |
| 2566 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2567 | /* sysfs bluetooth enable ---------------------------------------------- */ |
| 2568 | static ssize_t bluetooth_enable_show(struct device *dev, |
| 2569 | struct device_attribute *attr, |
| 2570 | char *buf) |
| 2571 | { |
| 2572 | int status; |
| 2573 | |
| 2574 | status = bluetooth_get_radiosw(); |
| 2575 | if (status < 0) |
| 2576 | return status; |
| 2577 | |
| 2578 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); |
| 2579 | } |
| 2580 | |
| 2581 | static ssize_t bluetooth_enable_store(struct device *dev, |
| 2582 | struct device_attribute *attr, |
| 2583 | const char *buf, size_t count) |
| 2584 | { |
| 2585 | unsigned long t; |
| 2586 | int res; |
| 2587 | |
| 2588 | if (parse_strtoul(buf, 1, &t)) |
| 2589 | return -EINVAL; |
| 2590 | |
| 2591 | res = bluetooth_set_radiosw(t); |
| 2592 | |
| 2593 | return (res) ? res : count; |
| 2594 | } |
| 2595 | |
| 2596 | static struct device_attribute dev_attr_bluetooth_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2597 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2598 | bluetooth_enable_show, bluetooth_enable_store); |
| 2599 | |
| 2600 | /* --------------------------------------------------------------------- */ |
| 2601 | |
| 2602 | static struct attribute *bluetooth_attributes[] = { |
| 2603 | &dev_attr_bluetooth_enable.attr, |
| 2604 | NULL |
| 2605 | }; |
| 2606 | |
| 2607 | static const struct attribute_group bluetooth_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2608 | .attrs = bluetooth_attributes, |
| 2609 | }; |
| 2610 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2611 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2613 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2614 | int status = 0; |
| 2615 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2616 | vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n"); |
| 2617 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2618 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2619 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2620 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 2621 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2622 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2623 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2625 | vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n", |
| 2626 | str_supported(tp_features.bluetooth), |
| 2627 | status); |
| 2628 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2629 | if (tp_features.bluetooth) { |
| 2630 | if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 2631 | /* no bluetooth hardware present in system */ |
| 2632 | tp_features.bluetooth = 0; |
| 2633 | dbg_printk(TPACPI_DBG_INIT, |
| 2634 | "bluetooth hardware not installed\n"); |
| 2635 | } else { |
| 2636 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2637 | &bluetooth_attr_group); |
| 2638 | if (res) |
| 2639 | return res; |
| 2640 | } |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2641 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2642 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2643 | return (tp_features.bluetooth)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2646 | static void bluetooth_exit(void) |
| 2647 | { |
| 2648 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2649 | &bluetooth_attr_group); |
| 2650 | } |
| 2651 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2652 | static int bluetooth_get_radiosw(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | { |
| 2654 | int status; |
| 2655 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2656 | if (!tp_features.bluetooth) |
| 2657 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2659 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 2660 | return -EIO; |
| 2661 | |
| 2662 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0); |
| 2663 | } |
| 2664 | |
| 2665 | static int bluetooth_set_radiosw(int radio_on) |
| 2666 | { |
| 2667 | int status; |
| 2668 | |
| 2669 | if (!tp_features.bluetooth) |
| 2670 | return -ENODEV; |
| 2671 | |
| 2672 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 2673 | return -EIO; |
| 2674 | if (radio_on) |
| 2675 | status |= TP_ACPI_BLUETOOTH_RADIOSSW; |
| 2676 | else |
| 2677 | status &= ~TP_ACPI_BLUETOOTH_RADIOSSW; |
| 2678 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 2679 | return -EIO; |
| 2680 | |
| 2681 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2684 | /* procfs -------------------------------------------------------------- */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2685 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | { |
| 2687 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2688 | int status = bluetooth_get_radiosw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2690 | if (!tp_features.bluetooth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2693 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2694 | (status)? "enabled" : "disabled"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 2696 | } |
| 2697 | |
| 2698 | return len; |
| 2699 | } |
| 2700 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2701 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2705 | if (!tp_features.bluetooth) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2706 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | |
| 2708 | while ((cmd = next_cmd(&buf))) { |
| 2709 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2710 | bluetooth_set_radiosw(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2712 | bluetooth_set_radiosw(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | } else |
| 2714 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | } |
| 2716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | return 0; |
| 2718 | } |
| 2719 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2720 | static struct ibm_struct bluetooth_driver_data = { |
| 2721 | .name = "bluetooth", |
| 2722 | .read = bluetooth_read, |
| 2723 | .write = bluetooth_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2724 | .exit = bluetooth_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2725 | }; |
| 2726 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2727 | /************************************************************************* |
| 2728 | * Wan subdriver |
| 2729 | */ |
| 2730 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2731 | enum { |
| 2732 | /* ACPI GWAN/SWAN bits */ |
| 2733 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ |
| 2734 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ |
| 2735 | TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */ |
| 2736 | }; |
| 2737 | |
| 2738 | static int wan_get_radiosw(void); |
| 2739 | static int wan_set_radiosw(int radio_on); |
| 2740 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2741 | /* sysfs wan enable ---------------------------------------------------- */ |
| 2742 | static ssize_t wan_enable_show(struct device *dev, |
| 2743 | struct device_attribute *attr, |
| 2744 | char *buf) |
| 2745 | { |
| 2746 | int status; |
| 2747 | |
| 2748 | status = wan_get_radiosw(); |
| 2749 | if (status < 0) |
| 2750 | return status; |
| 2751 | |
| 2752 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); |
| 2753 | } |
| 2754 | |
| 2755 | static ssize_t wan_enable_store(struct device *dev, |
| 2756 | struct device_attribute *attr, |
| 2757 | const char *buf, size_t count) |
| 2758 | { |
| 2759 | unsigned long t; |
| 2760 | int res; |
| 2761 | |
| 2762 | if (parse_strtoul(buf, 1, &t)) |
| 2763 | return -EINVAL; |
| 2764 | |
| 2765 | res = wan_set_radiosw(t); |
| 2766 | |
| 2767 | return (res) ? res : count; |
| 2768 | } |
| 2769 | |
| 2770 | static struct device_attribute dev_attr_wan_enable = |
Henrique de Moraes Holschuh | cc4c24e | 2007-05-30 20:50:14 -0300 | [diff] [blame] | 2771 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2772 | wan_enable_show, wan_enable_store); |
| 2773 | |
| 2774 | /* --------------------------------------------------------------------- */ |
| 2775 | |
| 2776 | static struct attribute *wan_attributes[] = { |
| 2777 | &dev_attr_wan_enable.attr, |
| 2778 | NULL |
| 2779 | }; |
| 2780 | |
| 2781 | static const struct attribute_group wan_attr_group = { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2782 | .attrs = wan_attributes, |
| 2783 | }; |
| 2784 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2785 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2786 | { |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2787 | int res; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2788 | int status = 0; |
| 2789 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2790 | vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n"); |
| 2791 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2792 | TPACPI_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2793 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2794 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2795 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2796 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2797 | vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n", |
| 2798 | str_supported(tp_features.wan), |
| 2799 | status); |
| 2800 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2801 | if (tp_features.wan) { |
| 2802 | if (!(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 2803 | /* no wan hardware present in system */ |
| 2804 | tp_features.wan = 0; |
| 2805 | dbg_printk(TPACPI_DBG_INIT, |
| 2806 | "wan hardware not installed\n"); |
| 2807 | } else { |
| 2808 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2809 | &wan_attr_group); |
| 2810 | if (res) |
| 2811 | return res; |
| 2812 | } |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2813 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2814 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2815 | return (tp_features.wan)? 0 : 1; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2816 | } |
| 2817 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2818 | static void wan_exit(void) |
| 2819 | { |
| 2820 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2821 | &wan_attr_group); |
| 2822 | } |
| 2823 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2824 | static int wan_get_radiosw(void) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2825 | { |
| 2826 | int status; |
| 2827 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2828 | if (!tp_features.wan) |
| 2829 | return -ENODEV; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2830 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2831 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 2832 | return -EIO; |
| 2833 | |
| 2834 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0); |
| 2835 | } |
| 2836 | |
| 2837 | static int wan_set_radiosw(int radio_on) |
| 2838 | { |
| 2839 | int status; |
| 2840 | |
| 2841 | if (!tp_features.wan) |
| 2842 | return -ENODEV; |
| 2843 | |
| 2844 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 2845 | return -EIO; |
| 2846 | if (radio_on) |
| 2847 | status |= TP_ACPI_WANCARD_RADIOSSW; |
| 2848 | else |
| 2849 | status &= ~TP_ACPI_WANCARD_RADIOSSW; |
| 2850 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 2851 | return -EIO; |
| 2852 | |
| 2853 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2854 | } |
| 2855 | |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2856 | /* procfs -------------------------------------------------------------- */ |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2857 | static int wan_read(char *p) |
| 2858 | { |
| 2859 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2860 | int status = wan_get_radiosw(); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2861 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2862 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2863 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2864 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2865 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2866 | (status)? "enabled" : "disabled"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2867 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 2868 | } |
| 2869 | |
| 2870 | return len; |
| 2871 | } |
| 2872 | |
| 2873 | static int wan_write(char *buf) |
| 2874 | { |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2875 | char *cmd; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2876 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2877 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2878 | return -ENODEV; |
| 2879 | |
| 2880 | while ((cmd = next_cmd(&buf))) { |
| 2881 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2882 | wan_set_radiosw(1); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2883 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 2884 | wan_set_radiosw(0); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2885 | } else |
| 2886 | return -EINVAL; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2887 | } |
| 2888 | |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2889 | return 0; |
| 2890 | } |
| 2891 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2892 | static struct ibm_struct wan_driver_data = { |
| 2893 | .name = "wan", |
| 2894 | .read = wan_read, |
| 2895 | .write = wan_write, |
Henrique de Moraes Holschuh | d3a6ade | 2007-04-27 22:00:17 -0300 | [diff] [blame] | 2896 | .exit = wan_exit, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 2897 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2898 | }; |
| 2899 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2900 | /************************************************************************* |
| 2901 | * Video subdriver |
| 2902 | */ |
| 2903 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 2904 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
| 2905 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2906 | enum video_access_mode { |
| 2907 | TPACPI_VIDEO_NONE = 0, |
| 2908 | TPACPI_VIDEO_570, /* 570 */ |
| 2909 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ |
| 2910 | TPACPI_VIDEO_NEW, /* all others */ |
| 2911 | }; |
| 2912 | |
| 2913 | enum { /* video status flags, based on VIDEO_570 */ |
| 2914 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ |
| 2915 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ |
| 2916 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ |
| 2917 | }; |
| 2918 | |
| 2919 | enum { /* TPACPI_VIDEO_570 constants */ |
| 2920 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ |
| 2921 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to |
| 2922 | * video_status_flags */ |
| 2923 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ |
| 2924 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ |
| 2925 | }; |
| 2926 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 2927 | static enum video_access_mode video_supported; |
| 2928 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2929 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 2930 | static int video_autosw_get(void); |
| 2931 | static int video_autosw_set(int enable); |
| 2932 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2933 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2934 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2935 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2937 | int ivga; |
| 2938 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2939 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 2940 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2941 | TPACPI_ACPIHANDLE_INIT(vid); |
| 2942 | TPACPI_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2943 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2944 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 2945 | /* G41, assume IVGA doesn't change */ |
| 2946 | vid_handle = vid2_handle; |
| 2947 | |
| 2948 | if (!vid_handle) |
| 2949 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2950 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2951 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 2952 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2953 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2954 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 2955 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2956 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2957 | else |
| 2958 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2959 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2961 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 2962 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 2963 | video_supported); |
| 2964 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2965 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2968 | static void video_exit(void) |
| 2969 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2970 | dbg_printk(TPACPI_DBG_EXIT, |
| 2971 | "restoring original video autoswitch mode\n"); |
| 2972 | if (video_autosw_set(video_orig_autosw)) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 2973 | printk(TPACPI_ERR "error while trying to restore original " |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2974 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2975 | } |
| 2976 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2977 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | { |
| 2979 | int status = 0; |
| 2980 | int i; |
| 2981 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 2982 | switch (video_supported) { |
| 2983 | case TPACPI_VIDEO_570: |
| 2984 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 2985 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 2986 | return -EIO; |
| 2987 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 2988 | break; |
| 2989 | case TPACPI_VIDEO_770: |
| 2990 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 2991 | return -EIO; |
| 2992 | if (i) |
| 2993 | status |= TP_ACPI_VIDEO_S_LCD; |
| 2994 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 2995 | return -EIO; |
| 2996 | if (i) |
| 2997 | status |= TP_ACPI_VIDEO_S_CRT; |
| 2998 | break; |
| 2999 | case TPACPI_VIDEO_NEW: |
| 3000 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 3001 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 3002 | return -EIO; |
| 3003 | if (i) |
| 3004 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3006 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 3007 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 3008 | return -EIO; |
| 3009 | if (i) |
| 3010 | status |= TP_ACPI_VIDEO_S_LCD; |
| 3011 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 3012 | return -EIO; |
| 3013 | if (i) |
| 3014 | status |= TP_ACPI_VIDEO_S_DVI; |
| 3015 | break; |
| 3016 | default: |
| 3017 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3018 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | |
| 3020 | return status; |
| 3021 | } |
| 3022 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3023 | static int video_outputsw_set(int status) |
| 3024 | { |
| 3025 | int autosw; |
| 3026 | int res = 0; |
| 3027 | |
| 3028 | switch (video_supported) { |
| 3029 | case TPACPI_VIDEO_570: |
| 3030 | res = acpi_evalf(NULL, NULL, |
| 3031 | "\\_SB.PHS2", "vdd", |
| 3032 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 3033 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 3034 | break; |
| 3035 | case TPACPI_VIDEO_770: |
| 3036 | autosw = video_autosw_get(); |
| 3037 | if (autosw < 0) |
| 3038 | return autosw; |
| 3039 | |
| 3040 | res = video_autosw_set(1); |
| 3041 | if (res) |
| 3042 | return res; |
| 3043 | res = acpi_evalf(vid_handle, NULL, |
| 3044 | "ASWT", "vdd", status * 0x100, 0); |
| 3045 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3046 | printk(TPACPI_ERR |
| 3047 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3048 | return -EIO; |
| 3049 | } |
| 3050 | break; |
| 3051 | case TPACPI_VIDEO_NEW: |
| 3052 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3053 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3054 | break; |
| 3055 | default: |
| 3056 | return -ENOSYS; |
| 3057 | } |
| 3058 | |
| 3059 | return (res)? 0 : -EIO; |
| 3060 | } |
| 3061 | |
| 3062 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3064 | int autosw = 0; |
| 3065 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3066 | switch (video_supported) { |
| 3067 | case TPACPI_VIDEO_570: |
| 3068 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 3069 | return -EIO; |
| 3070 | break; |
| 3071 | case TPACPI_VIDEO_770: |
| 3072 | case TPACPI_VIDEO_NEW: |
| 3073 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 3074 | return -EIO; |
| 3075 | break; |
| 3076 | default: |
| 3077 | return -ENOSYS; |
| 3078 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3079 | |
| 3080 | return autosw & 1; |
| 3081 | } |
| 3082 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3083 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3084 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3085 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3086 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3087 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3088 | } |
| 3089 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3090 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3091 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3092 | int autosw = video_autosw_get(); |
| 3093 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3094 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3095 | if (autosw < 0) |
| 3096 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3097 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3098 | switch (video_supported) { |
| 3099 | case TPACPI_VIDEO_570: |
| 3100 | res = video_autosw_set(1); |
| 3101 | if (res) |
| 3102 | return res; |
| 3103 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 3104 | break; |
| 3105 | case TPACPI_VIDEO_770: |
| 3106 | case TPACPI_VIDEO_NEW: |
| 3107 | res = video_autosw_set(1); |
| 3108 | if (res) |
| 3109 | return res; |
| 3110 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 3111 | break; |
| 3112 | default: |
| 3113 | return -ENOSYS; |
| 3114 | } |
| 3115 | if (!autosw && video_autosw_set(autosw)) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3116 | printk(TPACPI_ERR |
| 3117 | "video auto-switch left enabled due to error\n"); |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3118 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3119 | } |
| 3120 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3121 | return (res)? 0 : -EIO; |
| 3122 | } |
| 3123 | |
| 3124 | static int video_expand_toggle(void) |
| 3125 | { |
| 3126 | switch (video_supported) { |
| 3127 | case TPACPI_VIDEO_570: |
| 3128 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 3129 | 0 : -EIO; |
| 3130 | case TPACPI_VIDEO_770: |
| 3131 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 3132 | 0 : -EIO; |
| 3133 | case TPACPI_VIDEO_NEW: |
| 3134 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 3135 | 0 : -EIO; |
| 3136 | default: |
| 3137 | return -ENOSYS; |
| 3138 | } |
| 3139 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3140 | } |
| 3141 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3142 | static int video_read(char *p) |
| 3143 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3144 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3145 | int len = 0; |
| 3146 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3147 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3148 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3149 | return len; |
| 3150 | } |
| 3151 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3152 | status = video_outputsw_get(); |
| 3153 | if (status < 0) |
| 3154 | return status; |
| 3155 | |
| 3156 | autosw = video_autosw_get(); |
| 3157 | if (autosw < 0) |
| 3158 | return autosw; |
| 3159 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3160 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 3161 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 3162 | 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] | 3163 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3164 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 3165 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 3166 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 3167 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3168 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3169 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 3170 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 3171 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 3172 | |
| 3173 | return len; |
| 3174 | } |
| 3175 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3176 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | { |
| 3178 | char *cmd; |
| 3179 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3180 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3182 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3183 | return -ENODEV; |
| 3184 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3185 | enable = 0; |
| 3186 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | |
| 3188 | while ((cmd = next_cmd(&buf))) { |
| 3189 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3190 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3192 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3194 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3196 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3197 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3198 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3199 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3200 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3201 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3202 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3204 | res = video_autosw_set(1); |
| 3205 | if (res) |
| 3206 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3208 | res = video_autosw_set(0); |
| 3209 | if (res) |
| 3210 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3212 | res = video_outputsw_cycle(); |
| 3213 | if (res) |
| 3214 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3216 | res = video_expand_toggle(); |
| 3217 | if (res) |
| 3218 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | } else |
| 3220 | return -EINVAL; |
| 3221 | } |
| 3222 | |
| 3223 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 3224 | status = video_outputsw_get(); |
| 3225 | if (status < 0) |
| 3226 | return status; |
| 3227 | res = video_outputsw_set((status & ~disable) | enable); |
| 3228 | if (res) |
| 3229 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | return 0; |
| 3233 | } |
| 3234 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3235 | static struct ibm_struct video_driver_data = { |
| 3236 | .name = "video", |
| 3237 | .read = video_read, |
| 3238 | .write = video_write, |
| 3239 | .exit = video_exit, |
| 3240 | }; |
| 3241 | |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 3242 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
| 3243 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3244 | /************************************************************************* |
| 3245 | * Light (thinklight) subdriver |
| 3246 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3248 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 3249 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3250 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3251 | static int light_get_status(void) |
| 3252 | { |
| 3253 | int status = 0; |
| 3254 | |
| 3255 | if (tp_features.light_status) { |
| 3256 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 3257 | return -EIO; |
| 3258 | return (!!status); |
| 3259 | } |
| 3260 | |
| 3261 | return -ENXIO; |
| 3262 | } |
| 3263 | |
| 3264 | static int light_set_status(int status) |
| 3265 | { |
| 3266 | int rc; |
| 3267 | |
| 3268 | if (tp_features.light) { |
| 3269 | if (cmos_handle) { |
| 3270 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", |
| 3271 | (status)? |
| 3272 | TP_CMOS_THINKLIGHT_ON : |
| 3273 | TP_CMOS_THINKLIGHT_OFF); |
| 3274 | } else { |
| 3275 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", |
| 3276 | (status)? 1 : 0); |
| 3277 | } |
| 3278 | return (rc)? 0 : -EIO; |
| 3279 | } |
| 3280 | |
| 3281 | return -ENXIO; |
| 3282 | } |
| 3283 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3284 | static void light_set_status_worker(struct work_struct *work) |
| 3285 | { |
| 3286 | struct tpacpi_led_classdev *data = |
| 3287 | container_of(work, struct tpacpi_led_classdev, work); |
| 3288 | |
| 3289 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
| 3290 | light_set_status((data->new_brightness != LED_OFF)); |
| 3291 | } |
| 3292 | |
| 3293 | static void light_sysfs_set(struct led_classdev *led_cdev, |
| 3294 | enum led_brightness brightness) |
| 3295 | { |
| 3296 | struct tpacpi_led_classdev *data = |
| 3297 | container_of(led_cdev, |
| 3298 | struct tpacpi_led_classdev, |
| 3299 | led_classdev); |
| 3300 | data->new_brightness = brightness; |
| 3301 | schedule_work(&data->work); |
| 3302 | } |
| 3303 | |
| 3304 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) |
| 3305 | { |
| 3306 | return (light_get_status() == 1)? LED_FULL : LED_OFF; |
| 3307 | } |
| 3308 | |
| 3309 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { |
| 3310 | .led_classdev = { |
| 3311 | .name = "tpacpi::thinklight", |
| 3312 | .brightness_set = &light_sysfs_set, |
| 3313 | .brightness_get = &light_sysfs_get, |
| 3314 | } |
| 3315 | }; |
| 3316 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3317 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | { |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3319 | int rc = 0; |
| 3320 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3321 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 3322 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3323 | TPACPI_ACPIHANDLE_INIT(ledb); |
| 3324 | TPACPI_ACPIHANDLE_INIT(lght); |
| 3325 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3326 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3327 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3328 | /* 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] | 3329 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3330 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3331 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3332 | /* light status not supported on |
| 3333 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3334 | tp_features.light_status = |
| 3335 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3337 | vdbg_printk(TPACPI_DBG_INIT, "light is %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3338 | str_supported(tp_features.light)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3339 | |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3340 | if (tp_features.light) { |
| 3341 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 3342 | &tpacpi_led_thinklight.led_classdev); |
| 3343 | } |
| 3344 | |
| 3345 | if (rc < 0) { |
| 3346 | tp_features.light = 0; |
| 3347 | tp_features.light_status = 0; |
| 3348 | } else { |
| 3349 | rc = (tp_features.light)? 0 : 1; |
| 3350 | } |
| 3351 | return rc; |
| 3352 | } |
| 3353 | |
| 3354 | static void light_exit(void) |
| 3355 | { |
| 3356 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); |
| 3357 | if (work_pending(&tpacpi_led_thinklight.work)) |
| 3358 | flush_scheduled_work(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | } |
| 3360 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3361 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | { |
| 3363 | int len = 0; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3364 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3366 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3367 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3368 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3369 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 3370 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 3371 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3372 | status = light_get_status(); |
| 3373 | if (status < 0) |
| 3374 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3376 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 3377 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | |
| 3379 | return len; |
| 3380 | } |
| 3381 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3382 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3385 | int newstatus = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3386 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3387 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3388 | return -ENODEV; |
| 3389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | while ((cmd = next_cmd(&buf))) { |
| 3391 | if (strlencmp(cmd, "on") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3392 | newstatus = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | } else if (strlencmp(cmd, "off") == 0) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3394 | newstatus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | } else |
| 3396 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | } |
| 3398 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3399 | return light_set_status(newstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | } |
| 3401 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3402 | static struct ibm_struct light_driver_data = { |
| 3403 | .name = "light", |
| 3404 | .read = light_read, |
| 3405 | .write = light_write, |
Henrique de Moraes Holschuh | e306501 | 2008-04-26 01:02:24 -0300 | [diff] [blame] | 3406 | .exit = light_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3407 | }; |
| 3408 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3409 | /************************************************************************* |
| 3410 | * Dock subdriver |
| 3411 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3413 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3414 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3415 | static void dock_notify(struct ibm_struct *ibm, u32 event); |
| 3416 | static int dock_read(char *p); |
| 3417 | static int dock_write(char *buf); |
| 3418 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3419 | TPACPI_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3420 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ |
| 3421 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ |
| 3422 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
| 3423 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
| 3424 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3425 | /* don't list other alternatives as we install a notify handler on the 570 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3426 | TPACPI_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3427 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3428 | static const struct acpi_device_id ibm_pci_device_ids[] = { |
| 3429 | {PCI_ROOT_HID_STRING, 0}, |
| 3430 | {"", 0}, |
| 3431 | }; |
| 3432 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3433 | static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = { |
| 3434 | { |
| 3435 | .notify = dock_notify, |
| 3436 | .handle = &dock_handle, |
| 3437 | .type = ACPI_SYSTEM_NOTIFY, |
| 3438 | }, |
| 3439 | { |
Henrique de Moraes Holschuh | 996fba0 | 2007-07-18 23:45:40 -0300 | [diff] [blame] | 3440 | /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING. |
| 3441 | * We just use it to get notifications of dock hotplug |
| 3442 | * in very old thinkpads */ |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3443 | .hid = ibm_pci_device_ids, |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3444 | .notify = dock_notify, |
| 3445 | .handle = &pci_handle, |
| 3446 | .type = ACPI_SYSTEM_NOTIFY, |
| 3447 | }, |
| 3448 | }; |
| 3449 | |
| 3450 | static struct ibm_struct dock_driver_data[2] = { |
| 3451 | { |
| 3452 | .name = "dock", |
| 3453 | .read = dock_read, |
| 3454 | .write = dock_write, |
| 3455 | .acpi = &ibm_dock_acpidriver[0], |
| 3456 | }, |
| 3457 | { |
| 3458 | .name = "dock", |
| 3459 | .acpi = &ibm_dock_acpidriver[1], |
| 3460 | }, |
| 3461 | }; |
| 3462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | #define dock_docked() (_sta(dock_handle) & 1) |
| 3464 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3465 | static int __init dock_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3466 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3467 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n"); |
| 3468 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3469 | TPACPI_ACPIHANDLE_INIT(dock); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3470 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3471 | vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n", |
| 3472 | str_supported(dock_handle != NULL)); |
| 3473 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3474 | return (dock_handle)? 0 : 1; |
| 3475 | } |
| 3476 | |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3477 | static int __init dock_init2(struct ibm_init_struct *iibm) |
| 3478 | { |
| 3479 | int dock2_needed; |
| 3480 | |
| 3481 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n"); |
| 3482 | |
| 3483 | if (dock_driver_data[0].flags.acpi_driver_registered && |
| 3484 | dock_driver_data[0].flags.acpi_notify_installed) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3485 | TPACPI_ACPIHANDLE_INIT(pci); |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 3486 | dock2_needed = (pci_handle != NULL); |
| 3487 | vdbg_printk(TPACPI_DBG_INIT, |
| 3488 | "dock PCI handler for the TP 570 is %s\n", |
| 3489 | str_supported(dock2_needed)); |
| 3490 | } else { |
| 3491 | vdbg_printk(TPACPI_DBG_INIT, |
| 3492 | "dock subdriver part 2 not required\n"); |
| 3493 | dock2_needed = 0; |
| 3494 | } |
| 3495 | |
| 3496 | return (dock2_needed)? 0 : 1; |
| 3497 | } |
| 3498 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3499 | static void dock_notify(struct ibm_struct *ibm, u32 event) |
| 3500 | { |
| 3501 | int docked = dock_docked(); |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 3502 | int pci = ibm->acpi->hid && ibm->acpi->device && |
| 3503 | acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3504 | int data; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3505 | |
| 3506 | if (event == 1 && !pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3507 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3508 | else if (event == 1 && pci) /* 570 */ |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3509 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3510 | else if (event == 3 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3511 | data = 1; /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3512 | else if (event == 3 && !docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3513 | data = 2; /* undock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3514 | else if (event == 0 && docked) |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3515 | data = 3; /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3516 | else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3517 | printk(TPACPI_ERR "unknown dock event %d, status %d\n", |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3518 | event, _sta(dock_handle)); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3519 | data = 0; /* unknown */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3520 | } |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 3521 | acpi_bus_generate_proc_event(ibm->acpi->device, event, data); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3522 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 3523 | ibm->acpi->device->dev.bus_id, |
| 3524 | event, data); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3525 | } |
| 3526 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3527 | static int dock_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | { |
| 3529 | int len = 0; |
| 3530 | int docked = dock_docked(); |
| 3531 | |
| 3532 | if (!dock_handle) |
| 3533 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3534 | else if (!docked) |
| 3535 | len += sprintf(p + len, "status:\t\tundocked\n"); |
| 3536 | else { |
| 3537 | len += sprintf(p + len, "status:\t\tdocked\n"); |
| 3538 | len += sprintf(p + len, "commands:\tdock, undock\n"); |
| 3539 | } |
| 3540 | |
| 3541 | return len; |
| 3542 | } |
| 3543 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3544 | static int dock_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | { |
| 3546 | char *cmd; |
| 3547 | |
| 3548 | if (!dock_docked()) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3549 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | |
| 3551 | while ((cmd = next_cmd(&buf))) { |
| 3552 | if (strlencmp(cmd, "undock") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3553 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || |
| 3554 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | return -EIO; |
| 3556 | } else if (strlencmp(cmd, "dock") == 0) { |
| 3557 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) |
| 3558 | return -EIO; |
| 3559 | } else |
| 3560 | return -EINVAL; |
| 3561 | } |
| 3562 | |
| 3563 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3566 | #endif /* CONFIG_THINKPAD_ACPI_DOCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3568 | /************************************************************************* |
| 3569 | * Bay subdriver |
| 3570 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3572 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3573 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3574 | TPACPI_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3575 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
| 3576 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ |
| 3577 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
| 3578 | ); /* A21e, R30, R31 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3579 | TPACPI_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3580 | "_EJ0", /* all others */ |
| 3581 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3582 | TPACPI_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3583 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ |
| 3584 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3585 | TPACPI_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3586 | "_EJ0", /* 770x */ |
| 3587 | ); /* all others */ |
| 3588 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3589 | static int __init bay_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3591 | vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n"); |
| 3592 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3593 | TPACPI_ACPIHANDLE_INIT(bay); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3594 | if (bay_handle) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3595 | TPACPI_ACPIHANDLE_INIT(bay_ej); |
| 3596 | TPACPI_ACPIHANDLE_INIT(bay2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3597 | if (bay2_handle) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3598 | TPACPI_ACPIHANDLE_INIT(bay2_ej); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3599 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3600 | tp_features.bay_status = bay_handle && |
| 3601 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); |
| 3602 | tp_features.bay_status2 = bay2_handle && |
| 3603 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3604 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3605 | tp_features.bay_eject = bay_handle && bay_ej_handle && |
| 3606 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); |
| 3607 | tp_features.bay_eject2 = bay2_handle && bay2_ej_handle && |
| 3608 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3610 | vdbg_printk(TPACPI_DBG_INIT, |
| 3611 | "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] | 3612 | str_supported(tp_features.bay_status), |
| 3613 | str_supported(tp_features.bay_eject), |
| 3614 | str_supported(tp_features.bay_status2), |
| 3615 | str_supported(tp_features.bay_eject2)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3616 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3617 | return (tp_features.bay_status || tp_features.bay_eject || |
| 3618 | tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | } |
| 3620 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3621 | static void bay_notify(struct ibm_struct *ibm, u32 event) |
| 3622 | { |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 3623 | acpi_bus_generate_proc_event(ibm->acpi->device, event, 0); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 3624 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
| 3625 | ibm->acpi->device->dev.bus_id, |
| 3626 | event, 0); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3627 | } |
| 3628 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3629 | #define bay_occupied(b) (_sta(b##_handle) & 1) |
| 3630 | |
| 3631 | static int bay_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | { |
| 3633 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3634 | int occupied = bay_occupied(bay); |
| 3635 | int occupied2 = bay_occupied(bay2); |
| 3636 | int eject, eject2; |
| 3637 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3638 | len += sprintf(p + len, "status:\t\t%s\n", |
| 3639 | tp_features.bay_status ? |
| 3640 | (occupied ? "occupied" : "unoccupied") : |
| 3641 | "not supported"); |
| 3642 | if (tp_features.bay_status2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3643 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? |
| 3644 | "occupied" : "unoccupied"); |
| 3645 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3646 | eject = tp_features.bay_eject && occupied; |
| 3647 | eject2 = tp_features.bay_eject2 && occupied2; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3648 | |
| 3649 | if (eject && eject2) |
| 3650 | len += sprintf(p + len, "commands:\teject, eject2\n"); |
| 3651 | else if (eject) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | len += sprintf(p + len, "commands:\teject\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3653 | else if (eject2) |
| 3654 | len += sprintf(p + len, "commands:\teject2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | |
| 3656 | return len; |
| 3657 | } |
| 3658 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3659 | static int bay_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | { |
| 3661 | char *cmd; |
| 3662 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3663 | if (!tp_features.bay_eject && !tp_features.bay_eject2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3664 | return -ENODEV; |
| 3665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3667 | if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3668 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) |
| 3669 | return -EIO; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3670 | } else if (tp_features.bay_eject2 && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3671 | strlencmp(cmd, "eject2") == 0) { |
| 3672 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | return -EIO; |
| 3674 | } else |
| 3675 | return -EINVAL; |
| 3676 | } |
| 3677 | |
| 3678 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3679 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3680 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3681 | static struct tp_acpi_drv_struct ibm_bay_acpidriver = { |
| 3682 | .notify = bay_notify, |
| 3683 | .handle = &bay_handle, |
| 3684 | .type = ACPI_SYSTEM_NOTIFY, |
| 3685 | }; |
| 3686 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3687 | static struct ibm_struct bay_driver_data = { |
| 3688 | .name = "bay", |
| 3689 | .read = bay_read, |
| 3690 | .write = bay_write, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3691 | .acpi = &ibm_bay_acpidriver, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3692 | }; |
| 3693 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3694 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3696 | /************************************************************************* |
| 3697 | * CMOS subdriver |
| 3698 | */ |
| 3699 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3700 | /* sysfs cmos_command -------------------------------------------------- */ |
| 3701 | static ssize_t cmos_command_store(struct device *dev, |
| 3702 | struct device_attribute *attr, |
| 3703 | const char *buf, size_t count) |
| 3704 | { |
| 3705 | unsigned long cmos_cmd; |
| 3706 | int res; |
| 3707 | |
| 3708 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 3709 | return -EINVAL; |
| 3710 | |
| 3711 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 3712 | return (res)? res : count; |
| 3713 | } |
| 3714 | |
| 3715 | static struct device_attribute dev_attr_cmos_command = |
| 3716 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 3717 | |
| 3718 | /* --------------------------------------------------------------------- */ |
| 3719 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3720 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3721 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3722 | int res; |
| 3723 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3724 | vdbg_printk(TPACPI_DBG_INIT, |
| 3725 | "initializing cmos commands subdriver\n"); |
| 3726 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3727 | TPACPI_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3728 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3729 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 3730 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3731 | |
| 3732 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 3733 | if (res) |
| 3734 | return res; |
| 3735 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3736 | return (cmos_handle)? 0 : 1; |
| 3737 | } |
| 3738 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3739 | static void cmos_exit(void) |
| 3740 | { |
| 3741 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 3742 | } |
| 3743 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3744 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | { |
| 3746 | int len = 0; |
| 3747 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3748 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 3749 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | if (!cmos_handle) |
| 3751 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3752 | else { |
| 3753 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3754 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | return len; |
| 3758 | } |
| 3759 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3760 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | { |
| 3762 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 3763 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | |
| 3765 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3766 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 3767 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | /* cmos_cmd set */ |
| 3769 | } else |
| 3770 | return -EINVAL; |
| 3771 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 3772 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 3773 | if (res) |
| 3774 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | } |
| 3776 | |
| 3777 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3778 | } |
| 3779 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3780 | static struct ibm_struct cmos_driver_data = { |
| 3781 | .name = "cmos", |
| 3782 | .read = cmos_read, |
| 3783 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame] | 3784 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3785 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3786 | |
| 3787 | /************************************************************************* |
| 3788 | * LED subdriver |
| 3789 | */ |
| 3790 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 3791 | enum led_access_mode { |
| 3792 | TPACPI_LED_NONE = 0, |
| 3793 | TPACPI_LED_570, /* 570 */ |
| 3794 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 3795 | TPACPI_LED_NEW, /* all others */ |
| 3796 | }; |
| 3797 | |
| 3798 | enum { /* For TPACPI_LED_OLD */ |
| 3799 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ |
| 3800 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ |
| 3801 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ |
| 3802 | }; |
| 3803 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3804 | enum led_status_t { |
| 3805 | TPACPI_LED_OFF = 0, |
| 3806 | TPACPI_LED_ON, |
| 3807 | TPACPI_LED_BLINK, |
| 3808 | }; |
| 3809 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 3810 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3811 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3812 | TPACPI_HANDLE(led, ec, "SLED", /* 570 */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 3813 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */ |
| 3814 | /* T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3815 | "LED", /* all others */ |
| 3816 | ); /* R30, R31 */ |
| 3817 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3818 | #define TPACPI_LED_NUMLEDS 8 |
| 3819 | static struct tpacpi_led_classdev *tpacpi_leds; |
| 3820 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; |
| 3821 | static const char const *tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
| 3822 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
| 3823 | "tpacpi::power", |
| 3824 | "tpacpi:orange:batt", |
| 3825 | "tpacpi:green:batt", |
| 3826 | "tpacpi::dock_active", |
| 3827 | "tpacpi::bay_active", |
| 3828 | "tpacpi::dock_batt", |
| 3829 | "tpacpi::unknown_led", |
| 3830 | "tpacpi::standby", |
| 3831 | }; |
| 3832 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3833 | static int led_get_status(unsigned int led) |
| 3834 | { |
| 3835 | int status; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3836 | enum led_status_t led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3837 | |
| 3838 | switch (led_supported) { |
| 3839 | case TPACPI_LED_570: |
| 3840 | if (!acpi_evalf(ec_handle, |
| 3841 | &status, "GLED", "dd", 1 << led)) |
| 3842 | return -EIO; |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3843 | led_s = (status == 0)? |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3844 | TPACPI_LED_OFF : |
| 3845 | ((status == 1)? |
| 3846 | TPACPI_LED_ON : |
| 3847 | TPACPI_LED_BLINK); |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3848 | tpacpi_led_state_cache[led] = led_s; |
| 3849 | return led_s; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3850 | default: |
| 3851 | return -ENXIO; |
| 3852 | } |
| 3853 | |
| 3854 | /* not reached */ |
| 3855 | } |
| 3856 | |
| 3857 | static int led_set_status(unsigned int led, enum led_status_t ledstatus) |
| 3858 | { |
| 3859 | /* off, on, blink. Index is led_status_t */ |
| 3860 | static const int const led_sled_arg1[] = { 0, 1, 3 }; |
| 3861 | static const int const led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */ |
| 3862 | static const int const led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */ |
| 3863 | static const int const led_led_arg1[] = { 0, 0x80, 0xc0 }; |
| 3864 | |
| 3865 | int rc = 0; |
| 3866 | |
| 3867 | switch (led_supported) { |
| 3868 | case TPACPI_LED_570: |
| 3869 | /* 570 */ |
| 3870 | led = 1 << led; |
| 3871 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 3872 | led, led_sled_arg1[ledstatus])) |
| 3873 | rc = -EIO; |
| 3874 | break; |
| 3875 | case TPACPI_LED_OLD: |
| 3876 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
| 3877 | led = 1 << led; |
| 3878 | rc = ec_write(TPACPI_LED_EC_HLMS, led); |
| 3879 | if (rc >= 0) |
| 3880 | rc = ec_write(TPACPI_LED_EC_HLBL, |
| 3881 | led * led_exp_hlbl[ledstatus]); |
| 3882 | if (rc >= 0) |
| 3883 | rc = ec_write(TPACPI_LED_EC_HLCL, |
Henrique de Moraes Holschuh | 10cc927 | 2008-04-26 01:02:27 -0300 | [diff] [blame^] | 3884 | led * led_exp_hlcl[ledstatus]); |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3885 | break; |
| 3886 | case TPACPI_LED_NEW: |
| 3887 | /* all others */ |
| 3888 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 3889 | led, led_led_arg1[ledstatus])) |
| 3890 | rc = -EIO; |
| 3891 | break; |
| 3892 | default: |
| 3893 | rc = -ENXIO; |
| 3894 | } |
| 3895 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3896 | if (!rc) |
| 3897 | tpacpi_led_state_cache[led] = ledstatus; |
| 3898 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 3899 | return rc; |
| 3900 | } |
| 3901 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3902 | static void led_sysfs_set_status(unsigned int led, |
| 3903 | enum led_brightness brightness) |
| 3904 | { |
| 3905 | led_set_status(led, |
| 3906 | (brightness == LED_OFF) ? |
| 3907 | TPACPI_LED_OFF : |
| 3908 | (tpacpi_led_state_cache[led] == TPACPI_LED_BLINK) ? |
| 3909 | TPACPI_LED_BLINK : TPACPI_LED_ON); |
| 3910 | } |
| 3911 | |
| 3912 | static void led_set_status_worker(struct work_struct *work) |
| 3913 | { |
| 3914 | struct tpacpi_led_classdev *data = |
| 3915 | container_of(work, struct tpacpi_led_classdev, work); |
| 3916 | |
| 3917 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) |
| 3918 | led_sysfs_set_status(data->led, data->new_brightness); |
| 3919 | } |
| 3920 | |
| 3921 | static void led_sysfs_set(struct led_classdev *led_cdev, |
| 3922 | enum led_brightness brightness) |
| 3923 | { |
| 3924 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 3925 | struct tpacpi_led_classdev, led_classdev); |
| 3926 | |
| 3927 | data->new_brightness = brightness; |
| 3928 | schedule_work(&data->work); |
| 3929 | } |
| 3930 | |
| 3931 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, |
| 3932 | unsigned long *delay_on, unsigned long *delay_off) |
| 3933 | { |
| 3934 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 3935 | struct tpacpi_led_classdev, led_classdev); |
| 3936 | |
| 3937 | /* Can we choose the flash rate? */ |
| 3938 | if (*delay_on == 0 && *delay_off == 0) { |
| 3939 | /* yes. set them to the hardware blink rate (1 Hz) */ |
| 3940 | *delay_on = 500; /* ms */ |
| 3941 | *delay_off = 500; /* ms */ |
| 3942 | } else if ((*delay_on != 500) || (*delay_off != 500)) |
| 3943 | return -EINVAL; |
| 3944 | |
| 3945 | data->new_brightness = TPACPI_LED_BLINK; |
| 3946 | schedule_work(&data->work); |
| 3947 | |
| 3948 | return 0; |
| 3949 | } |
| 3950 | |
| 3951 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) |
| 3952 | { |
| 3953 | int rc; |
| 3954 | |
| 3955 | struct tpacpi_led_classdev *data = container_of(led_cdev, |
| 3956 | struct tpacpi_led_classdev, led_classdev); |
| 3957 | |
| 3958 | rc = led_get_status(data->led); |
| 3959 | |
| 3960 | if (rc == TPACPI_LED_OFF || rc < 0) |
| 3961 | rc = LED_OFF; /* no error handling in led class :( */ |
| 3962 | else |
| 3963 | rc = LED_FULL; |
| 3964 | |
| 3965 | return rc; |
| 3966 | } |
| 3967 | |
| 3968 | static void led_exit(void) |
| 3969 | { |
| 3970 | unsigned int i; |
| 3971 | |
| 3972 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 3973 | if (tpacpi_leds[i].led_classdev.name) |
| 3974 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); |
| 3975 | } |
| 3976 | |
| 3977 | kfree(tpacpi_leds); |
| 3978 | tpacpi_leds = NULL; |
| 3979 | } |
| 3980 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3981 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3982 | { |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 3983 | unsigned int i; |
| 3984 | int rc; |
| 3985 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3986 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 3987 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 3988 | TPACPI_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3989 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3990 | if (!led_handle) |
| 3991 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3992 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3993 | else if (strlencmp(led_path, "SLED") == 0) |
| 3994 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3995 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3996 | else if (strlencmp(led_path, "SYSL") == 0) |
| 3997 | /* 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] | 3998 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3999 | else |
| 4000 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4001 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4002 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4003 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 4004 | str_supported(led_supported), led_supported); |
| 4005 | |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4006 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
| 4007 | GFP_KERNEL); |
| 4008 | if (!tpacpi_leds) { |
| 4009 | printk(TPACPI_ERR "Out of memory for LED data\n"); |
| 4010 | return -ENOMEM; |
| 4011 | } |
| 4012 | |
| 4013 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
| 4014 | tpacpi_leds[i].led = i; |
| 4015 | |
| 4016 | tpacpi_leds[i].led_classdev.brightness_set = &led_sysfs_set; |
| 4017 | tpacpi_leds[i].led_classdev.blink_set = &led_sysfs_blink_set; |
| 4018 | if (led_supported == TPACPI_LED_570) |
| 4019 | tpacpi_leds[i].led_classdev.brightness_get = |
| 4020 | &led_sysfs_get; |
| 4021 | |
| 4022 | tpacpi_leds[i].led_classdev.name = tpacpi_led_names[i]; |
| 4023 | |
| 4024 | INIT_WORK(&tpacpi_leds[i].work, led_set_status_worker); |
| 4025 | |
| 4026 | rc = led_classdev_register(&tpacpi_pdev->dev, |
| 4027 | &tpacpi_leds[i].led_classdev); |
| 4028 | if (rc < 0) { |
| 4029 | tpacpi_leds[i].led_classdev.name = NULL; |
| 4030 | led_exit(); |
| 4031 | return rc; |
| 4032 | } |
| 4033 | } |
| 4034 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4035 | return (led_supported != TPACPI_LED_NONE)? 0 : 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4036 | } |
| 4037 | |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4038 | #define str_led_status(s) \ |
| 4039 | ((s) == TPACPI_LED_OFF ? "off" : \ |
| 4040 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4041 | |
| 4042 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | { |
| 4044 | int len = 0; |
| 4045 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4046 | if (!led_supported) { |
| 4047 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4048 | return len; |
| 4049 | } |
| 4050 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 4051 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4052 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4053 | /* 570 */ |
| 4054 | int i, status; |
| 4055 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4056 | status = led_get_status(i); |
| 4057 | if (status < 0) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4058 | return -EIO; |
| 4059 | len += sprintf(p + len, "%d:\t\t%s\n", |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4060 | i, str_led_status(status)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4061 | } |
| 4062 | } |
| 4063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | len += sprintf(p + len, "commands:\t" |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4065 | "<led> on, <led> off, <led> blink (<led> is 0-7)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | |
| 4067 | return len; |
| 4068 | } |
| 4069 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4070 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | { |
| 4072 | char *cmd; |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4073 | int led, rc; |
| 4074 | enum led_status_t s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4075 | |
| 4076 | if (!led_supported) |
| 4077 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | |
| 4079 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4080 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | return -EINVAL; |
| 4082 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4083 | if (strstr(cmd, "off")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4084 | s = TPACPI_LED_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | } else if (strstr(cmd, "on")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4086 | s = TPACPI_LED_ON; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4087 | } else if (strstr(cmd, "blink")) { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4088 | s = TPACPI_LED_BLINK; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4089 | } else { |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4090 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4091 | } |
Henrique de Moraes Holschuh | 4fa6811 | 2008-04-26 01:02:23 -0300 | [diff] [blame] | 4092 | |
| 4093 | rc = led_set_status(led, s); |
| 4094 | if (rc < 0) |
| 4095 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4099 | } |
| 4100 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4101 | static struct ibm_struct led_driver_data = { |
| 4102 | .name = "led", |
| 4103 | .read = led_read, |
| 4104 | .write = led_write, |
Henrique de Moraes Holschuh | af11610 | 2008-04-26 01:02:25 -0300 | [diff] [blame] | 4105 | .exit = led_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4106 | }; |
| 4107 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4108 | /************************************************************************* |
| 4109 | * Beep subdriver |
| 4110 | */ |
| 4111 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4112 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4113 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4114 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4115 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4116 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 4117 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4118 | TPACPI_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4119 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4120 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 4121 | str_supported(beep_handle != NULL)); |
| 4122 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4123 | return (beep_handle)? 0 : 1; |
| 4124 | } |
| 4125 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4126 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | { |
| 4128 | int len = 0; |
| 4129 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4130 | if (!beep_handle) |
| 4131 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 4132 | else { |
| 4133 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 4134 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 4135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | |
| 4137 | return len; |
| 4138 | } |
| 4139 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4140 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | { |
| 4142 | char *cmd; |
| 4143 | int beep_cmd; |
| 4144 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4145 | if (!beep_handle) |
| 4146 | return -ENODEV; |
| 4147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4149 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 4150 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | /* beep_cmd set */ |
| 4152 | } else |
| 4153 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4154 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | return -EIO; |
| 4156 | } |
| 4157 | |
| 4158 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4159 | } |
| 4160 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4161 | static struct ibm_struct beep_driver_data = { |
| 4162 | .name = "beep", |
| 4163 | .read = beep_read, |
| 4164 | .write = beep_write, |
| 4165 | }; |
| 4166 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4167 | /************************************************************************* |
| 4168 | * Thermal subdriver |
| 4169 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4170 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4171 | enum thermal_access_mode { |
| 4172 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ |
| 4173 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ |
| 4174 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ |
| 4175 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ |
| 4176 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ |
| 4177 | }; |
| 4178 | |
| 4179 | enum { /* TPACPI_THERMAL_TPEC_* */ |
| 4180 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ |
| 4181 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ |
| 4182 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ |
| 4183 | }; |
| 4184 | |
| 4185 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
| 4186 | struct ibm_thermal_sensors_struct { |
| 4187 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; |
| 4188 | }; |
| 4189 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4190 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4191 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4192 | /* idx is zero-based */ |
| 4193 | static int thermal_get_sensor(int idx, s32 *value) |
| 4194 | { |
| 4195 | int t; |
| 4196 | s8 tmp; |
| 4197 | char tmpi[5]; |
| 4198 | |
| 4199 | t = TP_EC_THERMAL_TMP0; |
| 4200 | |
| 4201 | switch (thermal_read_mode) { |
| 4202 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 4203 | case TPACPI_THERMAL_TPEC_16: |
| 4204 | if (idx >= 8 && idx <= 15) { |
| 4205 | t = TP_EC_THERMAL_TMP8; |
| 4206 | idx -= 8; |
| 4207 | } |
| 4208 | /* fallthrough */ |
| 4209 | #endif |
| 4210 | case TPACPI_THERMAL_TPEC_8: |
| 4211 | if (idx <= 7) { |
| 4212 | if (!acpi_ec_read(t + idx, &tmp)) |
| 4213 | return -EIO; |
| 4214 | *value = tmp * 1000; |
| 4215 | return 0; |
| 4216 | } |
| 4217 | break; |
| 4218 | |
| 4219 | case TPACPI_THERMAL_ACPI_UPDT: |
| 4220 | if (idx <= 7) { |
| 4221 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 4222 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 4223 | return -EIO; |
| 4224 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 4225 | return -EIO; |
| 4226 | *value = (t - 2732) * 100; |
| 4227 | return 0; |
| 4228 | } |
| 4229 | break; |
| 4230 | |
| 4231 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4232 | if (idx <= 7) { |
| 4233 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 4234 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 4235 | return -EIO; |
| 4236 | if (t > 127 || t < -127) |
| 4237 | t = TP_EC_THERMAL_TMP_NA; |
| 4238 | *value = t * 1000; |
| 4239 | return 0; |
| 4240 | } |
| 4241 | break; |
| 4242 | |
| 4243 | case TPACPI_THERMAL_NONE: |
| 4244 | default: |
| 4245 | return -ENOSYS; |
| 4246 | } |
| 4247 | |
| 4248 | return -EINVAL; |
| 4249 | } |
| 4250 | |
| 4251 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 4252 | { |
| 4253 | int res, i; |
| 4254 | int n; |
| 4255 | |
| 4256 | n = 8; |
| 4257 | i = 0; |
| 4258 | |
| 4259 | if (!s) |
| 4260 | return -EINVAL; |
| 4261 | |
| 4262 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 4263 | n = 16; |
| 4264 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4265 | for (i = 0 ; i < n; i++) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4266 | res = thermal_get_sensor(i, &s->temp[i]); |
| 4267 | if (res) |
| 4268 | return res; |
| 4269 | } |
| 4270 | |
| 4271 | return n; |
| 4272 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4273 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4274 | /* sysfs temp##_input -------------------------------------------------- */ |
| 4275 | |
| 4276 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 4277 | struct device_attribute *attr, |
| 4278 | char *buf) |
| 4279 | { |
| 4280 | struct sensor_device_attribute *sensor_attr = |
| 4281 | to_sensor_dev_attr(attr); |
| 4282 | int idx = sensor_attr->index; |
| 4283 | s32 value; |
| 4284 | int res; |
| 4285 | |
| 4286 | res = thermal_get_sensor(idx, &value); |
| 4287 | if (res) |
| 4288 | return res; |
| 4289 | if (value == TP_EC_THERMAL_TMP_NA * 1000) |
| 4290 | return -ENXIO; |
| 4291 | |
| 4292 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 4293 | } |
| 4294 | |
| 4295 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4296 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
| 4297 | thermal_temp_input_show, NULL, _idxB) |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4298 | |
| 4299 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 4300 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 4301 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 4302 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 4303 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 4304 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 4305 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 4306 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 4307 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 4308 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 4309 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 4310 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 4311 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 4312 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 4313 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 4314 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 4315 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 4316 | }; |
| 4317 | |
| 4318 | #define THERMAL_ATTRS(X) \ |
| 4319 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 4320 | |
| 4321 | static struct attribute *thermal_temp_input_attr[] = { |
| 4322 | THERMAL_ATTRS(8), |
| 4323 | THERMAL_ATTRS(9), |
| 4324 | THERMAL_ATTRS(10), |
| 4325 | THERMAL_ATTRS(11), |
| 4326 | THERMAL_ATTRS(12), |
| 4327 | THERMAL_ATTRS(13), |
| 4328 | THERMAL_ATTRS(14), |
| 4329 | THERMAL_ATTRS(15), |
| 4330 | THERMAL_ATTRS(0), |
| 4331 | THERMAL_ATTRS(1), |
| 4332 | THERMAL_ATTRS(2), |
| 4333 | THERMAL_ATTRS(3), |
| 4334 | THERMAL_ATTRS(4), |
| 4335 | THERMAL_ATTRS(5), |
| 4336 | THERMAL_ATTRS(6), |
| 4337 | THERMAL_ATTRS(7), |
| 4338 | NULL |
| 4339 | }; |
| 4340 | |
| 4341 | static const struct attribute_group thermal_temp_input16_group = { |
| 4342 | .attrs = thermal_temp_input_attr |
| 4343 | }; |
| 4344 | |
| 4345 | static const struct attribute_group thermal_temp_input8_group = { |
| 4346 | .attrs = &thermal_temp_input_attr[8] |
| 4347 | }; |
| 4348 | |
| 4349 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 4350 | #undef THERMAL_ATTRS |
| 4351 | |
| 4352 | /* --------------------------------------------------------------------- */ |
| 4353 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4354 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4355 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4356 | u8 t, ta1, ta2; |
| 4357 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4358 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4359 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4360 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4361 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 4362 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 4363 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4364 | |
Henrique de Moraes Holschuh | 3d6f99c | 2007-07-18 23:45:46 -0300 | [diff] [blame] | 4365 | if (thinkpad_id.ec_model) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4366 | /* |
| 4367 | * Direct EC access mode: sensors at registers |
| 4368 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 4369 | * non-implemented, thermal sensors return 0x80 when |
| 4370 | * not available |
| 4371 | */ |
| 4372 | |
| 4373 | ta1 = ta2 = 0; |
| 4374 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4375 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4376 | ta1 |= t; |
| 4377 | } else { |
| 4378 | ta1 = 0; |
| 4379 | break; |
| 4380 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 4381 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4382 | ta2 |= t; |
| 4383 | } else { |
| 4384 | ta1 = 0; |
| 4385 | break; |
| 4386 | } |
| 4387 | } |
| 4388 | if (ta1 == 0) { |
| 4389 | /* This is sheer paranoia, but we handle it anyway */ |
| 4390 | if (acpi_tmp7) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4391 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4392 | "ThinkPad ACPI EC access misbehaving, " |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4393 | "falling back to ACPI TMPx access " |
| 4394 | "mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4395 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4396 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4397 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4398 | "ThinkPad ACPI EC access misbehaving, " |
| 4399 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4400 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4401 | } |
| 4402 | } else { |
| 4403 | thermal_read_mode = |
| 4404 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4405 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4406 | } |
| 4407 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4408 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 4409 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4410 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4411 | } else { |
| 4412 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4413 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4414 | } |
| 4415 | } else { |
| 4416 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4417 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4418 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4419 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4420 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 4421 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 4422 | thermal_read_mode); |
| 4423 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4424 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4425 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4426 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4427 | &thermal_temp_input16_group); |
| 4428 | if (res) |
| 4429 | return res; |
| 4430 | break; |
| 4431 | case TPACPI_THERMAL_TPEC_8: |
| 4432 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4433 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4434 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4435 | &thermal_temp_input8_group); |
| 4436 | if (res) |
| 4437 | return res; |
| 4438 | break; |
| 4439 | case TPACPI_THERMAL_NONE: |
| 4440 | default: |
| 4441 | return 1; |
| 4442 | } |
| 4443 | |
| 4444 | return 0; |
| 4445 | } |
| 4446 | |
| 4447 | static void thermal_exit(void) |
| 4448 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4449 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4450 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4451 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4452 | &thermal_temp_input16_group); |
| 4453 | break; |
| 4454 | case TPACPI_THERMAL_TPEC_8: |
| 4455 | case TPACPI_THERMAL_ACPI_TMP07: |
| 4456 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 4457 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4458 | &thermal_temp_input16_group); |
| 4459 | break; |
| 4460 | case TPACPI_THERMAL_NONE: |
| 4461 | default: |
| 4462 | break; |
| 4463 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | static int thermal_read(char *p) |
| 4467 | { |
| 4468 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4469 | int n, i; |
| 4470 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4471 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4472 | n = thermal_get_sensors(&t); |
| 4473 | if (unlikely(n < 0)) |
| 4474 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4475 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4476 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4477 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 4478 | if (n > 0) { |
| 4479 | for (i = 0; i < (n - 1); i++) |
| 4480 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 4481 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 4482 | } else |
| 4483 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4484 | |
| 4485 | return len; |
| 4486 | } |
| 4487 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4488 | static struct ibm_struct thermal_driver_data = { |
| 4489 | .name = "thermal", |
| 4490 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 4491 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4492 | }; |
| 4493 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4494 | /************************************************************************* |
| 4495 | * EC Dump subdriver |
| 4496 | */ |
| 4497 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4498 | static u8 ecdump_regs[256]; |
| 4499 | |
| 4500 | static int ecdump_read(char *p) |
| 4501 | { |
| 4502 | int len = 0; |
| 4503 | int i, j; |
| 4504 | u8 v; |
| 4505 | |
| 4506 | len += sprintf(p + len, "EC " |
| 4507 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 4508 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 4509 | for (i = 0; i < 256; i += 16) { |
| 4510 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 4511 | for (j = 0; j < 16; j++) { |
| 4512 | if (!acpi_ec_read(i + j, &v)) |
| 4513 | break; |
| 4514 | if (v != ecdump_regs[i + j]) |
| 4515 | len += sprintf(p + len, " *%02x", v); |
| 4516 | else |
| 4517 | len += sprintf(p + len, " %02x", v); |
| 4518 | ecdump_regs[i + j] = v; |
| 4519 | } |
| 4520 | len += sprintf(p + len, "\n"); |
| 4521 | if (j != 16) |
| 4522 | break; |
| 4523 | } |
| 4524 | |
| 4525 | /* These are way too dangerous to advertise openly... */ |
| 4526 | #if 0 |
| 4527 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 4528 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 4529 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 4530 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 4531 | #endif |
| 4532 | return len; |
| 4533 | } |
| 4534 | |
| 4535 | static int ecdump_write(char *buf) |
| 4536 | { |
| 4537 | char *cmd; |
| 4538 | int i, v; |
| 4539 | |
| 4540 | while ((cmd = next_cmd(&buf))) { |
| 4541 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 4542 | /* i and v set */ |
| 4543 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 4544 | /* i and v set */ |
| 4545 | } else |
| 4546 | return -EINVAL; |
| 4547 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 4548 | if (!acpi_ec_write(i, v)) |
| 4549 | return -EIO; |
| 4550 | } else |
| 4551 | return -EINVAL; |
| 4552 | } |
| 4553 | |
| 4554 | return 0; |
| 4555 | } |
| 4556 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4557 | static struct ibm_struct ecdump_driver_data = { |
| 4558 | .name = "ecdump", |
| 4559 | .read = ecdump_read, |
| 4560 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 4561 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4562 | }; |
| 4563 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4564 | /************************************************************************* |
| 4565 | * Backlight/brightness subdriver |
| 4566 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 4567 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4568 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
| 4569 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4570 | enum { |
| 4571 | TP_EC_BACKLIGHT = 0x31, |
| 4572 | |
| 4573 | /* TP_EC_BACKLIGHT bitmasks */ |
| 4574 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, |
| 4575 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, |
| 4576 | TP_EC_BACKLIGHT_MAPSW = 0x20, |
| 4577 | }; |
| 4578 | |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 4579 | static struct backlight_device *ibm_backlight_device; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4580 | static int brightness_mode; |
| 4581 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
| 4582 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4583 | static struct mutex brightness_mutex; |
| 4584 | |
| 4585 | /* |
| 4586 | * ThinkPads can read brightness from two places: EC 0x31, or |
| 4587 | * CMOS NVRAM byte 0x5E, bits 0-3. |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4588 | * |
| 4589 | * EC 0x31 has the following layout |
| 4590 | * Bit 7: unknown function |
| 4591 | * Bit 6: unknown function |
| 4592 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes |
| 4593 | * Bit 4: must be set to zero to avoid problems |
| 4594 | * Bit 3-0: backlight brightness level |
| 4595 | * |
| 4596 | * brightness_get_raw returns status data in the EC 0x31 layout |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4597 | */ |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4598 | static int brightness_get_raw(int *status) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4599 | { |
| 4600 | u8 lec = 0, lcmos = 0, level = 0; |
| 4601 | |
| 4602 | if (brightness_mode & 1) { |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4603 | if (!acpi_ec_read(TP_EC_BACKLIGHT, &lec)) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4604 | return -EIO; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4605 | level = lec & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4606 | }; |
| 4607 | if (brightness_mode & 2) { |
| 4608 | lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
| 4609 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) |
| 4610 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; |
| 4611 | lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07; |
| 4612 | level = lcmos; |
| 4613 | } |
| 4614 | |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 4615 | if (brightness_mode == 3) { |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4616 | *status = lec; /* Prefer EC, CMOS is just a backing store */ |
| 4617 | lec &= TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | 2d5e94d | 2008-04-26 01:02:20 -0300 | [diff] [blame] | 4618 | if (lec == lcmos) |
| 4619 | tp_warned.bright_cmos_ec_unsync = 0; |
| 4620 | else { |
| 4621 | if (!tp_warned.bright_cmos_ec_unsync) { |
| 4622 | printk(TPACPI_ERR |
| 4623 | "CMOS NVRAM (%u) and EC (%u) do not " |
| 4624 | "agree on display brightness level\n", |
| 4625 | (unsigned int) lcmos, |
| 4626 | (unsigned int) lec); |
| 4627 | tp_warned.bright_cmos_ec_unsync = 1; |
| 4628 | } |
| 4629 | return -EIO; |
| 4630 | } |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4631 | } else { |
| 4632 | *status = level; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4633 | } |
| 4634 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4635 | return 0; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | /* May return EINTR which can always be mapped to ERESTARTSYS */ |
| 4639 | static int brightness_set(int value) |
| 4640 | { |
| 4641 | int cmos_cmd, inc, i, res; |
| 4642 | int current_value; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4643 | int command_bits; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4644 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4645 | if (value > ((tp_features.bright_16levels)? 15 : 7) || |
| 4646 | value < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4647 | return -EINVAL; |
| 4648 | |
| 4649 | res = mutex_lock_interruptible(&brightness_mutex); |
| 4650 | if (res < 0) |
| 4651 | return res; |
| 4652 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4653 | res = brightness_get_raw(¤t_value); |
| 4654 | if (res < 0) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4655 | goto errout; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4656 | |
| 4657 | command_bits = current_value & TP_EC_BACKLIGHT_CMDMSK; |
| 4658 | current_value &= TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4659 | |
| 4660 | cmos_cmd = value > current_value ? |
| 4661 | TP_CMOS_BRIGHTNESS_UP : |
| 4662 | TP_CMOS_BRIGHTNESS_DOWN; |
| 4663 | inc = (value > current_value)? 1 : -1; |
| 4664 | |
| 4665 | res = 0; |
| 4666 | for (i = current_value; i != value; i += inc) { |
| 4667 | if ((brightness_mode & 2) && |
| 4668 | issue_thinkpad_cmos_command(cmos_cmd)) { |
| 4669 | res = -EIO; |
| 4670 | goto errout; |
| 4671 | } |
| 4672 | if ((brightness_mode & 1) && |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4673 | !acpi_ec_write(TP_EC_BACKLIGHT, |
| 4674 | (i + inc) | command_bits)) { |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4675 | res = -EIO; |
| 4676 | goto errout;; |
| 4677 | } |
| 4678 | } |
| 4679 | |
| 4680 | errout: |
| 4681 | mutex_unlock(&brightness_mutex); |
| 4682 | return res; |
| 4683 | } |
| 4684 | |
| 4685 | /* sysfs backlight class ----------------------------------------------- */ |
| 4686 | |
| 4687 | static int brightness_update_status(struct backlight_device *bd) |
| 4688 | { |
| 4689 | /* it is the backlight class's job (caller) to handle |
| 4690 | * EINTR and other errors properly */ |
| 4691 | return brightness_set( |
| 4692 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 4693 | bd->props.power == FB_BLANK_UNBLANK) ? |
| 4694 | bd->props.brightness : 0); |
| 4695 | } |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 4696 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4697 | static int brightness_get(struct backlight_device *bd) |
| 4698 | { |
| 4699 | int status, res; |
| 4700 | |
| 4701 | res = brightness_get_raw(&status); |
| 4702 | if (res < 0) |
| 4703 | return 0; /* FIXME: teach backlight about error handling */ |
| 4704 | |
| 4705 | return status & TP_EC_BACKLIGHT_LVLMSK; |
| 4706 | } |
| 4707 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 4708 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4709 | .get_brightness = brightness_get, |
| 4710 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4711 | }; |
| 4712 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 4713 | /* --------------------------------------------------------------------- */ |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4714 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4715 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4716 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4717 | int b; |
| 4718 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4719 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 4720 | |
Henrique de Moraes Holschuh | f432255 | 2007-07-18 23:45:48 -0300 | [diff] [blame] | 4721 | mutex_init(&brightness_mutex); |
| 4722 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 4723 | /* |
| 4724 | * We always attempt to detect acpi support, so as to switch |
| 4725 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not |
| 4726 | * going to publish a backlight interface |
| 4727 | */ |
| 4728 | b = tpacpi_check_std_acpi_brightness_support(); |
| 4729 | if (b > 0) { |
| 4730 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { |
| 4731 | printk(TPACPI_NOTICE |
| 4732 | "Lenovo BIOS switched to ACPI backlight " |
| 4733 | "control mode\n"); |
| 4734 | } |
| 4735 | if (brightness_enable > 1) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4736 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4737 | "standard ACPI backlight interface " |
| 4738 | "available, not loading native one...\n"); |
Henrique de Moraes Holschuh | e11e211 | 2007-10-30 17:46:22 -0200 | [diff] [blame] | 4739 | return 1; |
| 4740 | } |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 4741 | } |
| 4742 | |
Henrique de Moraes Holschuh | b597279 | 2008-04-26 01:02:17 -0300 | [diff] [blame] | 4743 | if (!brightness_enable) { |
| 4744 | dbg_printk(TPACPI_DBG_INIT, |
| 4745 | "brightness support disabled by " |
| 4746 | "module parameter\n"); |
| 4747 | return 1; |
| 4748 | } |
| 4749 | |
| 4750 | if (b > 16) { |
| 4751 | printk(TPACPI_ERR |
| 4752 | "Unsupported brightness interface, " |
| 4753 | "please contact %s\n", TPACPI_MAIL); |
| 4754 | return 1; |
| 4755 | } |
| 4756 | if (b == 16) |
| 4757 | tp_features.bright_16levels = 1; |
| 4758 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4759 | if (!brightness_mode) { |
| 4760 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) |
| 4761 | brightness_mode = 2; |
| 4762 | else |
| 4763 | brightness_mode = 3; |
| 4764 | |
| 4765 | dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n", |
| 4766 | brightness_mode); |
| 4767 | } |
| 4768 | |
| 4769 | if (brightness_mode > 3) |
| 4770 | return -EINVAL; |
| 4771 | |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4772 | if (brightness_get_raw(&b) < 0) |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 4773 | return 1; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4774 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4775 | if (tp_features.bright_16levels) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4776 | printk(TPACPI_INFO |
| 4777 | "detected a 16-level brightness capable ThinkPad\n"); |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4778 | |
Henrique de Moraes Holschuh | 7d5a015 | 2007-04-24 11:48:20 -0300 | [diff] [blame] | 4779 | ibm_backlight_device = backlight_device_register( |
| 4780 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
| 4781 | &ibm_backlight_data); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4782 | if (IS_ERR(ibm_backlight_device)) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 4783 | printk(TPACPI_ERR "Could not register backlight device\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4784 | return PTR_ERR(ibm_backlight_device); |
| 4785 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4786 | vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4787 | |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4788 | ibm_backlight_device->props.max_brightness = |
| 4789 | (tp_features.bright_16levels)? 15 : 7; |
Henrique de Moraes Holschuh | e11aecf | 2008-04-26 01:02:21 -0300 | [diff] [blame] | 4790 | ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 4791 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 4792 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4793 | return 0; |
| 4794 | } |
| 4795 | |
| 4796 | static void brightness_exit(void) |
| 4797 | { |
| 4798 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 4799 | vdbg_printk(TPACPI_DBG_EXIT, |
| 4800 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 4801 | backlight_device_unregister(ibm_backlight_device); |
| 4802 | ibm_backlight_device = NULL; |
| 4803 | } |
| 4804 | } |
| 4805 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4806 | static int brightness_read(char *p) |
| 4807 | { |
| 4808 | int len = 0; |
| 4809 | int level; |
| 4810 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4811 | level = brightness_get(NULL); |
| 4812 | if (level < 0) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4813 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 4814 | } else { |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4815 | len += sprintf(p + len, "level:\t\t%d\n", level); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4816 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 4817 | len += sprintf(p + len, "commands:\tlevel <level>" |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4818 | " (<level> is 0-%d)\n", |
| 4819 | (tp_features.bright_16levels) ? 15 : 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4820 | } |
| 4821 | |
| 4822 | return len; |
| 4823 | } |
| 4824 | |
| 4825 | static int brightness_write(char *buf) |
| 4826 | { |
| 4827 | int level; |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4828 | int rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4829 | char *cmd; |
Henrique de Moraes Holschuh | a3f104c | 2007-10-30 17:46:20 -0200 | [diff] [blame] | 4830 | int max_level = (tp_features.bright_16levels) ? 15 : 7; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4831 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4832 | level = brightness_get(NULL); |
| 4833 | if (level < 0) |
| 4834 | return level; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4835 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4836 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4837 | if (strlencmp(cmd, "up") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4838 | if (level < max_level) |
| 4839 | level++; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4840 | } else if (strlencmp(cmd, "down") == 0) { |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4841 | if (level > 0) |
| 4842 | level--; |
| 4843 | } else if (sscanf(cmd, "level %d", &level) == 1 && |
| 4844 | level >= 0 && level <= max_level) { |
| 4845 | /* new level set */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4846 | } else |
| 4847 | return -EINVAL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4848 | } |
| 4849 | |
Henrique de Moraes Holschuh | 4273af8 | 2007-10-30 17:46:25 -0200 | [diff] [blame] | 4850 | /* |
| 4851 | * Now we know what the final level should be, so we try to set it. |
| 4852 | * Doing it this way makes the syscall restartable in case of EINTR |
| 4853 | */ |
| 4854 | rc = brightness_set(level); |
| 4855 | return (rc == -EINTR)? ERESTARTSYS : rc; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4856 | } |
| 4857 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4858 | static struct ibm_struct brightness_driver_data = { |
| 4859 | .name = "brightness", |
| 4860 | .read = brightness_read, |
| 4861 | .write = brightness_write, |
| 4862 | .exit = brightness_exit, |
| 4863 | }; |
| 4864 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4865 | /************************************************************************* |
| 4866 | * Volume subdriver |
| 4867 | */ |
| 4868 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 4869 | static int volume_offset = 0x30; |
| 4870 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4871 | static int volume_read(char *p) |
| 4872 | { |
| 4873 | int len = 0; |
| 4874 | u8 level; |
| 4875 | |
| 4876 | if (!acpi_ec_read(volume_offset, &level)) { |
| 4877 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 4878 | } else { |
| 4879 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 4880 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 4881 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 4882 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 4883 | " (<level> is 0-15)\n"); |
| 4884 | } |
| 4885 | |
| 4886 | return len; |
| 4887 | } |
| 4888 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4889 | static int volume_write(char *buf) |
| 4890 | { |
| 4891 | int cmos_cmd, inc, i; |
| 4892 | u8 level, mute; |
| 4893 | int new_level, new_mute; |
| 4894 | char *cmd; |
| 4895 | |
| 4896 | while ((cmd = next_cmd(&buf))) { |
| 4897 | if (!acpi_ec_read(volume_offset, &level)) |
| 4898 | return -EIO; |
| 4899 | new_mute = mute = level & 0x40; |
| 4900 | new_level = level = level & 0xf; |
| 4901 | |
| 4902 | if (strlencmp(cmd, "up") == 0) { |
| 4903 | if (mute) |
| 4904 | new_mute = 0; |
| 4905 | else |
| 4906 | new_level = level == 15 ? 15 : level + 1; |
| 4907 | } else if (strlencmp(cmd, "down") == 0) { |
| 4908 | if (mute) |
| 4909 | new_mute = 0; |
| 4910 | else |
| 4911 | new_level = level == 0 ? 0 : level - 1; |
| 4912 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 4913 | new_level >= 0 && new_level <= 15) { |
| 4914 | /* new_level set */ |
| 4915 | } else if (strlencmp(cmd, "mute") == 0) { |
| 4916 | new_mute = 0x40; |
| 4917 | } else |
| 4918 | return -EINVAL; |
| 4919 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4920 | if (new_level != level) { |
| 4921 | /* mute doesn't change */ |
| 4922 | |
| 4923 | cmos_cmd = (new_level > level) ? |
| 4924 | TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4925 | inc = new_level > level ? 1 : -1; |
| 4926 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4927 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4928 | !acpi_ec_write(volume_offset, level))) |
| 4929 | return -EIO; |
| 4930 | |
| 4931 | for (i = level; i != new_level; i += inc) |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4932 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4933 | !acpi_ec_write(volume_offset, i + inc)) |
| 4934 | return -EIO; |
| 4935 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4936 | if (mute && |
| 4937 | (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
| 4938 | !acpi_ec_write(volume_offset, new_level + mute))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4939 | return -EIO; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4940 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4941 | } |
| 4942 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 4943 | if (new_mute != mute) { |
| 4944 | /* level doesn't change */ |
| 4945 | |
| 4946 | cmos_cmd = (new_mute) ? |
| 4947 | TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4948 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 4949 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 4950 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 4951 | return -EIO; |
| 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | return 0; |
| 4956 | } |
| 4957 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 4958 | static struct ibm_struct volume_driver_data = { |
| 4959 | .name = "volume", |
| 4960 | .read = volume_read, |
| 4961 | .write = volume_write, |
| 4962 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4963 | |
| 4964 | /************************************************************************* |
| 4965 | * Fan subdriver |
| 4966 | */ |
| 4967 | |
| 4968 | /* |
| 4969 | * FAN ACCESS MODES |
| 4970 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4971 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4972 | * ACPI GFAN method: returns fan level |
| 4973 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4974 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4975 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4976 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4977 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4978 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 4979 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4980 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 4981 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4982 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 4983 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4984 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 4985 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 4986 | * |
| 4987 | * Fan speed changes of any sort (including those caused by the |
| 4988 | * disengaged mode) are usually done slowly by the firmware as the |
| 4989 | * maximum ammount of fan duty cycle change per second seems to be |
| 4990 | * limited. |
| 4991 | * |
| 4992 | * Reading is not available if GFAN exists. |
| 4993 | * Writing is not available if SFAN exists. |
| 4994 | * |
| 4995 | * Bits |
| 4996 | * 7 automatic mode engaged; |
| 4997 | * (default operation mode of the ThinkPad) |
| 4998 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 4999 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5000 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 5001 | * the tachometer while the fan controller ramps up |
| 5002 | * the speed (which can take up to a few *minutes*). |
| 5003 | * Speeds up fan to 100% duty-cycle, which is far above |
| 5004 | * the standard RPM levels. It is not impossible that |
| 5005 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5006 | * 5-3 unused in some models. Extra bits for fan level |
| 5007 | * in others, but still useless as all values above |
| 5008 | * 7 map to the same speed as level 7 in these models. |
| 5009 | * 2-0 fan level (0..7 usually) |
| 5010 | * 0x00 = stop |
| 5011 | * 0x07 = max (set when temperatures critical) |
| 5012 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5013 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5014 | * |
| 5015 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 5016 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 5017 | * does so, its initial value is meaningless (0x07). |
| 5018 | * |
| 5019 | * For firmware bugs, refer to: |
| 5020 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 5021 | * |
| 5022 | * ---- |
| 5023 | * |
| 5024 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 5025 | * Main fan tachometer reading (in RPM) |
| 5026 | * |
| 5027 | * This register is present on all ThinkPads with a new-style EC, and |
| 5028 | * it is known not to be present on the A21m/e, and T22, as there is |
| 5029 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 5030 | * ThinkPads from this same time period (and earlier) probably lack the |
| 5031 | * tachometer as well. |
| 5032 | * |
| 5033 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare |
| 5034 | * was never fixed by IBM to report the EC firmware version string |
| 5035 | * probably support the tachometer (like the early X models), so |
| 5036 | * detecting it is quite hard. We need more data to know for sure. |
| 5037 | * |
| 5038 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 5039 | * might result. |
| 5040 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 5041 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 5042 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5043 | * |
| 5044 | * For firmware bugs, refer to: |
| 5045 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 5046 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5047 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5048 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 5049 | * |
| 5050 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 5051 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 5052 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 5053 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 5054 | * |
| 5055 | * The speeds are stored on handles |
| 5056 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 5057 | * |
| 5058 | * There are three default speed sets, acessible as handles: |
| 5059 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 5060 | * |
| 5061 | * ACPI DSDT switches which set is in use depending on various |
| 5062 | * factors. |
| 5063 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5064 | * 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] | 5065 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 5066 | * but the ACPI tables just mention level 7. |
| 5067 | */ |
| 5068 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5069 | enum { /* Fan control constants */ |
| 5070 | fan_status_offset = 0x2f, /* EC register 0x2f */ |
| 5071 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) |
| 5072 | * 0x84 must be read before 0x85 */ |
| 5073 | |
| 5074 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ |
| 5075 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ |
| 5076 | |
| 5077 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ |
| 5078 | }; |
| 5079 | |
| 5080 | enum fan_status_access_mode { |
| 5081 | TPACPI_FAN_NONE = 0, /* No fan status or control */ |
| 5082 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ |
| 5083 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ |
| 5084 | }; |
| 5085 | |
| 5086 | enum fan_control_access_mode { |
| 5087 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ |
| 5088 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ |
| 5089 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ |
| 5090 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ |
| 5091 | }; |
| 5092 | |
| 5093 | enum fan_control_commands { |
| 5094 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ |
| 5095 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ |
| 5096 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, |
| 5097 | * and also watchdog cmd */ |
| 5098 | }; |
| 5099 | |
| 5100 | static int fan_control_allowed; |
| 5101 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5102 | static enum fan_status_access_mode fan_status_access_mode; |
| 5103 | static enum fan_control_access_mode fan_control_access_mode; |
| 5104 | static enum fan_control_commands fan_control_commands; |
| 5105 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5106 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5107 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5108 | static int fan_watchdog_maxinterval; |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5109 | |
| 5110 | static struct mutex fan_mutex; |
| 5111 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 5112 | static void fan_watchdog_fire(struct work_struct *ignored); |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 5113 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5114 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5115 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 5116 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5117 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 5118 | ); /* all others */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5119 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5120 | "JFNS", /* 770x-JL */ |
| 5121 | ); /* all others */ |
| 5122 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5123 | /* |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5124 | * Call with fan_mutex held |
| 5125 | */ |
| 5126 | static void fan_update_desired_level(u8 status) |
| 5127 | { |
| 5128 | if ((status & |
| 5129 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 5130 | if (status > 7) |
| 5131 | fan_control_desired_level = 7; |
| 5132 | else |
| 5133 | fan_control_desired_level = status; |
| 5134 | } |
| 5135 | } |
| 5136 | |
| 5137 | static int fan_get_status(u8 *status) |
| 5138 | { |
| 5139 | u8 s; |
| 5140 | |
| 5141 | /* TODO: |
| 5142 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
| 5143 | |
| 5144 | switch (fan_status_access_mode) { |
| 5145 | case TPACPI_FAN_RD_ACPI_GFAN: |
| 5146 | /* 570, 600e/x, 770e, 770x */ |
| 5147 | |
| 5148 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
| 5149 | return -EIO; |
| 5150 | |
| 5151 | if (likely(status)) |
| 5152 | *status = s & 0x07; |
| 5153 | |
| 5154 | break; |
| 5155 | |
| 5156 | case TPACPI_FAN_RD_TPEC: |
| 5157 | /* all except 570, 600e/x, 770e, 770x */ |
| 5158 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 5159 | return -EIO; |
| 5160 | |
| 5161 | if (likely(status)) |
| 5162 | *status = s; |
| 5163 | |
| 5164 | break; |
| 5165 | |
| 5166 | default: |
| 5167 | return -ENXIO; |
| 5168 | } |
| 5169 | |
| 5170 | return 0; |
| 5171 | } |
| 5172 | |
| 5173 | static int fan_get_status_safe(u8 *status) |
| 5174 | { |
| 5175 | int rc; |
| 5176 | u8 s; |
| 5177 | |
| 5178 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5179 | return -ERESTARTSYS; |
| 5180 | rc = fan_get_status(&s); |
| 5181 | if (!rc) |
| 5182 | fan_update_desired_level(s); |
| 5183 | mutex_unlock(&fan_mutex); |
| 5184 | |
| 5185 | if (status) |
| 5186 | *status = s; |
| 5187 | |
| 5188 | return rc; |
| 5189 | } |
| 5190 | |
| 5191 | static int fan_get_speed(unsigned int *speed) |
| 5192 | { |
| 5193 | u8 hi, lo; |
| 5194 | |
| 5195 | switch (fan_status_access_mode) { |
| 5196 | case TPACPI_FAN_RD_TPEC: |
| 5197 | /* all except 570, 600e/x, 770e, 770x */ |
| 5198 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 5199 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 5200 | return -EIO; |
| 5201 | |
| 5202 | if (likely(speed)) |
| 5203 | *speed = (hi << 8) | lo; |
| 5204 | |
| 5205 | break; |
| 5206 | |
| 5207 | default: |
| 5208 | return -ENXIO; |
| 5209 | } |
| 5210 | |
| 5211 | return 0; |
| 5212 | } |
| 5213 | |
| 5214 | static int fan_set_level(int level) |
| 5215 | { |
| 5216 | if (!fan_control_allowed) |
| 5217 | return -EPERM; |
| 5218 | |
| 5219 | switch (fan_control_access_mode) { |
| 5220 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 5221 | if (level >= 0 && level <= 7) { |
| 5222 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 5223 | return -EIO; |
| 5224 | } else |
| 5225 | return -EINVAL; |
| 5226 | break; |
| 5227 | |
| 5228 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5229 | case TPACPI_FAN_WR_TPEC: |
| 5230 | if ((level != TP_EC_FAN_AUTO) && |
| 5231 | (level != TP_EC_FAN_FULLSPEED) && |
| 5232 | ((level < 0) || (level > 7))) |
| 5233 | return -EINVAL; |
| 5234 | |
| 5235 | /* safety net should the EC not support AUTO |
| 5236 | * or FULLSPEED mode bits and just ignore them */ |
| 5237 | if (level & TP_EC_FAN_FULLSPEED) |
| 5238 | level |= 7; /* safety min speed 7 */ |
Roel Kluin | 547266e | 2008-02-05 00:24:56 +0100 | [diff] [blame] | 5239 | else if (level & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5240 | level |= 4; /* safety min speed 4 */ |
| 5241 | |
| 5242 | if (!acpi_ec_write(fan_status_offset, level)) |
| 5243 | return -EIO; |
| 5244 | else |
| 5245 | tp_features.fan_ctrl_status_undef = 0; |
| 5246 | break; |
| 5247 | |
| 5248 | default: |
| 5249 | return -ENXIO; |
| 5250 | } |
| 5251 | return 0; |
| 5252 | } |
| 5253 | |
| 5254 | static int fan_set_level_safe(int level) |
| 5255 | { |
| 5256 | int rc; |
| 5257 | |
| 5258 | if (!fan_control_allowed) |
| 5259 | return -EPERM; |
| 5260 | |
| 5261 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5262 | return -ERESTARTSYS; |
| 5263 | |
| 5264 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 5265 | level = fan_control_desired_level; |
| 5266 | |
| 5267 | rc = fan_set_level(level); |
| 5268 | if (!rc) |
| 5269 | fan_update_desired_level(level); |
| 5270 | |
| 5271 | mutex_unlock(&fan_mutex); |
| 5272 | return rc; |
| 5273 | } |
| 5274 | |
| 5275 | static int fan_set_enable(void) |
| 5276 | { |
| 5277 | u8 s; |
| 5278 | int rc; |
| 5279 | |
| 5280 | if (!fan_control_allowed) |
| 5281 | return -EPERM; |
| 5282 | |
| 5283 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5284 | return -ERESTARTSYS; |
| 5285 | |
| 5286 | switch (fan_control_access_mode) { |
| 5287 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5288 | case TPACPI_FAN_WR_TPEC: |
| 5289 | rc = fan_get_status(&s); |
| 5290 | if (rc < 0) |
| 5291 | break; |
| 5292 | |
| 5293 | /* Don't go out of emergency fan mode */ |
| 5294 | if (s != 7) { |
| 5295 | s &= 0x07; |
| 5296 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 5297 | } |
| 5298 | |
| 5299 | if (!acpi_ec_write(fan_status_offset, s)) |
| 5300 | rc = -EIO; |
| 5301 | else { |
| 5302 | tp_features.fan_ctrl_status_undef = 0; |
| 5303 | rc = 0; |
| 5304 | } |
| 5305 | break; |
| 5306 | |
| 5307 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 5308 | rc = fan_get_status(&s); |
| 5309 | if (rc < 0) |
| 5310 | break; |
| 5311 | |
| 5312 | s &= 0x07; |
| 5313 | |
| 5314 | /* Set fan to at least level 4 */ |
| 5315 | s |= 4; |
| 5316 | |
| 5317 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5318 | rc = -EIO; |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5319 | else |
| 5320 | rc = 0; |
| 5321 | break; |
| 5322 | |
| 5323 | default: |
| 5324 | rc = -ENXIO; |
| 5325 | } |
| 5326 | |
| 5327 | mutex_unlock(&fan_mutex); |
| 5328 | return rc; |
| 5329 | } |
| 5330 | |
| 5331 | static int fan_set_disable(void) |
| 5332 | { |
| 5333 | int rc; |
| 5334 | |
| 5335 | if (!fan_control_allowed) |
| 5336 | return -EPERM; |
| 5337 | |
| 5338 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5339 | return -ERESTARTSYS; |
| 5340 | |
| 5341 | rc = 0; |
| 5342 | switch (fan_control_access_mode) { |
| 5343 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5344 | case TPACPI_FAN_WR_TPEC: |
| 5345 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 5346 | rc = -EIO; |
| 5347 | else { |
| 5348 | fan_control_desired_level = 0; |
| 5349 | tp_features.fan_ctrl_status_undef = 0; |
| 5350 | } |
| 5351 | break; |
| 5352 | |
| 5353 | case TPACPI_FAN_WR_ACPI_SFAN: |
| 5354 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 5355 | rc = -EIO; |
| 5356 | else |
| 5357 | fan_control_desired_level = 0; |
| 5358 | break; |
| 5359 | |
| 5360 | default: |
| 5361 | rc = -ENXIO; |
| 5362 | } |
| 5363 | |
| 5364 | |
| 5365 | mutex_unlock(&fan_mutex); |
| 5366 | return rc; |
| 5367 | } |
| 5368 | |
| 5369 | static int fan_set_speed(int speed) |
| 5370 | { |
| 5371 | int rc; |
| 5372 | |
| 5373 | if (!fan_control_allowed) |
| 5374 | return -EPERM; |
| 5375 | |
| 5376 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5377 | return -ERESTARTSYS; |
| 5378 | |
| 5379 | rc = 0; |
| 5380 | switch (fan_control_access_mode) { |
| 5381 | case TPACPI_FAN_WR_ACPI_FANS: |
| 5382 | if (speed >= 0 && speed <= 65535) { |
| 5383 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 5384 | speed, speed, speed)) |
| 5385 | rc = -EIO; |
| 5386 | } else |
| 5387 | rc = -EINVAL; |
| 5388 | break; |
| 5389 | |
| 5390 | default: |
| 5391 | rc = -ENXIO; |
| 5392 | } |
| 5393 | |
| 5394 | mutex_unlock(&fan_mutex); |
| 5395 | return rc; |
| 5396 | } |
| 5397 | |
| 5398 | static void fan_watchdog_reset(void) |
| 5399 | { |
| 5400 | static int fan_watchdog_active; |
| 5401 | |
| 5402 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
| 5403 | return; |
| 5404 | |
| 5405 | if (fan_watchdog_active) |
| 5406 | cancel_delayed_work(&fan_watchdog_task); |
| 5407 | |
| 5408 | if (fan_watchdog_maxinterval > 0 && |
| 5409 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { |
| 5410 | fan_watchdog_active = 1; |
| 5411 | if (!schedule_delayed_work(&fan_watchdog_task, |
| 5412 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 5413 | * 1000))) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5414 | printk(TPACPI_ERR |
| 5415 | "failed to schedule the fan watchdog, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5416 | "watchdog will not trigger\n"); |
| 5417 | } |
| 5418 | } else |
| 5419 | fan_watchdog_active = 0; |
| 5420 | } |
| 5421 | |
| 5422 | static void fan_watchdog_fire(struct work_struct *ignored) |
| 5423 | { |
| 5424 | int rc; |
| 5425 | |
| 5426 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
| 5427 | return; |
| 5428 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5429 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5430 | rc = fan_set_enable(); |
| 5431 | if (rc < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5432 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 5433 | "will try again later...\n", -rc); |
| 5434 | /* reschedule for later */ |
| 5435 | fan_watchdog_reset(); |
| 5436 | } |
| 5437 | } |
| 5438 | |
| 5439 | /* |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5440 | * SYSFS fan layout: hwmon compatible (device) |
| 5441 | * |
| 5442 | * pwm*_enable: |
| 5443 | * 0: "disengaged" mode |
| 5444 | * 1: manual mode |
| 5445 | * 2: native EC "auto" mode (recommended, hardware default) |
| 5446 | * |
| 5447 | * pwm*: set speed in manual mode, ignored otherwise. |
| 5448 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 5449 | * interpolation. |
| 5450 | * |
| 5451 | * fan*_input: tachometer reading, RPM |
| 5452 | * |
| 5453 | * |
| 5454 | * SYSFS fan layout: extensions |
| 5455 | * |
| 5456 | * fan_watchdog (driver): |
| 5457 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 5458 | */ |
| 5459 | |
| 5460 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 5461 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 5462 | struct device_attribute *attr, |
| 5463 | char *buf) |
| 5464 | { |
| 5465 | int res, mode; |
| 5466 | u8 status; |
| 5467 | |
| 5468 | res = fan_get_status_safe(&status); |
| 5469 | if (res) |
| 5470 | return res; |
| 5471 | |
| 5472 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 5473 | if (status != fan_control_initial_status) { |
| 5474 | tp_features.fan_ctrl_status_undef = 0; |
| 5475 | } else { |
| 5476 | /* Return most likely status. In fact, it |
| 5477 | * might be the only possible status */ |
| 5478 | status = TP_EC_FAN_AUTO; |
| 5479 | } |
| 5480 | } |
| 5481 | |
| 5482 | if (status & TP_EC_FAN_FULLSPEED) { |
| 5483 | mode = 0; |
| 5484 | } else if (status & TP_EC_FAN_AUTO) { |
| 5485 | mode = 2; |
| 5486 | } else |
| 5487 | mode = 1; |
| 5488 | |
| 5489 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 5490 | } |
| 5491 | |
| 5492 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 5493 | struct device_attribute *attr, |
| 5494 | const char *buf, size_t count) |
| 5495 | { |
| 5496 | unsigned long t; |
| 5497 | int res, level; |
| 5498 | |
| 5499 | if (parse_strtoul(buf, 2, &t)) |
| 5500 | return -EINVAL; |
| 5501 | |
| 5502 | switch (t) { |
| 5503 | case 0: |
| 5504 | level = TP_EC_FAN_FULLSPEED; |
| 5505 | break; |
| 5506 | case 1: |
| 5507 | level = TPACPI_FAN_LAST_LEVEL; |
| 5508 | break; |
| 5509 | case 2: |
| 5510 | level = TP_EC_FAN_AUTO; |
| 5511 | break; |
| 5512 | case 3: |
| 5513 | /* reserved for software-controlled auto mode */ |
| 5514 | return -ENOSYS; |
| 5515 | default: |
| 5516 | return -EINVAL; |
| 5517 | } |
| 5518 | |
| 5519 | res = fan_set_level_safe(level); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 5520 | if (res == -ENXIO) |
| 5521 | return -EINVAL; |
| 5522 | else if (res < 0) |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5523 | return res; |
| 5524 | |
| 5525 | fan_watchdog_reset(); |
| 5526 | |
| 5527 | return count; |
| 5528 | } |
| 5529 | |
| 5530 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 5531 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 5532 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 5533 | |
| 5534 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 5535 | static ssize_t fan_pwm1_show(struct device *dev, |
| 5536 | struct device_attribute *attr, |
| 5537 | char *buf) |
| 5538 | { |
| 5539 | int res; |
| 5540 | u8 status; |
| 5541 | |
| 5542 | res = fan_get_status_safe(&status); |
| 5543 | if (res) |
| 5544 | return res; |
| 5545 | |
| 5546 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 5547 | if (status != fan_control_initial_status) { |
| 5548 | tp_features.fan_ctrl_status_undef = 0; |
| 5549 | } else { |
| 5550 | status = TP_EC_FAN_AUTO; |
| 5551 | } |
| 5552 | } |
| 5553 | |
| 5554 | if ((status & |
| 5555 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 5556 | status = fan_control_desired_level; |
| 5557 | |
| 5558 | if (status > 7) |
| 5559 | status = 7; |
| 5560 | |
| 5561 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 5562 | } |
| 5563 | |
| 5564 | static ssize_t fan_pwm1_store(struct device *dev, |
| 5565 | struct device_attribute *attr, |
| 5566 | const char *buf, size_t count) |
| 5567 | { |
| 5568 | unsigned long s; |
| 5569 | int rc; |
| 5570 | u8 status, newlevel; |
| 5571 | |
| 5572 | if (parse_strtoul(buf, 255, &s)) |
| 5573 | return -EINVAL; |
| 5574 | |
| 5575 | /* scale down from 0-255 to 0-7 */ |
| 5576 | newlevel = (s >> 5) & 0x07; |
| 5577 | |
Henrique de Moraes Holschuh | fc589a3 | 2007-10-30 17:46:24 -0200 | [diff] [blame] | 5578 | if (mutex_lock_interruptible(&fan_mutex)) |
| 5579 | return -ERESTARTSYS; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5580 | |
| 5581 | rc = fan_get_status(&status); |
| 5582 | if (!rc && (status & |
| 5583 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 5584 | rc = fan_set_level(newlevel); |
Henrique de Moraes Holschuh | c573ddb | 2007-04-27 22:00:12 -0300 | [diff] [blame] | 5585 | if (rc == -ENXIO) |
| 5586 | rc = -EINVAL; |
| 5587 | else if (!rc) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5588 | fan_update_desired_level(newlevel); |
Henrique de Moraes Holschuh | ca4ac2f | 2007-04-27 22:00:11 -0300 | [diff] [blame] | 5589 | fan_watchdog_reset(); |
| 5590 | } |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5591 | } |
| 5592 | |
| 5593 | mutex_unlock(&fan_mutex); |
| 5594 | return (rc)? rc : count; |
| 5595 | } |
| 5596 | |
| 5597 | static struct device_attribute dev_attr_fan_pwm1 = |
| 5598 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 5599 | fan_pwm1_show, fan_pwm1_store); |
| 5600 | |
| 5601 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 5602 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 5603 | struct device_attribute *attr, |
| 5604 | char *buf) |
| 5605 | { |
| 5606 | int res; |
| 5607 | unsigned int speed; |
| 5608 | |
| 5609 | res = fan_get_speed(&speed); |
| 5610 | if (res < 0) |
| 5611 | return res; |
| 5612 | |
| 5613 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 5614 | } |
| 5615 | |
| 5616 | static struct device_attribute dev_attr_fan_fan1_input = |
| 5617 | __ATTR(fan1_input, S_IRUGO, |
| 5618 | fan_fan1_input_show, NULL); |
| 5619 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5620 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5621 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 5622 | char *buf) |
| 5623 | { |
| 5624 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 5625 | } |
| 5626 | |
| 5627 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 5628 | const char *buf, size_t count) |
| 5629 | { |
| 5630 | unsigned long t; |
| 5631 | |
| 5632 | if (parse_strtoul(buf, 120, &t)) |
| 5633 | return -EINVAL; |
| 5634 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5635 | if (!fan_control_allowed) |
| 5636 | return -EPERM; |
| 5637 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5638 | fan_watchdog_maxinterval = t; |
| 5639 | fan_watchdog_reset(); |
| 5640 | |
| 5641 | return count; |
| 5642 | } |
| 5643 | |
| 5644 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 5645 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 5646 | |
| 5647 | /* --------------------------------------------------------------------- */ |
| 5648 | static struct attribute *fan_attributes[] = { |
| 5649 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 5650 | &dev_attr_fan_fan1_input.attr, |
| 5651 | NULL |
| 5652 | }; |
| 5653 | |
| 5654 | static const struct attribute_group fan_attr_group = { |
| 5655 | .attrs = fan_attributes, |
| 5656 | }; |
| 5657 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5658 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5659 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5660 | int rc; |
| 5661 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5662 | vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n"); |
| 5663 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 5664 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5665 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 5666 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5667 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5668 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5669 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5670 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5671 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5672 | TPACPI_ACPIHANDLE_INIT(fans); |
| 5673 | TPACPI_ACPIHANDLE_INIT(gfan); |
| 5674 | TPACPI_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5675 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5676 | if (gfan_handle) { |
| 5677 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5678 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5679 | } else { |
| 5680 | /* all other ThinkPads: note that even old-style |
| 5681 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5682 | if (likely(acpi_ec_read(fan_status_offset, |
| 5683 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5684 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5685 | |
| 5686 | /* In some ThinkPads, neither the EC nor the ACPI |
| 5687 | * DSDT initialize the fan status, and it ends up |
| 5688 | * being set to 0x07 when it *could* be either |
| 5689 | * 0x07 or 0x80. |
| 5690 | * |
| 5691 | * Enable for TP-1Y (T43), TP-78 (R51e), |
| 5692 | * TP-76 (R52), TP-70 (T43, R52), which are known |
| 5693 | * to be buggy. */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5694 | if (fan_control_initial_status == 0x07) { |
| 5695 | switch (thinkpad_id.ec_model) { |
| 5696 | case 0x5931: /* TP-1Y */ |
| 5697 | case 0x3837: /* TP-78 */ |
| 5698 | case 0x3637: /* TP-76 */ |
| 5699 | case 0x3037: /* TP-70 */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5700 | printk(TPACPI_NOTICE |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5701 | "fan_init: initial fan status " |
| 5702 | "is unknown, assuming it is " |
| 5703 | "in auto mode\n"); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 5704 | tp_features.fan_ctrl_status_undef = 1; |
| 5705 | ;; |
| 5706 | } |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5707 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5708 | } else { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5709 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5710 | "ThinkPad ACPI EC access misbehaving, " |
| 5711 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 5712 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5713 | } |
| 5714 | } |
| 5715 | |
| 5716 | if (sfan_handle) { |
| 5717 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5718 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 5719 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5720 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5721 | } else { |
| 5722 | if (!gfan_handle) { |
| 5723 | /* gfan without sfan means no fan control */ |
| 5724 | /* all other models implement TP EC 0x2f control */ |
| 5725 | |
| 5726 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5727 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5728 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5729 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5730 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5731 | TPACPI_FAN_CMD_SPEED | |
| 5732 | TPACPI_FAN_CMD_LEVEL | |
| 5733 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5734 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5735 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5736 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5737 | TPACPI_FAN_CMD_LEVEL | |
| 5738 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 5739 | } |
| 5740 | } |
| 5741 | } |
| 5742 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 5743 | vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n", |
| 5744 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 5745 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 5746 | fan_status_access_mode, fan_control_access_mode); |
| 5747 | |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 5748 | /* fan control master switch */ |
| 5749 | if (!fan_control_allowed) { |
| 5750 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
| 5751 | fan_control_commands = 0; |
| 5752 | dbg_printk(TPACPI_DBG_INIT, |
| 5753 | "fan control features disabled by parameter\n"); |
| 5754 | } |
| 5755 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5756 | /* update fan_control_desired_level */ |
| 5757 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 5758 | fan_get_status_safe(NULL); |
| 5759 | |
| 5760 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 5761 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5762 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5763 | &fan_attr_group); |
| 5764 | if (!(rc < 0)) |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5765 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5766 | &driver_attr_fan_watchdog); |
| 5767 | if (rc < 0) |
| 5768 | return rc; |
| 5769 | return 0; |
| 5770 | } else |
| 5771 | return 1; |
| 5772 | } |
| 5773 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5774 | static void fan_exit(void) |
| 5775 | { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5776 | vdbg_printk(TPACPI_DBG_EXIT, |
| 5777 | "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5778 | |
| 5779 | /* FIXME: can we really do this unconditionally? */ |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5780 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group); |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5781 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
| 5782 | &driver_attr_fan_watchdog); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5783 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5784 | cancel_delayed_work(&fan_watchdog_task); |
| 5785 | flush_scheduled_work(); |
| 5786 | } |
| 5787 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5788 | static int fan_read(char *p) |
| 5789 | { |
| 5790 | int len = 0; |
| 5791 | int rc; |
| 5792 | u8 status; |
| 5793 | unsigned int speed = 0; |
| 5794 | |
| 5795 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5796 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5797 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5798 | rc = fan_get_status_safe(&status); |
| 5799 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5800 | return rc; |
| 5801 | |
| 5802 | len += sprintf(p + len, "status:\t\t%s\n" |
| 5803 | "level:\t\t%d\n", |
| 5804 | (status != 0) ? "enabled" : "disabled", status); |
| 5805 | break; |
| 5806 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5807 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5808 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5809 | rc = fan_get_status_safe(&status); |
| 5810 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5811 | return rc; |
| 5812 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5813 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5814 | if (status != fan_control_initial_status) |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 5815 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5816 | else |
| 5817 | /* Return most likely status. In fact, it |
| 5818 | * might be the only possible status */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5819 | status = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5820 | } |
| 5821 | |
| 5822 | len += sprintf(p + len, "status:\t\t%s\n", |
| 5823 | (status != 0) ? "enabled" : "disabled"); |
| 5824 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5825 | rc = fan_get_speed(&speed); |
| 5826 | if (rc < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5827 | return rc; |
| 5828 | |
| 5829 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 5830 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5831 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5832 | /* Disengaged mode takes precedence */ |
| 5833 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5834 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5835 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 5836 | else |
| 5837 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 5838 | break; |
| 5839 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5840 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5841 | default: |
| 5842 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 5843 | } |
| 5844 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5845 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5846 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 5847 | |
| 5848 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5849 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5850 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 5851 | break; |
| 5852 | |
| 5853 | default: |
| 5854 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5855 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5856 | break; |
| 5857 | } |
| 5858 | } |
| 5859 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5860 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5861 | len += sprintf(p + len, "commands:\tenable, disable\n" |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5862 | "commands:\twatchdog <timeout> (<timeout> " |
| 5863 | "is 0 (off), 1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5864 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5865 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5866 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 5867 | " (<speed> is 0-65535)\n"); |
| 5868 | |
| 5869 | return len; |
| 5870 | } |
| 5871 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5872 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 5873 | { |
| 5874 | int level; |
| 5875 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5876 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5877 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 5878 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5879 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5880 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 5881 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5882 | return 0; |
| 5883 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5884 | *rc = fan_set_level_safe(level); |
| 5885 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5886 | printk(TPACPI_ERR "level command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5887 | "access mode %d", fan_control_access_mode); |
| 5888 | |
| 5889 | return 1; |
| 5890 | } |
| 5891 | |
| 5892 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 5893 | { |
| 5894 | if (strlencmp(cmd, "enable") != 0) |
| 5895 | return 0; |
| 5896 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5897 | *rc = fan_set_enable(); |
| 5898 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5899 | printk(TPACPI_ERR "enable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5900 | "access mode %d", fan_control_access_mode); |
| 5901 | |
| 5902 | return 1; |
| 5903 | } |
| 5904 | |
| 5905 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 5906 | { |
| 5907 | if (strlencmp(cmd, "disable") != 0) |
| 5908 | return 0; |
| 5909 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5910 | *rc = fan_set_disable(); |
| 5911 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5912 | printk(TPACPI_ERR "disable command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5913 | "access mode %d", fan_control_access_mode); |
| 5914 | |
| 5915 | return 1; |
| 5916 | } |
| 5917 | |
| 5918 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 5919 | { |
| 5920 | int speed; |
| 5921 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5922 | /* TODO: |
| 5923 | * Support speed <low> <medium> <high> ? */ |
| 5924 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5925 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 5926 | return 0; |
| 5927 | |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 5928 | *rc = fan_set_speed(speed); |
| 5929 | if (*rc == -ENXIO) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5930 | printk(TPACPI_ERR "speed command accepted for unsupported " |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5931 | "access mode %d", fan_control_access_mode); |
| 5932 | |
| 5933 | return 1; |
| 5934 | } |
| 5935 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5936 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 5937 | { |
| 5938 | int interval; |
| 5939 | |
| 5940 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 5941 | return 0; |
| 5942 | |
| 5943 | if (interval < 0 || interval > 120) |
| 5944 | *rc = -EINVAL; |
| 5945 | else |
| 5946 | fan_watchdog_maxinterval = interval; |
| 5947 | |
| 5948 | return 1; |
| 5949 | } |
| 5950 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5951 | static int fan_write(char *buf) |
| 5952 | { |
| 5953 | char *cmd; |
| 5954 | int rc = 0; |
| 5955 | |
| 5956 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5957 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5958 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5959 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5960 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5961 | fan_write_cmd_disable(cmd, &rc) || |
| 5962 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 5963 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5964 | fan_write_cmd_speed(cmd, &rc)) |
| 5965 | ) |
| 5966 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 5967 | else if (!rc) |
| 5968 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5969 | } |
| 5970 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 5971 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5972 | } |
| 5973 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5974 | static struct ibm_struct fan_driver_data = { |
| 5975 | .name = "fan", |
| 5976 | .read = fan_read, |
| 5977 | .write = fan_write, |
| 5978 | .exit = fan_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 5979 | }; |
| 5980 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 5981 | /**************************************************************************** |
| 5982 | **************************************************************************** |
| 5983 | * |
| 5984 | * Infrastructure |
| 5985 | * |
| 5986 | **************************************************************************** |
| 5987 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5988 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5989 | /* sysfs name ---------------------------------------------------------- */ |
| 5990 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, |
| 5991 | struct device_attribute *attr, |
| 5992 | char *buf) |
| 5993 | { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 5994 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 5995 | } |
| 5996 | |
| 5997 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
| 5998 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); |
| 5999 | |
| 6000 | /* --------------------------------------------------------------------- */ |
| 6001 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6002 | /* /proc support */ |
Henrique de Moraes Holschuh | 94954cc6 | 2007-07-18 23:45:27 -0300 | [diff] [blame] | 6003 | static struct proc_dir_entry *proc_dir; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6004 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6005 | /* |
| 6006 | * Module and infrastructure proble, init and exit handling |
| 6007 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6008 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6009 | static int force_load; |
| 6010 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6011 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6012 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6013 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6014 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6015 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6016 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6017 | } |
| 6018 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 6019 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6020 | static void ibm_exit(struct ibm_struct *ibm) |
| 6021 | { |
| 6022 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
| 6023 | |
| 6024 | list_del_init(&ibm->all_drivers); |
| 6025 | |
| 6026 | if (ibm->flags.acpi_notify_installed) { |
| 6027 | dbg_printk(TPACPI_DBG_EXIT, |
| 6028 | "%s: acpi_remove_notify_handler\n", ibm->name); |
| 6029 | BUG_ON(!ibm->acpi); |
| 6030 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 6031 | ibm->acpi->type, |
| 6032 | dispatch_acpi_notify); |
| 6033 | ibm->flags.acpi_notify_installed = 0; |
| 6034 | ibm->flags.acpi_notify_installed = 0; |
| 6035 | } |
| 6036 | |
| 6037 | if (ibm->flags.proc_created) { |
| 6038 | dbg_printk(TPACPI_DBG_EXIT, |
| 6039 | "%s: remove_proc_entry\n", ibm->name); |
| 6040 | remove_proc_entry(ibm->name, proc_dir); |
| 6041 | ibm->flags.proc_created = 0; |
| 6042 | } |
| 6043 | |
| 6044 | if (ibm->flags.acpi_driver_registered) { |
| 6045 | dbg_printk(TPACPI_DBG_EXIT, |
| 6046 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
| 6047 | BUG_ON(!ibm->acpi); |
| 6048 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 6049 | kfree(ibm->acpi->driver); |
| 6050 | ibm->acpi->driver = NULL; |
| 6051 | ibm->flags.acpi_driver_registered = 0; |
| 6052 | } |
| 6053 | |
| 6054 | if (ibm->flags.init_called && ibm->exit) { |
| 6055 | ibm->exit(); |
| 6056 | ibm->flags.init_called = 0; |
| 6057 | } |
| 6058 | |
| 6059 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
| 6060 | } |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6061 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6062 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6063 | { |
| 6064 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6065 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6066 | struct proc_dir_entry *entry; |
| 6067 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6068 | BUG_ON(ibm == NULL); |
| 6069 | |
| 6070 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 6071 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 6072 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6073 | return 0; |
| 6074 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6075 | dbg_printk(TPACPI_DBG_INIT, |
| 6076 | "probing for %s\n", ibm->name); |
| 6077 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6078 | if (iibm->init) { |
| 6079 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6080 | if (ret > 0) |
| 6081 | return 0; /* probe failed */ |
| 6082 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6083 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6084 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 6085 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6086 | } |
| 6087 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6088 | if (ibm->acpi) { |
| 6089 | if (ibm->acpi->hid) { |
| 6090 | ret = register_tpacpi_subdriver(ibm); |
| 6091 | if (ret) |
| 6092 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6093 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6094 | |
| 6095 | if (ibm->acpi->notify) { |
| 6096 | ret = setup_acpi_notify(ibm); |
| 6097 | if (ret == -ENODEV) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6098 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6099 | ibm->name); |
| 6100 | ret = 0; |
| 6101 | goto err_out; |
| 6102 | } |
| 6103 | if (ret < 0) |
| 6104 | goto err_out; |
| 6105 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6106 | } |
| 6107 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6108 | dbg_printk(TPACPI_DBG_INIT, |
| 6109 | "%s installed\n", ibm->name); |
| 6110 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6111 | if (ibm->read) { |
| 6112 | entry = create_proc_entry(ibm->name, |
| 6113 | S_IFREG | S_IRUGO | S_IWUSR, |
| 6114 | proc_dir); |
| 6115 | if (!entry) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6116 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6117 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6118 | ret = -ENODEV; |
| 6119 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6120 | } |
| 6121 | entry->owner = THIS_MODULE; |
| 6122 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6123 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6124 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 6125 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 6126 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6128 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6129 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 6130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6131 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6132 | |
| 6133 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 6134 | dbg_printk(TPACPI_DBG_INIT, |
| 6135 | "%s: at error exit path with result %d\n", |
| 6136 | ibm->name, ret); |
| 6137 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6138 | ibm_exit(ibm); |
| 6139 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6140 | } |
| 6141 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6142 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6143 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6144 | 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] | 6145 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 6146 | const struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 6147 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6148 | |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6149 | if (!tp) |
| 6150 | return; |
| 6151 | |
| 6152 | memset(tp, 0, sizeof(*tp)); |
| 6153 | |
| 6154 | if (dmi_name_in_vendors("IBM")) |
| 6155 | tp->vendor = PCI_VENDOR_ID_IBM; |
| 6156 | else if (dmi_name_in_vendors("LENOVO")) |
| 6157 | tp->vendor = PCI_VENDOR_ID_LENOVO; |
| 6158 | else |
| 6159 | return; |
| 6160 | |
| 6161 | tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION), |
| 6162 | GFP_KERNEL); |
| 6163 | if (!tp->bios_version_str) |
| 6164 | return; |
| 6165 | tp->bios_model = tp->bios_version_str[0] |
| 6166 | | (tp->bios_version_str[1] << 8); |
| 6167 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6168 | /* |
| 6169 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 6170 | * X32 or newer, all Z series; Some models must have an |
| 6171 | * up-to-date BIOS or they will not be detected. |
| 6172 | * |
| 6173 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 6174 | */ |
| 6175 | 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] | 6176 | if (sscanf(dev->name, |
| 6177 | "IBM ThinkPad Embedded Controller -[%17c", |
| 6178 | ec_fw_string) == 1) { |
| 6179 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 6180 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6181 | |
| 6182 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); |
| 6183 | tp->ec_model = ec_fw_string[0] |
| 6184 | | (ec_fw_string[1] << 8); |
| 6185 | break; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 6186 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 6187 | } |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6188 | |
| 6189 | tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION), |
| 6190 | GFP_KERNEL); |
| 6191 | if (strnicmp(tp->model_str, "ThinkPad", 8) != 0) { |
| 6192 | kfree(tp->model_str); |
| 6193 | tp->model_str = NULL; |
| 6194 | } |
Henrique de Moraes Holschuh | 8c74adb | 2008-04-26 01:02:19 -0300 | [diff] [blame] | 6195 | |
| 6196 | tp->nummodel_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_NAME), |
| 6197 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6198 | } |
| 6199 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6200 | static int __init probe_for_thinkpad(void) |
| 6201 | { |
| 6202 | int is_thinkpad; |
| 6203 | |
| 6204 | if (acpi_disabled) |
| 6205 | return -ENODEV; |
| 6206 | |
| 6207 | /* |
| 6208 | * Non-ancient models have better DMI tagging, but very old models |
| 6209 | * don't. |
| 6210 | */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6211 | is_thinkpad = (thinkpad_id.model_str != NULL); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6212 | |
| 6213 | /* ec is required because many other handles are relative to it */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6214 | TPACPI_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6215 | if (!ec_handle) { |
| 6216 | if (is_thinkpad) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6217 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6218 | "Not yet supported ThinkPad detected!\n"); |
| 6219 | return -ENODEV; |
| 6220 | } |
| 6221 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 6222 | /* |
| 6223 | * Risks a regression on very old machines, but reduces potential |
| 6224 | * false positives a damn great deal |
| 6225 | */ |
| 6226 | if (!is_thinkpad) |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6227 | is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 6228 | |
| 6229 | if (!is_thinkpad && !force_load) |
| 6230 | return -ENODEV; |
| 6231 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6232 | return 0; |
| 6233 | } |
| 6234 | |
| 6235 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6236 | /* Module init, exit, parameters */ |
| 6237 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6238 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 6239 | { |
| 6240 | .init = thinkpad_acpi_driver_init, |
| 6241 | .data = &thinkpad_acpi_driver_data, |
| 6242 | }, |
| 6243 | { |
| 6244 | .init = hotkey_init, |
| 6245 | .data = &hotkey_driver_data, |
| 6246 | }, |
| 6247 | { |
| 6248 | .init = bluetooth_init, |
| 6249 | .data = &bluetooth_driver_data, |
| 6250 | }, |
| 6251 | { |
| 6252 | .init = wan_init, |
| 6253 | .data = &wan_driver_data, |
| 6254 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 6255 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6256 | { |
| 6257 | .init = video_init, |
| 6258 | .data = &video_driver_data, |
| 6259 | }, |
Henrique de Moraes Holschuh | d7c1d17 | 2008-02-16 02:17:54 -0200 | [diff] [blame] | 6260 | #endif |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6261 | { |
| 6262 | .init = light_init, |
| 6263 | .data = &light_driver_data, |
| 6264 | }, |
| 6265 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
| 6266 | { |
| 6267 | .init = dock_init, |
| 6268 | .data = &dock_driver_data[0], |
| 6269 | }, |
| 6270 | { |
Henrique de Moraes Holschuh | d94a7f1 | 2007-04-27 22:00:15 -0300 | [diff] [blame] | 6271 | .init = dock_init2, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6272 | .data = &dock_driver_data[1], |
| 6273 | }, |
| 6274 | #endif |
| 6275 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 6276 | { |
| 6277 | .init = bay_init, |
| 6278 | .data = &bay_driver_data, |
| 6279 | }, |
| 6280 | #endif |
| 6281 | { |
| 6282 | .init = cmos_init, |
| 6283 | .data = &cmos_driver_data, |
| 6284 | }, |
| 6285 | { |
| 6286 | .init = led_init, |
| 6287 | .data = &led_driver_data, |
| 6288 | }, |
| 6289 | { |
| 6290 | .init = beep_init, |
| 6291 | .data = &beep_driver_data, |
| 6292 | }, |
| 6293 | { |
| 6294 | .init = thermal_init, |
| 6295 | .data = &thermal_driver_data, |
| 6296 | }, |
| 6297 | { |
| 6298 | .data = &ecdump_driver_data, |
| 6299 | }, |
| 6300 | { |
| 6301 | .init = brightness_init, |
| 6302 | .data = &brightness_driver_data, |
| 6303 | }, |
| 6304 | { |
| 6305 | .data = &volume_driver_data, |
| 6306 | }, |
| 6307 | { |
| 6308 | .init = fan_init, |
| 6309 | .data = &fan_driver_data, |
| 6310 | }, |
| 6311 | }; |
| 6312 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6313 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 6314 | { |
| 6315 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6316 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6317 | |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 6318 | if (!kp || !kp->name || !val) |
| 6319 | return -EINVAL; |
| 6320 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6321 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 6322 | ibm = ibms_init[i].data; |
Henrique de Moraes Holschuh | 59f91ff | 2007-11-18 09:18:29 -0200 | [diff] [blame] | 6323 | WARN_ON(ibm == NULL); |
| 6324 | |
| 6325 | if (!ibm || !ibm->name) |
| 6326 | continue; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6327 | |
| 6328 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 6329 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6330 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6331 | strcpy(ibms_init[i].param, val); |
| 6332 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6333 | return 0; |
| 6334 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6335 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6336 | |
| 6337 | return -EINVAL; |
| 6338 | } |
| 6339 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6340 | module_param(experimental, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6341 | MODULE_PARM_DESC(experimental, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6342 | "Enables experimental features when non-zero"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6343 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 6344 | module_param_named(debug, dbg_level, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6345 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 6346 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 6347 | module_param(force_load, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6348 | MODULE_PARM_DESC(force_load, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6349 | "Attempts to load the driver even on a " |
| 6350 | "mis-identified ThinkPad when true"); |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 6351 | |
Henrique de Moraes Holschuh | 86cc944 | 2007-07-18 23:45:41 -0300 | [diff] [blame] | 6352 | module_param_named(fan_control, fan_control_allowed, bool, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6353 | MODULE_PARM_DESC(fan_control, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6354 | "Enables setting fan parameters features when true"); |
Henrique de Moraes Holschuh | ecf2a80 | 2007-04-27 22:00:09 -0300 | [diff] [blame] | 6355 | |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6356 | module_param_named(brightness_mode, brightness_mode, int, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6357 | MODULE_PARM_DESC(brightness_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6358 | "Selects brightness control strategy: " |
| 6359 | "0=auto, 1=EC, 2=CMOS, 3=both"); |
Henrique de Moraes Holschuh | 24d3b77 | 2007-07-18 23:45:43 -0300 | [diff] [blame] | 6360 | |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6361 | module_param(brightness_enable, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6362 | MODULE_PARM_DESC(brightness_enable, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6363 | "Enables backlight control when 1, disables when 0"); |
Henrique de Moraes Holschuh | 87cc537 | 2007-10-30 18:02:07 -0200 | [diff] [blame] | 6364 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6365 | module_param(hotkey_report_mode, uint, 0); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6366 | MODULE_PARM_DESC(hotkey_report_mode, |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6367 | "used for backwards compatibility with userspace, " |
| 6368 | "see documentation"); |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6369 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6370 | #define TPACPI_PARAM(feature) \ |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6371 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
Henrique de Moraes Holschuh | cbb1484 | 2008-02-16 02:17:50 -0200 | [diff] [blame] | 6372 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6373 | "at module load, see documentation") |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6374 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6375 | TPACPI_PARAM(hotkey); |
| 6376 | TPACPI_PARAM(bluetooth); |
| 6377 | TPACPI_PARAM(video); |
| 6378 | TPACPI_PARAM(light); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6379 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6380 | TPACPI_PARAM(dock); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6381 | #endif |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6382 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6383 | TPACPI_PARAM(bay); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 6384 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6385 | TPACPI_PARAM(cmos); |
| 6386 | TPACPI_PARAM(led); |
| 6387 | TPACPI_PARAM(beep); |
| 6388 | TPACPI_PARAM(ecdump); |
| 6389 | TPACPI_PARAM(brightness); |
| 6390 | TPACPI_PARAM(volume); |
| 6391 | TPACPI_PARAM(fan); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 6392 | |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6393 | static void thinkpad_acpi_module_exit(void) |
| 6394 | { |
| 6395 | struct ibm_struct *ibm, *itmp; |
| 6396 | |
| 6397 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
| 6398 | |
| 6399 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 6400 | &tpacpi_all_drivers, |
| 6401 | all_drivers) { |
| 6402 | ibm_exit(ibm); |
| 6403 | } |
| 6404 | |
| 6405 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
| 6406 | |
| 6407 | if (tpacpi_inputdev) { |
| 6408 | if (tp_features.input_device_registered) |
| 6409 | input_unregister_device(tpacpi_inputdev); |
| 6410 | else |
| 6411 | input_free_device(tpacpi_inputdev); |
| 6412 | } |
| 6413 | |
| 6414 | if (tpacpi_hwmon) |
| 6415 | hwmon_device_unregister(tpacpi_hwmon); |
| 6416 | |
| 6417 | if (tp_features.sensors_pdev_attrs_registered) |
| 6418 | device_remove_file(&tpacpi_sensors_pdev->dev, |
| 6419 | &dev_attr_thinkpad_acpi_pdev_name); |
| 6420 | if (tpacpi_sensors_pdev) |
| 6421 | platform_device_unregister(tpacpi_sensors_pdev); |
| 6422 | if (tpacpi_pdev) |
| 6423 | platform_device_unregister(tpacpi_pdev); |
| 6424 | |
| 6425 | if (tp_features.sensors_pdrv_attrs_registered) |
| 6426 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); |
| 6427 | if (tp_features.platform_drv_attrs_registered) |
| 6428 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
| 6429 | |
| 6430 | if (tp_features.sensors_pdrv_registered) |
| 6431 | platform_driver_unregister(&tpacpi_hwmon_pdriver); |
| 6432 | |
| 6433 | if (tp_features.platform_drv_registered) |
| 6434 | platform_driver_unregister(&tpacpi_pdriver); |
| 6435 | |
| 6436 | if (proc_dir) |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6437 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | b21a15f | 2008-01-08 13:02:45 -0200 | [diff] [blame] | 6438 | |
| 6439 | kfree(thinkpad_id.bios_version_str); |
| 6440 | kfree(thinkpad_id.ec_version_str); |
| 6441 | kfree(thinkpad_id.model_str); |
| 6442 | } |
| 6443 | |
Henrique de Moraes Holschuh | f74a27d | 2008-01-08 13:02:44 -0200 | [diff] [blame] | 6444 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6445 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6446 | { |
| 6447 | int ret, i; |
| 6448 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6449 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
| 6450 | |
Henrique de Moraes Holschuh | ff80f13 | 2007-09-04 11:13:15 -0300 | [diff] [blame] | 6451 | /* Parameter checking */ |
| 6452 | if (hotkey_report_mode > 2) |
| 6453 | return -EINVAL; |
| 6454 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6455 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6456 | |
| 6457 | get_thinkpad_model_data(&thinkpad_id); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6458 | ret = probe_for_thinkpad(); |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6459 | if (ret) { |
| 6460 | thinkpad_acpi_module_exit(); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 6461 | return ret; |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6462 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6463 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6464 | /* Driver initialization */ |
Henrique de Moraes Holschuh | d5a2f2f | 2007-07-18 23:45:42 -0300 | [diff] [blame] | 6465 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6466 | TPACPI_ACPIHANDLE_INIT(ecrd); |
| 6467 | TPACPI_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6468 | |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6469 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6470 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6471 | printk(TPACPI_ERR |
| 6472 | "unable to create proc dir " TPACPI_PROC_DIR); |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6473 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6474 | return -ENODEV; |
| 6475 | } |
| 6476 | proc_dir->owner = THIS_MODULE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 6477 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6478 | ret = platform_driver_register(&tpacpi_pdriver); |
| 6479 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6480 | printk(TPACPI_ERR |
| 6481 | "unable to register main platform driver\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6482 | thinkpad_acpi_module_exit(); |
| 6483 | return ret; |
| 6484 | } |
Henrique de Moraes Holschuh | ac36393 | 2007-07-27 17:04:40 -0300 | [diff] [blame] | 6485 | tp_features.platform_drv_registered = 1; |
| 6486 | |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6487 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
| 6488 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6489 | printk(TPACPI_ERR |
| 6490 | "unable to register hwmon platform driver\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6491 | thinkpad_acpi_module_exit(); |
| 6492 | return ret; |
| 6493 | } |
| 6494 | tp_features.sensors_pdrv_registered = 1; |
| 6495 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6496 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6497 | if (!ret) { |
| 6498 | tp_features.platform_drv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6499 | ret = tpacpi_create_driver_attributes( |
| 6500 | &tpacpi_hwmon_pdriver.driver); |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6501 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6502 | if (ret) { |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6503 | printk(TPACPI_ERR |
| 6504 | "unable to create sysfs driver attributes\n"); |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6505 | thinkpad_acpi_module_exit(); |
| 6506 | return ret; |
| 6507 | } |
Henrique de Moraes Holschuh | 2369cc9 | 2007-09-23 11:39:07 -0300 | [diff] [blame] | 6508 | tp_features.sensors_pdrv_attrs_registered = 1; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 6509 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6510 | |
| 6511 | /* Device initialization */ |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6512 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6513 | NULL, 0); |
| 6514 | if (IS_ERR(tpacpi_pdev)) { |
| 6515 | ret = PTR_ERR(tpacpi_pdev); |
| 6516 | tpacpi_pdev = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6517 | printk(TPACPI_ERR "unable to register platform device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6518 | thinkpad_acpi_module_exit(); |
| 6519 | return ret; |
| 6520 | } |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6521 | tpacpi_sensors_pdev = platform_device_register_simple( |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6522 | TPACPI_HWMON_DRVR_NAME, |
| 6523 | -1, NULL, 0); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6524 | if (IS_ERR(tpacpi_sensors_pdev)) { |
| 6525 | ret = PTR_ERR(tpacpi_sensors_pdev); |
| 6526 | tpacpi_sensors_pdev = NULL; |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6527 | printk(TPACPI_ERR |
| 6528 | "unable to register hwmon platform device\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6529 | thinkpad_acpi_module_exit(); |
| 6530 | return ret; |
| 6531 | } |
| 6532 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
| 6533 | &dev_attr_thinkpad_acpi_pdev_name); |
| 6534 | if (ret) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6535 | printk(TPACPI_ERR |
Henrique de Moraes Holschuh | 35ff8b9 | 2008-01-08 13:02:49 -0200 | [diff] [blame] | 6536 | "unable to create sysfs hwmon device attributes\n"); |
Henrique de Moraes Holschuh | 7fd4002 | 2007-09-25 06:38:03 -0300 | [diff] [blame] | 6537 | thinkpad_acpi_module_exit(); |
| 6538 | return ret; |
| 6539 | } |
| 6540 | tp_features.sensors_pdev_attrs_registered = 1; |
| 6541 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6542 | if (IS_ERR(tpacpi_hwmon)) { |
| 6543 | ret = PTR_ERR(tpacpi_hwmon); |
| 6544 | tpacpi_hwmon = NULL; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6545 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 6546 | thinkpad_acpi_module_exit(); |
| 6547 | return ret; |
| 6548 | } |
Henrique de Moraes Holschuh | 8523ed6 | 2007-09-23 11:39:01 -0300 | [diff] [blame] | 6549 | mutex_init(&tpacpi_inputdev_send_mutex); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6550 | tpacpi_inputdev = input_allocate_device(); |
| 6551 | if (!tpacpi_inputdev) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6552 | printk(TPACPI_ERR "unable to allocate input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6553 | thinkpad_acpi_module_exit(); |
| 6554 | return -ENOMEM; |
| 6555 | } else { |
| 6556 | /* Prepare input device, but don't register */ |
| 6557 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6558 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6559 | tpacpi_inputdev->id.bustype = BUS_HOST; |
Henrique de Moraes Holschuh | edf0e0e | 2007-07-18 23:45:44 -0300 | [diff] [blame] | 6560 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
| 6561 | thinkpad_id.vendor : |
| 6562 | PCI_VENDOR_ID_IBM; |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6563 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
| 6564 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; |
| 6565 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 6566 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 6567 | ret = ibm_init(&ibms_init[i]); |
| 6568 | if (ret >= 0 && *ibms_init[i].param) |
| 6569 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6570 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6571 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6572 | return ret; |
| 6573 | } |
| 6574 | } |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6575 | ret = input_register_device(tpacpi_inputdev); |
| 6576 | if (ret < 0) { |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6577 | printk(TPACPI_ERR "unable to register input device\n"); |
Henrique de Moraes Holschuh | 7f5d1cd | 2007-07-18 23:45:34 -0300 | [diff] [blame] | 6578 | thinkpad_acpi_module_exit(); |
| 6579 | return ret; |
| 6580 | } else { |
| 6581 | tp_features.input_device_registered = 1; |
| 6582 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6583 | |
Henrique de Moraes Holschuh | 8fef502 | 2007-09-23 11:39:02 -0300 | [diff] [blame] | 6584 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6585 | return 0; |
| 6586 | } |
| 6587 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6588 | /* Please remove this in year 2009 */ |
| 6589 | MODULE_ALIAS("ibm_acpi"); |
| 6590 | |
Henrique de Moraes Holschuh | 95e57ab | 2008-04-26 01:02:22 -0300 | [diff] [blame] | 6591 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
| 6592 | |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6593 | /* |
| 6594 | * DMI matching for module autoloading |
| 6595 | * |
| 6596 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 6597 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads |
| 6598 | * |
| 6599 | * Only models listed in thinkwiki will be supported, so add yours |
| 6600 | * if it is not there yet. |
| 6601 | */ |
| 6602 | #define IBM_BIOS_MODULE_ALIAS(__type) \ |
| 6603 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW") |
| 6604 | |
| 6605 | /* Non-ancient thinkpads */ |
| 6606 | MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*"); |
| 6607 | MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*"); |
| 6608 | |
| 6609 | /* Ancient thinkpad BIOSes have to be identified by |
| 6610 | * BIOS type or model number, and there are far less |
| 6611 | * BIOS types than model numbers... */ |
| 6612 | IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]"); |
| 6613 | IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]"); |
| 6614 | IBM_BIOS_MODULE_ALIAS("K[U,X-Z]"); |
| 6615 | |
| 6616 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
Henrique de Moraes Holschuh | e0c7dfe | 2008-01-08 13:02:48 -0200 | [diff] [blame] | 6617 | MODULE_DESCRIPTION(TPACPI_DESC); |
| 6618 | MODULE_VERSION(TPACPI_VERSION); |
Henrique de Moraes Holschuh | f68080f | 2008-01-08 13:02:47 -0200 | [diff] [blame] | 6619 | MODULE_LICENSE("GPL"); |
| 6620 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 6621 | module_init(thinkpad_acpi_module_init); |
| 6622 | module_exit(thinkpad_acpi_module_exit); |